From cbce76ed13a56cc5726d4f8691f8b161f8993824 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 3 Apr 2018 12:27:16 -0700 Subject: [PATCH] Consider jscontainer aliases as referencible even if they have other local meanings (#23119) --- src/compiler/checker.ts | 4 +++- .../exportDefaultMarksIdentifierAsUsed.js | 20 +++++++++++++++++++ ...exportDefaultMarksIdentifierAsUsed.symbols | 16 +++++++++++++++ .../exportDefaultMarksIdentifierAsUsed.types | 19 ++++++++++++++++++ .../exportDefaultMarksIdentifierAsUsed.ts | 12 +++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.js create mode 100644 tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.symbols create mode 100644 tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.types create mode 100644 tests/cases/compiler/exportDefaultMarksIdentifierAsUsed.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 651736e5f64..18f0846b713 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1933,9 +1933,11 @@ namespace ts { /** * Indicates that a symbol is an alias that does not merge with a local declaration. + * OR Is a JSContainer which may merge an alias with a local declaration */ function isNonLocalAlias(symbol: Symbol, excludes = SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace) { - return symbol && (symbol.flags & (SymbolFlags.Alias | excludes)) === SymbolFlags.Alias; + if (!symbol) return false; + return (symbol.flags & (SymbolFlags.Alias | excludes)) === SymbolFlags.Alias || (symbol.flags & SymbolFlags.Alias && symbol.flags & SymbolFlags.JSContainer); } function resolveSymbol(symbol: Symbol, dontResolveAlias?: boolean): Symbol { diff --git a/tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.js b/tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.js new file mode 100644 index 00000000000..5772dcfa15f --- /dev/null +++ b/tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/exportDefaultMarksIdentifierAsUsed.ts] //// + +//// [a.js] +const Obj = {}; +export default Obj; +//// [b.js] +import Obj from './a'; + +Obj.fn = function() {}; + +//// [a.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const Obj = {}; +exports.default = Obj; +//// [b.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const a_1 = require("./a"); +a_1.default.fn = function () { }; diff --git a/tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.symbols b/tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.symbols new file mode 100644 index 00000000000..ffb9643c6bb --- /dev/null +++ b/tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/a.js === +const Obj = {}; +>Obj : Symbol(Obj, Decl(a.js, 0, 5)) + +export default Obj; +>Obj : Symbol(Obj, Decl(a.js, 0, 5)) + +=== tests/cases/compiler/b.js === +import Obj from './a'; +>Obj : Symbol(Obj, Decl(b.js, 0, 6), Decl(b.js, 0, 22)) + +Obj.fn = function() {}; +>Obj.fn : Symbol(Obj.fn, Decl(b.js, 0, 22)) +>Obj : Symbol(Obj, Decl(b.js, 0, 6), Decl(b.js, 0, 22)) +>fn : Symbol(Obj.fn, Decl(b.js, 0, 22)) + diff --git a/tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.types b/tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.types new file mode 100644 index 00000000000..73ab0a11b21 --- /dev/null +++ b/tests/baselines/reference/exportDefaultMarksIdentifierAsUsed.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/a.js === +const Obj = {}; +>Obj : { [x: string]: any; } +>{} : { [x: string]: any; } + +export default Obj; +>Obj : { [x: string]: any; } + +=== tests/cases/compiler/b.js === +import Obj from './a'; +>Obj : typeof Obj + +Obj.fn = function() {}; +>Obj.fn = function() {} : () => void +>Obj.fn : () => void +>Obj : typeof Obj +>fn : () => void +>function() {} : () => void + diff --git a/tests/cases/compiler/exportDefaultMarksIdentifierAsUsed.ts b/tests/cases/compiler/exportDefaultMarksIdentifierAsUsed.ts new file mode 100644 index 00000000000..f11e61ccbb7 --- /dev/null +++ b/tests/cases/compiler/exportDefaultMarksIdentifierAsUsed.ts @@ -0,0 +1,12 @@ +// @target: es2017 +// @module: commonjs +// @strict: true +// @allowJs: true +// @outDir: /dist +// @filename: a.js +const Obj = {}; +export default Obj; +// @filename: b.js +import Obj from './a'; + +Obj.fn = function() {}; \ No newline at end of file