diff --git a/util/usage.ts b/util/usage.ts index 17eefd4..063d807 100644 --- a/util/usage.ts +++ b/util/usage.ts @@ -21,6 +21,13 @@ interface InternalVariableInfo { uses: VariableUse[]; } +function identifierToKeywordKind(node) { + if (ts.identifierToKeywordkind === undefined) { + return node.originalKeywordKind; + } + return ts.identifierToKeywordkind(node); +} + export interface VariableInfo { domain: DeclarationDomain; exported: boolean; @@ -56,7 +63,7 @@ export function getUsageDomain(node: ts.Identifier): UsageDomain | undefined { const parent = node.parent!; switch (parent.kind) { case ts.SyntaxKind.TypeReference: - return node.originalKeywordKind !== ts.SyntaxKind.ConstKeyword ? UsageDomain.Type : undefined; + return identifierToKeywordKind(node) !== ts.SyntaxKind.ConstKeyword ? UsageDomain.Type : undefined; case ts.SyntaxKind.ExpressionWithTypeArguments: return (parent.parent).token === ts.SyntaxKind.ImplementsKeyword || parent.parent!.parent!.kind === ts.SyntaxKind.InterfaceDeclaration @@ -147,7 +154,8 @@ export function getDeclarationDomain(node: ts.Identifier): DeclarationDomain | u case ts.SyntaxKind.ModuleDeclaration: return DeclarationDomain.Namespace; case ts.SyntaxKind.Parameter: - if (node.parent!.parent!.kind === ts.SyntaxKind.IndexSignature || node.originalKeywordKind === ts.SyntaxKind.ThisKeyword) + if (node.parent!.parent!.kind === ts.SyntaxKind.IndexSignature || + identifierToKeywordKind(node) === ts.SyntaxKind.ThisKeyword) return; // falls through case ts.SyntaxKind.BindingElement: @@ -647,7 +655,7 @@ class UsageWalker { case ts.SyntaxKind.Parameter: if (node.parent!.kind !== ts.SyntaxKind.IndexSignature && ((node).name.kind !== ts.SyntaxKind.Identifier || - ((node).name).originalKeywordKind !== ts.SyntaxKind.ThisKeyword)) + identifierToKeywordKind((node).name) !== ts.SyntaxKind.ThisKeyword)) this._handleBindingName((node).name, false, false); break; case ts.SyntaxKind.EnumMember: diff --git a/util/util.ts b/util/util.ts index 5b4d92c..f0ed39d 100644 --- a/util/util.ts +++ b/util/util.ts @@ -9,6 +9,14 @@ import { import { isBigIntLiteral, isUniqueESSymbolType } from '../typeguard/3.2'; import { isBooleanLiteralType, unionTypeParts, getPropertyNameFromType } from './type'; + +function identifierToKeywordKind(node) { + if (ts.identifierToKeywordkind === undefined) { + return node.originalKeywordKind; + } + return ts.identifierToKeywordkind(node); +} + export function getChildOfKind(node: ts.Node, kind: T, sourceFile?: ts.SourceFile) { for (const child of node.getChildren(sourceFile)) if (child.kind === kind) @@ -40,7 +48,7 @@ export function isKeywordKind(kind: ts.SyntaxKind) { } export function isThisParameter(parameter: ts.ParameterDeclaration): boolean { - return parameter.name.kind === ts.SyntaxKind.Identifier && parameter.name.originalKeywordKind === ts.SyntaxKind.ThisKeyword; + return parameter.name.kind === ts.SyntaxKind.Identifier && identifierToKeywordKind(parameter.name) === ts.SyntaxKind.ThisKeyword; } export function getModifier(node: ts.Node, kind: ts.Modifier['kind']): ts.Modifier | undefined {