Skip to content
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

feat(ast-spec): extract AssignmentOperatorToText #3570

Merged
merged 3 commits into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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
@@ -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;
}
@@ -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
@@ -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
@@ -0,0 +1 @@
export type ValueOf<T> = T[keyof T];
10 changes: 10 additions & 0 deletions packages/ast-spec/tests/AssignmentOperatorToText.test.ts
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in #3529

Comment needed to be added after readonly line because of prettier/prettier#11098

// AssignmentOperatorToText, then this line will error with "Type 'T' cannot
// be used to index type 'AssignmentOperatorToText'."
};