@goto-bus-stop/common-shake
Version:
CommonJS Tree Shake (fork)
25 lines (17 loc) • 522 B
JavaScript
;
function evaluateBinary(node) {
const op = node.operator;
const left = evaluateConst(node.left);
const right = evaluateConst(node.right);
if (op === '+')
return left + right;
throw new Error(`Unsupported binary operation: "${op}"`);
}
function evaluateConst(node) {
if (node.type === 'Literal')
return node.value;
if (node.type === 'BinaryExpression')
return evaluateBinary(node);
throw new Error(`Unsupported node type: "${node.type}"`);
}
module.exports = evaluateConst;