Make getLocalSymbolForExportDefault look harder for an export

Look for a symbol that has a `.localSymbol` property instead of blindly
using the first one.

Fixes #37829.
This commit is contained in:
Eli Barzilay 2020-07-29 11:41:58 -04:00
parent b601487905
commit a320e1b554
5 changed files with 39 additions and 1 deletions

View file

@ -4769,7 +4769,11 @@ namespace ts {
}
export function getLocalSymbolForExportDefault(symbol: Symbol) {
return isExportDefaultSymbol(symbol) ? symbol.declarations[0].localSymbol : undefined;
if (!isExportDefaultSymbol(symbol)) return undefined;
for (const decl of symbol.declarations) {
if (decl.localSymbol) return decl.localSymbol;
}
return undefined;
}
function isExportDefaultSymbol(symbol: Symbol): boolean {

View file

@ -0,0 +1,11 @@
//// [exportDefaultInterfaceAndValue.ts]
export default interface A { a: string; }
export default function() { return 1; }
declare var x: A;
//// [exportDefaultInterfaceAndValue.js]
"use strict";
exports.__esModule = true;
function default_1() { return 1; }
exports["default"] = default_1;

View file

@ -0,0 +1,10 @@
=== tests/cases/compiler/exportDefaultInterfaceAndValue.ts ===
export default interface A { a: string; }
>A : Symbol(A, Decl(exportDefaultInterfaceAndValue.ts, 0, 41), Decl(exportDefaultInterfaceAndValue.ts, 0, 0))
>a : Symbol(A.a, Decl(exportDefaultInterfaceAndValue.ts, 0, 28))
export default function() { return 1; }
declare var x: A;
>x : Symbol(x, Decl(exportDefaultInterfaceAndValue.ts, 2, 11))
>A : Symbol(A, Decl(exportDefaultInterfaceAndValue.ts, 0, 41), Decl(exportDefaultInterfaceAndValue.ts, 0, 0))

View file

@ -0,0 +1,10 @@
=== tests/cases/compiler/exportDefaultInterfaceAndValue.ts ===
export default interface A { a: string; }
>a : string
export default function() { return 1; }
>1 : 1
declare var x: A;
>x : A

View file

@ -0,0 +1,3 @@
export default interface A { a: string; }
export default function() { return 1; }
declare var x: A;