Skip to content

Commit

Permalink
fix(ast-spec): make PunctuatorTokenToText more type-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Jun 20, 2021
1 parent 44f9c07 commit 5ef6efb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Expand Up @@ -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]: '-=';
Expand All @@ -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]: '^=';
}
11 changes: 11 additions & 0 deletions 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'."
};

0 comments on commit 5ef6efb

Please sign in to comment.