Skip to content

Commit 38402e6

Browse files
Remove originalKeywordKind from Identifier nodes.
1 parent e4816ed commit 38402e6

File tree

14 files changed

+56
-56
lines changed

14 files changed

+56
-56
lines changed

src/compiler/binder.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ import {
283283
SpreadElement,
284284
Statement,
285285
StringLiteral,
286+
stringToToken,
286287
SuperExpression,
287288
SwitchStatement,
288289
Symbol,
@@ -2419,14 +2420,20 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
24192420
!(node.flags & NodeFlags.JSDoc) &&
24202421
!isIdentifierName(node)) {
24212422

2423+
2424+
const originalKeywordKind = stringToToken(node.escapedText as string);
2425+
if (originalKeywordKind === undefined) {
2426+
return;
2427+
}
2428+
24222429
// strict mode identifiers
24232430
if (inStrictMode &&
2424-
node.originalKeywordKind! >= SyntaxKind.FirstFutureReservedWord &&
2425-
node.originalKeywordKind! <= SyntaxKind.LastFutureReservedWord) {
2431+
originalKeywordKind >= SyntaxKind.FirstFutureReservedWord &&
2432+
originalKeywordKind <= SyntaxKind.LastFutureReservedWord) {
24262433
file.bindDiagnostics.push(createDiagnosticForNode(node,
24272434
getStrictModeIdentifierMessage(node), declarationNameToString(node)));
24282435
}
2429-
else if (node.originalKeywordKind === SyntaxKind.AwaitKeyword) {
2436+
else if (originalKeywordKind === SyntaxKind.AwaitKeyword) {
24302437
if (isExternalModule(file) && isInTopLevelContext(node)) {
24312438
file.bindDiagnostics.push(createDiagnosticForNode(node,
24322439
Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module,
@@ -2438,7 +2445,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
24382445
declarationNameToString(node)));
24392446
}
24402447
}
2441-
else if (node.originalKeywordKind === SyntaxKind.YieldKeyword && node.flags & NodeFlags.YieldContext) {
2448+
else if (originalKeywordKind === SyntaxKind.YieldKeyword && node.flags & NodeFlags.YieldContext) {
24422449
file.bindDiagnostics.push(createDiagnosticForNode(node,
24432450
Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here,
24442451
declarationNameToString(node)));

src/compiler/checker.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ import {
923923
StringLiteralLike,
924924
StringLiteralType,
925925
StringMappingType,
926+
stringToToken,
926927
stripQuotes,
927928
StructuredType,
928929
SubstitutionType,
@@ -23117,11 +23118,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2311723118
break;
2311823119
case SyntaxKind.Parameter:
2311923120
const param = declaration as ParameterDeclaration;
23121+
let keywordKind: SyntaxKind | undefined;
2312023122
if (isIdentifier(param.name) &&
23121-
(isCallSignatureDeclaration(param.parent) || isMethodSignature(param.parent) || isFunctionTypeNode(param.parent)) &&
23122-
param.parent.parameters.indexOf(param) > -1 &&
23123-
(resolveName(param, param.name.escapedText, SymbolFlags.Type, undefined, param.name.escapedText, /*isUse*/ true) ||
23124-
param.name.originalKeywordKind && isTypeNodeKind(param.name.originalKeywordKind))) {
23123+
(isCallSignatureDeclaration(param.parent) || isMethodSignature(param.parent) || isFunctionTypeNode(param.parent)) &&
23124+
param.parent.parameters.indexOf(param) > -1 &&
23125+
(resolveName(param, param.name.escapedText, SymbolFlags.Type, undefined, param.name.escapedText, /*isUse*/ true) ||
23126+
(keywordKind = stringToToken(param.name.escapedText as string)) && isTypeNodeKind(keywordKind))) {
2312523127
const newName = "arg" + param.parent.parameters.indexOf(param);
2312623128
const typeName = declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : "");
2312723129
errorOrSuggestion(noImplicitAny, declaration, Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName);
@@ -46687,7 +46689,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4668746689

4668846690
function checkGrammarNameInLetOrConstDeclarations(name: Identifier | BindingPattern): boolean {
4668946691
if (name.kind === SyntaxKind.Identifier) {
46690-
if (name.originalKeywordKind === SyntaxKind.LetKeyword) {
46692+
if (name.escapedText === "let") {
4669146693
return grammarErrorOnNode(name, Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations);
4669246694
}
4669346695
}

src/compiler/factory/nodeFactory.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ import {
407407
startsWith,
408408
Statement,
409409
StringLiteral,
410-
stringToToken,
411410
SuperExpression,
412411
SwitchStatement,
413412
SyntaxKind,
@@ -1150,16 +1149,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
11501149
// Identifiers
11511150
//
11521151

1153-
function createBaseIdentifier(escapedText: __String, originalKeywordKind: SyntaxKind | undefined) {
1152+
function createBaseIdentifier(escapedText: __String) {
11541153
const node = baseFactory.createBaseIdentifierNode(SyntaxKind.Identifier) as Mutable<Identifier>;
1155-
node.originalKeywordKind = originalKeywordKind;
11561154
node.escapedText = escapedText;
11571155
node.autoGenerateFlags = GeneratedIdentifierFlags.None;
11581156
return node;
11591157
}
11601158

11611159
function createBaseGeneratedIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) {
1162-
const node = createBaseIdentifier(escapeLeadingUnderscores(text), /*originalKeywordKind*/ undefined) as Mutable<GeneratedIdentifier>;
1160+
const node = createBaseIdentifier(escapeLeadingUnderscores(text)) as Mutable<GeneratedIdentifier>;
11631161
node.autoGenerateFlags = autoGenerateFlags;
11641162
node.autoGenerateId = nextAutoGenerateId;
11651163
node.autoGeneratePrefix = prefix;
@@ -1168,16 +1166,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
11681166
return node;
11691167
}
11701168

1171-
// @api
1172-
function createIdentifier(text: string, typeArguments?: readonly (TypeNode | TypeParameterDeclaration)[], originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier {
1173-
if (originalKeywordKind === undefined && text) {
1174-
originalKeywordKind = stringToToken(text);
1175-
}
1176-
if (originalKeywordKind === SyntaxKind.Identifier) {
1177-
originalKeywordKind = undefined;
1178-
}
1179-
1180-
const node = createBaseIdentifier(escapeLeadingUnderscores(text), originalKeywordKind);
1169+
/**
1170+
*
1171+
* @param text
1172+
* @param typeArguments
1173+
* @param originalKeywordKind ONLY provided by the parser.
1174+
* @param hasExtendedUnicodeEscape ONLY provided by the parser.
1175+
* @returns
1176+
*/
1177+
// @api
1178+
function createIdentifier(text: string, typeArguments?: readonly (TypeNode | TypeParameterDeclaration)[], originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier {
1179+
const node = createBaseIdentifier(escapeLeadingUnderscores(text));
11811180
node.typeArguments = asNodeArray(typeArguments);
11821181
node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape;
11831182
node.jsDoc = undefined; // initialized by parser (JsDocContainer)
@@ -1186,7 +1185,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
11861185
node.symbol = undefined!; // initialized by checker
11871186

11881187
// NOTE: we do not include transform flags of typeArguments in an identifier as they do not contribute to transformations
1189-
if (node.originalKeywordKind === SyntaxKind.AwaitKeyword) {
1188+
if (originalKeywordKind === SyntaxKind.AwaitKeyword) {
11901189
node.transformFlags |= TransformFlags.ContainsPossibleTopLevelAwait;
11911190
}
11921191
if (node.hasExtendedUnicodeEscape) {
@@ -6372,7 +6371,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
63726371
}
63736372

63746373
function cloneGeneratedIdentifier(node: GeneratedIdentifier): GeneratedIdentifier {
6375-
const clone = createBaseIdentifier(node.escapedText, /*originalKeywordKind*/ undefined) as Mutable<GeneratedIdentifier>;
6374+
const clone = createBaseIdentifier(node.escapedText) as Mutable<GeneratedIdentifier>;
63766375
clone.flags |= node.flags & ~NodeFlags.Synthesized;
63776376
clone.autoGenerateFlags = node.autoGenerateFlags;
63786377
clone.autoGenerateId = node.autoGenerateId;
@@ -6384,7 +6383,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
63846383
}
63856384

63866385
function cloneIdentifier(node: Identifier): Identifier {
6387-
const clone = createBaseIdentifier(node.escapedText, node.originalKeywordKind);
6386+
const clone = createBaseIdentifier(node.escapedText);
63886387
clone.flags |= node.flags & ~NodeFlags.Synthesized;
63896388
clone.typeArguments = node.typeArguments;
63906389
clone.hasExtendedUnicodeEscape = node.hasExtendedUnicodeEscape;

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,7 @@ namespace Parser {
31943194
// into an actual .ConstructorDeclaration.
31953195
const methodDeclaration = node as MethodDeclaration;
31963196
const nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier &&
3197-
methodDeclaration.name.originalKeywordKind === SyntaxKind.ConstructorKeyword;
3197+
methodDeclaration.name.escapedText === "constructor";
31983198

31993199
return !nameIsConstructor;
32003200
}

src/compiler/transformers/es2015.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import {
105105
isHoistedFunction,
106106
isHoistedVariableStatement,
107107
isIdentifier,
108-
isIdentifierANonContextualKeyword,
108+
isStringANonContextualKeyword,
109109
isIfStatement,
110110
isInternalName,
111111
isIterationStatement,
@@ -1074,7 +1074,7 @@ export function transformES2015(context: TransformationContext): (x: SourceFile
10741074
function transformClassBody(node: ClassExpression | ClassDeclaration, extendsClauseElement: ExpressionWithTypeArguments | undefined): Block {
10751075
const statements: Statement[] = [];
10761076
const name = factory.getInternalName(node);
1077-
const constructorLikeName = isIdentifierANonContextualKeyword(name) ? factory.getGeneratedNameForNode(name) : name;
1077+
const constructorLikeName = isStringANonContextualKeyword(idText(name)) ? factory.getGeneratedNameForNode(name) : name;
10781078
startLexicalEnvironment();
10791079
addExtendsHelperIfNeeded(statements, node, extendsClauseElement);
10801080
addConstructor(statements, node, constructorLikeName, extendsClauseElement);

src/compiler/transformers/es5.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
Expression,
66
getOriginalNodeId,
77
Identifier,
8-
idText,
98
isIdentifier,
109
isPrivateIdentifier,
1110
isPropertyAccessExpression,
@@ -15,7 +14,6 @@ import {
1514
JsxOpeningElement,
1615
JsxSelfClosingElement,
1716
Node,
18-
nodeIsSynthesized,
1917
PropertyAccessExpression,
2018
PropertyAssignment,
2119
setTextRange,
@@ -139,7 +137,7 @@ export function transformES5(context: TransformationContext): (x: SourceFile | B
139137
* @param name An Identifier
140138
*/
141139
function trySubstituteReservedName(name: Identifier) {
142-
const token = name.originalKeywordKind || (nodeIsSynthesized(name) ? stringToToken(idText(name)) : undefined);
140+
const token = stringToToken(name.escapedText as string);
143141
if (token !== undefined && token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastReservedWord) {
144142
return setTextRange(factory.createStringLiteralFromNode(name), name);
145143
}

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,6 @@ export interface Identifier extends PrimaryExpression, Declaration, JSDocContain
16771677
* Text of identifier, but if the identifier begins with two underscores, this will begin with three.
16781678
*/
16791679
readonly escapedText: __String;
1680-
readonly originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later
16811680
/** @internal */ readonly autoGenerateFlags?: GeneratedIdentifierFlags; // Specifies whether to auto-generate the text for an identifier.
16821681
/** @internal */ readonly autoGenerateId?: number; // Ensures unique generated identifiers get unique names, but clones get the same name.
16831682
/** @internal */ readonly autoGeneratePrefix?: string | GeneratedNamePart;

src/compiler/utilities.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,11 +4340,6 @@ export function isStringAKeyword(name: string) {
43404340
return token !== undefined && isKeyword(token);
43414341
}
43424342

4343-
/** @internal */
4344-
export function isIdentifierANonContextualKeyword({ originalKeywordKind }: Identifier): boolean {
4345-
return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind);
4346-
}
4347-
43484343
/** @internal */
43494344
export function isTrivia(token: SyntaxKind): token is TriviaSyntaxKind {
43504345
return SyntaxKind.FirstTriviaToken <= token && token <= SyntaxKind.LastTriviaToken;
@@ -5709,7 +5704,7 @@ export function isThisInTypeQuery(node: Node): boolean {
57095704

57105705
/** @internal */
57115706
export function identifierIsThisKeyword(id: Identifier): boolean {
5712-
return id.originalKeywordKind === SyntaxKind.ThisKeyword;
5707+
return id.escapedText === "this";
57135708
}
57145709

57155710
/** @internal */

src/harness/harnessUtils.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,10 @@ export function sourceFileToJSON(file: ts.Node): string {
206206
break;
207207

208208
case "hasExtendedUnicodeEscape":
209-
if ((n as any).hasExtendedUnicodeEscape) {
209+
if ((n as ts.Identifier).hasExtendedUnicodeEscape) {
210210
o.hasExtendedUnicodeEscape = true;
211211
}
212212
break;
213-
214-
case "originalKeywordKind":
215-
o[propertyName] = getKindName((n as any)[propertyName]);
216-
break;
217-
218213
case "flags":
219214
// Clear the flags that are produced by aggregating child values. That is ephemeral
220215
// data we don't care about in the dump. We only care what the parser set directly

src/services/codefixes/convertToEsModule.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import {
7575
SourceFile,
7676
Statement,
7777
StringLiteralLike,
78+
stringToToken,
7879
SymbolFlags,
7980
SyntaxKind,
8081
textChanges,
@@ -161,8 +162,9 @@ type ExportRenames = ReadonlyMap<string, string>;
161162
function collectExportRenames(sourceFile: SourceFile, checker: TypeChecker, identifiers: Identifiers): ExportRenames {
162163
const res = new Map<string, string>();
163164
forEachExportReference(sourceFile, node => {
164-
const { text, originalKeywordKind } = node.name;
165-
if (!res.has(text) && (originalKeywordKind !== undefined && isNonContextualKeyword(originalKeywordKind)
165+
const text = node.name.text;
166+
const keywordKind = stringToToken(text);
167+
if (!res.has(text) && (keywordKind !== undefined && isNonContextualKeyword(keywordKind)
166168
|| checker.resolveName(text, node, SymbolFlags.Value, /*excludeGlobals*/ true))) {
167169
// Unconditionally add an underscore in case `text` is a keyword.
168170
res.set(text, makeUniqueName(`_${text}`, identifiers));

0 commit comments

Comments
 (0)