Consider jscontainer aliases as referencible even if they have other local meanings (#23119)

This commit is contained in:
Wesley Wigham
2018-04-03 12:27:16 -07:00
committed by GitHub
parent a81a645128
commit cbce76ed13
5 changed files with 70 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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 () { };

View File

@@ -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))

View File

@@ -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

View File

@@ -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() {};