Skip to content

Commit 1bd567b

Browse files
committed
refactor(compiler): tighten Binary.operation type
Improve `Binary.operation` types
1 parent 4929577 commit 1bd567b

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

  • packages/compiler/src/expression_parser

packages/compiler/src/expression_parser/ast.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,39 @@ export class Interpolation extends AST {
268268
}
269269
}
270270

271+
type AssignmentOperation = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '&&=' | '||=' | '??=';
272+
type BinaryOperation =
273+
| AssignmentOperation
274+
// Logical
275+
| '&&'
276+
| '||'
277+
| '??'
278+
// Equality
279+
| '=='
280+
| '!='
281+
| '==='
282+
| '!=='
283+
// Relational
284+
| '<'
285+
| '>'
286+
| '<='
287+
| '>='
288+
| 'in'
289+
// Additive
290+
| '+'
291+
| '-'
292+
// Multiplicative
293+
| '*'
294+
| '%'
295+
| '/'
296+
// Exponentiation
297+
| '**';
298+
271299
export class Binary extends AST {
272300
constructor(
273301
span: ParseSpan,
274302
sourceSpan: AbsoluteSourceSpan,
275-
public operation: string,
303+
public operation: BinaryOperation,
276304
public left: AST,
277305
public right: AST,
278306
) {
@@ -349,7 +377,7 @@ export class Unary extends Binary {
349377
sourceSpan: AbsoluteSourceSpan,
350378
public operator: string,
351379
public expr: AST,
352-
binaryOp: string,
380+
binaryOp: BinaryOperation,
353381
binaryLeft: AST,
354382
binaryRight: AST,
355383
) {

0 commit comments

Comments
 (0)