Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use identifierToKeywordKind when available (TypeScript 5+) #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions util/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (<ts.HeritageClause>parent.parent).token === ts.SyntaxKind.ImplementsKeyword ||
parent.parent!.parent!.kind === ts.SyntaxKind.InterfaceDeclaration
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -647,7 +655,7 @@ class UsageWalker {
case ts.SyntaxKind.Parameter:
if (node.parent!.kind !== ts.SyntaxKind.IndexSignature &&
((<ts.ParameterDeclaration>node).name.kind !== ts.SyntaxKind.Identifier ||
(<ts.Identifier>(<ts.NamedDeclaration>node).name).originalKeywordKind !== ts.SyntaxKind.ThisKeyword))
identifierToKeywordKind(<ts.Identifier>(<ts.NamedDeclaration>node).name) !== ts.SyntaxKind.ThisKeyword))
this._handleBindingName(<ts.Identifier>(<ts.NamedDeclaration>node).name, false, false);
break;
case ts.SyntaxKind.EnumMember:
Expand Down
10 changes: 9 additions & 1 deletion util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends ts.SyntaxKind>(node: ts.Node, kind: T, sourceFile?: ts.SourceFile) {
for (const child of node.getChildren(sourceFile))
if (child.kind === kind)
Expand Down Expand Up @@ -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 {
Expand Down