UNPKG

ts-flex-query

Version:
33 lines 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LetExpression = void 0; exports.letIn = letIn; const evaluate_expression_1 = require("../helpers/evaluate-expression"); const evaluation_context_utils_1 = require("../helpers/evaluation-context-utils"); const variable_1 = require("./variable"); class LetExpression { get dataType() { return this.body.dataType; } constructor(input, variableSymbol, body) { this.input = input; this.variableSymbol = variableSymbol; this.body = body; } evaluate(context) { const inputValue = (0, evaluate_expression_1.evaluateExpression)(this.input, context); const result = (0, evaluate_expression_1.evaluateExpression)(this.body, (0, evaluation_context_utils_1.addVariable)(context, this.variableSymbol, inputValue)); return result; } } exports.LetExpression = LetExpression; function letIn(value, body) { if (value instanceof variable_1.VariableExpression) { // The LetExpression is not required if the value already is a variable. return body(value); } const variableSymbol = Symbol('vLet'); const variable = new variable_1.VariableExpression(value.dataType, variableSymbol); return new LetExpression(value, variableSymbol, body(variable)); } //# sourceMappingURL=let.js.map