All files / src/ast/reference compound-expression.ts

100% Statements 19/19
100% Branches 8/8
100% Functions 3/3
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  1x 1x 1x   1x 1x 87x 87x   1x 58x 58x 116x 116x 116x 52x 58x   1x 17x 17x 1x  
import type { ExpressionState } from '../../expression-state.js';
import { TypedValue } from '../../typed-value.js';
import { SpelNodeImpl } from '../spel-node.js';
import { NodeType } from '../../language/node-type.js';
 
export class CompoundExpression extends SpelNodeImpl {
  constructor(startPos: number, endPos: number, ...children: SpelNodeImpl[]) {
    super(NodeType.COMPOUND_EXPRESSION, startPos, endPos, ...children);
  }
 
  public getValueInternal(state: ExpressionState): TypedValue {
    let result: TypedValue = TypedValue.NULL;
    for (let i = 0; i < this.children.length; i++) {
      const childState = i === 0 ? state : state.createChildState(result.getValue());
      result = this.children[i]!.getValue(childState);
    }
    return result;
  }
 
  public toStringAST(): string {
    return this.children.map((c) => c.toStringAST()).join('.');
  }
}