Skip to content

Commit 1e39130

Browse files
committed
Unified logic for renamed block scoped locals and other generated names
1 parent 8b7caed commit 1e39130

File tree

3 files changed

+111
-135
lines changed

3 files changed

+111
-135
lines changed

src/compiler/checker.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11821,6 +11821,38 @@ module ts {
1182111821
}
1182211822
}
1182311823

11824+
function isStatementWithLocals(node: Node) {
11825+
switch (node.kind) {
11826+
case SyntaxKind.Block:
11827+
case SyntaxKind.CaseBlock:
11828+
case SyntaxKind.ForStatement:
11829+
case SyntaxKind.ForInStatement:
11830+
case SyntaxKind.ForOfStatement:
11831+
return true;
11832+
}
11833+
return false;
11834+
}
11835+
11836+
function getIsNestedRedeclaration(symbol: Symbol): boolean {
11837+
let links = getSymbolLinks(symbol);
11838+
if (links.isNestedRedeclaration === undefined) {
11839+
let container = getEnclosingBlockScopeContainer(symbol.valueDeclaration);
11840+
links.isNestedRedeclaration = isStatementWithLocals(container) &&
11841+
!!resolveName(container.parent, symbol.name, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
11842+
}
11843+
return links.isNestedRedeclaration;
11844+
}
11845+
11846+
function getReferencedNestedRedeclaration(node: Identifier): Declaration {
11847+
let symbol = getReferencedValueSymbol(node);
11848+
return symbol && symbol.flags & SymbolFlags.BlockScoped && getIsNestedRedeclaration(symbol) ? symbol.valueDeclaration : undefined;
11849+
}
11850+
11851+
function isNestedRedeclaration(node: Declaration): boolean {
11852+
let symbol = getSymbolOfNode(node);
11853+
return symbol.flags & SymbolFlags.BlockScoped && getIsNestedRedeclaration(symbol);
11854+
}
11855+
1182411856
function isValueAliasDeclaration(node: Node): boolean {
1182511857
switch (node.kind) {
1182611858
case SyntaxKind.ImportEqualsDeclaration:
@@ -11924,8 +11956,10 @@ module ts {
1192411956
/** Serializes an EntityName (with substitutions) to an appropriate JS constructor value. Used by the __metadata decorator. */
1192511957
function serializeEntityName(node: EntityName, getGeneratedNameForNode: (Node: Node) => string, fallbackPath?: string[]): string {
1192611958
if (node.kind === SyntaxKind.Identifier) {
11927-
var substitution = getExpressionNameSubstitution(<Identifier>node, getGeneratedNameForNode);
11928-
var text = substitution || (<Identifier>node).text;
11959+
// TODO(andersh): Fix this
11960+
// var substitution = getExpressionNameSubstitution(<Identifier>node, getGeneratedNameForNode);
11961+
// var text = substitution || (<Identifier>node).text;
11962+
var text = (<Identifier>node).text;
1192911963
if (fallbackPath) {
1193011964
fallbackPath.push(text);
1193111965
}
@@ -12140,11 +12174,6 @@ module ts {
1214012174
return hasProperty(globals, name);
1214112175
}
1214212176

12143-
function resolvesToSomeValue(location: Node, name: string): boolean {
12144-
Debug.assert(!nodeIsSynthesized(location), "resolvesToSomeValue called with a synthesized location");
12145-
return !!resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
12146-
}
12147-
1214812177
function getReferencedValueSymbol(reference: Identifier): Symbol {
1214912178
return getNodeLinks(reference).resolvedSymbol ||
1215012179
resolveName(reference, reference.text, SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias,
@@ -12198,9 +12227,10 @@ module ts {
1219812227

1219912228
function createResolver(): EmitResolver {
1220012229
return {
12201-
getExpressionNameSubstitution,
1220212230
getReferencedExportContainer,
1220312231
getReferencedImportDeclaration,
12232+
getReferencedNestedRedeclaration,
12233+
isNestedRedeclaration,
1220412234
isValueAliasDeclaration,
1220512235
hasGlobalName,
1220612236
isReferencedAliasDeclaration,
@@ -12214,7 +12244,6 @@ module ts {
1221412244
isSymbolAccessible,
1221512245
isEntityNameVisible,
1221612246
getConstantValue,
12217-
resolvesToSomeValue,
1221812247
collectLinkedAliases,
1221912248
getBlockScopedVariableId,
1222012249
getReferencedValueDeclaration,

0 commit comments

Comments
 (0)