twing
Version:
First-class Twig engine for Node.js
39 lines (38 loc) • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeUnaryNodeSynchronously = exports.executeUnaryNode = void 0;
const runtime_1 = require("../../error/runtime");
const executeUnaryNode = (node, executionContext) => {
const { operand } = node.children;
const { nodeExecutor: execute, template } = executionContext;
switch (node.type) {
case "negative": {
return execute(operand, executionContext).then((value) => -(value));
}
case "not": {
return execute(operand, executionContext).then((value) => !(value));
}
case "positive": {
return execute(operand, executionContext).then((value) => +(value));
}
}
return Promise.reject((0, runtime_1.createRuntimeError)(`Unrecognized unary node of type "${node.type}"`, node, template.source));
};
exports.executeUnaryNode = executeUnaryNode;
const executeUnaryNodeSynchronously = (node, executionContext) => {
const { operand } = node.children;
const { nodeExecutor: execute, template } = executionContext;
switch (node.type) {
case "negative": {
return -execute(operand, executionContext);
}
case "not": {
return !execute(operand, executionContext);
}
case "positive": {
return +execute(operand, executionContext);
}
}
throw (0, runtime_1.createRuntimeError)(`Unrecognized unary node of type "${node.type}"`, node, template.source);
};
exports.executeUnaryNodeSynchronously = executeUnaryNodeSynchronously;