Skip to content

feat(ast-spec): extract AssignmentOperatorToText #3570

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

Merged
merged 3 commits into from
Jun 13, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { SyntaxKind } from 'typescript';

export interface AssignmentOperatorToText {
[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]: '||=';
[SyntaxKind.AmpersandAmpersandEqualsToken]: '&&=';
[SyntaxKind.QuestionQuestionEqualsToken]: '??=';
[SyntaxKind.CaretEqualsToken]: '^=';
}
22 changes: 5 additions & 17 deletions packages/ast-spec/src/expression/AssignmentExpression/spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BaseNode } from '../../base/BaseNode';
import type { Expression } from '../../unions/Expression';
import type { ValueOf } from '../../utils';
import type { AssignmentOperatorToText } from './AssignmentOperatorToText';

export * from './AssignmentOperatorToText';

export interface AssignmentExpression extends BaseNode {
type: AST_NODE_TYPES.AssignmentExpression;
operator:
| '-='
| '??='
| '**='
| '*='
| '/='
| '&&='
| '&='
| '%='
| '^='
| '+='
| '<<='
| '='
| '>>='
| '>>>='
| '|='
| '||=';
operator: ValueOf<AssignmentOperatorToText>;
left: Expression;
right: Expression;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { SyntaxKind } from 'typescript';

export interface PunctuatorTokenToText {
import type { AssignmentOperatorToText } from '../../expression/AssignmentExpression/AssignmentOperatorToText';

export interface PunctuatorTokenToText extends AssignmentOperatorToText {
[SyntaxKind.OpenBraceToken]: '{';
[SyntaxKind.CloseBraceToken]: '}';
[SyntaxKind.OpenParenToken]: '(';
Expand Down Expand Up @@ -46,20 +48,4 @@ export interface PunctuatorTokenToText {
[SyntaxKind.QuestionQuestionToken]: '??';
[SyntaxKind.BacktickToken]: '`';
[SyntaxKind.HashToken]: '#';
[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]: '||=';
[SyntaxKind.AmpersandAmpersandEqualsToken]: '&&=';
[SyntaxKind.QuestionQuestionEqualsToken]: '??=';
[SyntaxKind.CaretEqualsToken]: '^=';
}
3 changes: 1 addition & 2 deletions packages/ast-spec/src/token/PunctuatorToken/spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { AST_TOKEN_TYPES } from '../../ast-token-types';
import type { BaseToken } from '../../base/BaseToken';
import type { ValueOf } from '../../utils';
import type { PunctuatorTokenToText } from './PunctuatorTokenToText';

export * from './PunctuatorTokenToText';

type ValueOf<T> = T[keyof T];

export interface PunctuatorToken extends BaseToken {
type: AST_TOKEN_TYPES.Punctuator;
value: ValueOf<PunctuatorTokenToText>;
Expand Down
1 change: 1 addition & 0 deletions packages/ast-spec/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ValueOf<T> = T[keyof T];
10 changes: 10 additions & 0 deletions packages/ast-spec/tests/AssignmentOperatorToText.type-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { AssignmentOperator } from 'typescript';

import { AssignmentOperatorToText } from '../src';

type _Test = {
readonly [T in AssignmentOperator]: AssignmentOperatorToText[T];
// If there are any AssignmentOperator members that don't have a corresponding
// AssignmentOperatorToText, then this line will error with "Type 'T' cannot
// be used to index type 'AssignmentOperatorToText'."
};