Skip to content

fix(types): Eliminate phantom dependency on "typescript" package #3623

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

Closed
Closed
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

This file was deleted.

131 changes: 131 additions & 0 deletions packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import type { SyntaxKind } from 'typescript';

export type PunctuatorTokenValue =
| '{'
| '}'
| '('
| ')'
| '['
| ']'
| '.'
| '...'
| ';'
| ','
| '?.'
| '<'
| '</'
| '>'
| '<='
| '>='
| '=='
| '!='
| '==='
| '!=='
| '=>'
| '+'
| '-'
| '*'
| '**'
| '/'
| '%'
| '++'
| '--'
| '<<'
| '>>'
| '>>>'
| '&'
| '|'
| '^'
| '!'
| '~'
| '&&'
| '||'
| '?'
| ':'
| '@'
| '??'
| '`'
//| '#'
| '='
| '+='
| '-='
| '*='
| '**='
| '/='
| '%='
| '<<='
| '>>='
| '>>>='
| '&='
| '|='
//| '||='
//| '&&='
//| '??='
| '^=';

// A mapping from the PunctuatorTokenValue strings to their corresponding ts.SyntaxKind enums.
// This mapping is only used by PunctuatorTokenValue.test.ts, but it is kept in this file to make
// it easier to keep in sync with the PunctuatorTokenValue list.
export interface PunctuatorTokenValueTestMap {
'{': SyntaxKind.OpenBraceToken;
'}': SyntaxKind.CloseBraceToken;
'(': SyntaxKind.OpenParenToken;
')': SyntaxKind.CloseParenToken;
'[': SyntaxKind.OpenBracketToken;
']': SyntaxKind.CloseBracketToken;
'.': SyntaxKind.DotToken;
'...': SyntaxKind.DotDotDotToken;
';': SyntaxKind.SemicolonToken;
',': SyntaxKind.CommaToken;
'?.': SyntaxKind.QuestionDotToken;
'<': SyntaxKind.LessThanToken;
'</': SyntaxKind.LessThanSlashToken;
'>': SyntaxKind.GreaterThanToken;
'<=': SyntaxKind.LessThanEqualsToken;
'>=': SyntaxKind.GreaterThanEqualsToken;
'==': SyntaxKind.EqualsEqualsToken;
'!=': SyntaxKind.ExclamationEqualsToken;
'===': SyntaxKind.EqualsEqualsEqualsToken;
'!==': SyntaxKind.ExclamationEqualsEqualsToken;
'=>': SyntaxKind.EqualsGreaterThanToken;
'+': SyntaxKind.PlusToken;
'-': SyntaxKind.MinusToken;
'*': SyntaxKind.AsteriskToken;
'**': SyntaxKind.AsteriskAsteriskToken;
'/': SyntaxKind.SlashToken;
'%': SyntaxKind.PercentToken;
'++': SyntaxKind.PlusPlusToken;
'--': SyntaxKind.MinusMinusToken;
'<<': SyntaxKind.LessThanLessThanToken;
'>>': SyntaxKind.GreaterThanGreaterThanToken;
'>>>': SyntaxKind.GreaterThanGreaterThanGreaterThanToken;
'&': SyntaxKind.AmpersandToken;
'|': SyntaxKind.BarToken;
'^': SyntaxKind.CaretToken;
'!': SyntaxKind.ExclamationToken;
'~': SyntaxKind.TildeToken;
'&&': SyntaxKind.AmpersandAmpersandToken;
'||': SyntaxKind.BarBarToken;
'?': SyntaxKind.QuestionToken;
':': SyntaxKind.ColonToken;
'@': SyntaxKind.AtToken;
'??': SyntaxKind.QuestionQuestionToken;
'`': SyntaxKind.BacktickToken;
// '#': SyntaxKind.HashToken; // new in PunctuationSyntaxKind in TS 4.4
'=': SyntaxKind.EqualsToken;
'+=': SyntaxKind.PlusEqualsToken;
'-=': SyntaxKind.MinusEqualsToken;
'*=': SyntaxKind.AsteriskEqualsToken;
'**=': SyntaxKind.AsteriskAsteriskEqualsToken;
'/=': SyntaxKind.SlashEqualsToken;
'%=': SyntaxKind.PercentEqualsToken;
'<<=': SyntaxKind.LessThanLessThanEqualsToken;
'>>=': SyntaxKind.GreaterThanGreaterThanEqualsToken;
'>>>=': SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken;
'&=': SyntaxKind.AmpersandEqualsToken;
'|=': SyntaxKind.BarEqualsToken;
// '||=': 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;
}
8 changes: 2 additions & 6 deletions packages/ast-spec/src/token/PunctuatorToken/spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import type { AST_TOKEN_TYPES } from '../../ast-token-types';
import type { BaseToken } from '../../base/BaseToken';
import type { PunctuatorTokenToText } from './PunctuatorTokenToText';

export * from './PunctuatorTokenToText';

type ValueOf<T> = T[keyof T];
import type { PunctuatorTokenValue } from './PunctuatorTokenValue';

export interface PunctuatorToken extends BaseToken {
type: AST_TOKEN_TYPES.Punctuator;
value: ValueOf<PunctuatorTokenToText>;
value: PunctuatorTokenValue;
}
11 changes: 0 additions & 11 deletions packages/ast-spec/tests/PunctuatorTokenToText.test.ts

This file was deleted.

34 changes: 34 additions & 0 deletions packages/ast-spec/tests/PunctuatorTokenValue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { PunctuationSyntaxKind } from 'typescript';

import type {
PunctuatorTokenValue,
PunctuatorTokenValueTestMap,
} from '../src/token/PunctuatorToken/PunctuatorTokenValue';

// The keys of PunctuatorTokenValueTestMap ('{', '}', '('...) should be the same as
// the members of our PunctuatorTokenValue union.
type InferredPunctuatorTokenValue = keyof PunctuatorTokenValueTestMap;

// The values of PunctuatorTokenValueTestMap (SyntaxKind.OpenBraceToken,
// SyntaxKind.CloseBraceToken, SyntaxKind.OpenParenToken...) should be the same as
// the members of TypeScript's PunctuationSyntaxKind union.
type InferredPunctuationSyntaxKind =
PunctuatorTokenValueTestMap[keyof PunctuatorTokenValueTestMap];

// If this function compiles without errors, it asserts that InferredPunctuationSyntaxKind and PunctuationSyntaxKind
// have the same elements.
export function testPunctuationSyntaxKind(
x: InferredPunctuationSyntaxKind,
y: PunctuationSyntaxKind,
): void {
testPunctuationSyntaxKind(y, x);
}

// If this function compiles without errors, it asserts that InferredPunctuatorTokenValue and PunctuatorTokenValue
// have the same elements.
export function testPunctuatorTokenValue(
x: InferredPunctuatorTokenValue,
y: PunctuatorTokenValue,
): void {
testPunctuatorTokenValue(y, x);
}