UNPKG

@qrvey/formula-lang

Version:

QFormula support for qrvey projects

32 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNumericValueFromArgument = exports.getNumberFromLiteral = void 0; const constants_1 = require("../constants"); function getNumberFromLiteral(value, argument) { if (argument.type === constants_1.AST_TYPES.literal && (argument.dataType === constants_1.AST_PRIMITIVES.NUMBER || argument.primitive === constants_1.AST_PRIMITIVES.NUMBER)) { const _value = value.replace('L', ''); return Number(_value); } return null; } exports.getNumberFromLiteral = getNumberFromLiteral; function getNumericValueFromArgument(param, argument) { var _a; const numberValue = getNumberFromLiteral(String(param), argument); if (numberValue !== null) return numberValue; const isUnaryExpression = argument.type === constants_1.AST_TYPES.unaryExpression; // Negative numbers arrive as unary expression if (isUnaryExpression) { const unaryExp = ('node' in argument ? argument.node : argument); const isNegative = unaryExp.operator === '-'; const isNumber = unaryExp.right.type === constants_1.AST_TYPES.literal && unaryExp.right.dataType === constants_1.AST_PRIMITIVES.NUMBER; if (isNumber) return (((_a = getNumberFromLiteral(String(unaryExp.right.value), unaryExp.right)) !== null && _a !== void 0 ? _a : 0) * (isNegative ? -1 : 1)); } return param; } exports.getNumericValueFromArgument = getNumericValueFromArgument; //# sourceMappingURL=getNumericValueFromArgument.js.map