Ensure we find export default declaration targets if we search for them by name

This commit is contained in:
Mohamed Hegazy
2015-03-30 16:59:34 -07:00
parent b180324da0
commit bea7221174
7 changed files with 145 additions and 0 deletions

View File

@@ -349,6 +349,13 @@ module ts {
}
result = undefined;
}
else if (location.kind === SyntaxKind.SourceFile) {
result = getSymbol(getSymbolOfNode(location).exports, "default", meaning & SymbolFlags.ModuleMember);
if (result && (result.flags & meaning) && result.valueDeclaration && (result.valueDeclaration.flags & NodeFlags.Default) && result.valueDeclaration.localSymbol.name === name) {
break loop;
}
result = undefined;
}
break;
case SyntaxKind.EnumDeclaration:
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.EnumMember)) {

View File

@@ -0,0 +1,35 @@
//// [es5ExportDefaultClassDeclaration3.ts]
var before: C = new C();
export default class C {
method(): C {
return new C();
}
}
var after: C = new C();
var t: typeof C = C;
//// [es5ExportDefaultClassDeclaration3.js]
var before = new C();
var C = (function () {
function C() {
}
C.prototype.method = function () {
return new C();
};
return C;
})();
exports.default = C;
var after = new C();
var t = C;
//// [es5ExportDefaultClassDeclaration3.d.ts]
export default class C {
method(): C;
}

View File

@@ -0,0 +1,33 @@
=== tests/cases/compiler/es5ExportDefaultClassDeclaration3.ts ===
var before: C = new C();
>before : C
>C : C
>new C() : C
>C : typeof C
export default class C {
>C : C
method(): C {
>method : () => C
>C : C
return new C();
>new C() : C
>C : typeof C
}
}
var after: C = new C();
>after : C
>C : C
>new C() : C
>C : typeof C
var t: typeof C = C;
>t : typeof C
>C : typeof C
>C : typeof C

View File

@@ -0,0 +1,21 @@
//// [es5ExportDefaultFunctionDeclaration3.ts]
var before: typeof func = func();
export default function func(): typeof func {
return func;
}
var after: typeof func = func();
//// [es5ExportDefaultFunctionDeclaration3.js]
var before = func();
function func() {
return func;
}
exports.default = func;
var after = func();
//// [es5ExportDefaultFunctionDeclaration3.d.ts]
export default function func(): typeof func;

View File

@@ -0,0 +1,22 @@
=== tests/cases/compiler/es5ExportDefaultFunctionDeclaration3.ts ===
var before: typeof func = func();
>before : () => typeof func
>func : () => typeof func
>func() : () => typeof func
>func : () => typeof func
export default function func(): typeof func {
>func : () => typeof func
>func : () => typeof func
return func;
>func : () => typeof func
}
var after: typeof func = func();
>after : () => typeof func
>func : () => typeof func
>func() : () => typeof func
>func : () => typeof func

View File

@@ -0,0 +1,16 @@
// @target: es5
// @module: commonjs
// @declaration: true
var before: C = new C();
export default class C {
method(): C {
return new C();
}
}
var after: C = new C();
var t: typeof C = C;

View File

@@ -0,0 +1,11 @@
// @target: es5
// @module: commonjs
// @declaration: true
var before: typeof func = func();
export default function func(): typeof func {
return func;
}
var after: typeof func = func();