UNPKG

numenor

Version:

Customizable, safe evaluator of JavaScript-like expressions.

44 lines (33 loc) 999 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArrayLiteral = void 0; var _ = require("./"); var _Parser = require("../../Parser"); var _Error = require("../Error"); var _util = require("./util"); var ArrayLiteral = function ArrayLiteral(expr, options, compile) { if (expr.type !== _Parser.ExpressionType.ArrayLiteral) { throw new TypeError((0, _Error.UnknownExpression)(expr)); } var isConst = true; var isAsync = false; var items = expr.items.map(function (itemExpr) { var item = compile(itemExpr, options, compile); if (isConst && !(0, _.hasConstValue)(item)) { isConst = false; } if (!isAsync && (0, _.hasAsyncValue)(item)) { isAsync = true; } return item; }); return (0, _.mark)({ isConst: isConst, isAsync: isAsync }, function (context, stack) { return (0, _util.evalMaybeAsyncSteps)(context, stack, items).then(_util.identity); }); }; exports.ArrayLiteral = ArrayLiteral;