Remove members from getAccessibleSymbolChain walk

This commit is contained in:
Mohamed Hegazy 2016-03-16 13:45:38 -07:00
parent 1156141b5e
commit e0ab009a98
10 changed files with 475 additions and 76 deletions

View File

@ -1444,12 +1444,6 @@ namespace ts {
return result;
}
break;
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
if (result = callback(getSymbolOfNode(location).members)) {
return result;
}
break;
}
}
@ -1515,7 +1509,9 @@ namespace ts {
}
if (symbol) {
return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
if (!(isPropertyOrMethodDeclarationSymbol(symbol))) {
return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
}
}
}
@ -1548,6 +1544,24 @@ namespace ts {
return qualify;
}
function isPropertyOrMethodDeclarationSymbol(symbol: Symbol) {
if (symbol.declarations && symbol.declarations.length) {
for (const declaration of symbol.declarations) {
switch (declaration.kind) {
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
continue;
default:
return false;
}
}
return true;
}
return false;
}
function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessibilityResult {
if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) {
const initialSymbol = symbol;

View File

@ -0,0 +1,112 @@
//// [declarationEmit_classMemberNameConflict.ts]
export class C1 {
C1() { } // has to be the same as the class name
bar() {
return function (t: typeof C1) {
};
}
}
export class C2 {
C2: any // has to be the same as the class name
bar() {
return function (t: typeof C2) {
};
}
}
export class C3 {
get C3() { return 0; } // has to be the same as the class name
bar() {
return function (t: typeof C3) {
};
}
}
export class C4 {
set C4(v) { } // has to be the same as the class name
bar() {
return function (t: typeof C4) {
};
}
}
//// [declarationEmit_classMemberNameConflict.js]
"use strict";
var C1 = (function () {
function C1() {
}
C1.prototype.C1 = function () { }; // has to be the same as the class name
C1.prototype.bar = function () {
return function (t) {
};
};
return C1;
}());
exports.C1 = C1;
var C2 = (function () {
function C2() {
}
C2.prototype.bar = function () {
return function (t) {
};
};
return C2;
}());
exports.C2 = C2;
var C3 = (function () {
function C3() {
}
Object.defineProperty(C3.prototype, "C3", {
get: function () { return 0; } // has to be the same as the class name
,
enumerable: true,
configurable: true
});
C3.prototype.bar = function () {
return function (t) {
};
};
return C3;
}());
exports.C3 = C3;
var C4 = (function () {
function C4() {
}
Object.defineProperty(C4.prototype, "C4", {
set: function (v) { } // has to be the same as the class name
,
enumerable: true,
configurable: true
});
C4.prototype.bar = function () {
return function (t) {
};
};
return C4;
}());
exports.C4 = C4;
//// [declarationEmit_classMemberNameConflict.d.ts]
export declare class C1 {
C1(): void;
bar(): (t: typeof C1) => void;
}
export declare class C2 {
C2: any;
bar(): (t: typeof C2) => void;
}
export declare class C3 {
readonly C3: number;
bar(): (t: typeof C3) => void;
}
export declare class C4 {
C4: any;
bar(): (t: typeof C4) => void;
}

View File

@ -0,0 +1,70 @@
=== tests/cases/compiler/declarationEmit_classMemberNameConflict.ts ===
export class C1 {
>C1 : Symbol(C1, Decl(declarationEmit_classMemberNameConflict.ts, 0, 0))
C1() { } // has to be the same as the class name
>C1 : Symbol(C1.C1, Decl(declarationEmit_classMemberNameConflict.ts, 1, 17))
bar() {
>bar : Symbol(C1.bar, Decl(declarationEmit_classMemberNameConflict.ts, 2, 12))
return function (t: typeof C1) {
>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 5, 25))
>C1 : Symbol(C1, Decl(declarationEmit_classMemberNameConflict.ts, 0, 0))
};
}
}
export class C2 {
>C2 : Symbol(C2, Decl(declarationEmit_classMemberNameConflict.ts, 8, 1))
C2: any // has to be the same as the class name
>C2 : Symbol(C2.C2, Decl(declarationEmit_classMemberNameConflict.ts, 10, 17))
bar() {
>bar : Symbol(C2.bar, Decl(declarationEmit_classMemberNameConflict.ts, 11, 11))
return function (t: typeof C2) {
>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 14, 25))
>C2 : Symbol(C2, Decl(declarationEmit_classMemberNameConflict.ts, 8, 1))
};
}
}
export class C3 {
>C3 : Symbol(C3, Decl(declarationEmit_classMemberNameConflict.ts, 17, 1))
get C3() { return 0; } // has to be the same as the class name
>C3 : Symbol(C3.C3, Decl(declarationEmit_classMemberNameConflict.ts, 19, 17))
bar() {
>bar : Symbol(C3.bar, Decl(declarationEmit_classMemberNameConflict.ts, 20, 26))
return function (t: typeof C3) {
>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 23, 25))
>C3 : Symbol(C3, Decl(declarationEmit_classMemberNameConflict.ts, 17, 1))
};
}
}
export class C4 {
>C4 : Symbol(C4, Decl(declarationEmit_classMemberNameConflict.ts, 26, 1))
set C4(v) { } // has to be the same as the class name
>C4 : Symbol(C4.C4, Decl(declarationEmit_classMemberNameConflict.ts, 28, 17))
>v : Symbol(v, Decl(declarationEmit_classMemberNameConflict.ts, 29, 11))
bar() {
>bar : Symbol(C4.bar, Decl(declarationEmit_classMemberNameConflict.ts, 29, 17))
return function (t: typeof C4) {
>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 32, 25))
>C4 : Symbol(C4, Decl(declarationEmit_classMemberNameConflict.ts, 26, 1))
};
}
}

View File

@ -0,0 +1,75 @@
=== tests/cases/compiler/declarationEmit_classMemberNameConflict.ts ===
export class C1 {
>C1 : C1
C1() { } // has to be the same as the class name
>C1 : () => void
bar() {
>bar : () => (t: typeof C1) => void
return function (t: typeof C1) {
>function (t: typeof C1) { } : (t: typeof C1) => void
>t : typeof C1
>C1 : typeof C1
};
}
}
export class C2 {
>C2 : C2
C2: any // has to be the same as the class name
>C2 : any
bar() {
>bar : () => (t: typeof C2) => void
return function (t: typeof C2) {
>function (t: typeof C2) { } : (t: typeof C2) => void
>t : typeof C2
>C2 : typeof C2
};
}
}
export class C3 {
>C3 : C3
get C3() { return 0; } // has to be the same as the class name
>C3 : number
>0 : number
bar() {
>bar : () => (t: typeof C3) => void
return function (t: typeof C3) {
>function (t: typeof C3) { } : (t: typeof C3) => void
>t : typeof C3
>C3 : typeof C3
};
}
}
export class C4 {
>C4 : C4
set C4(v) { } // has to be the same as the class name
>C4 : any
>v : any
bar() {
>bar : () => (t: typeof C4) => void
return function (t: typeof C4) {
>function (t: typeof C4) { } : (t: typeof C4) => void
>t : typeof C4
>C4 : typeof C4
};
}
}

View File

@ -0,0 +1,59 @@
//// [declarationEmit_classMemberNameConflict2.ts]
const Bar = 'bar';
enum Hello {
World
}
enum Hello1 {
World1
}
class Foo {
// Same names + string => OK
Bar = Bar;
// Same names + enum => OK
Hello = Hello;
// Different names + enum => OK
Hello2 = Hello1;
}
//// [declarationEmit_classMemberNameConflict2.js]
var Bar = 'bar';
var Hello;
(function (Hello) {
Hello[Hello["World"] = 0] = "World";
})(Hello || (Hello = {}));
var Hello1;
(function (Hello1) {
Hello1[Hello1["World1"] = 0] = "World1";
})(Hello1 || (Hello1 = {}));
var Foo = (function () {
function Foo() {
// Same names + string => OK
this.Bar = Bar;
// Same names + enum => OK
this.Hello = Hello;
// Different names + enum => OK
this.Hello2 = Hello1;
}
return Foo;
}());
//// [declarationEmit_classMemberNameConflict2.d.ts]
declare const Bar: string;
declare enum Hello {
World = 0,
}
declare enum Hello1 {
World1 = 0,
}
declare class Foo {
Bar: string;
Hello: typeof Hello;
Hello2: typeof Hello1;
}

View File

@ -0,0 +1,37 @@
=== tests/cases/compiler/declarationEmit_classMemberNameConflict2.ts ===
const Bar = 'bar';
>Bar : Symbol(Bar, Decl(declarationEmit_classMemberNameConflict2.ts, 1, 5))
enum Hello {
>Hello : Symbol(Hello, Decl(declarationEmit_classMemberNameConflict2.ts, 1, 18))
World
>World : Symbol(Hello.World, Decl(declarationEmit_classMemberNameConflict2.ts, 3, 12))
}
enum Hello1 {
>Hello1 : Symbol(Hello1, Decl(declarationEmit_classMemberNameConflict2.ts, 5, 1))
World1
>World1 : Symbol(Hello1.World1, Decl(declarationEmit_classMemberNameConflict2.ts, 7, 13))
}
class Foo {
>Foo : Symbol(Foo, Decl(declarationEmit_classMemberNameConflict2.ts, 9, 1))
// Same names + string => OK
Bar = Bar;
>Bar : Symbol(Foo.Bar, Decl(declarationEmit_classMemberNameConflict2.ts, 11, 11))
>Bar : Symbol(Bar, Decl(declarationEmit_classMemberNameConflict2.ts, 1, 5))
// Same names + enum => OK
Hello = Hello;
>Hello : Symbol(Foo.Hello, Decl(declarationEmit_classMemberNameConflict2.ts, 13, 14))
>Hello : Symbol(Hello, Decl(declarationEmit_classMemberNameConflict2.ts, 1, 18))
// Different names + enum => OK
Hello2 = Hello1;
>Hello2 : Symbol(Foo.Hello2, Decl(declarationEmit_classMemberNameConflict2.ts, 16, 18))
>Hello1 : Symbol(Hello1, Decl(declarationEmit_classMemberNameConflict2.ts, 5, 1))
}

View File

@ -0,0 +1,38 @@
=== tests/cases/compiler/declarationEmit_classMemberNameConflict2.ts ===
const Bar = 'bar';
>Bar : string
>'bar' : string
enum Hello {
>Hello : Hello
World
>World : Hello
}
enum Hello1 {
>Hello1 : Hello1
World1
>World1 : Hello1
}
class Foo {
>Foo : Foo
// Same names + string => OK
Bar = Bar;
>Bar : string
>Bar : string
// Same names + enum => OK
Hello = Hello;
>Hello : typeof Hello
>Hello : typeof Hello
// Different names + enum => OK
Hello2 = Hello1;
>Hello2 : typeof Hello1
>Hello1 : typeof Hello1
}

View File

@ -1,69 +0,0 @@
=== tests/cases/compiler/map1.ts ===
import { Observable } from "./observable"
>Observable : typeof Observable
(<any>Observable.prototype).map = function() { }
>(<any>Observable.prototype).map = function() { } : () => void
>(<any>Observable.prototype).map : any
>(<any>Observable.prototype) : any
><any>Observable.prototype : any
>Observable.prototype : Observable<any>
>Observable : typeof Observable
>prototype : Observable<any>
>map : any
>function() { } : () => void
declare module "./observable" {
interface I {x0}
>I : I
>x0 : any
}
=== tests/cases/compiler/map2.ts ===
import { Observable } from "./observable"
>Observable : typeof Observable
(<any>Observable.prototype).map = function() { }
>(<any>Observable.prototype).map = function() { } : () => void
>(<any>Observable.prototype).map : any
>(<any>Observable.prototype) : any
><any>Observable.prototype : any
>Observable.prototype : Observable<any>
>Observable : typeof Observable
>prototype : Observable<any>
>map : any
>function() { } : () => void
declare module "./observable" {
interface I {x1}
>I : I
>x1 : any
}
=== tests/cases/compiler/observable.ts ===
export declare class Observable<T> {
>Observable : Observable<T>
>T : T
filter(pred: (e:T) => boolean): Observable<T>;
>filter : (pred: (e: T) => boolean) => Observable<T>
>pred : (e: T) => boolean
>e : T
>T : T
>Observable : Observable<T>
>T : T
}
=== tests/cases/compiler/main.ts ===
import { Observable } from "./observable"
>Observable : typeof Observable
import "./map1";
import "./map2";
let x: Observable<number>;
>x : Observable<number>
>Observable : Observable<T>

View File

@ -0,0 +1,39 @@
// @target: es5
// @module: commonjs
// @declaration: true
export class C1 {
C1() { } // has to be the same as the class name
bar() {
return function (t: typeof C1) {
};
}
}
export class C2 {
C2: any // has to be the same as the class name
bar() {
return function (t: typeof C2) {
};
}
}
export class C3 {
get C3() { return 0; } // has to be the same as the class name
bar() {
return function (t: typeof C3) {
};
}
}
export class C4 {
set C4(v) { } // has to be the same as the class name
bar() {
return function (t: typeof C4) {
};
}
}

View File

@ -0,0 +1,24 @@
// @target: es5
// @module: commonjs
// @declaration: true
const Bar = 'bar';
enum Hello {
World
}
enum Hello1 {
World1
}
class Foo {
// Same names + string => OK
Bar = Bar;
// Same names + enum => OK
Hello = Hello;
// Different names + enum => OK
Hello2 = Hello1;
}