Skip to content

Commit

Permalink
fix(compiler): resolve deprecation warning with TypeScript 5.1 (#50460)
Browse files Browse the repository at this point in the history
We have a code path that accesses the `originalKeywordKind` property which logs a deprecation warning in version 5.1, but isn't available in some of the earlier versions that we support. These changes add a compatibility layer that goes through the non-deprecated function, if it exists.

PR Close #50460
  • Loading branch information
crisbeto authored and thePunderWoman committed May 25, 2023
1 parent 258c773 commit 721bc72
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class StaticInterpreter {
private visitIdentifier(node: ts.Identifier, context: Context): ResolvedValue {
const decl = this.host.getDeclarationOfIdentifier(node);
if (decl === null) {
if (node.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword) {
if (getOriginalKeywordKind(node) === ts.SyntaxKind.UndefinedKeyword) {
return undefined;
} else {
// Check if the symbol here is imported.
Expand Down Expand Up @@ -763,3 +763,14 @@ function owningModule(context: Context, override: OwningModule|null = null): Own
return null;
}
}

/**
* Gets the original keyword kind of an identifier. This is a compatibility
* layer while we need to support TypeScript versions less than 5.1
* TODO(crisbeto): remove this function once support for TS 4.9 is removed.
*/
function getOriginalKeywordKind(identifier: ts.Identifier): ts.SyntaxKind|undefined {
return typeof (ts as any).identifierToKeywordKind === 'function' ?
(ts as any).identifierToKeywordKind(identifier) :
identifier.originalKeywordKind;
}

0 comments on commit 721bc72

Please sign in to comment.