expression-language
Version:
Javascript implementation of symfony/expression-language
50 lines (49 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _Node = _interopRequireDefault(require("./Node"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
class FunctionNode extends _Node.default {
constructor(name, _arguments2) {
//console.log("Creating function node: ", name, _arguments);
super({
fnArguments: _arguments2
}, {
name: name
});
_defineProperty(this, "compile", compiler => {
let _arguments = [];
for (let node of Object.values(this.nodes.fnArguments.nodes)) {
_arguments.push(compiler.subcompile(node));
}
let fn = compiler.getFunction(this.attributes.name);
compiler.raw(fn.compiler.apply(null, _arguments));
});
_defineProperty(this, "evaluate", (functions, values) => {
let _arguments = [values];
for (let node of Object.values(this.nodes.fnArguments.nodes)) {
//console.log("Testing: ", node, functions, values);
_arguments.push(node.evaluate(functions, values));
}
return functions[this.attributes.name]['evaluator'].apply(null, _arguments);
});
_defineProperty(this, "toArray", () => {
let array = [];
array.push(this.attributes.name);
for (let node of Object.values(this.nodes.fnArguments.nodes)) {
array.push(', ');
array.push(node);
}
array[1] = '(';
array.push(')');
return array;
});
this.name = 'FunctionNode';
}
}
exports.default = FunctionNode;