Skip to content

Commit eadd084

Browse files
author
Andy
authored
Add 'name' property to Identifier (#17329)
* Add 'name' property to Identifier * Rename to unescapedText * Rename 'id.text' to 'id.escapedText' * Rename 'id.unescapedText' to 'id.text' * Make escapeIdentifier and unescapeIdentifier do nothing
1 parent d4f8da0 commit eadd084

File tree

84 files changed

+428
-383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+428
-383
lines changed

src/compiler/binder.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ namespace ts {
242242
}
243243

244244
Debug.assert(isWellKnownSymbolSyntactically(nameExpression));
245-
return getPropertyNameForKnownSymbolName(unescapeLeadingUnderscores((<PropertyAccessExpression>nameExpression).name.text));
245+
return getPropertyNameForKnownSymbolName(unescapeLeadingUnderscores((<PropertyAccessExpression>nameExpression).name.escapedText));
246246
}
247247
return getEscapedTextOfIdentifierOrLiteral(<Identifier | LiteralExpression>name);
248248
}
@@ -287,8 +287,8 @@ namespace ts {
287287
if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) {
288288
if ((<VariableStatement>parentNode).declarationList.declarations.length > 0) {
289289
const nameIdentifier = (<VariableStatement>parentNode).declarationList.declarations[0].name;
290-
if (nameIdentifier.kind === SyntaxKind.Identifier) {
291-
nameFromParentNode = (<Identifier>nameIdentifier).text;
290+
if (isIdentifier(nameIdentifier)) {
291+
nameFromParentNode = nameIdentifier.escapedText;
292292
}
293293
}
294294
}
@@ -1031,7 +1031,7 @@ namespace ts {
10311031
function bindBreakOrContinueStatement(node: BreakOrContinueStatement): void {
10321032
bind(node.label);
10331033
if (node.label) {
1034-
const activeLabel = findActiveLabel(node.label.text);
1034+
const activeLabel = findActiveLabel(node.label.escapedText);
10351035
if (activeLabel) {
10361036
activeLabel.referenced = true;
10371037
bindBreakOrContinueFlow(node, activeLabel.breakTarget, activeLabel.continueTarget);
@@ -1192,7 +1192,7 @@ namespace ts {
11921192
const postStatementLabel = createBranchLabel();
11931193
bind(node.label);
11941194
addAntecedent(preStatementLabel, currentFlow);
1195-
const activeLabel = pushActiveLabel(node.label.text, postStatementLabel, preStatementLabel);
1195+
const activeLabel = pushActiveLabel(node.label.escapedText, postStatementLabel, preStatementLabel);
11961196
bind(node.statement);
11971197
popActiveLabel();
11981198
if (!activeLabel.referenced && !options.allowUnusedLabels) {
@@ -1680,9 +1680,9 @@ namespace ts {
16801680
? ElementKind.Property
16811681
: ElementKind.Accessor;
16821682

1683-
const existingKind = seen.get(identifier.text);
1683+
const existingKind = seen.get(identifier.escapedText);
16841684
if (!existingKind) {
1685-
seen.set(identifier.text, currentKind);
1685+
seen.set(identifier.escapedText, currentKind);
16861686
continue;
16871687
}
16881688

@@ -1792,8 +1792,7 @@ namespace ts {
17921792
}
17931793

17941794
function isEvalOrArgumentsIdentifier(node: Node): boolean {
1795-
return node.kind === SyntaxKind.Identifier &&
1796-
((<Identifier>node).text === "eval" || (<Identifier>node).text === "arguments");
1795+
return isIdentifier(node) && (node.escapedText === "eval" || node.escapedText === "arguments");
17971796
}
17981797

17991798
function checkStrictModeEvalOrArguments(contextNode: Node, name: Node) {
@@ -1804,7 +1803,7 @@ namespace ts {
18041803
// otherwise report generic error message.
18051804
const span = getErrorSpanForNode(file, name);
18061805
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length,
1807-
getStrictModeEvalOrArgumentsMessage(contextNode), unescapeLeadingUnderscores(identifier.text)));
1806+
getStrictModeEvalOrArgumentsMessage(contextNode), unescapeLeadingUnderscores(identifier.escapedText)));
18081807
}
18091808
}
18101809
}
@@ -2295,14 +2294,10 @@ namespace ts {
22952294
}
22962295

22972296
function isNameOfExportsOrModuleExportsAliasDeclaration(node: Node) {
2298-
if (node.kind === SyntaxKind.Identifier) {
2299-
const symbol = lookupSymbolForName((<Identifier>node).text);
2300-
if (symbol && symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.VariableDeclaration) {
2301-
const declaration = symbol.valueDeclaration as VariableDeclaration;
2302-
if (declaration.initializer) {
2303-
return isExportsOrModuleExportsOrAliasOrAssignment(declaration.initializer);
2304-
}
2305-
}
2297+
if (isIdentifier(node)) {
2298+
const symbol = lookupSymbolForName(node.escapedText);
2299+
return symbol && symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) &&
2300+
symbol.valueDeclaration.initializer && isExportsOrModuleExportsOrAliasOrAssignment(symbol.valueDeclaration.initializer);
23062301
}
23072302
return false;
23082303
}
@@ -2369,7 +2364,7 @@ namespace ts {
23692364
constructorFunction.parent = classPrototype;
23702365
classPrototype.parent = leftSideOfAssignment;
23712366

2372-
bindPropertyAssignment(constructorFunction.text, leftSideOfAssignment, /*isPrototypeProperty*/ true);
2367+
bindPropertyAssignment(constructorFunction.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ true);
23732368
}
23742369

23752370
function bindStaticPropertyAssignment(node: BinaryExpression) {
@@ -2391,7 +2386,7 @@ namespace ts {
23912386
bindExportsPropertyAssignment(node);
23922387
}
23932388
else {
2394-
bindPropertyAssignment(target.text, leftSideOfAssignment, /*isPrototypeProperty*/ false);
2389+
bindPropertyAssignment(target.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ false);
23952390
}
23962391
}
23972392

@@ -2432,11 +2427,11 @@ namespace ts {
24322427
bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
24332428
}
24342429
else {
2435-
const bindingName = node.name ? node.name.text : InternalSymbolName.Class;
2430+
const bindingName = node.name ? node.name.escapedText : InternalSymbolName.Class;
24362431
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
24372432
// Add name of class expression into the map for semantic classifier
24382433
if (node.name) {
2439-
classifiableNames.set(node.name.text, true);
2434+
classifiableNames.set(node.name.escapedText, true);
24402435
}
24412436
}
24422437

@@ -2545,7 +2540,7 @@ namespace ts {
25452540
node.flowNode = currentFlow;
25462541
}
25472542
checkStrictModeFunctionName(node);
2548-
const bindingName = node.name ? node.name.text : InternalSymbolName.Function;
2543+
const bindingName = node.name ? node.name.escapedText : InternalSymbolName.Function;
25492544
return bindAnonymousDeclaration(node, SymbolFlags.Function, bindingName);
25502545
}
25512546

0 commit comments

Comments
 (0)