From 5ef6efb5ba5f52b708210f328ce86824ea343d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Mon, 14 Jun 2021 12:52:29 +0200 Subject: [PATCH] fix(ast-spec): make `PunctuatorTokenToText` more type-safe --- .../token/PunctuatorToken/PunctuatorTokenToText.ts | 8 +++++--- packages/ast-spec/tests/PunctuatorTokenToText.test.ts | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 packages/ast-spec/tests/PunctuatorTokenToText.test.ts diff --git a/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts b/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts index a3ab12ee856..174e98e6c6b 100644 --- a/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts +++ b/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts @@ -44,6 +44,8 @@ export interface PunctuatorTokenToText { [SyntaxKind.ColonToken]: ':'; [SyntaxKind.AtToken]: '@'; [SyntaxKind.QuestionQuestionToken]: '??'; + [SyntaxKind.BacktickToken]: '`'; + // [SyntaxKind.HashToken]: '#'; // new in PunctuationSyntaxKind in TS 4.4 [SyntaxKind.EqualsToken]: '='; [SyntaxKind.PlusEqualsToken]: '+='; [SyntaxKind.MinusEqualsToken]: '-='; @@ -56,8 +58,8 @@ export interface PunctuatorTokenToText { [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: '>>>='; [SyntaxKind.AmpersandEqualsToken]: '&='; [SyntaxKind.BarEqualsToken]: '|='; - [SyntaxKind.BarBarEqualsToken]: '||='; - [SyntaxKind.AmpersandAmpersandEqualsToken]: '&&='; - [SyntaxKind.QuestionQuestionEqualsToken]: '??='; + [SyntaxKind.BarBarEqualsToken]: '||='; // included in PunctuationSyntaxKind in TS 4.4 + [SyntaxKind.AmpersandAmpersandEqualsToken]: '&&='; // included in PunctuationSyntaxKind in TS 4.4 + [SyntaxKind.QuestionQuestionEqualsToken]: '??='; // included in PunctuationSyntaxKind in TS 4.4 [SyntaxKind.CaretEqualsToken]: '^='; } diff --git a/packages/ast-spec/tests/PunctuatorTokenToText.test.ts b/packages/ast-spec/tests/PunctuatorTokenToText.test.ts new file mode 100644 index 00000000000..32deee0bea9 --- /dev/null +++ b/packages/ast-spec/tests/PunctuatorTokenToText.test.ts @@ -0,0 +1,11 @@ +import type { PunctuationSyntaxKind } from 'typescript'; + +import type { PunctuatorTokenToText } from '../src'; + +// @ts-expect-error: purposely unused +type _Test = { + readonly [T in PunctuationSyntaxKind]: PunctuatorTokenToText[T]; + // If there are any PunctuationSyntaxKind members that don't have a + // corresponding PunctuatorTokenToText, then this line will error with + // "Type 'T' cannot be used to index type 'PunctuatorTokenToText'." +};