Skip to content

Commit b9a4758

Browse files
Use some string predicates that perform their own keyword lookup.
1 parent 6ba90be commit b9a4758

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

src/compiler/binder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
24202420
!(node.flags & NodeFlags.JSDoc) &&
24212421
!isIdentifierName(node)) {
24222422

2423-
24242423
const originalKeywordKind = stringToToken(node.escapedText as string);
24252424
if (originalKeywordKind === undefined) {
24262425
return;

src/services/codefixes/convertToEsModule.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ import {
5050
isExportsOrModuleExportsOrAlias,
5151
isFunctionExpression,
5252
isIdentifier,
53-
isNonContextualKeyword,
5453
isObjectLiteralExpression,
5554
isPropertyAccessExpression,
5655
isRequireCall,
56+
isStringANonContextualKeyword,
5757
isVariableStatement,
5858
makeImport,
5959
map,
@@ -75,7 +75,6 @@ import {
7575
SourceFile,
7676
Statement,
7777
StringLiteralLike,
78-
stringToToken,
7978
SymbolFlags,
8079
SyntaxKind,
8180
textChanges,
@@ -163,9 +162,7 @@ function collectExportRenames(sourceFile: SourceFile, checker: TypeChecker, iden
163162
const res = new Map<string, string>();
164163
forEachExportReference(sourceFile, node => {
165164
const text = node.name.text;
166-
const keywordKind = stringToToken(text);
167-
if (!res.has(text) && (keywordKind !== undefined && isNonContextualKeyword(keywordKind)
168-
|| checker.resolveName(text, node, SymbolFlags.Value, /*excludeGlobals*/ true))) {
165+
if (!res.has(text) && (isStringANonContextualKeyword(text) || checker.resolveName(text, node, SymbolFlags.Value, /*excludeGlobals*/ true))) {
169166
// Unconditionally add an underscore in case `text` is a keyword.
170167
res.set(text, makeUniqueName(`_${text}`, identifiers));
171168
}

src/services/completions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ import {
217217
isStatement,
218218
isStatic,
219219
isString,
220+
isStringAKeyword,
220221
isStringANonContextualKeyword,
221222
isStringLiteralLike,
222223
isStringLiteralOrTemplate,
@@ -4827,8 +4828,7 @@ function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile,
48274828
}
48284829
break;
48294830
case SyntaxKind.Identifier: {
4830-
const originalKeywordKind = stringToToken((location as Identifier).text);
4831-
if (originalKeywordKind && isKeyword(originalKeywordKind)) {
4831+
if (isStringAKeyword((location as Identifier).text)) {
48324832
return undefined;
48334833
}
48344834
// class c { public prop = c| }

0 commit comments

Comments
 (0)