Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 30d973b

Browse filesBrowse files
author
Andy
authored
Rename symbol.name to escapedName and make name unescaped (microsoft#17412)
1 parent e515151 commit 30d973b
Copy full SHA for 30d973b

17 files changed

+147-142Lines changed: 147 additions & 142 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/binder.ts‎

Copy file name to clipboardExpand all lines: src/compiler/binder.ts
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ namespace ts {
16491649
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type);
16501650
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
16511651
typeLiteralSymbol.members = createSymbolTable();
1652-
typeLiteralSymbol.members.set(symbol.name, symbol);
1652+
typeLiteralSymbol.members.set(symbol.escapedName, symbol);
16531653
}
16541654

16551655
function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
@@ -2447,14 +2447,14 @@ namespace ts {
24472447
// module might have an exported variable called 'prototype'. We can't allow that as
24482448
// that would clash with the built-in 'prototype' for the class.
24492449
const prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype" as __String);
2450-
const symbolExport = symbol.exports.get(prototypeSymbol.name);
2450+
const symbolExport = symbol.exports.get(prototypeSymbol.escapedName);
24512451
if (symbolExport) {
24522452
if (node.name) {
24532453
node.name.parent = node;
24542454
}
2455-
file.bindDiagnostics.push(createDiagnosticForNode(symbolExport.declarations[0], Diagnostics.Duplicate_identifier_0, unescapeLeadingUnderscores(prototypeSymbol.name)));
2455+
file.bindDiagnostics.push(createDiagnosticForNode(symbolExport.declarations[0], Diagnostics.Duplicate_identifier_0, unescapeLeadingUnderscores(prototypeSymbol.escapedName)));
24562456
}
2457-
symbol.exports.set(prototypeSymbol.name, prototypeSymbol);
2457+
symbol.exports.set(prototypeSymbol.escapedName, prototypeSymbol);
24582458
prototypeSymbol.parent = symbol;
24592459
}
24602460

Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+97-97Lines changed: 97 additions & 97 deletions
Large diffs are not rendered by default.
Collapse file

‎src/compiler/core.ts‎

Copy file name to clipboardExpand all lines: src/compiler/core.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace ts {
5959
const result = createMap<Symbol>() as SymbolTable;
6060
if (symbols) {
6161
for (const symbol of symbols) {
62-
result.set(symbol.name, symbol);
62+
result.set(symbol.escapedName, symbol);
6363
}
6464
}
6565
return result;
@@ -2306,7 +2306,7 @@ namespace ts {
23062306

23072307
function Symbol(this: Symbol, flags: SymbolFlags, name: __String) {
23082308
this.flags = flags;
2309-
this.name = name;
2309+
this.escapedName = name;
23102310
this.declarations = undefined;
23112311
}
23122312

Collapse file

‎src/compiler/transformers/ts.ts‎

Copy file name to clipboardExpand all lines: src/compiler/transformers/ts.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,7 @@ namespace ts {
26442644
* on symbol names.
26452645
*/
26462646
function recordEmittedDeclarationInScope(node: Node) {
2647-
const name = node.symbol && node.symbol.name;
2647+
const name = node.symbol && node.symbol.escapedName;
26482648
if (name) {
26492649
if (!currentScopeFirstDeclarationsOfName) {
26502650
currentScopeFirstDeclarationsOfName = createUnderscoreEscapedMap<Node>();
@@ -2662,7 +2662,7 @@ namespace ts {
26622662
*/
26632663
function isFirstEmittedDeclarationInScope(node: Node) {
26642664
if (currentScopeFirstDeclarationsOfName) {
2665-
const name = node.symbol && node.symbol.name;
2665+
const name = node.symbol && node.symbol.escapedName;
26662666
if (name) {
26672667
return currentScopeFirstDeclarationsOfName.get(name) === node;
26682668
}
Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,7 @@ namespace ts {
28992899

29002900
export interface Symbol {
29012901
flags: SymbolFlags; // Symbol flags
2902-
name: __String; // Name of symbol
2902+
escapedName: __String; // Name of symbol
29032903
declarations?: Declaration[]; // Declarations associated with this symbol
29042904
valueDeclaration?: Declaration; // First value declaration of the symbol
29052905
members?: SymbolTable; // Class, interface or literal instance members
Collapse file

‎src/services/codefixes/helpers.ts‎

Copy file name to clipboardExpand all lines: src/services/codefixes/helpers.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace ts.codefix {
3535
*/
3636
export function createMissingMemberNodes(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: Symbol[], checker: TypeChecker): Node[] {
3737
const classMembers = classDeclaration.symbol.members;
38-
const missingMembers = possiblyMissingSymbols.filter(symbol => !classMembers.has(symbol.name));
38+
const missingMembers = possiblyMissingSymbols.filter(symbol => !classMembers.has(symbol.escapedName));
3939

4040
let newNodes: Node[] = [];
4141
for (const symbol of missingMembers) {
@@ -205,7 +205,7 @@ namespace ts.codefix {
205205
}
206206
}
207207
const maxNonRestArgs = maxArgsSignature.parameters.length - (maxArgsSignature.hasRestParameter ? 1 : 0);
208-
const maxArgsParameterSymbolNames = maxArgsSignature.parameters.map(symbol => symbol.getUnescapedName());
208+
const maxArgsParameterSymbolNames = maxArgsSignature.parameters.map(symbol => symbol.name);
209209

210210
const parameters = createDummyParameters(maxNonRestArgs, maxArgsParameterSymbolNames, minArgumentCount, /*addAnyType*/ true);
211211

Collapse file

‎src/services/codefixes/importFixes.ts‎

Copy file name to clipboardExpand all lines: src/services/codefixes/importFixes.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ namespace ts.codefix {
148148
else if (isJsxOpeningLikeElement(token.parent) && token.parent.tagName === token) {
149149
// The error wasn't for the symbolAtLocation, it was for the JSX tag itself, which needs access to e.g. `React`.
150150
symbol = checker.getAliasedSymbol(checker.resolveNameAtLocation(token, checker.getJsxNamespace(), SymbolFlags.Value));
151-
symbolName = symbol.getUnescapedName();
151+
symbolName = symbol.name;
152152
}
153153
else {
154154
Debug.fail("Either the symbol or the JSX namespace should be a UMD global if we got here");
@@ -171,7 +171,7 @@ namespace ts.codefix {
171171
const defaultExport = checker.tryGetMemberInModuleExports("default", moduleSymbol);
172172
if (defaultExport) {
173173
const localSymbol = getLocalSymbolForExportDefault(defaultExport);
174-
if (localSymbol && localSymbol.name === name && checkSymbolHasMeaning(localSymbol, currentTokenMeaning)) {
174+
if (localSymbol && localSymbol.escapedName === name && checkSymbolHasMeaning(localSymbol, currentTokenMeaning)) {
175175
// check if this symbol is already used
176176
const symbolId = getUniqueSymbolId(localSymbol);
177177
symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, name, /*isDefault*/ true));
Collapse file

‎src/services/completions.ts‎

Copy file name to clipboardExpand all lines: src/services/completions.ts
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ namespace ts.Completions {
606606
if (symbol.flags & (SymbolFlags.Module | SymbolFlags.Enum)) {
607607
// Extract module or enum members
608608
const exportedSymbols = typeChecker.getExportsOfModule(symbol);
609-
const isValidValueAccess = (symbol: Symbol) => typeChecker.isValidPropertyAccess(<PropertyAccessExpression>(node.parent), symbol.getUnescapedName());
609+
const isValidValueAccess = (symbol: Symbol) => typeChecker.isValidPropertyAccess(<PropertyAccessExpression>(node.parent), symbol.name);
610610
const isValidTypeAccess = (symbol: Symbol) => symbolCanBeReferencedAtTypeLocation(symbol);
611611
const isValidAccess = isRhsOfImportDeclaration ?
612612
// Any kind is allowed when dotting off namespace in internal import equals declaration
@@ -636,7 +636,7 @@ namespace ts.Completions {
636636
function addTypeProperties(type: Type) {
637637
// Filter private properties
638638
for (const symbol of type.getApparentProperties()) {
639-
if (typeChecker.isValidPropertyAccess(<PropertyAccessExpression>(node.parent), symbol.getUnescapedName())) {
639+
if (typeChecker.isValidPropertyAccess(<PropertyAccessExpression>(node.parent), symbol.name)) {
640640
symbols.push(symbol);
641641
}
642642
}
@@ -1457,10 +1457,10 @@ namespace ts.Completions {
14571457
}
14581458

14591459
if (existingImportsOrExports.size === 0) {
1460-
return filter(exportsOfModule, e => e.name !== "default");
1460+
return filter(exportsOfModule, e => e.escapedName !== "default");
14611461
}
14621462

1463-
return filter(exportsOfModule, e => e.name !== "default" && !existingImportsOrExports.get(e.name));
1463+
return filter(exportsOfModule, e => e.escapedName !== "default" && !existingImportsOrExports.get(e.escapedName));
14641464
}
14651465

14661466
/**
@@ -1510,7 +1510,7 @@ namespace ts.Completions {
15101510
existingMemberNames.set(existingName, true);
15111511
}
15121512

1513-
return filter(contextualMemberSymbols, m => !existingMemberNames.get(m.name));
1513+
return filter(contextualMemberSymbols, m => !existingMemberNames.get(m.escapedName));
15141514
}
15151515

15161516
/**
@@ -1571,7 +1571,7 @@ namespace ts.Completions {
15711571
}
15721572

15731573
function isValidProperty(propertySymbol: Symbol, inValidModifierFlags: ModifierFlags) {
1574-
return !existingMemberNames.get(propertySymbol.name) &&
1574+
return !existingMemberNames.get(propertySymbol.escapedName) &&
15751575
propertySymbol.getDeclarations() &&
15761576
!(getDeclarationModifierFlagsFromSymbol(propertySymbol) & inValidModifierFlags);
15771577
}
@@ -1596,7 +1596,7 @@ namespace ts.Completions {
15961596
}
15971597
}
15981598

1599-
return filter(symbols, a => !seenNames.get(a.name));
1599+
return filter(symbols, a => !seenNames.get(a.escapedName));
16001600
}
16011601

16021602
function isCurrentlyEditingNode(node: Node): boolean {
@@ -1610,7 +1610,7 @@ namespace ts.Completions {
16101610
* @return undefined if the name is of external module
16111611
*/
16121612
function getCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean): string | undefined {
1613-
const name = symbol.getUnescapedName();
1613+
const name = symbol.name;
16141614
if (!name) return undefined;
16151615

16161616
// First check of the displayName is not external module; if it is an external module, it is not valid entry
Collapse file

‎src/services/findAllReferences.ts‎

Copy file name to clipboardExpand all lines: src/services/findAllReferences.ts
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ namespace ts.FindAllReferences.Core {
14171417
// Property Declaration symbol is a member of the class, so the symbol is stored in its class Declaration.symbol.members
14181418
if (symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.Parameter &&
14191419
isParameterPropertyDeclaration(<ParameterDeclaration>symbol.valueDeclaration)) {
1420-
addRange(result, checker.getSymbolsOfParameterPropertyDeclaration(<ParameterDeclaration>symbol.valueDeclaration, symbol.getUnescapedName()));
1420+
addRange(result, checker.getSymbolsOfParameterPropertyDeclaration(<ParameterDeclaration>symbol.valueDeclaration, symbol.name));
14211421
}
14221422

14231423
// If this is symbol of binding element without propertyName declaration in Object binding pattern
@@ -1436,7 +1436,7 @@ namespace ts.FindAllReferences.Core {
14361436

14371437
// Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions
14381438
if (!implementations && rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
1439-
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getUnescapedName(), result, /*previousIterationSymbolsCache*/ createSymbolTable(), checker);
1439+
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.name, result, /*previousIterationSymbolsCache*/ createSymbolTable(), checker);
14401440
}
14411441
}
14421442

@@ -1467,7 +1467,7 @@ namespace ts.FindAllReferences.Core {
14671467
// the function will add any found symbol of the property-name, then its sub-routine will call
14681468
// getPropertySymbolsFromBaseTypes again to walk up any base types to prevent revisiting already
14691469
// visited symbol, interface "C", the sub-routine will pass the current symbol as previousIterationSymbol.
1470-
if (previousIterationSymbolsCache.has(symbol.name)) {
1470+
if (previousIterationSymbolsCache.has(symbol.escapedName)) {
14711471
return;
14721472
}
14731473

@@ -1494,7 +1494,7 @@ namespace ts.FindAllReferences.Core {
14941494
}
14951495

14961496
// Visit the typeReference as well to see if it directly or indirectly use that property
1497-
previousIterationSymbolsCache.set(symbol.name, symbol);
1497+
previousIterationSymbolsCache.set(symbol.escapedName, symbol);
14981498
getPropertySymbolsFromBaseTypes(type.symbol, propertyName, result, previousIterationSymbolsCache, checker);
14991499
}
15001500
}
@@ -1554,7 +1554,7 @@ namespace ts.FindAllReferences.Core {
15541554
}
15551555

15561556
const result: Symbol[] = [];
1557-
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getUnescapedName(), result, /*previousIterationSymbolsCache*/ createSymbolTable(), state.checker);
1557+
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.name, result, /*previousIterationSymbolsCache*/ createSymbolTable(), state.checker);
15581558
return find(result, search.includes);
15591559
}
15601560

Collapse file

‎src/services/importTracker.ts‎

Copy file name to clipboardExpand all lines: src/services/importTracker.ts
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ namespace ts.FindAllReferences {
180180
* But re-exports will be placed in 'singleReferences' since they cannot be locally referenced.
181181
*/
182182
function getSearchesFromDirectImports(directImports: Importer[], exportSymbol: Symbol, exportKind: ExportKind, checker: TypeChecker, isForRename: boolean): Pick<ImportsResult, "importSearches" | "singleReferences"> {
183-
const exportName = exportSymbol.name;
183+
const exportName = exportSymbol.escapedName;
184184
const importSearches: Array<[Identifier, Symbol]> = [];
185185
const singleReferences: Identifier[] = [];
186186
function addSearch(location: Identifier, symbol: Symbol): void {
@@ -521,11 +521,11 @@ namespace ts.FindAllReferences {
521521
// Search on the local symbol in the exporting module, not the exported symbol.
522522
importedSymbol = skipExportSpecifierSymbol(importedSymbol, checker);
523523
// Similarly, skip past the symbol for 'export ='
524-
if (importedSymbol.name === "export=") {
524+
if (importedSymbol.escapedName === "export=") {
525525
importedSymbol = getExportEqualsLocalSymbol(importedSymbol, checker);
526526
}
527527

528-
if (symbolName(importedSymbol) === symbol.name) { // If this is a rename import, do not continue searching.
528+
if (symbolName(importedSymbol) === symbol.escapedName) { // If this is a rename import, do not continue searching.
529529
return { kind: ImportExport.Import, symbol: importedSymbol, ...isImport };
530530
}
531531
}
@@ -595,8 +595,8 @@ namespace ts.FindAllReferences {
595595
}
596596

597597
function symbolName(symbol: Symbol): __String | undefined {
598-
if (symbol.name !== "default") {
599-
return symbol.getName();
598+
if (symbol.escapedName !== "default") {
599+
return symbol.escapedName;
600600
}
601601

602602
return forEach(symbol.declarations, decl => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.