-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ast-spec): extract
AssignmentOperatorToText
- Loading branch information
1 parent
44c583a
commit 81350af
Showing
6 changed files
with
41 additions
and
36 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/ast-spec/src/expression/AssignmentExpression/AssignmentOperatorToText.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]: '||='; // 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]: '^='; | ||
} |
22 changes: 5 additions & 17 deletions
22
packages/ast-spec/src/expression/AssignmentExpression/spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
import type { AST_NODE_TYPES } from '../../ast-node-types'; | ||
import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase'; | ||
import type { ValueOf } from '../../utils'; | ||
import type { AssignmentOperatorToText } from './AssignmentOperatorToText'; | ||
|
||
export * from './AssignmentOperatorToText'; | ||
|
||
export interface AssignmentExpression extends BinaryExpressionBase { | ||
type: AST_NODE_TYPES.AssignmentExpression; | ||
operator: | ||
| '-=' | ||
| '??=' | ||
| '**=' | ||
| '*=' | ||
| '/=' | ||
| '&&=' | ||
| '&=' | ||
| '%=' | ||
| '^=' | ||
| '+=' | ||
| '<<=' | ||
| '=' | ||
| '>>=' | ||
| '>>>=' | ||
| '|=' | ||
| '||='; | ||
operator: ValueOf<AssignmentOperatorToText>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type ValueOf<T> = T[keyof T]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { AssignmentOperator } from 'typescript'; | ||
|
||
import { AssignmentOperatorToText } from '../src'; | ||
|
||
// @ts-expect-error: purposely unused | ||
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'." | ||
}; |