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

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