Skip to content

Commit 9ae5865

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

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/services/codefixes/convertToEsModule.ts

Lines changed: 2 additions & 4 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,
@@ -163,9 +163,7 @@ function collectExportRenames(sourceFile: SourceFile, checker: TypeChecker, iden
163163
const res = new Map<string, string>();
164164
forEachExportReference(sourceFile, node => {
165165
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))) {
166+
if (!res.has(text) && (isStringANonContextualKeyword(text) || checker.resolveName(text, node, SymbolFlags.Value, /*excludeGlobals*/ true))) {
169167
// Unconditionally add an underscore in case `text` is a keyword.
170168
res.set(text, makeUniqueName(`_${text}`, identifiers));
171169
}

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)