Skip to content

Commit 1deca8c

Browse files
committed
refactor: _ParseAST.isAssignmentOperator to type guard
Update `_ParseAST.isAssignmentOperator` to type guard
1 parent 1bd567b commit 1deca8c

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/compiler/src/expression_parser/ast.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,17 @@ export class Interpolation extends AST {
268268
}
269269
}
270270

271-
type AssignmentOperation = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '&&=' | '||=' | '??=';
271+
export type AssignmentOperation =
272+
| '='
273+
| '+='
274+
| '-='
275+
| '*='
276+
| '/='
277+
| '%='
278+
| '**='
279+
| '&&='
280+
| '||='
281+
| '??=';
272282
type BinaryOperation =
273283
| AssignmentOperation
274284
// Logical

packages/compiler/src/expression_parser/parser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
Unary,
5757
VariableBinding,
5858
VoidExpression,
59+
type AssignmentOperation,
5960
} from './ast';
6061
import {EOF, Lexer, StringTokenKind, Token, TokenType} from './lexer';
6162
export interface InterpolationPiece {
@@ -730,7 +731,10 @@ class _ParseAST {
730731
}
731732
}
732733

733-
private isAssignmentOperator(token: Token): boolean {
734+
private isAssignmentOperator(token: Token): token is Token & {
735+
type: typeof TokenType.Operator;
736+
strValue: AssignmentOperation;
737+
} {
734738
return token.type === TokenType.Operator && Binary.isAssignmentOperation(token.strValue);
735739
}
736740

0 commit comments

Comments
 (0)