refactor(compiler): tighten Binary.operation type

Improve `Binary.operation` types
This commit is contained in:
fisker 2026-01-09 08:06:30 +08:00 committed by Jessica Janiuk
parent 04ba09a8d9
commit 07a08ab9f8

View file

@ -268,11 +268,39 @@ export class Interpolation extends AST {
}
}
type AssignmentOperation = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '&&=' | '||=' | '??=';
type BinaryOperation =
| AssignmentOperation
// Logical
| '&&'
| '||'
| '??'
// Equality
| '=='
| '!='
| '==='
| '!=='
// Relational
| '<'
| '>'
| '<='
| '>='
| 'in'
// Additive
| '+'
| '-'
// Multiplicative
| '*'
| '%'
| '/'
// Exponentiation
| '**';
export class Binary extends AST {
constructor(
span: ParseSpan,
sourceSpan: AbsoluteSourceSpan,
public operation: string,
public operation: BinaryOperation,
public left: AST,
public right: AST,
) {
@ -349,7 +377,7 @@ export class Unary extends Binary {
sourceSpan: AbsoluteSourceSpan,
public operator: string,
public expr: AST,
binaryOp: string,
binaryOp: BinaryOperation,
binaryLeft: AST,
binaryRight: AST,
) {