refactor: _ParseAST.isAssignmentOperator to type guard

Update `_ParseAST.isAssignmentOperator` to type guard
This commit is contained in:
fisker 2026-01-09 19:04:01 +08:00 committed by Jessica Janiuk
parent 07a08ab9f8
commit 4d19408e9b
2 changed files with 16 additions and 2 deletions

View file

@ -268,7 +268,17 @@ export class Interpolation extends AST {
}
}
type AssignmentOperation = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '&&=' | '||=' | '??=';
export type AssignmentOperation =
| '='
| '+='
| '-='
| '*='
| '/='
| '%='
| '**='
| '&&='
| '||='
| '??=';
type BinaryOperation =
| AssignmentOperation
// Logical

View file

@ -56,6 +56,7 @@ import {
Unary,
VariableBinding,
VoidExpression,
type AssignmentOperation,
} from './ast';
import {EOF, Lexer, StringTokenKind, Token, TokenType} from './lexer';
export interface InterpolationPiece {
@ -730,7 +731,10 @@ class _ParseAST {
}
}
private isAssignmentOperator(token: Token): boolean {
private isAssignmentOperator(token: Token): token is Token & {
type: typeof TokenType.Operator;
strValue: AssignmentOperation;
} {
return token.type === TokenType.Operator && Binary.isAssignmentOperation(token.strValue);
}