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

100% Statements 9/9
100% Branches 2/2
100% Functions 4/4
100% Lines 7/7

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              167x       140x 140x 280x 280x   124x       34x      
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('.');
  }
}