Fix emit when type import merges with local value

This commit is contained in:
Ron Buckton 2017-06-05 18:39:32 -07:00
parent c179d9a22d
commit b5f81f9ede
6 changed files with 79 additions and 4 deletions

View File

@ -925,7 +925,7 @@ function runConsoleTests(defaultReporter, runInParallel) {
}
}
var testTimeout = 20000;
var testTimeout = 22000;
desc("Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true.");
task("runtests-parallel", ["build-rules", "tests", builtLocalDirectory], function () {
runConsoleTests('min', /*runInParallel*/ true);

View File

@ -1473,8 +1473,15 @@ namespace ts {
}
}
/**
* Indicates that a symbol is an alias that does not merge with a local declaration.
*/
function isNonLocalAlias(symbol: Symbol, excludes = SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace) {
return symbol && (symbol.flags & (SymbolFlags.Alias | excludes)) === SymbolFlags.Alias;
}
function resolveSymbol(symbol: Symbol, dontResolveAlias?: boolean): Symbol {
const shouldResolve = !dontResolveAlias && symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace));
const shouldResolve = !dontResolveAlias && isNonLocalAlias(symbol);
return shouldResolve ? resolveAlias(symbol) : symbol;
}
@ -12015,7 +12022,9 @@ namespace ts {
return getTypeOfSymbol(symbol);
}
if (symbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
// We should only mark aliases as referenced if there isn't a local value declaration
// for the symbol.
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
markAliasSymbolAsReferenced(symbol);
}
@ -22864,7 +22873,9 @@ namespace ts {
node = getParseTreeNode(node, isIdentifier);
if (node) {
const symbol = getReferencedValueSymbol(node);
if (symbol && symbol.flags & SymbolFlags.Alias) {
// We should only get the declaration of an alias if there isn't a local value
// declaration for the symbol
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value)) {
return getDeclarationOfAliasSymbol(symbol);
}
}

View File

@ -0,0 +1,17 @@
//// [tests/cases/compiler/symbolMergeValueAndImportedType.ts] ////
//// [main.ts]
import { X } from "./other";
const X = 42;
console.log('X is ' + X);
//// [other.ts]
export type X = {};
//// [other.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [main.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const X = 42;
console.log('X is ' + X);

View File

@ -0,0 +1,17 @@
=== tests/cases/compiler/main.ts ===
import { X } from "./other";
>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5))
const X = 42;
>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5))
console.log('X is ' + X);
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5))
=== tests/cases/compiler/other.ts ===
export type X = {};
>X : Symbol(X, Decl(other.ts, 0, 0))

View File

@ -0,0 +1,21 @@
=== tests/cases/compiler/main.ts ===
import { X } from "./other";
>X : 42
const X = 42;
>X : 42
>42 : 42
console.log('X is ' + X);
>console.log('X is ' + X) : void
>console.log : (message?: any, ...optionalParams: any[]) => void
>console : Console
>log : (message?: any, ...optionalParams: any[]) => void
>'X is ' + X : string
>'X is ' : "X is "
>X : 42
=== tests/cases/compiler/other.ts ===
export type X = {};
>X : X

View File

@ -0,0 +1,9 @@
// @target: es2015
// @module: commonjs
// @lib: es2015,dom
// @filename: main.ts
import { X } from "./other";
const X = 42;
console.log('X is ' + X);
// @filename: other.ts
export type X = {};