From f34e162825e9b5a708341ccba5aeaaa385f1679f Mon Sep 17 00:00:00 2001 From: Avinash Thakur Date: Sat, 24 Dec 2022 04:03:13 +0530 Subject: [PATCH 01/12] add safe eval for browser and `evalType` option update test html file to use compiled module update demo html file to include sample & prevent submit --- .eslintignore | 5 +- .eslintrc.cjs | 1 + .babelrc.json => babel.config.json | 0 demo/index.html | 43 +- dist/index-browser-esm.js | 1626 +++++++++++++++++++++++++++- dist/index-browser-esm.min.js | 2 +- dist/index-browser-esm.min.js.map | 2 +- dist/index-browser-umd.cjs | 1626 +++++++++++++++++++++++++++- dist/index-browser-umd.min.cjs | 2 +- dist/index-browser-umd.min.cjs.map | 2 +- dist/index-node-cjs.cjs | 17 +- dist/index-node-esm.js | 17 +- package.json | 4 + pnpm-lock.yaml | 111 ++ rollup.config.js | 4 +- src/jsonpath-browser.js | 147 +++ src/jsonpath-node.js | 1 + src/jsonpath.js | 19 +- test/index.html | 2 +- 19 files changed, 3599 insertions(+), 32 deletions(-) rename .babelrc.json => babel.config.json (100%) diff --git a/.eslintignore b/.eslintignore index 60b57a4..7d8c3cf 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ -node_modules -dist +node_modules/ +dist/ docs/ts coverage ignore !*.js +!.config.js \ No newline at end of file diff --git a/.eslintrc.cjs b/.eslintrc.cjs index e179b9d..47f803b 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -17,6 +17,7 @@ module.exports = { 'XMLHttpRequest' ] }, + parser: '@babel/eslint-parser', overrides: [ { files: ['src/jsonpath-node.js', 'test-helpers/node-env.js'], diff --git a/.babelrc.json b/babel.config.json similarity index 100% rename from .babelrc.json rename to babel.config.json diff --git a/demo/index.html b/demo/index.html index 1a45098..f1ad2b2 100644 --- a/demo/index.html +++ b/demo/index.html @@ -9,15 +9,52 @@

JSONPath Demo (To demo on Node instead, see the library on Runkit.)

-
+
diff --git a/dist/index-browser-esm.js b/dist/index-browser-esm.js index fe0d4e9..b24d798 100644 --- a/dist/index-browser-esm.js +++ b/dist/index-browser-esm.js @@ -1,3 +1,29 @@ +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + function _typeof(obj) { "@babel/helpers - typeof"; @@ -33,6 +59,21 @@ function _createClass(Constructor, protoProps, staticProps) { return Constructor; } +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); @@ -261,6 +302,1341 @@ function _createForOfIteratorHelper(o, allowArrayLike) { }; } +/** + * @implements {IHooks} + */ +var Hooks = /*#__PURE__*/function () { + function Hooks() { + _classCallCheck(this, Hooks); + } + + _createClass(Hooks, [{ + key: "add", + value: + /** + * @callback HookCallback + * @this {*|Jsep} this + * @param {Jsep} env + * @returns: void + */ + + /** + * Adds the given callback to the list of callbacks for the given hook. + * + * The callback will be invoked when the hook it is registered for is run. + * + * One callback function can be registered to multiple hooks and the same hook multiple times. + * + * @param {string|object} name The name of the hook, or an object of callbacks keyed by name + * @param {HookCallback|boolean} callback The callback function which is given environment variables. + * @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom) + * @public + */ + function add(name, callback, first) { + if (typeof arguments[0] != 'string') { + // Multiple hook callbacks, keyed by name + for (var _name in arguments[0]) { + this.add(_name, arguments[0][_name], arguments[1]); + } + } else { + (Array.isArray(name) ? name : [name]).forEach(function (name) { + this[name] = this[name] || []; + + if (callback) { + this[name][first ? 'unshift' : 'push'](callback); + } + }, this); + } + } + /** + * Runs a hook invoking all registered callbacks with the given environment variables. + * + * Callbacks will be invoked synchronously and in the order in which they were registered. + * + * @param {string} name The name of the hook. + * @param {Object} env The environment variables of the hook passed to all callbacks registered. + * @public + */ + + }, { + key: "run", + value: function run(name, env) { + this[name] = this[name] || []; + this[name].forEach(function (callback) { + callback.call(env && env.context ? env.context : env, env); + }); + } + }]); + + return Hooks; +}(); +/** + * @implements {IPlugins} + */ + + +var Plugins = /*#__PURE__*/function () { + function Plugins(jsep) { + _classCallCheck(this, Plugins); + + this.jsep = jsep; + this.registered = {}; + } + /** + * @callback PluginSetup + * @this {Jsep} jsep + * @returns: void + */ + + /** + * Adds the given plugin(s) to the registry + * + * @param {object} plugins + * @param {string} plugins.name The name of the plugin + * @param {PluginSetup} plugins.init The init function + * @public + */ + + + _createClass(Plugins, [{ + key: "register", + value: function register() { + var _this = this; + + for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) { + plugins[_key] = arguments[_key]; + } + + plugins.forEach(function (plugin) { + if (_typeof(plugin) !== 'object' || !plugin.name || !plugin.init) { + throw new Error('Invalid JSEP plugin format'); + } + + if (_this.registered[plugin.name]) { + // already registered. Ignore. + return; + } + + plugin.init(_this.jsep); + _this.registered[plugin.name] = plugin; + }); + } + }]); + + return Plugins; +}(); // JavaScript Expression Parser (JSEP) 1.3.8 + + +var Jsep = /*#__PURE__*/function () { + /** + * @param {string} expr a string with the passed in express + * @returns Jsep + */ + function Jsep(expr) { + _classCallCheck(this, Jsep); + + // `index` stores the character number we are currently at + // All of the gobbles below will modify `index` as we move along + this.expr = expr; + this.index = 0; + } + /** + * static top-level parser + * @returns {jsep.Expression} + */ + + + _createClass(Jsep, [{ + key: "char", + get: // ==================== END CONFIG ============================ + + /** + * @returns {string} + */ + function get() { + return this.expr.charAt(this.index); + } + /** + * @returns {number} + */ + + }, { + key: "code", + get: function get() { + return this.expr.charCodeAt(this.index); + } + }, { + key: "throwError", + value: + /** + * throw error at index of the expression + * @param {string} message + * @throws + */ + function throwError(message) { + var error = new Error(message + ' at character ' + this.index); + error.index = this.index; + error.description = message; + throw error; + } + /** + * Run a given hook + * @param {string} name + * @param {jsep.Expression|false} [node] + * @returns {?jsep.Expression} + */ + + }, { + key: "runHook", + value: function runHook(name, node) { + if (Jsep.hooks[name]) { + var env = { + context: this, + node: node + }; + Jsep.hooks.run(name, env); + return env.node; + } + + return node; + } + /** + * Runs a given hook until one returns a node + * @param {string} name + * @returns {?jsep.Expression} + */ + + }, { + key: "searchHook", + value: function searchHook(name) { + if (Jsep.hooks[name]) { + var env = { + context: this + }; + Jsep.hooks[name].find(function (callback) { + callback.call(env.context, env); + return env.node; + }); + return env.node; + } + } + /** + * Push `index` up to the next non-space character + */ + + }, { + key: "gobbleSpaces", + value: function gobbleSpaces() { + var ch = this.code; // Whitespace + + while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) { + ch = this.expr.charCodeAt(++this.index); + } + + this.runHook('gobble-spaces'); + } + /** + * Top-level method to parse all expressions and returns compound or single node + * @returns {jsep.Expression} + */ + + }, { + key: "parse", + value: function parse() { + this.runHook('before-all'); + var nodes = this.gobbleExpressions(); // If there's only one expression just try returning the expression + + var node = nodes.length === 1 ? nodes[0] : { + type: Jsep.COMPOUND, + body: nodes + }; + return this.runHook('after-all', node); + } + /** + * top-level parser (but can be reused within as well) + * @param {number} [untilICode] + * @returns {jsep.Expression[]} + */ + + }, { + key: "gobbleExpressions", + value: function gobbleExpressions(untilICode) { + var nodes = [], + ch_i, + node; + + while (this.index < this.expr.length) { + ch_i = this.code; // Expressions can be separated by semicolons, commas, or just inferred without any + // separators + + if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) { + this.index++; // ignore separators + } else { + // Try to gobble each expression individually + if (node = this.gobbleExpression()) { + nodes.push(node); // If we weren't able to find a binary expression and are out of room, then + // the expression passed in probably has too much + } else if (this.index < this.expr.length) { + if (ch_i === untilICode) { + break; + } + + this.throwError('Unexpected "' + this["char"] + '"'); + } + } + } + + return nodes; + } + /** + * The main parsing function. + * @returns {?jsep.Expression} + */ + + }, { + key: "gobbleExpression", + value: function gobbleExpression() { + var node = this.searchHook('gobble-expression') || this.gobbleBinaryExpression(); + this.gobbleSpaces(); + return this.runHook('after-expression', node); + } + /** + * Search for the operation portion of the string (e.g. `+`, `===`) + * Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`) + * and move down from 3 to 2 to 1 character until a matching binary operation is found + * then, return that binary operation + * @returns {string|boolean} + */ + + }, { + key: "gobbleBinaryOp", + value: function gobbleBinaryOp() { + this.gobbleSpaces(); + var to_check = this.expr.substr(this.index, Jsep.max_binop_len); + var tc_len = to_check.length; + + while (tc_len > 0) { + // Don't accept a binary op when it is an identifier. + // Binary ops that start with a identifier-valid character must be followed + // by a non identifier-part valid character + if (Jsep.binary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) { + this.index += tc_len; + return to_check; + } + + to_check = to_check.substr(0, --tc_len); + } + + return false; + } + /** + * This function is responsible for gobbling an individual expression, + * e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)` + * @returns {?jsep.BinaryExpression} + */ + + }, { + key: "gobbleBinaryExpression", + value: function gobbleBinaryExpression() { + var node, biop, prec, stack, biop_info, left, right, i, cur_biop; // First, try to get the leftmost thing + // Then, check to see if there's a binary operator operating on that leftmost thing + // Don't gobbleBinaryOp without a left-hand-side + + left = this.gobbleToken(); + + if (!left) { + return left; + } + + biop = this.gobbleBinaryOp(); // If there wasn't a binary operator, just return the leftmost node + + if (!biop) { + return left; + } // Otherwise, we need to start a stack to properly place the binary operations in their + // precedence structure + + + biop_info = { + value: biop, + prec: Jsep.binaryPrecedence(biop), + right_a: Jsep.right_associative.has(biop) + }; + right = this.gobbleToken(); + + if (!right) { + this.throwError("Expected expression after " + biop); + } + + stack = [left, biop_info, right]; // Properly deal with precedence using [recursive descent](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm) + + while (biop = this.gobbleBinaryOp()) { + prec = Jsep.binaryPrecedence(biop); + + if (prec === 0) { + this.index -= biop.length; + break; + } + + biop_info = { + value: biop, + prec: prec, + right_a: Jsep.right_associative.has(biop) + }; + cur_biop = biop; // Reduce: make a binary expression from the three topmost entries. + + var comparePrev = function comparePrev(prev) { + return biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec; + }; + + while (stack.length > 2 && comparePrev(stack[stack.length - 2])) { + right = stack.pop(); + biop = stack.pop().value; + left = stack.pop(); + node = { + type: Jsep.BINARY_EXP, + operator: biop, + left: left, + right: right + }; + stack.push(node); + } + + node = this.gobbleToken(); + + if (!node) { + this.throwError("Expected expression after " + cur_biop); + } + + stack.push(biop_info, node); + } + + i = stack.length - 1; + node = stack[i]; + + while (i > 1) { + node = { + type: Jsep.BINARY_EXP, + operator: stack[i - 1].value, + left: stack[i - 2], + right: node + }; + i -= 2; + } + + return node; + } + /** + * An individual part of a binary expression: + * e.g. `foo.bar(baz)`, `1`, `"abc"`, `(a % 2)` (because it's in parenthesis) + * @returns {boolean|jsep.Expression} + */ + + }, { + key: "gobbleToken", + value: function gobbleToken() { + var ch, to_check, tc_len, node; + this.gobbleSpaces(); + node = this.searchHook('gobble-token'); + + if (node) { + return this.runHook('after-token', node); + } + + ch = this.code; + + if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) { + // Char code 46 is a dot `.` which can start off a numeric literal + return this.gobbleNumericLiteral(); + } + + if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) { + // Single or double quotes + node = this.gobbleStringLiteral(); + } else if (ch === Jsep.OBRACK_CODE) { + node = this.gobbleArray(); + } else { + to_check = this.expr.substr(this.index, Jsep.max_unop_len); + tc_len = to_check.length; + + while (tc_len > 0) { + // Don't accept an unary op when it is an identifier. + // Unary ops that start with a identifier-valid character must be followed + // by a non identifier-part valid character + if (Jsep.unary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) { + this.index += tc_len; + var argument = this.gobbleToken(); + + if (!argument) { + this.throwError('missing unaryOp argument'); + } + + return this.runHook('after-token', { + type: Jsep.UNARY_EXP, + operator: to_check, + argument: argument, + prefix: true + }); + } + + to_check = to_check.substr(0, --tc_len); + } + + if (Jsep.isIdentifierStart(ch)) { + node = this.gobbleIdentifier(); + + if (Jsep.literals.hasOwnProperty(node.name)) { + node = { + type: Jsep.LITERAL, + value: Jsep.literals[node.name], + raw: node.name + }; + } else if (node.name === Jsep.this_str) { + node = { + type: Jsep.THIS_EXP + }; + } + } else if (ch === Jsep.OPAREN_CODE) { + // open parenthesis + node = this.gobbleGroup(); + } + } + + if (!node) { + return this.runHook('after-token', false); + } + + node = this.gobbleTokenProperty(node); + return this.runHook('after-token', node); + } + /** + * Gobble properties of of identifiers/strings/arrays/groups. + * e.g. `foo`, `bar.baz`, `foo['bar'].baz` + * It also gobbles function calls: + * e.g. `Math.acos(obj.angle)` + * @param {jsep.Expression} node + * @returns {jsep.Expression} + */ + + }, { + key: "gobbleTokenProperty", + value: function gobbleTokenProperty(node) { + this.gobbleSpaces(); + var ch = this.code; + + while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) { + var optional = void 0; + + if (ch === Jsep.QUMARK_CODE) { + if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) { + break; + } + + optional = true; + this.index += 2; + this.gobbleSpaces(); + ch = this.code; + } + + this.index++; + + if (ch === Jsep.OBRACK_CODE) { + node = { + type: Jsep.MEMBER_EXP, + computed: true, + object: node, + property: this.gobbleExpression() + }; + this.gobbleSpaces(); + ch = this.code; + + if (ch !== Jsep.CBRACK_CODE) { + this.throwError('Unclosed ['); + } + + this.index++; + } else if (ch === Jsep.OPAREN_CODE) { + // A function call is being made; gobble all the arguments + node = { + type: Jsep.CALL_EXP, + 'arguments': this.gobbleArguments(Jsep.CPAREN_CODE), + callee: node + }; + } else if (ch === Jsep.PERIOD_CODE || optional) { + if (optional) { + this.index--; + } + + this.gobbleSpaces(); + node = { + type: Jsep.MEMBER_EXP, + computed: false, + object: node, + property: this.gobbleIdentifier() + }; + } + + if (optional) { + node.optional = true; + } // else leave undefined for compatibility with esprima + + + this.gobbleSpaces(); + ch = this.code; + } + + return node; + } + /** + * Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to + * keep track of everything in the numeric literal and then calling `parseFloat` on that string + * @returns {jsep.Literal} + */ + + }, { + key: "gobbleNumericLiteral", + value: function gobbleNumericLiteral() { + var number = '', + ch, + chCode; + + while (Jsep.isDecimalDigit(this.code)) { + number += this.expr.charAt(this.index++); + } + + if (this.code === Jsep.PERIOD_CODE) { + // can start with a decimal marker + number += this.expr.charAt(this.index++); + + while (Jsep.isDecimalDigit(this.code)) { + number += this.expr.charAt(this.index++); + } + } + + ch = this["char"]; + + if (ch === 'e' || ch === 'E') { + // exponent marker + number += this.expr.charAt(this.index++); + ch = this["char"]; + + if (ch === '+' || ch === '-') { + // exponent sign + number += this.expr.charAt(this.index++); + } + + while (Jsep.isDecimalDigit(this.code)) { + // exponent itself + number += this.expr.charAt(this.index++); + } + + if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) { + this.throwError('Expected exponent (' + number + this["char"] + ')'); + } + } + + chCode = this.code; // Check to make sure this isn't a variable name that start with a number (123abc) + + if (Jsep.isIdentifierStart(chCode)) { + this.throwError('Variable names cannot start with a number (' + number + this["char"] + ')'); + } else if (chCode === Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE) { + this.throwError('Unexpected period'); + } + + return { + type: Jsep.LITERAL, + value: parseFloat(number), + raw: number + }; + } + /** + * Parses a string literal, staring with single or double quotes with basic support for escape codes + * e.g. `"hello world"`, `'this is\nJSEP'` + * @returns {jsep.Literal} + */ + + }, { + key: "gobbleStringLiteral", + value: function gobbleStringLiteral() { + var str = ''; + var startIndex = this.index; + var quote = this.expr.charAt(this.index++); + var closed = false; + + while (this.index < this.expr.length) { + var ch = this.expr.charAt(this.index++); + + if (ch === quote) { + closed = true; + break; + } else if (ch === '\\') { + // Check for all of the common escape codes + ch = this.expr.charAt(this.index++); + + switch (ch) { + case 'n': + str += '\n'; + break; + + case 'r': + str += '\r'; + break; + + case 't': + str += '\t'; + break; + + case 'b': + str += '\b'; + break; + + case 'f': + str += '\f'; + break; + + case 'v': + str += '\x0B'; + break; + + default: + str += ch; + } + } else { + str += ch; + } + } + + if (!closed) { + this.throwError('Unclosed quote after "' + str + '"'); + } + + return { + type: Jsep.LITERAL, + value: str, + raw: this.expr.substring(startIndex, this.index) + }; + } + /** + * Gobbles only identifiers + * e.g.: `foo`, `_value`, `$x1` + * Also, this function checks if that identifier is a literal: + * (e.g. `true`, `false`, `null`) or `this` + * @returns {jsep.Identifier} + */ + + }, { + key: "gobbleIdentifier", + value: function gobbleIdentifier() { + var ch = this.code, + start = this.index; + + if (Jsep.isIdentifierStart(ch)) { + this.index++; + } else { + this.throwError('Unexpected ' + this["char"]); + } + + while (this.index < this.expr.length) { + ch = this.code; + + if (Jsep.isIdentifierPart(ch)) { + this.index++; + } else { + break; + } + } + + return { + type: Jsep.IDENTIFIER, + name: this.expr.slice(start, this.index) + }; + } + /** + * Gobbles a list of arguments within the context of a function call + * or array literal. This function also assumes that the opening character + * `(` or `[` has already been gobbled, and gobbles expressions and commas + * until the terminator character `)` or `]` is encountered. + * e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]` + * @param {number} termination + * @returns {jsep.Expression[]} + */ + + }, { + key: "gobbleArguments", + value: function gobbleArguments(termination) { + var args = []; + var closed = false; + var separator_count = 0; + + while (this.index < this.expr.length) { + this.gobbleSpaces(); + var ch_i = this.code; + + if (ch_i === termination) { + // done parsing + closed = true; + this.index++; + + if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) { + this.throwError('Unexpected token ' + String.fromCharCode(termination)); + } + + break; + } else if (ch_i === Jsep.COMMA_CODE) { + // between expressions + this.index++; + separator_count++; + + if (separator_count !== args.length) { + // missing argument + if (termination === Jsep.CPAREN_CODE) { + this.throwError('Unexpected token ,'); + } else if (termination === Jsep.CBRACK_CODE) { + for (var arg = args.length; arg < separator_count; arg++) { + args.push(null); + } + } + } + } else if (args.length !== separator_count && separator_count !== 0) { + // NOTE: `&& separator_count !== 0` allows for either all commas, or all spaces as arguments + this.throwError('Expected comma'); + } else { + var node = this.gobbleExpression(); + + if (!node || node.type === Jsep.COMPOUND) { + this.throwError('Expected comma'); + } + + args.push(node); + } + } + + if (!closed) { + this.throwError('Expected ' + String.fromCharCode(termination)); + } + + return args; + } + /** + * Responsible for parsing a group of things within parentheses `()` + * that have no identifier in front (so not a function call) + * This function assumes that it needs to gobble the opening parenthesis + * and then tries to gobble everything within that parenthesis, assuming + * that the next thing it should see is the close parenthesis. If not, + * then the expression probably doesn't have a `)` + * @returns {boolean|jsep.Expression} + */ + + }, { + key: "gobbleGroup", + value: function gobbleGroup() { + this.index++; + var nodes = this.gobbleExpressions(Jsep.CPAREN_CODE); + + if (this.code === Jsep.CPAREN_CODE) { + this.index++; + + if (nodes.length === 1) { + return nodes[0]; + } else if (!nodes.length) { + return false; + } else { + return { + type: Jsep.SEQUENCE_EXP, + expressions: nodes + }; + } + } else { + this.throwError('Unclosed ('); + } + } + /** + * Responsible for parsing Array literals `[1, 2, 3]` + * This function assumes that it needs to gobble the opening bracket + * and then tries to gobble the expressions as arguments. + * @returns {jsep.ArrayExpression} + */ + + }, { + key: "gobbleArray", + value: function gobbleArray() { + this.index++; + return { + type: Jsep.ARRAY_EXP, + elements: this.gobbleArguments(Jsep.CBRACK_CODE) + }; + } + }], [{ + key: "version", + get: + /** + * @returns {string} + */ + function get() { + // To be filled in by the template + return '1.3.8'; + } + /** + * @returns {string} + */ + + }, { + key: "toString", + value: function toString() { + return 'JavaScript Expression Parser (JSEP) v' + Jsep.version; + } + }, { + key: "addUnaryOp", + value: // ==================== CONFIG ================================ + + /** + * @method addUnaryOp + * @param {string} op_name The name of the unary op to add + * @returns {Jsep} + */ + function addUnaryOp(op_name) { + Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len); + Jsep.unary_ops[op_name] = 1; + return Jsep; + } + /** + * @method jsep.addBinaryOp + * @param {string} op_name The name of the binary op to add + * @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence + * @param {boolean} [isRightAssociative=false] whether operator is right-associative + * @returns {Jsep} + */ + + }, { + key: "addBinaryOp", + value: function addBinaryOp(op_name, precedence, isRightAssociative) { + Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len); + Jsep.binary_ops[op_name] = precedence; + + if (isRightAssociative) { + Jsep.right_associative.add(op_name); + } else { + Jsep.right_associative["delete"](op_name); + } + + return Jsep; + } + /** + * @method addIdentifierChar + * @param {string} char The additional character to treat as a valid part of an identifier + * @returns {Jsep} + */ + + }, { + key: "addIdentifierChar", + value: function addIdentifierChar(_char) { + Jsep.additional_identifier_chars.add(_char); + return Jsep; + } + /** + * @method addLiteral + * @param {string} literal_name The name of the literal to add + * @param {*} literal_value The value of the literal + * @returns {Jsep} + */ + + }, { + key: "addLiteral", + value: function addLiteral(literal_name, literal_value) { + Jsep.literals[literal_name] = literal_value; + return Jsep; + } + /** + * @method removeUnaryOp + * @param {string} op_name The name of the unary op to remove + * @returns {Jsep} + */ + + }, { + key: "removeUnaryOp", + value: function removeUnaryOp(op_name) { + delete Jsep.unary_ops[op_name]; + + if (op_name.length === Jsep.max_unop_len) { + Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops); + } + + return Jsep; + } + /** + * @method removeAllUnaryOps + * @returns {Jsep} + */ + + }, { + key: "removeAllUnaryOps", + value: function removeAllUnaryOps() { + Jsep.unary_ops = {}; + Jsep.max_unop_len = 0; + return Jsep; + } + /** + * @method removeIdentifierChar + * @param {string} char The additional character to stop treating as a valid part of an identifier + * @returns {Jsep} + */ + + }, { + key: "removeIdentifierChar", + value: function removeIdentifierChar(_char2) { + Jsep.additional_identifier_chars["delete"](_char2); + return Jsep; + } + /** + * @method removeBinaryOp + * @param {string} op_name The name of the binary op to remove + * @returns {Jsep} + */ + + }, { + key: "removeBinaryOp", + value: function removeBinaryOp(op_name) { + delete Jsep.binary_ops[op_name]; + + if (op_name.length === Jsep.max_binop_len) { + Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops); + } + + Jsep.right_associative["delete"](op_name); + return Jsep; + } + /** + * @method removeAllBinaryOps + * @returns {Jsep} + */ + + }, { + key: "removeAllBinaryOps", + value: function removeAllBinaryOps() { + Jsep.binary_ops = {}; + Jsep.max_binop_len = 0; + return Jsep; + } + /** + * @method removeLiteral + * @param {string} literal_name The name of the literal to remove + * @returns {Jsep} + */ + + }, { + key: "removeLiteral", + value: function removeLiteral(literal_name) { + delete Jsep.literals[literal_name]; + return Jsep; + } + /** + * @method removeAllLiterals + * @returns {Jsep} + */ + + }, { + key: "removeAllLiterals", + value: function removeAllLiterals() { + Jsep.literals = {}; + return Jsep; + } + }, { + key: "parse", + value: function parse(expr) { + return new Jsep(expr).parse(); + } + /** + * Get the longest key length of any object + * @param {object} obj + * @returns {number} + */ + + }, { + key: "getMaxKeyLen", + value: function getMaxKeyLen(obj) { + return Math.max.apply(Math, [0].concat(_toConsumableArray(Object.keys(obj).map(function (k) { + return k.length; + })))); + } + /** + * `ch` is a character code in the next three functions + * @param {number} ch + * @returns {boolean} + */ + + }, { + key: "isDecimalDigit", + value: function isDecimalDigit(ch) { + return ch >= 48 && ch <= 57; // 0...9 + } + /** + * Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float. + * @param {string} op_val + * @returns {number} + */ + + }, { + key: "binaryPrecedence", + value: function binaryPrecedence(op_val) { + return Jsep.binary_ops[op_val] || 0; + } + /** + * Looks for start of identifier + * @param {number} ch + * @returns {boolean} + */ + + }, { + key: "isIdentifierStart", + value: function isIdentifierStart(ch) { + return ch >= 65 && ch <= 90 || // A...Z + ch >= 97 && ch <= 122 || // a...z + ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)] || // any non-ASCII that is not an operator + Jsep.additional_identifier_chars.has(String.fromCharCode(ch)); // additional characters + } + /** + * @param {number} ch + * @returns {boolean} + */ + + }, { + key: "isIdentifierPart", + value: function isIdentifierPart(ch) { + return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch); + } + }]); + + return Jsep; +}(); // Static fields: + + +var hooks = new Hooks(); +Object.assign(Jsep, { + hooks: hooks, + plugins: new Plugins(Jsep), + // Node Types + // ---------- + // This is the full set of types that any JSEP node can be. + // Store them here to save space when minified + COMPOUND: 'Compound', + SEQUENCE_EXP: 'SequenceExpression', + IDENTIFIER: 'Identifier', + MEMBER_EXP: 'MemberExpression', + LITERAL: 'Literal', + THIS_EXP: 'ThisExpression', + CALL_EXP: 'CallExpression', + UNARY_EXP: 'UnaryExpression', + BINARY_EXP: 'BinaryExpression', + ARRAY_EXP: 'ArrayExpression', + TAB_CODE: 9, + LF_CODE: 10, + CR_CODE: 13, + SPACE_CODE: 32, + PERIOD_CODE: 46, + // '.' + COMMA_CODE: 44, + // ',' + SQUOTE_CODE: 39, + // single quote + DQUOTE_CODE: 34, + // double quotes + OPAREN_CODE: 40, + // ( + CPAREN_CODE: 41, + // ) + OBRACK_CODE: 91, + // [ + CBRACK_CODE: 93, + // ] + QUMARK_CODE: 63, + // ? + SEMCOL_CODE: 59, + // ; + COLON_CODE: 58, + // : + // Operations + // ---------- + // Use a quickly-accessible map to store all of the unary operators + // Values are set to `1` (it really doesn't matter) + unary_ops: { + '-': 1, + '!': 1, + '~': 1, + '+': 1 + }, + // Also use a map for the binary operations but set their values to their + // binary precedence for quick reference (higher number = higher precedence) + // see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) + binary_ops: { + '||': 1, + '&&': 2, + '|': 3, + '^': 4, + '&': 5, + '==': 6, + '!=': 6, + '===': 6, + '!==': 6, + '<': 7, + '>': 7, + '<=': 7, + '>=': 7, + '<<': 8, + '>>': 8, + '>>>': 8, + '+': 9, + '-': 9, + '*': 10, + '/': 10, + '%': 10 + }, + // sets specific binary_ops as right-associative + right_associative: new Set(), + // Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char) + additional_identifier_chars: new Set(['$', '_']), + // Literals + // ---------- + // Store the values to return for the various literals we may encounter + literals: { + 'true': true, + 'false': false, + 'null': null + }, + // Except for `this`, which is special. This could be changed to something like `'self'` as well + this_str: 'this' +}); +Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops); +Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops); // Backward Compatibility: + +var jsep = function jsep(expr) { + return new Jsep(expr).parse(); +}; + +var staticMethods = Object.getOwnPropertyNames(Jsep); +staticMethods.forEach(function (m) { + if (jsep[m] === undefined && m !== 'prototype') { + jsep[m] = Jsep[m]; + } +}); +jsep.Jsep = Jsep; // allows for const { Jsep } = require('jsep'); + +var CONDITIONAL_EXP = 'ConditionalExpression'; +var ternary = { + name: 'ternary', + init: function init(jsep) { + // Ternary expression: test ? consequent : alternate + jsep.hooks.add('after-expression', function gobbleTernary(env) { + if (env.node && this.code === jsep.QUMARK_CODE) { + this.index++; + var test = env.node; + var consequent = this.gobbleExpression(); + + if (!consequent) { + this.throwError('Expected expression'); + } + + this.gobbleSpaces(); + + if (this.code === jsep.COLON_CODE) { + this.index++; + var alternate = this.gobbleExpression(); + + if (!alternate) { + this.throwError('Expected expression'); + } + + env.node = { + type: CONDITIONAL_EXP, + test: test, + consequent: consequent, + alternate: alternate + }; // check for operators of higher priority than ternary (i.e. assignment) + // jsep sets || at 1, and assignment at 0.9, and conditional should be between them + + if (test.operator && jsep.binary_ops[test.operator] <= 0.9) { + var newTest = test; + + while (newTest.right.operator && jsep.binary_ops[newTest.right.operator] <= 0.9) { + newTest = newTest.right; + } + + env.node.test = newTest.right; + newTest.right = env.node; + env.node = test; + } + } else { + this.throwError('Expected :'); + } + } + }); + } +}; // Add default plugins: + +jsep.plugins.register(ternary); + +var FSLASH_CODE = 47; // '/' + +var BSLASH_CODE = 92; // '\\' + +var index = { + name: 'regex', + init: function init(jsep) { + // Regex literal: /abc123/ig + jsep.hooks.add('gobble-token', function gobbleRegexLiteral(env) { + if (this.code === FSLASH_CODE) { + var patternIndex = ++this.index; + var inCharSet = false; + + while (this.index < this.expr.length) { + if (this.code === FSLASH_CODE && !inCharSet) { + var pattern = this.expr.slice(patternIndex, this.index); + var flags = ''; + + while (++this.index < this.expr.length) { + var code = this.code; + + if (code >= 97 && code <= 122 // a...z + || code >= 65 && code <= 90 // A...Z + || code >= 48 && code <= 57) { + // 0-9 + flags += this["char"]; + } else { + break; + } + } + + var value = void 0; + + try { + value = new RegExp(pattern, flags); + } catch (e) { + this.throwError(e.message); + } + + env.node = { + type: jsep.LITERAL, + value: value, + raw: this.expr.slice(patternIndex - 1, this.index) + }; // allow . [] and () after regex: /regex/.test(a) + + env.node = this.gobbleTokenProperty(env.node); + return env.node; + } + + if (this.code === jsep.OBRACK_CODE) { + inCharSet = true; + } else if (inCharSet && this.code === jsep.CBRACK_CODE) { + inCharSet = false; + } + + this.index += this.code === BSLASH_CODE ? 2 : 1; + } + + this.throwError('Unclosed Regex'); + } + }); + } +}; + var hasOwnProp = Object.prototype.hasOwnProperty; /** * @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject @@ -363,6 +1739,7 @@ var NewError = /*#__PURE__*/function (_Error) { * @property {boolean} [wrap=true] * @property {PlainObject} [sandbox={}] * @property {boolean} [preventEval=false] + * @property {"safe"|"native"|"none"} [evalType='safe'] * @property {PlainObject|GenericArray|null} [parent=null] * @property {string|null} [parentProperty=null] * @property {JSONPathCallback} [callback] @@ -421,6 +1798,7 @@ function JSONPath(opts, expr, obj, callback, otherTypeCallback) { this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true; this.sandbox = opts.sandbox || {}; this.preventEval = opts.preventEval || false; + this.evalType = opts.evalType || 'safe'; this.parent = opts.parent || null; this.parentProperty = opts.parentProperty || null; this.callback = opts.callback || callback || null; @@ -460,6 +1838,7 @@ JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) wrap = this.wrap; this.currResultType = this.resultType; this.currPreventEval = this.preventEval; + this.currEvalType = this.evalType; this.currSandbox = this.sandbox; callback = callback || this.callback; this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback; @@ -482,6 +1861,7 @@ JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) this.currSandbox = hasOwnProp.call(expr, 'sandbox') ? expr.sandbox : this.currSandbox; wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap; this.currPreventEval = hasOwnProp.call(expr, 'preventEval') ? expr.preventEval : this.currPreventEval; + this.currEvalType = hasOwnProp.call(expr, 'evalType') ? expr.evalType : this.currEvalType; callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback; this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback') ? expr.otherTypeCallback : this.currOtherTypeCallback; currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent; @@ -682,7 +2062,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c addRet(this._slice(loc, x, val, path, parent, parentPropName, callback)); } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [?(expr)] prevented in JSONPath expression.'); } @@ -695,7 +2075,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c }); } else if (loc[0] === '(') { // [(expr)] (dynamic property/index) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [(expr)] prevented in JSONPath expression.'); } // As this will resolve to a property name (but we don't know it // yet), property and parent information is relative to the @@ -902,7 +2282,7 @@ JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropN this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname])); } - var scriptCacheKey = 'script:' + code; + var scriptCacheKey = this.currEvalType + 'Script:' + code; if (!JSONPath.cache[scriptCacheKey]) { var script = code.replace(/@parentProperty/g, '_$_parentProperty').replace(/@parent/g, '_$_parent').replace(/@property/g, '_$_property').replace(/@root/g, '_$_root').replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g, '_$_v$1'); @@ -911,7 +2291,11 @@ JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropN script = script.replace(/@path/g, '_$_path'); } - JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + if (this.currEvalType === 'safe') { + JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script); + } else if (this.currEvalType === 'native') { + JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + } } try { @@ -1034,11 +2418,242 @@ var moveToAnotherArray = function moveToAnotherArray(source, target, conditionCb target.push(source.splice(i--, 1)[0]); } } +}; // register plugins + + +jsep.plugins.register(index); +var SafeEval = { + eval: function _eval(code) { + var substitions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var ast = jsep(code); + return SafeEval.evalAst(ast, substitions); + }, + + /** + * @param {jsep.Expression} ast + * @param {Record} subs + */ + evalAst: function evalAst(ast, subs) { + switch (ast.type) { + case 'BinaryExpression': + case 'LogicalExpression': + return SafeEval.evalBinaryExpression(ast, subs); + + case 'Compound': + return SafeEval.evalCompound(ast, subs); + + case 'ConditionalExpression': + return SafeEval.evalConditionalExpression(ast, subs); + + case 'Identifier': + return SafeEval.evalIdentifier(ast, subs); + + case 'Literal': + return SafeEval.evalLiteral(ast, subs); + + case 'MemberExpression': + return SafeEval.evalMemberExpression(ast, subs); + + case 'UnaryExpression': + return SafeEval.evalUnaryExpression(ast, subs); + + case 'ArrayExpression': + return SafeEval.evalArrayExpression(ast, subs); + + case 'CallExpression': + return SafeEval.evalCallExpression(ast, subs); + + default: + throw SyntaxError('Unexpected expression', ast); + } + }, + evalBinaryExpression: function evalBinaryExpression(ast, subs) { + var result = { + '||': function _(a, b) { + return a || b(); + }, + '&&': function _(a, b) { + return a && b(); + }, + '|': function _(a, b) { + return a | b(); + }, + '^': function _(a, b) { + return a ^ b(); + }, + '&': function _(a, b) { + return a & b(); + }, + // eslint-disable-next-line eqeqeq + '==': function _(a, b) { + return a == b(); + }, + // eslint-disable-next-line eqeqeq + '!=': function _(a, b) { + return a != b(); + }, + '===': function _(a, b) { + return a === b(); + }, + '!==': function _(a, b) { + return a !== b(); + }, + '<': function _(a, b) { + return a < b(); + }, + '>': function _(a, b) { + return a > b(); + }, + '<=': function _(a, b) { + return a <= b(); + }, + '>=': function _(a, b) { + return a >= b(); + }, + '<<': function _(a, b) { + return a << b(); + }, + '>>': function _(a, b) { + return a >> b(); + }, + '>>>': function _(a, b) { + return a >>> b(); + }, + '+': function _(a, b) { + return a + b(); + }, + '-': function _(a, b) { + return a - b(); + }, + '*': function _(a, b) { + return a * b(); + }, + '/': function _(a, b) { + return a / b(); + }, + '%': function _(a, b) { + return a % b(); + } + }[ast.operator](SafeEval.evalAst(ast.left, subs), function () { + return SafeEval.evalAst(ast.right, subs); + }); + return result; + }, + evalCompound: function evalCompound(ast, subs) { + var last; + + var _iterator = _createForOfIteratorHelper(ast.body), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var expr = _step.value; + last = this.evalAst(expr, subs); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return last; + }, + evalConditionalExpression: function evalConditionalExpression(ast, subs) { + if (SafeEval.evalAst(ast.test, subs)) { + return SafeEval.evalAst(ast.consequent, subs); + } + + return SafeEval.evalAst(ast.alternate, subs); + }, + evalIdentifier: function evalIdentifier(ast, subs) { + if (ast.name in subs) { + return subs[ast.name]; + } + + throw ReferenceError("".concat(ast.name, " is not defined")); + }, + evalLiteral: function evalLiteral(ast, subs) { + return ast.value; + }, + evalMemberExpression: function evalMemberExpression(ast, subs) { + var prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]` + : ast.property.name; // `object.property` property is identifier + + var obj = SafeEval.evalAst(ast.object, subs); + var result = obj[prop]; + + if (typeof result === 'function') { + return result.bind(obj); // arrow functions aren't affected by bind. + } + + return result; + }, + evalUnaryExpression: function evalUnaryExpression(ast, subs) { + var result = { + '-': function _(a) { + return -SafeEval.evalAst(a); + }, + '!': function _(a) { + return !SafeEval.evalAst(a); + }, + '~': function _(a) { + return ~SafeEval.evalAst(a); + }, + // eslint-disable-next-line no-implicit-coercion + '+': function _(a) { + return +SafeEval.evalAst(a); + } + }[ast.operator](ast.argument); + return result; + }, + evalArrayExpression: function evalArrayExpression(ast, subs) { + return ast.elements.map(function (el) { + return SafeEval.evalAst(el, subs); + }); + }, + evalCallExpression: function evalCallExpression(ast, subs) { + var args = ast.arguments.map(function (arg) { + return SafeEval.evalAst(arg, subs); + }); + var func = SafeEval.evalAst(ast.callee, subs); + return func.apply(void 0, _toConsumableArray(args)); + } }; /** * In-browser replacement for NodeJS' VM.Script. */ +var SafeScript = /*#__PURE__*/function () { + /** + * @param {string} expr Expression to evaluate + */ + function SafeScript(expr) { + _classCallCheck(this, SafeScript); + + this.code = expr; + } + /** + * @param {PlainObject} context Object whose items will be added + * to evaluation + * @returns {EvaluatedResult} Result of evaluated code + */ + + + _createClass(SafeScript, [{ + key: "runInNewContext", + value: function runInNewContext(context) { + var keyMap = _objectSpread2({}, context); + + return SafeEval.eval(this.code, keyMap); + } + }]); + + return SafeScript; +}(); +/** + * In-browser replacement for NodeJS' VM.Script. + */ + var Script = /*#__PURE__*/function () { /** @@ -1101,5 +2716,8 @@ var Script = /*#__PURE__*/function () { JSONPath.prototype.vm = { Script: Script }; +JSONPath.prototype.safeVm = { + Script: SafeScript +}; export { JSONPath }; diff --git a/dist/index-browser-esm.min.js b/dist/index-browser-esm.min.js index 09f6c04..24c16ca 100644 --- a/dist/index-browser-esm.min.js +++ b/dist/index-browser-esm.min.js @@ -1,2 +1,2 @@ -function t(r){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(r)}function r(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function e(t,r){for(var e=0;et.length)&&(r=t.length);for(var e=0,n=new Array(r);e1&&s.shift(),this._hasParentSelector=null;var p=this._trace(s,e,["$"],u,i,n).filter((function(t){return t&&!t.isParentSelector}));return p.length?l||1!==p.length||p[0].hasArrExpr?p.reduce((function(t,r){var e=o._getPreferredOutput(r);return c&&Array.isArray(e)?t=t.concat(e):t.push(e),t}),[]):this._getPreferredOutput(p[0]):l?[]:void 0}},F.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){case"all":var e=Array.isArray(t.path)?t.path:F.toPathArray(t.path);return t.pointer=F.toPointer(e),t.path="string"==typeof t.path?t.path:F.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return F.toPathString(t[r]);case"pointer":return F.toPointer(t.path);default:throw new TypeError("Unknown result type")}},F.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:F.toPathString(t.path),r(n,e,t)}},F.prototype._trace=function(r,e,n,a,o,u,i,c){var l,s=this;if(!r.length)return l={path:n,value:e,parent:a,parentProperty:o,hasArrExpr:i},this._handleCallback(l,u,"value"),l;var h=r[0],b=r.slice(1),F=[];function d(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof h||c)&&e&&f.call(e,h))d(this._trace(b,e[h],y(n,h),e,h,u,i));else if("*"===h)this._walk(e,(function(t){d(s._trace(b,e[t],y(n,t),e,t,u,!0,!0))}));else if(".."===h)d(this._trace(b,e,n,a,o,u,i)),this._walk(e,(function(a){"object"===t(e[a])&&d(s._trace(r.slice(),e[a],y(n,a),e,a,u,!0))}));else{if("^"===h)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:b,isParentSelector:!0};if("~"===h)return l={path:y(n,h),value:o,parent:a,parentProperty:null},this._handleCallback(l,u,"property"),l;if("$"===h)d(this._trace(b,e,n,null,null,u,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(h))d(this._slice(h,b,e,n,a,o,u));else if(0===h.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");var g=h.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1");this._walk(e,(function(t){s._eval(g,e[t],t,n,a,o)&&d(s._trace(b,e[t],y(n,t),e,t,u,!0))}))}else if("("===h[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");d(this._trace(v(this._eval(h,e,n[n.length-1],n.slice(0,-1),a,o),b),e,n,a,o,u,i))}else if("@"===h[0]){var w=!1,_=h.slice(1,-2);switch(_){case"scalar":e&&["object","function"].includes(t(e))||(w=!0);break;case"boolean":case"string":case"undefined":case"function":t(e)===_&&(w=!0);break;case"integer":!Number.isFinite(e)||e%1||(w=!0);break;case"number":Number.isFinite(e)&&(w=!0);break;case"nonFinite":"number"!=typeof e||Number.isFinite(e)||(w=!0);break;case"object":e&&t(e)===_&&(w=!0);break;case"array":Array.isArray(e)&&(w=!0);break;case"other":w=this.currOtherTypeCallback(e,n,a,o);break;case"null":null===e&&(w=!0);break;default:throw new TypeError("Unknown value type "+_)}if(w)return l={path:n,value:e,parent:a,parentProperty:o},this._handleCallback(l,u,"value"),l}else if("`"===h[0]&&e&&f.call(e,h.slice(1))){var m=h.slice(1);d(this._trace(b,e[m],y(n,m),e,m,u,i,!0))}else if(h.includes(",")){var D,P=function(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=p(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,a=function(){};return{s:a,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,i=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return u=t.done,t},e:function(t){i=!0,o=t},f:function(){try{u||null==e.return||e.return()}finally{if(i)throw o}}}}(h.split(","));try{for(P.s();!(D=P.n()).done;){var S=D.value;d(this._trace(v(S,b),e,n,a,o,u,!0))}}catch(t){P.e(t)}finally{P.f()}}else!c&&e&&f.call(e,h)&&d(this._trace(b,e[h],y(n,h),e,h,u,i,!0))}if(this._hasParentSelector)for(var x=0;x-1?r.slice(0,u+1)+" return "+r.slice(u+1):" return "+r;return i(Function,e.concat([c])).apply(void 0,s(a))}}]),t}();F.prototype.vm={Script:d};export{F as JSONPath}; +function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var r=0;re.length)&&(t=e.length);for(var r=0,n=new Array(t);r=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}var b=function(){function e(){r(this,e)}return i(e,[{key:"add",value:function(e,t,r){if("string"!=typeof arguments[0])for(var n in arguments[0])this.add(n,arguments[0][n],arguments[1]);else(Array.isArray(e)?e:[e]).forEach((function(e){this[e]=this[e]||[],t&&this[e][r?"unshift":"push"](t)}),this)}},{key:"run",value:function(e,t){this[e]=this[e]||[],this[e].forEach((function(e){e.call(t&&t.context?t.context:t,t)}))}}]),e}(),v=function(){function e(t){r(this,e),this.jsep=t,this.registered={}}return i(e,[{key:"register",value:function(){for(var e=this,r=arguments.length,n=new Array(r),i=0;i0;){if(e.binary_ops.hasOwnProperty(t)&&(!e.isIdentifierStart(this.code)||this.index+t.length2&&(l=i[i.length-2],o.right_a&&l.right_a?n>l.prec:n<=l.prec);)s=i.pop(),r=i.pop().value,a=i.pop(),t={type:e.BINARY_EXP,operator:r,left:a,right:s},i.push(t);(t=this.gobbleToken())||this.throwError("Expected expression after "+c),i.push(o,t)}for(t=i[u=i.length-1];u>1;)t={type:e.BINARY_EXP,operator:i[u-1].value,left:i[u-2],right:t},u-=2;return t}},{key:"gobbleToken",value:function(){var t,r,n,i;if(this.gobbleSpaces(),i=this.searchHook("gobble-token"))return this.runHook("after-token",i);if(t=this.code,e.isDecimalDigit(t)||t===e.PERIOD_CODE)return this.gobbleNumericLiteral();if(t===e.SQUOTE_CODE||t===e.DQUOTE_CODE)i=this.gobbleStringLiteral();else if(t===e.OBRACK_CODE)i=this.gobbleArray();else{for(n=(r=this.expr.substr(this.index,e.max_unop_len)).length;n>0;){if(e.unary_ops.hasOwnProperty(r)&&(!e.isIdentifierStart(this.code)||this.index+r.length=r.length&&this.throwError("Unexpected token "+String.fromCharCode(t));break}if(o===e.COMMA_CODE){if(this.index++,++i!==r.length)if(t===e.CPAREN_CODE)this.throwError("Unexpected token ,");else if(t===e.CBRACK_CODE)for(var a=r.length;a=48&&e<=57}},{key:"binaryPrecedence",value:function(t){return e.binary_ops[t]||0}},{key:"isIdentifierStart",value:function(t){return t>=65&&t<=90||t>=97&&t<=122||t>=128&&!e.binary_ops[String.fromCharCode(t)]||e.additional_identifier_chars.has(String.fromCharCode(t))}},{key:"isIdentifierPart",value:function(t){return e.isIdentifierStart(t)||e.isDecimalDigit(t)}}]),e}(),g=new b;Object.assign(E,{hooks:g,plugins:new v(E),COMPOUND:"Compound",SEQUENCE_EXP:"SequenceExpression",IDENTIFIER:"Identifier",MEMBER_EXP:"MemberExpression",LITERAL:"Literal",THIS_EXP:"ThisExpression",CALL_EXP:"CallExpression",UNARY_EXP:"UnaryExpression",BINARY_EXP:"BinaryExpression",ARRAY_EXP:"ArrayExpression",TAB_CODE:9,LF_CODE:10,CR_CODE:13,SPACE_CODE:32,PERIOD_CODE:46,COMMA_CODE:44,SQUOTE_CODE:39,DQUOTE_CODE:34,OPAREN_CODE:40,CPAREN_CODE:41,OBRACK_CODE:91,CBRACK_CODE:93,QUMARK_CODE:63,SEMCOL_CODE:59,COLON_CODE:58,unary_ops:{"-":1,"!":1,"~":1,"+":1},binary_ops:{"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},right_associative:new Set,additional_identifier_chars:new Set(["$","_"]),literals:{true:!0,false:!1,null:null},this_str:"this"}),E.max_unop_len=E.getMaxKeyLen(E.unary_ops),E.max_binop_len=E.getMaxKeyLen(E.binary_ops);var x=function(e){return new E(e).parse()};Object.getOwnPropertyNames(E).forEach((function(e){void 0===x[e]&&"prototype"!==e&&(x[e]=E[e])})),x.Jsep=E;var _={name:"ternary",init:function(e){e.hooks.add("after-expression",(function(t){if(t.node&&this.code===e.QUMARK_CODE){this.index++;var r=t.node,n=this.gobbleExpression();if(n||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===e.COLON_CODE){this.index++;var i=this.gobbleExpression();if(i||this.throwError("Expected expression"),t.node={type:"ConditionalExpression",test:r,consequent:n,alternate:i},r.operator&&e.binary_ops[r.operator]<=.9){for(var o=r;o.right.operator&&e.binary_ops[o.right.operator]<=.9;)o=o.right;t.node.test=o.right,o.right=t.node,t.node=r}}else this.throwError("Expected :")}}))}};x.plugins.register(_);var O={name:"regex",init:function(e){e.hooks.add("gobble-token",(function(t){if(47===this.code){for(var r=++this.index,n=!1;this.index=97&&a<=122||a>=65&&a<=90||a>=48&&a<=57))break;o+=this.char}var s=void 0;try{s=new RegExp(i,o)}catch(e){this.throwError(e.message)}return t.node={type:e.LITERAL,value:s,raw:this.expr.slice(r-1,this.index)},t.node=this.gobbleTokenProperty(t.node),t.node}this.code===e.OBRACK_CODE?n=!0:n&&this.code===e.CBRACK_CODE&&(n=!1),this.index+=92===this.code?2:1}this.throwError("Unclosed Regex")}}))}},m=Object.prototype.hasOwnProperty;function C(e,t){return(e=e.slice()).push(t),e}function D(e,t){return(t=t.slice()).unshift(e),t}var A=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&s(e,t)}(c,l(Error));var t,n,o=(t=c,n=u(),function(){var e,r=a(t);if(n){var i=a(this).constructor;e=Reflect.construct(r,arguments,i)}else e=r.apply(this,arguments);return h(this,e)});function c(e){var t;return r(this,c),(t=o.call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)')).avoidNew=!0,t.value=e,t.name="NewError",t}return i(c)}();function k(e,r,n,i,o){if(!(this instanceof k))try{return new k(e,r,n,i,o)}catch(e){if(!e.avoidNew)throw e;return e.value}"string"==typeof e&&(o=i,i=n,n=r,r=e,e=null);var a=e&&"object"===t(e);if(e=e||{},this.json=e.json||n,this.path=e.path||r,this.resultType=e.resultType||"value",this.flatten=e.flatten||!1,this.wrap=!m.call(e,"wrap")||e.wrap,this.sandbox=e.sandbox||{},this.preventEval=e.preventEval||!1,this.evalType=e.evalType||"safe",this.parent=e.parent||null,this.parentProperty=e.parentProperty||null,this.callback=e.callback||i||null,this.otherTypeCallback=e.otherTypeCallback||o||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==e.autostart){var s={path:a?e.path:r};a?"json"in e&&(s.json=e.json):s.json=n;var u=this.evaluate(s);if(!u||"object"!==t(u))throw new A(u);return u}}k.prototype.evaluate=function(e,r,n,i){var o=this,a=this.parent,s=this.parentProperty,u=this.flatten,c=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currEvalType=this.evalType,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=i||this.otherTypeCallback,r=r||this.json,(e=e||this.path)&&"object"===t(e)&&!Array.isArray(e)){if(!e.path&&""!==e.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!m.call(e,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');r=e.json,u=m.call(e,"flatten")?e.flatten:u,this.currResultType=m.call(e,"resultType")?e.resultType:this.currResultType,this.currSandbox=m.call(e,"sandbox")?e.sandbox:this.currSandbox,c=m.call(e,"wrap")?e.wrap:c,this.currPreventEval=m.call(e,"preventEval")?e.preventEval:this.currPreventEval,this.currEvalType=m.call(e,"evalType")?e.evalType:this.currEvalType,n=m.call(e,"callback")?e.callback:n,this.currOtherTypeCallback=m.call(e,"otherTypeCallback")?e.otherTypeCallback:this.currOtherTypeCallback,a=m.call(e,"parent")?e.parent:a,s=m.call(e,"parentProperty")?e.parentProperty:s,e=e.path}if(a=a||null,s=s||null,Array.isArray(e)&&(e=k.toPathString(e)),(e||""===e)&&r){var l=k.toPathArray(e);"$"===l[0]&&l.length>1&&l.shift(),this._hasParentSelector=null;var h=this._trace(l,r,["$"],a,s,n).filter((function(e){return e&&!e.isParentSelector}));return h.length?c||1!==h.length||h[0].hasArrExpr?h.reduce((function(e,t){var r=o._getPreferredOutput(t);return u&&Array.isArray(r)?e=e.concat(r):e.push(r),e}),[]):this._getPreferredOutput(h[0]):c?[]:void 0}},k.prototype._getPreferredOutput=function(e){var t=this.currResultType;switch(t){case"all":var r=Array.isArray(e.path)?e.path:k.toPathArray(e.path);return e.pointer=k.toPointer(r),e.path="string"==typeof e.path?e.path:k.toPathString(e.path),e;case"value":case"parent":case"parentProperty":return e[t];case"path":return k.toPathString(e[t]);case"pointer":return k.toPointer(e.path);default:throw new TypeError("Unknown result type")}},k.prototype._handleCallback=function(e,t,r){if(t){var n=this._getPreferredOutput(e);e.path="string"==typeof e.path?e.path:k.toPathString(e.path),t(n,r,e)}},k.prototype._trace=function(e,r,n,i,o,a,s,u){var c,l=this;if(!e.length)return c={path:n,value:r,parent:i,parentProperty:o,hasArrExpr:s},this._handleCallback(c,a,"value"),c;var h=e[0],p=e.slice(1),f=[];function y(e){Array.isArray(e)?e.forEach((function(e){f.push(e)})):f.push(e)}if(("string"!=typeof h||u)&&r&&m.call(r,h))y(this._trace(p,r[h],C(n,h),r,h,a,s));else if("*"===h)this._walk(r,(function(e){y(l._trace(p,r[e],C(n,e),r,e,a,!0,!0))}));else if(".."===h)y(this._trace(p,r,n,i,o,a,s)),this._walk(r,(function(i){"object"===t(r[i])&&y(l._trace(e.slice(),r[i],C(n,i),r,i,a,!0))}));else{if("^"===h)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:p,isParentSelector:!0};if("~"===h)return c={path:C(n,h),value:o,parent:i,parentProperty:null},this._handleCallback(c,a,"property"),c;if("$"===h)y(this._trace(p,r,n,null,null,a,s));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(h))y(this._slice(h,p,r,n,i,o,a));else if(0===h.indexOf("?(")){if(this.currPreventEval||"none"===this.currEvalType)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");var b=h.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1");this._walk(r,(function(e){l._eval(b,r[e],e,n,i,o)&&y(l._trace(p,r[e],C(n,e),r,e,a,!0))}))}else if("("===h[0]){if(this.currPreventEval||"none"===this.currEvalType)throw new Error("Eval [(expr)] prevented in JSONPath expression.");y(this._trace(D(this._eval(h,r,n[n.length-1],n.slice(0,-1),i,o),p),r,n,i,o,a,s))}else if("@"===h[0]){var v=!1,E=h.slice(1,-2);switch(E){case"scalar":r&&["object","function"].includes(t(r))||(v=!0);break;case"boolean":case"string":case"undefined":case"function":t(r)===E&&(v=!0);break;case"integer":!Number.isFinite(r)||r%1||(v=!0);break;case"number":Number.isFinite(r)&&(v=!0);break;case"nonFinite":"number"!=typeof r||Number.isFinite(r)||(v=!0);break;case"object":r&&t(r)===E&&(v=!0);break;case"array":Array.isArray(r)&&(v=!0);break;case"other":v=this.currOtherTypeCallback(r,n,i,o);break;case"null":null===r&&(v=!0);break;default:throw new TypeError("Unknown value type "+E)}if(v)return c={path:n,value:r,parent:i,parentProperty:o},this._handleCallback(c,a,"value"),c}else if("`"===h[0]&&r&&m.call(r,h.slice(1))){var g=h.slice(1);y(this._trace(p,r[g],C(n,g),r,g,a,s,!0))}else if(h.includes(",")){var x,_=d(h.split(","));try{for(_.s();!(x=_.n()).done;){var O=x.value;y(this._trace(D(O,p),r,n,i,o,a,!0))}}catch(e){_.e(e)}finally{_.f()}}else!u&&r&&m.call(r,h)&&y(this._trace(p,r[h],C(n,h),r,h,a,s,!0))}if(this._hasParentSelector)for(var A=0;A1&&void 0!==arguments[1]?arguments[1]:{},r=x(e);return w.evalAst(r,t)},evalAst:function(e,t){switch(e.type){case"BinaryExpression":case"LogicalExpression":return w.evalBinaryExpression(e,t);case"Compound":return w.evalCompound(e,t);case"ConditionalExpression":return w.evalConditionalExpression(e,t);case"Identifier":return w.evalIdentifier(e,t);case"Literal":return w.evalLiteral(e,t);case"MemberExpression":return w.evalMemberExpression(e,t);case"UnaryExpression":return w.evalUnaryExpression(e,t);case"ArrayExpression":return w.evalArrayExpression(e,t);case"CallExpression":return w.evalCallExpression(e,t);default:throw SyntaxError("Unexpected expression",e)}},evalBinaryExpression:function(e,t){return{"||":function(e,t){return e||t()},"&&":function(e,t){return e&&t()},"|":function(e,t){return e|t()},"^":function(e,t){return e^t()},"&":function(e,t){return e&t()},"==":function(e,t){return e==t()},"!=":function(e,t){return e!=t()},"===":function(e,t){return e===t()},"!==":function(e,t){return e!==t()},"<":function(e,t){return e":function(e,t){return e>t()},"<=":function(e,t){return e<=t()},">=":function(e,t){return e>=t()},"<<":function(e,t){return e<>":function(e,t){return e>>t()},">>>":function(e,t){return e>>>t()},"+":function(e,t){return e+t()},"-":function(e,t){return e-t()},"*":function(e,t){return e*t()},"/":function(e,t){return e/t()},"%":function(e,t){return e%t()}}[e.operator](w.evalAst(e.left,t),(function(){return w.evalAst(e.right,t)}))},evalCompound:function(e,t){var r,n,i=d(e.body);try{for(i.s();!(n=i.n()).done;){var o=n.value;r=this.evalAst(o,t)}}catch(e){i.e(e)}finally{i.f()}return r},evalConditionalExpression:function(e,t){return w.evalAst(e.test,t)?w.evalAst(e.consequent,t):w.evalAst(e.alternate,t)},evalIdentifier:function(e,t){if(e.name in t)return t[e.name];throw ReferenceError("".concat(e.name," is not defined"))},evalLiteral:function(e,t){return e.value},evalMemberExpression:function(e,t){var r=e.computed?w.evalAst(e.property):e.property.name,n=w.evalAst(e.object,t),i=n[r];return"function"==typeof i?i.bind(n):i},evalUnaryExpression:function(e,t){return{"-":function(e){return-w.evalAst(e)},"!":function(e){return!w.evalAst(e)},"~":function(e){return~w.evalAst(e)},"+":function(e){return+w.evalAst(e)}}[e.operator](e.argument)},evalArrayExpression:function(e,t){return e.elements.map((function(e){return w.evalAst(e,t)}))},evalCallExpression:function(e,t){var r=e.arguments.map((function(e){return w.evalAst(e,t)}));return w.evalAst(e.callee,t).apply(void 0,p(r))}},P=function(){function t(e){r(this,t),this.code=e}return i(t,[{key:"runInNewContext",value:function(t){var r=function(t){for(var r=1;r-1?t.slice(0,a+1)+" return "+t.slice(a+1):" return "+t;return c(Function,r.concat([s])).apply(void 0,p(i))}}]),e}();k.prototype.vm={Script:F},k.prototype.safeVm={Script:P};export{k as JSONPath}; //# sourceMappingURL=index-browser-esm.min.js.map diff --git a/dist/index-browser-esm.min.js.map b/dist/index-browser-esm.min.js.map index 2bcaa8a..f7af11a 100644 --- a/dist/index-browser-esm.min.js.map +++ b/dist/index-browser-esm.min.js.map @@ -1 +1 @@ -{"version":3,"file":"index-browser-esm.min.js","sources":["../src/jsonpath.js","../src/jsonpath-browser.js"],"sourcesContent":["const {hasOwnProperty: hasOwnProp} = Object.prototype;\n\n/**\n * @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject\n */\n\n/**\n * @typedef {any} AnyItem\n */\n\n/**\n * @typedef {any} AnyResult\n */\n\n/**\n * Copies array and then pushes item into it.\n * @param {GenericArray} arr Array to copy and into which to push\n * @param {AnyItem} item Array item to add (to end)\n * @returns {GenericArray} Copy of the original array\n */\nfunction push (arr, item) {\n arr = arr.slice();\n arr.push(item);\n return arr;\n}\n/**\n * Copies array and then unshifts item into it.\n * @param {AnyItem} item Array item to add (to beginning)\n * @param {GenericArray} arr Array to copy and into which to unshift\n * @returns {GenericArray} Copy of the original array\n */\nfunction unshift (item, arr) {\n arr = arr.slice();\n arr.unshift(item);\n return arr;\n}\n\n/**\n * Caught when JSONPath is used without `new` but rethrown if with `new`\n * @extends Error\n */\nclass NewError extends Error {\n /**\n * @param {AnyResult} value The evaluated scalar value\n */\n constructor (value) {\n super(\n 'JSONPath should not be called with \"new\" (it prevents return ' +\n 'of (unwrapped) scalar values)'\n );\n this.avoidNew = true;\n this.value = value;\n this.name = 'NewError';\n }\n}\n\n/**\n* @typedef {PlainObject} ReturnObject\n* @property {string} path\n* @property {JSONObject} value\n* @property {PlainObject|GenericArray} parent\n* @property {string} parentProperty\n*/\n\n/**\n* @callback JSONPathCallback\n* @param {string|PlainObject} preferredOutput\n* @param {\"value\"|\"property\"} type\n* @param {ReturnObject} fullRetObj\n* @returns {void}\n*/\n\n/**\n* @callback OtherTypeCallback\n* @param {JSONObject} val\n* @param {string} path\n* @param {PlainObject|GenericArray} parent\n* @param {string} parentPropName\n* @returns {boolean}\n*/\n\n/* eslint-disable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */\n/**\n * @typedef {PlainObject} JSONPathOptions\n * @property {JSON} json\n * @property {string|string[]} path\n * @property {\"value\"|\"path\"|\"pointer\"|\"parent\"|\"parentProperty\"|\"all\"} [resultType=\"value\"]\n * @property {boolean} [flatten=false]\n * @property {boolean} [wrap=true]\n * @property {PlainObject} [sandbox={}]\n * @property {boolean} [preventEval=false]\n * @property {PlainObject|GenericArray|null} [parent=null]\n * @property {string|null} [parentProperty=null]\n * @property {JSONPathCallback} [callback]\n * @property {OtherTypeCallback} [otherTypeCallback] Defaults to\n * function which throws on encountering `@other`\n * @property {boolean} [autostart=true]\n */\n/* eslint-enable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */\n\n/**\n * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`\n * @param {string} [expr] JSON path to evaluate\n * @param {JSON} [obj] JSON object to evaluate against\n * @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload\n * per `resultType`, 2) `\"value\"|\"property\"`, 3) Full returned object with\n * all payloads\n * @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end\n * of one's query, this will be invoked with the value of the item, its\n * path, its parent, and its parent's property name, and it should return\n * a boolean indicating whether the supplied value belongs to the \"other\"\n * type or not (or it may handle transformations and return `false`).\n * @returns {JSONPath}\n * @class\n */\nfunction JSONPath (opts, expr, obj, callback, otherTypeCallback) {\n // eslint-disable-next-line no-restricted-syntax\n if (!(this instanceof JSONPath)) {\n try {\n return new JSONPath(opts, expr, obj, callback, otherTypeCallback);\n } catch (e) {\n if (!e.avoidNew) {\n throw e;\n }\n return e.value;\n }\n }\n\n if (typeof opts === 'string') {\n otherTypeCallback = callback;\n callback = obj;\n obj = expr;\n expr = opts;\n opts = null;\n }\n const optObj = opts && typeof opts === 'object';\n opts = opts || {};\n this.json = opts.json || obj;\n this.path = opts.path || expr;\n this.resultType = opts.resultType || 'value';\n this.flatten = opts.flatten || false;\n this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;\n this.sandbox = opts.sandbox || {};\n this.preventEval = opts.preventEval || false;\n this.parent = opts.parent || null;\n this.parentProperty = opts.parentProperty || null;\n this.callback = opts.callback || callback || null;\n this.otherTypeCallback = opts.otherTypeCallback ||\n otherTypeCallback ||\n function () {\n throw new TypeError(\n 'You must supply an otherTypeCallback callback option ' +\n 'with the @other() operator.'\n );\n };\n\n if (opts.autostart !== false) {\n const args = {\n path: (optObj ? opts.path : expr)\n };\n if (!optObj) {\n args.json = obj;\n } else if ('json' in opts) {\n args.json = opts.json;\n }\n const ret = this.evaluate(args);\n if (!ret || typeof ret !== 'object') {\n throw new NewError(ret);\n }\n return ret;\n }\n}\n\n// PUBLIC METHODS\nJSONPath.prototype.evaluate = function (\n expr, json, callback, otherTypeCallback\n) {\n let currParent = this.parent,\n currParentProperty = this.parentProperty;\n let {flatten, wrap} = this;\n\n this.currResultType = this.resultType;\n this.currPreventEval = this.preventEval;\n this.currSandbox = this.sandbox;\n callback = callback || this.callback;\n this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;\n\n json = json || this.json;\n expr = expr || this.path;\n if (expr && typeof expr === 'object' && !Array.isArray(expr)) {\n if (!expr.path && expr.path !== '') {\n throw new TypeError(\n 'You must supply a \"path\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n if (!(hasOwnProp.call(expr, 'json'))) {\n throw new TypeError(\n 'You must supply a \"json\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n ({json} = expr);\n flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;\n this.currResultType = hasOwnProp.call(expr, 'resultType')\n ? expr.resultType\n : this.currResultType;\n this.currSandbox = hasOwnProp.call(expr, 'sandbox')\n ? expr.sandbox\n : this.currSandbox;\n wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;\n this.currPreventEval = hasOwnProp.call(expr, 'preventEval')\n ? expr.preventEval\n : this.currPreventEval;\n callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;\n this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback')\n ? expr.otherTypeCallback\n : this.currOtherTypeCallback;\n currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;\n currParentProperty = hasOwnProp.call(expr, 'parentProperty')\n ? expr.parentProperty\n : currParentProperty;\n expr = expr.path;\n }\n currParent = currParent || null;\n currParentProperty = currParentProperty || null;\n\n if (Array.isArray(expr)) {\n expr = JSONPath.toPathString(expr);\n }\n if ((!expr && expr !== '') || !json) {\n return undefined;\n }\n\n const exprList = JSONPath.toPathArray(expr);\n if (exprList[0] === '$' && exprList.length > 1) { exprList.shift(); }\n this._hasParentSelector = null;\n const result = this\n ._trace(\n exprList, json, ['$'], currParent, currParentProperty, callback\n )\n .filter(function (ea) { return ea && !ea.isParentSelector; });\n\n if (!result.length) { return wrap ? [] : undefined; }\n if (!wrap && result.length === 1 && !result[0].hasArrExpr) {\n return this._getPreferredOutput(result[0]);\n }\n return result.reduce((rslt, ea) => {\n const valOrPath = this._getPreferredOutput(ea);\n if (flatten && Array.isArray(valOrPath)) {\n rslt = rslt.concat(valOrPath);\n } else {\n rslt.push(valOrPath);\n }\n return rslt;\n }, []);\n};\n\n// PRIVATE METHODS\n\nJSONPath.prototype._getPreferredOutput = function (ea) {\n const resultType = this.currResultType;\n switch (resultType) {\n case 'all': {\n const path = Array.isArray(ea.path)\n ? ea.path\n : JSONPath.toPathArray(ea.path);\n ea.pointer = JSONPath.toPointer(path);\n ea.path = typeof ea.path === 'string'\n ? ea.path\n : JSONPath.toPathString(ea.path);\n return ea;\n } case 'value': case 'parent': case 'parentProperty':\n return ea[resultType];\n case 'path':\n return JSONPath.toPathString(ea[resultType]);\n case 'pointer':\n return JSONPath.toPointer(ea.path);\n default:\n throw new TypeError('Unknown result type');\n }\n};\n\nJSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {\n if (callback) {\n const preferredOutput = this._getPreferredOutput(fullRetObj);\n fullRetObj.path = typeof fullRetObj.path === 'string'\n ? fullRetObj.path\n : JSONPath.toPathString(fullRetObj.path);\n // eslint-disable-next-line n/callback-return\n callback(preferredOutput, type, fullRetObj);\n }\n};\n\n/**\n *\n * @param {string} expr\n * @param {JSONObject} val\n * @param {string} path\n * @param {PlainObject|GenericArray} parent\n * @param {string} parentPropName\n * @param {JSONPathCallback} callback\n * @param {boolean} hasArrExpr\n * @param {boolean} literalPriority\n * @returns {ReturnObject|ReturnObject[]}\n */\nJSONPath.prototype._trace = function (\n expr, val, path, parent, parentPropName, callback, hasArrExpr,\n literalPriority\n) {\n // No expr to follow? return path and value as the result of\n // this trace branch\n let retObj;\n if (!expr.length) {\n retObj = {\n path,\n value: val,\n parent,\n parentProperty: parentPropName,\n hasArrExpr\n };\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n\n const loc = expr[0], x = expr.slice(1);\n\n // We need to gather the return value of recursive trace calls in order to\n // do the parent sel computation.\n const ret = [];\n /**\n *\n * @param {ReturnObject|ReturnObject[]} elems\n * @returns {void}\n */\n function addRet (elems) {\n if (Array.isArray(elems)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test:\n // `ret.push(...elems);`\n elems.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(elems);\n }\n }\n if ((typeof loc !== 'string' || literalPriority) && val &&\n hasOwnProp.call(val, loc)\n ) { // simple case--directly follow property\n addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback,\n hasArrExpr));\n // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`\n } else if (loc === '*') { // all child properties\n this._walk(val, (m) => {\n addRet(this._trace(\n x, val[m], push(path, m), val, m, callback, true, true\n ));\n });\n } else if (loc === '..') { // all descendent parent properties\n // Check remaining expression with val's immediate children\n addRet(\n this._trace(x, val, path, parent, parentPropName, callback,\n hasArrExpr)\n );\n this._walk(val, (m) => {\n // We don't join m and x here because we only want parents,\n // not scalar values\n if (typeof val[m] === 'object') {\n // Keep going with recursive descent on val's\n // object children\n addRet(this._trace(\n expr.slice(), val[m], push(path, m), val, m, callback, true\n ));\n }\n });\n // The parent sel computation is handled in the frame above using the\n // ancestor object of val\n } else if (loc === '^') {\n // This is not a final endpoint, so we do not invoke the callback here\n this._hasParentSelector = true;\n return {\n path: path.slice(0, -1),\n expr: x,\n isParentSelector: true\n };\n } else if (loc === '~') { // property name\n retObj = {\n path: push(path, loc),\n value: parentPropName,\n parent,\n parentProperty: null\n };\n this._handleCallback(retObj, callback, 'property');\n return retObj;\n } else if (loc === '$') { // root only\n addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));\n } else if ((/^(-?\\d*):(-?\\d*):?(\\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax\n addRet(\n this._slice(loc, x, val, path, parent, parentPropName, callback)\n );\n } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering)\n if (this.currPreventEval) {\n throw new Error('Eval [?(expr)] prevented in JSONPath expression.');\n }\n const safeLoc = loc.replace(/^\\?\\((.*?)\\)$/u, '$1');\n this._walk(val, (m) => {\n if (this._eval(safeLoc, val[m], m, path, parent, parentPropName)) {\n addRet(this._trace(x, val[m], push(path, m), val, m, callback,\n true));\n }\n });\n } else if (loc[0] === '(') { // [(expr)] (dynamic property/index)\n if (this.currPreventEval) {\n throw new Error('Eval [(expr)] prevented in JSONPath expression.');\n }\n // As this will resolve to a property name (but we don't know it\n // yet), property and parent information is relative to the\n // parent of the property to which this expression will resolve\n addRet(this._trace(unshift(\n this._eval(\n loc, val, path[path.length - 1],\n path.slice(0, -1), parent, parentPropName\n ),\n x\n ), val, path, parent, parentPropName, callback, hasArrExpr));\n } else if (loc[0] === '@') { // value type: @boolean(), etc.\n let addType = false;\n const valueType = loc.slice(1, -2);\n switch (valueType) {\n case 'scalar':\n if (!val || !(['object', 'function'].includes(typeof val))) {\n addType = true;\n }\n break;\n case 'boolean': case 'string': case 'undefined': case 'function':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType) {\n addType = true;\n }\n break;\n case 'integer':\n if (Number.isFinite(val) && !(val % 1)) {\n addType = true;\n }\n break;\n case 'number':\n if (Number.isFinite(val)) {\n addType = true;\n }\n break;\n case 'nonFinite':\n if (typeof val === 'number' && !Number.isFinite(val)) {\n addType = true;\n }\n break;\n case 'object':\n // eslint-disable-next-line valid-typeof\n if (val && typeof val === valueType) {\n addType = true;\n }\n break;\n case 'array':\n if (Array.isArray(val)) {\n addType = true;\n }\n break;\n case 'other':\n addType = this.currOtherTypeCallback(\n val, path, parent, parentPropName\n );\n break;\n case 'null':\n if (val === null) {\n addType = true;\n }\n break;\n /* c8 ignore next 2 */\n default:\n throw new TypeError('Unknown value type ' + valueType);\n }\n if (addType) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n // `-escaped property\n } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {\n const locProp = loc.slice(1);\n addRet(this._trace(\n x, val[locProp], push(path, locProp), val, locProp, callback,\n hasArrExpr, true\n ));\n } else if (loc.includes(',')) { // [name1,name2,...]\n const parts = loc.split(',');\n for (const part of parts) {\n addRet(this._trace(\n unshift(part, x), val, path, parent, parentPropName, callback,\n true\n ));\n }\n // simple case--directly follow property\n } else if (\n !literalPriority && val && hasOwnProp.call(val, loc)\n ) {\n addRet(\n this._trace(x, val[loc], push(path, loc), val, loc, callback,\n hasArrExpr, true)\n );\n }\n\n // We check the resulting values for parent selections. For parent\n // selections we discard the value object and continue the trace with the\n // current val object\n if (this._hasParentSelector) {\n for (let t = 0; t < ret.length; t++) {\n const rett = ret[t];\n if (rett && rett.isParentSelector) {\n const tmp = this._trace(\n rett.expr, val, rett.path, parent, parentPropName, callback,\n hasArrExpr\n );\n if (Array.isArray(tmp)) {\n ret[t] = tmp[0];\n const tl = tmp.length;\n for (let tt = 1; tt < tl; tt++) {\n t++;\n ret.splice(t, 0, tmp[tt]);\n }\n } else {\n ret[t] = tmp;\n }\n }\n }\n }\n return ret;\n};\n\nJSONPath.prototype._walk = function (val, f) {\n if (Array.isArray(val)) {\n const n = val.length;\n for (let i = 0; i < n; i++) {\n f(i);\n }\n } else if (val && typeof val === 'object') {\n Object.keys(val).forEach((m) => {\n f(m);\n });\n }\n};\n\nJSONPath.prototype._slice = function (\n loc, expr, val, path, parent, parentPropName, callback\n) {\n if (!Array.isArray(val)) { return undefined; }\n const len = val.length, parts = loc.split(':'),\n step = (parts[2] && Number.parseInt(parts[2])) || 1;\n let start = (parts[0] && Number.parseInt(parts[0])) || 0,\n end = (parts[1] && Number.parseInt(parts[1])) || len;\n start = (start < 0) ? Math.max(0, start + len) : Math.min(len, start);\n end = (end < 0) ? Math.max(0, end + len) : Math.min(len, end);\n const ret = [];\n for (let i = start; i < end; i += step) {\n const tmp = this._trace(\n unshift(i, expr), val, path, parent, parentPropName, callback, true\n );\n // Should only be possible to be an array here since first part of\n // ``unshift(i, expr)` passed in above would not be empty, nor `~`,\n // nor begin with `@` (as could return objects)\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test: `ret.push(...tmp);`\n tmp.forEach((t) => {\n ret.push(t);\n });\n }\n return ret;\n};\n\nJSONPath.prototype._eval = function (\n code, _v, _vname, path, parent, parentPropName\n) {\n this.currSandbox._$_parentProperty = parentPropName;\n this.currSandbox._$_parent = parent;\n this.currSandbox._$_property = _vname;\n this.currSandbox._$_root = this.json;\n this.currSandbox._$_v = _v;\n\n const containsPath = code.includes('@path');\n if (containsPath) {\n this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));\n }\n\n const scriptCacheKey = 'script:' + code;\n if (!JSONPath.cache[scriptCacheKey]) {\n let script = code\n .replace(/@parentProperty/gu, '_$_parentProperty')\n .replace(/@parent/gu, '_$_parent')\n .replace(/@property/gu, '_$_property')\n .replace(/@root/gu, '_$_root')\n .replace(/@([.\\s)[])/gu, '_$_v$1');\n if (containsPath) {\n script = script.replace(/@path/gu, '_$_path');\n }\n\n JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);\n }\n\n try {\n return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);\n } catch (e) {\n throw new Error('jsonPath: ' + e.message + ': ' + code);\n }\n};\n\n// PUBLIC CLASS PROPERTIES AND METHODS\n\n// Could store the cache object itself\nJSONPath.cache = {};\n\n/**\n * @param {string[]} pathArr Array to convert\n * @returns {string} The path string\n */\nJSONPath.toPathString = function (pathArr) {\n const x = pathArr, n = x.length;\n let p = '$';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += (/^[0-9*]+$/u).test(x[i]) ? ('[' + x[i] + ']') : (\"['\" + x[i] + \"']\");\n }\n }\n return p;\n};\n\n/**\n * @param {string} pointer JSON Path\n * @returns {string} JSON Pointer\n */\nJSONPath.toPointer = function (pointer) {\n const x = pointer, n = x.length;\n let p = '';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += '/' + x[i].toString()\n .replace(/~/gu, '~0')\n .replace(/\\//gu, '~1');\n }\n }\n return p;\n};\n\n/**\n * @param {string} expr Expression to convert\n * @returns {string[]}\n */\nJSONPath.toPathArray = function (expr) {\n const {cache} = JSONPath;\n if (cache[expr]) { return cache[expr].concat(); }\n const subx = [];\n const normalized = expr\n // Properties\n .replace(\n /@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\\(\\)/gu,\n ';$&;'\n )\n // Parenthetical evaluations (filtering and otherwise), directly\n // within brackets or single quotes\n .replace(/[['](\\??\\(.*?\\))[\\]']/gu, function ($0, $1) {\n return '[#' + (subx.push($1) - 1) + ']';\n })\n // Escape periods and tildes within properties\n .replace(/\\[['\"]([^'\\]]*)['\"]\\]/gu, function ($0, prop) {\n return \"['\" + prop\n .replace(/\\./gu, '%@%')\n .replace(/~/gu, '%%@@%%') +\n \"']\";\n })\n // Properties operator\n .replace(/~/gu, ';~;')\n // Split by property boundaries\n .replace(/['\"]?\\.['\"]?(?![^[]*\\])|\\[['\"]?/gu, ';')\n // Reinsert periods within properties\n .replace(/%@%/gu, '.')\n // Reinsert tildes within properties\n .replace(/%%@@%%/gu, '~')\n // Parent\n .replace(/(?:;)?(\\^+)(?:;)?/gu, function ($0, ups) {\n return ';' + ups.split('').join(';') + ';';\n })\n // Descendents\n .replace(/;;;|;;/gu, ';..;')\n // Remove trailing\n .replace(/;$|'?\\]|'$/gu, '');\n\n const exprList = normalized.split(';').map(function (exp) {\n const match = exp.match(/#(\\d+)/u);\n return !match || !match[1] ? exp : subx[match[1]];\n });\n cache[expr] = exprList;\n return cache[expr].concat();\n};\n\nexport {JSONPath};\n","import {JSONPath} from './jsonpath.js';\n\n/**\n * @typedef {any} ContextItem\n */\n\n/**\n * @typedef {any} EvaluatedResult\n */\n\n/**\n * @callback ConditionCallback\n * @param {ContextItem} item\n * @returns {boolean}\n */\n\n/**\n * Copy items out of one array into another.\n * @param {GenericArray} source Array with items to copy\n * @param {GenericArray} target Array to which to copy\n * @param {ConditionCallback} conditionCb Callback passed the current item;\n * will move item if evaluates to `true`\n * @returns {void}\n */\nconst moveToAnotherArray = function (source, target, conditionCb) {\n const il = source.length;\n for (let i = 0; i < il; i++) {\n const item = source[i];\n if (conditionCb(item)) {\n target.push(source.splice(i--, 1)[0]);\n }\n }\n};\n\n/**\n * In-browser replacement for NodeJS' VM.Script.\n */\nclass Script {\n /**\n * @param {string} expr Expression to evaluate\n */\n constructor (expr) {\n this.code = expr;\n }\n\n /**\n * @param {PlainObject} context Object whose items will be added\n * to evaluation\n * @returns {EvaluatedResult} Result of evaluated code\n */\n runInNewContext (context) {\n let expr = this.code;\n const keys = Object.keys(context);\n const funcs = [];\n moveToAnotherArray(keys, funcs, (key) => {\n return typeof context[key] === 'function';\n });\n const values = keys.map((vr, i) => {\n return context[vr];\n });\n\n const funcString = funcs.reduce((s, func) => {\n let fString = context[func].toString();\n if (!(/function/u).test(fString)) {\n fString = 'function ' + fString;\n }\n return 'var ' + func + '=' + fString + ';' + s;\n }, '');\n\n expr = funcString + expr;\n\n // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function\n if (!(/(['\"])use strict\\1/u).test(expr) &&\n !keys.includes('arguments')\n ) {\n expr = 'var arguments = undefined;' + expr;\n }\n\n // Remove last semi so `return` will be inserted before\n // the previous one instead, allowing for the return\n // of a bare ending expression\n expr = expr.replace(/;\\s*$/u, '');\n\n // Insert `return`\n const lastStatementEnd = expr.lastIndexOf(';');\n const code = (lastStatementEnd > -1\n ? expr.slice(0, lastStatementEnd + 1) +\n ' return ' + expr.slice(lastStatementEnd + 1)\n : ' return ' + expr);\n\n // eslint-disable-next-line no-new-func\n return (new Function(...keys, code))(...values);\n }\n}\n\nJSONPath.prototype.vm = {\n Script\n};\n\nexport {JSONPath};\n"],"names":["hasOwnProp","Object","prototype","hasOwnProperty","push","arr","item","slice","unshift","NewError","Error","value","_this","_classCallCheck","this","_super","call","avoidNew","name","JSONPath","opts","expr","obj","callback","otherTypeCallback","e","optObj","_typeof","json","path","resultType","flatten","wrap","sandbox","preventEval","parent","parentProperty","TypeError","autostart","args","ret","evaluate","_this2","currParent","currParentProperty","currResultType","currPreventEval","currSandbox","currOtherTypeCallback","Array","isArray","toPathString","exprList","toPathArray","length","shift","_hasParentSelector","result","_trace","filter","ea","isParentSelector","hasArrExpr","reduce","rslt","valOrPath","_getPreferredOutput","concat","undefined","pointer","toPointer","_handleCallback","fullRetObj","type","preferredOutput","val","parentPropName","literalPriority","retObj","_this3","loc","x","addRet","elems","forEach","t","_walk","m","test","_slice","indexOf","safeLoc","replace","_eval","addType","valueType","includes","Number","isFinite","locProp","_step","_iterator","_createForOfIteratorHelper","split","s","n","done","part","err","f","rett","tmp","tl","tt","splice","i","keys","len","parts","step","parseInt","start","end","Math","max","min","code","_v","_vname","_$_parentProperty","_$_parent","_$_property","_$_root","_$_v","containsPath","_$_path","scriptCacheKey","cache","script","vm","Script","runInNewContext","message","pathArr","p","toString","subx","$0","$1","prop","ups","join","map","exp","match","context","funcs","source","target","conditionCb","il","moveToAnotherArray","key","values","vr","funcString","func","fString","lastStatementEnd","lastIndexOf","_construct","Function","apply","_toConsumableArray"],"mappings":"4yFAAA,IAAuBA,EAAcC,OAAOC,UAArCC,eAoBP,SAASC,EAAMC,EAAKC,GAGhB,OAFAD,EAAMA,EAAIE,SACNH,KAAKE,GACFD,CACV,CAOD,SAASG,EAASF,EAAMD,GAGpB,OAFAA,EAAMA,EAAIE,SACNC,QAAQF,GACLD,CACV,KAMKI,ySAAiBC,0KAInB,SAAAD,EAAaE,GAAO,IAAAC,EAAA,OAAAC,EAAAC,KAAAL,IAChBG,EAAAG,EAAAC,KAAAF,KACI,+FAGCG,UAAW,EAChBL,EAAKD,MAAQA,EACbC,EAAKM,KAAO,WAPIN,CAQnB,gBA8DL,SAASO,EAAUC,EAAMC,EAAMC,EAAKC,EAAUC,GAE1C,KAAMV,gBAAgBK,GAClB,IACI,OAAO,IAAIA,EA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Q,yEAAU,KAGA6E,YAAY,KACpC3C,EAAQ0C,GAAoB,EAC5BnJ,EAAKd,MAAM,EAAGiK,EAAmB,GAC/B,WAAanJ,EAAKd,MAAMiK,EAAmB,GAC7C,WAAanJ,EAGnB,OAAOqJ,EAAKC,SAAYvD,UAAMU,KAAvB8C,WAAA,EAAAC,EAAiCV,GAC3C,UAGLhJ,EAASjB,UAAUyI,GAAK,CACpBC,OAAAA"} \ No newline at end of file +{"version":3,"file":"index-browser-esm.min.js","sources":["../node_modules/.pnpm/jsep@1.3.8/node_modules/jsep/dist/jsep.js","../node_modules/.pnpm/@jsep-plugin+regex@1.0.3_jsep@1.3.8/node_modules/@jsep-plugin/regex/dist/index.js","../src/jsonpath.js","../src/jsonpath-browser.js"],"sourcesContent":["/**\n * @implements {IHooks}\n */\nclass Hooks {\n\t/**\n\t * @callback HookCallback\n\t * @this {*|Jsep} this\n\t * @param {Jsep} env\n\t * @returns: void\n\t */\n\t/**\n\t * Adds the given callback to the list of callbacks for the given hook.\n\t *\n\t * The callback will be invoked when the hook it is registered for is run.\n\t *\n\t * One callback function can be registered to multiple hooks and the same hook multiple times.\n\t *\n\t * @param {string|object} name The name of the hook, or an object of callbacks keyed by name\n\t * @param {HookCallback|boolean} callback The callback function which is given environment variables.\n\t * @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom)\n\t * @public\n\t */\n\tadd(name, callback, first) {\n\t\tif (typeof arguments[0] != 'string') {\n\t\t\t// Multiple hook callbacks, keyed by name\n\t\t\tfor (let name in arguments[0]) {\n\t\t\t\tthis.add(name, arguments[0][name], arguments[1]);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t(Array.isArray(name) ? name : [name]).forEach(function (name) {\n\t\t\t\tthis[name] = this[name] || [];\n\n\t\t\t\tif (callback) {\n\t\t\t\t\tthis[name][first ? 'unshift' : 'push'](callback);\n\t\t\t\t}\n\t\t\t}, this);\n\t\t}\n\t}\n\n\t/**\n\t * Runs a hook invoking all registered callbacks with the given environment variables.\n\t *\n\t * Callbacks will be invoked synchronously and in the order in which they were registered.\n\t *\n\t * @param {string} name The name of the hook.\n\t * @param {Object} env The environment variables of the hook passed to all callbacks registered.\n\t * @public\n\t */\n\trun(name, env) {\n\t\tthis[name] = this[name] || [];\n\t\tthis[name].forEach(function (callback) {\n\t\t\tcallback.call(env && env.context ? env.context : env, env);\n\t\t});\n\t}\n}\n\n/**\n * @implements {IPlugins}\n */\nclass Plugins {\n\tconstructor(jsep) {\n\t\tthis.jsep = jsep;\n\t\tthis.registered = {};\n\t}\n\n\t/**\n\t * @callback PluginSetup\n\t * @this {Jsep} jsep\n\t * @returns: void\n\t */\n\t/**\n\t * Adds the given plugin(s) to the registry\n\t *\n\t * @param {object} plugins\n\t * @param {string} plugins.name The name of the plugin\n\t * @param {PluginSetup} plugins.init The init function\n\t * @public\n\t */\n\tregister(...plugins) {\n\t\tplugins.forEach((plugin) => {\n\t\t\tif (typeof plugin !== 'object' || !plugin.name || !plugin.init) {\n\t\t\t\tthrow new Error('Invalid JSEP plugin format');\n\t\t\t}\n\t\t\tif (this.registered[plugin.name]) {\n\t\t\t\t// already registered. Ignore.\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tplugin.init(this.jsep);\n\t\t\tthis.registered[plugin.name] = plugin;\n\t\t});\n\t}\n}\n\n// JavaScript Expression Parser (JSEP) 1.3.8\n\nclass Jsep {\n\t/**\n\t * @returns {string}\n\t */\n\tstatic get version() {\n\t\t// To be filled in by the template\n\t\treturn '1.3.8';\n\t}\n\n\t/**\n\t * @returns {string}\n\t */\n\tstatic toString() {\n\t\treturn 'JavaScript Expression Parser (JSEP) v' + Jsep.version;\n\t};\n\n\t// ==================== CONFIG ================================\n\t/**\n\t * @method addUnaryOp\n\t * @param {string} op_name The name of the unary op to add\n\t * @returns {Jsep}\n\t */\n\tstatic addUnaryOp(op_name) {\n\t\tJsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);\n\t\tJsep.unary_ops[op_name] = 1;\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method jsep.addBinaryOp\n\t * @param {string} op_name The name of the binary op to add\n\t * @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence\n\t * @param {boolean} [isRightAssociative=false] whether operator is right-associative\n\t * @returns {Jsep}\n\t */\n\tstatic addBinaryOp(op_name, precedence, isRightAssociative) {\n\t\tJsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);\n\t\tJsep.binary_ops[op_name] = precedence;\n\t\tif (isRightAssociative) {\n\t\t\tJsep.right_associative.add(op_name);\n\t\t}\n\t\telse {\n\t\t\tJsep.right_associative.delete(op_name);\n\t\t}\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method addIdentifierChar\n\t * @param {string} char The additional character to treat as a valid part of an identifier\n\t * @returns {Jsep}\n\t */\n\tstatic addIdentifierChar(char) {\n\t\tJsep.additional_identifier_chars.add(char);\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method addLiteral\n\t * @param {string} literal_name The name of the literal to add\n\t * @param {*} literal_value The value of the literal\n\t * @returns {Jsep}\n\t */\n\tstatic addLiteral(literal_name, literal_value) {\n\t\tJsep.literals[literal_name] = literal_value;\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeUnaryOp\n\t * @param {string} op_name The name of the unary op to remove\n\t * @returns {Jsep}\n\t */\n\tstatic removeUnaryOp(op_name) {\n\t\tdelete Jsep.unary_ops[op_name];\n\t\tif (op_name.length === Jsep.max_unop_len) {\n\t\t\tJsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);\n\t\t}\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeAllUnaryOps\n\t * @returns {Jsep}\n\t */\n\tstatic removeAllUnaryOps() {\n\t\tJsep.unary_ops = {};\n\t\tJsep.max_unop_len = 0;\n\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeIdentifierChar\n\t * @param {string} char The additional character to stop treating as a valid part of an identifier\n\t * @returns {Jsep}\n\t */\n\tstatic removeIdentifierChar(char) {\n\t\tJsep.additional_identifier_chars.delete(char);\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeBinaryOp\n\t * @param {string} op_name The name of the binary op to remove\n\t * @returns {Jsep}\n\t */\n\tstatic removeBinaryOp(op_name) {\n\t\tdelete Jsep.binary_ops[op_name];\n\n\t\tif (op_name.length === Jsep.max_binop_len) {\n\t\t\tJsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);\n\t\t}\n\t\tJsep.right_associative.delete(op_name);\n\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeAllBinaryOps\n\t * @returns {Jsep}\n\t */\n\tstatic removeAllBinaryOps() {\n\t\tJsep.binary_ops = {};\n\t\tJsep.max_binop_len = 0;\n\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeLiteral\n\t * @param {string} literal_name The name of the literal to remove\n\t * @returns {Jsep}\n\t */\n\tstatic removeLiteral(literal_name) {\n\t\tdelete Jsep.literals[literal_name];\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeAllLiterals\n\t * @returns {Jsep}\n\t */\n\tstatic removeAllLiterals() {\n\t\tJsep.literals = {};\n\n\t\treturn Jsep;\n\t}\n\t// ==================== END CONFIG ============================\n\n\n\t/**\n\t * @returns {string}\n\t */\n\tget char() {\n\t\treturn this.expr.charAt(this.index);\n\t}\n\n\t/**\n\t * @returns {number}\n\t */\n\tget code() {\n\t\treturn this.expr.charCodeAt(this.index);\n\t};\n\n\n\t/**\n\t * @param {string} expr a string with the passed in express\n\t * @returns Jsep\n\t */\n\tconstructor(expr) {\n\t\t// `index` stores the character number we are currently at\n\t\t// All of the gobbles below will modify `index` as we move along\n\t\tthis.expr = expr;\n\t\tthis.index = 0;\n\t}\n\n\t/**\n\t * static top-level parser\n\t * @returns {jsep.Expression}\n\t */\n\tstatic parse(expr) {\n\t\treturn (new Jsep(expr)).parse();\n\t}\n\n\t/**\n\t * Get the longest key length of any object\n\t * @param {object} obj\n\t * @returns {number}\n\t */\n\tstatic getMaxKeyLen(obj) {\n\t\treturn Math.max(0, ...Object.keys(obj).map(k => k.length));\n\t}\n\n\t/**\n\t * `ch` is a character code in the next three functions\n\t * @param {number} ch\n\t * @returns {boolean}\n\t */\n\tstatic isDecimalDigit(ch) {\n\t\treturn (ch >= 48 && ch <= 57); // 0...9\n\t}\n\n\t/**\n\t * Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float.\n\t * @param {string} op_val\n\t * @returns {number}\n\t */\n\tstatic binaryPrecedence(op_val) {\n\t\treturn Jsep.binary_ops[op_val] || 0;\n\t}\n\n\t/**\n\t * Looks for start of identifier\n\t * @param {number} ch\n\t * @returns {boolean}\n\t */\n\tstatic isIdentifierStart(ch) {\n\t\treturn (ch >= 65 && ch <= 90) || // A...Z\n\t\t\t(ch >= 97 && ch <= 122) || // a...z\n\t\t\t(ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)]) || // any non-ASCII that is not an operator\n\t\t\t(Jsep.additional_identifier_chars.has(String.fromCharCode(ch))); // additional characters\n\t}\n\n\t/**\n\t * @param {number} ch\n\t * @returns {boolean}\n\t */\n\tstatic isIdentifierPart(ch) {\n\t\treturn Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);\n\t}\n\n\t/**\n\t * throw error at index of the expression\n\t * @param {string} message\n\t * @throws\n\t */\n\tthrowError(message) {\n\t\tconst error = new Error(message + ' at character ' + this.index);\n\t\terror.index = this.index;\n\t\terror.description = message;\n\t\tthrow error;\n\t}\n\n\t/**\n\t * Run a given hook\n\t * @param {string} name\n\t * @param {jsep.Expression|false} [node]\n\t * @returns {?jsep.Expression}\n\t */\n\trunHook(name, node) {\n\t\tif (Jsep.hooks[name]) {\n\t\t\tconst env = { context: this, node };\n\t\t\tJsep.hooks.run(name, env);\n\t\t\treturn env.node;\n\t\t}\n\t\treturn node;\n\t}\n\n\t/**\n\t * Runs a given hook until one returns a node\n\t * @param {string} name\n\t * @returns {?jsep.Expression}\n\t */\n\tsearchHook(name) {\n\t\tif (Jsep.hooks[name]) {\n\t\t\tconst env = { context: this };\n\t\t\tJsep.hooks[name].find(function (callback) {\n\t\t\t\tcallback.call(env.context, env);\n\t\t\t\treturn env.node;\n\t\t\t});\n\t\t\treturn env.node;\n\t\t}\n\t}\n\n\t/**\n\t * Push `index` up to the next non-space character\n\t */\n\tgobbleSpaces() {\n\t\tlet ch = this.code;\n\t\t// Whitespace\n\t\twhile (ch === Jsep.SPACE_CODE\n\t\t|| ch === Jsep.TAB_CODE\n\t\t|| ch === Jsep.LF_CODE\n\t\t|| ch === Jsep.CR_CODE) {\n\t\t\tch = this.expr.charCodeAt(++this.index);\n\t\t}\n\t\tthis.runHook('gobble-spaces');\n\t}\n\n\t/**\n\t * Top-level method to parse all expressions and returns compound or single node\n\t * @returns {jsep.Expression}\n\t */\n\tparse() {\n\t\tthis.runHook('before-all');\n\t\tconst nodes = this.gobbleExpressions();\n\n\t\t// If there's only one expression just try returning the expression\n\t\tconst node = nodes.length === 1\n\t\t ? nodes[0]\n\t\t\t: {\n\t\t\t\ttype: Jsep.COMPOUND,\n\t\t\t\tbody: nodes\n\t\t\t};\n\t\treturn this.runHook('after-all', node);\n\t}\n\n\t/**\n\t * top-level parser (but can be reused within as well)\n\t * @param {number} [untilICode]\n\t * @returns {jsep.Expression[]}\n\t */\n\tgobbleExpressions(untilICode) {\n\t\tlet nodes = [], ch_i, node;\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tch_i = this.code;\n\n\t\t\t// Expressions can be separated by semicolons, commas, or just inferred without any\n\t\t\t// separators\n\t\t\tif (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {\n\t\t\t\tthis.index++; // ignore separators\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// Try to gobble each expression individually\n\t\t\t\tif (node = this.gobbleExpression()) {\n\t\t\t\t\tnodes.push(node);\n\t\t\t\t\t// If we weren't able to find a binary expression and are out of room, then\n\t\t\t\t\t// the expression passed in probably has too much\n\t\t\t\t}\n\t\t\t\telse if (this.index < this.expr.length) {\n\t\t\t\t\tif (ch_i === untilICode) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tthis.throwError('Unexpected \"' + this.char + '\"');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn nodes;\n\t}\n\n\t/**\n\t * The main parsing function.\n\t * @returns {?jsep.Expression}\n\t */\n\tgobbleExpression() {\n\t\tconst node = this.searchHook('gobble-expression') || this.gobbleBinaryExpression();\n\t\tthis.gobbleSpaces();\n\n\t\treturn this.runHook('after-expression', node);\n\t}\n\n\t/**\n\t * Search for the operation portion of the string (e.g. `+`, `===`)\n\t * Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)\n\t * and move down from 3 to 2 to 1 character until a matching binary operation is found\n\t * then, return that binary operation\n\t * @returns {string|boolean}\n\t */\n\tgobbleBinaryOp() {\n\t\tthis.gobbleSpaces();\n\t\tlet to_check = this.expr.substr(this.index, Jsep.max_binop_len);\n\t\tlet tc_len = to_check.length;\n\n\t\twhile (tc_len > 0) {\n\t\t\t// Don't accept a binary op when it is an identifier.\n\t\t\t// Binary ops that start with a identifier-valid character must be followed\n\t\t\t// by a non identifier-part valid character\n\t\t\tif (Jsep.binary_ops.hasOwnProperty(to_check) && (\n\t\t\t\t!Jsep.isIdentifierStart(this.code) ||\n\t\t\t\t(this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))\n\t\t\t)) {\n\t\t\t\tthis.index += tc_len;\n\t\t\t\treturn to_check;\n\t\t\t}\n\t\t\tto_check = to_check.substr(0, --tc_len);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * This function is responsible for gobbling an individual expression,\n\t * e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`\n\t * @returns {?jsep.BinaryExpression}\n\t */\n\tgobbleBinaryExpression() {\n\t\tlet node, biop, prec, stack, biop_info, left, right, i, cur_biop;\n\n\t\t// First, try to get the leftmost thing\n\t\t// Then, check to see if there's a binary operator operating on that leftmost thing\n\t\t// Don't gobbleBinaryOp without a left-hand-side\n\t\tleft = this.gobbleToken();\n\t\tif (!left) {\n\t\t\treturn left;\n\t\t}\n\t\tbiop = this.gobbleBinaryOp();\n\n\t\t// If there wasn't a binary operator, just return the leftmost node\n\t\tif (!biop) {\n\t\t\treturn left;\n\t\t}\n\n\t\t// Otherwise, we need to start a stack to properly place the binary operations in their\n\t\t// precedence structure\n\t\tbiop_info = { value: biop, prec: Jsep.binaryPrecedence(biop), right_a: Jsep.right_associative.has(biop) };\n\n\t\tright = this.gobbleToken();\n\n\t\tif (!right) {\n\t\t\tthis.throwError(\"Expected expression after \" + biop);\n\t\t}\n\n\t\tstack = [left, biop_info, right];\n\n\t\t// Properly deal with precedence using [recursive descent](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm)\n\t\twhile ((biop = this.gobbleBinaryOp())) {\n\t\t\tprec = Jsep.binaryPrecedence(biop);\n\n\t\t\tif (prec === 0) {\n\t\t\t\tthis.index -= biop.length;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tbiop_info = { value: biop, prec, right_a: Jsep.right_associative.has(biop) };\n\n\t\t\tcur_biop = biop;\n\n\t\t\t// Reduce: make a binary expression from the three topmost entries.\n\t\t\tconst comparePrev = prev => biop_info.right_a && prev.right_a\n\t\t\t\t? prec > prev.prec\n\t\t\t\t: prec <= prev.prec;\n\t\t\twhile ((stack.length > 2) && comparePrev(stack[stack.length - 2])) {\n\t\t\t\tright = stack.pop();\n\t\t\t\tbiop = stack.pop().value;\n\t\t\t\tleft = stack.pop();\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.BINARY_EXP,\n\t\t\t\t\toperator: biop,\n\t\t\t\t\tleft,\n\t\t\t\t\tright\n\t\t\t\t};\n\t\t\t\tstack.push(node);\n\t\t\t}\n\n\t\t\tnode = this.gobbleToken();\n\n\t\t\tif (!node) {\n\t\t\t\tthis.throwError(\"Expected expression after \" + cur_biop);\n\t\t\t}\n\n\t\t\tstack.push(biop_info, node);\n\t\t}\n\n\t\ti = stack.length - 1;\n\t\tnode = stack[i];\n\n\t\twhile (i > 1) {\n\t\t\tnode = {\n\t\t\t\ttype: Jsep.BINARY_EXP,\n\t\t\t\toperator: stack[i - 1].value,\n\t\t\t\tleft: stack[i - 2],\n\t\t\t\tright: node\n\t\t\t};\n\t\t\ti -= 2;\n\t\t}\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * An individual part of a binary expression:\n\t * e.g. `foo.bar(baz)`, `1`, `\"abc\"`, `(a % 2)` (because it's in parenthesis)\n\t * @returns {boolean|jsep.Expression}\n\t */\n\tgobbleToken() {\n\t\tlet ch, to_check, tc_len, node;\n\n\t\tthis.gobbleSpaces();\n\t\tnode = this.searchHook('gobble-token');\n\t\tif (node) {\n\t\t\treturn this.runHook('after-token', node);\n\t\t}\n\n\t\tch = this.code;\n\n\t\tif (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {\n\t\t\t// Char code 46 is a dot `.` which can start off a numeric literal\n\t\t\treturn this.gobbleNumericLiteral();\n\t\t}\n\n\t\tif (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {\n\t\t\t// Single or double quotes\n\t\t\tnode = this.gobbleStringLiteral();\n\t\t}\n\t\telse if (ch === Jsep.OBRACK_CODE) {\n\t\t\tnode = this.gobbleArray();\n\t\t}\n\t\telse {\n\t\t\tto_check = this.expr.substr(this.index, Jsep.max_unop_len);\n\t\t\ttc_len = to_check.length;\n\n\t\t\twhile (tc_len > 0) {\n\t\t\t\t// Don't accept an unary op when it is an identifier.\n\t\t\t\t// Unary ops that start with a identifier-valid character must be followed\n\t\t\t\t// by a non identifier-part valid character\n\t\t\t\tif (Jsep.unary_ops.hasOwnProperty(to_check) && (\n\t\t\t\t\t!Jsep.isIdentifierStart(this.code) ||\n\t\t\t\t\t(this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))\n\t\t\t\t)) {\n\t\t\t\t\tthis.index += tc_len;\n\t\t\t\t\tconst argument = this.gobbleToken();\n\t\t\t\t\tif (!argument) {\n\t\t\t\t\t\tthis.throwError('missing unaryOp argument');\n\t\t\t\t\t}\n\t\t\t\t\treturn this.runHook('after-token', {\n\t\t\t\t\t\ttype: Jsep.UNARY_EXP,\n\t\t\t\t\t\toperator: to_check,\n\t\t\t\t\t\targument,\n\t\t\t\t\t\tprefix: true\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tto_check = to_check.substr(0, --tc_len);\n\t\t\t}\n\n\t\t\tif (Jsep.isIdentifierStart(ch)) {\n\t\t\t\tnode = this.gobbleIdentifier();\n\t\t\t\tif (Jsep.literals.hasOwnProperty(node.name)) {\n\t\t\t\t\tnode = {\n\t\t\t\t\t\ttype: Jsep.LITERAL,\n\t\t\t\t\t\tvalue: Jsep.literals[node.name],\n\t\t\t\t\t\traw: node.name,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (node.name === Jsep.this_str) {\n\t\t\t\t\tnode = { type: Jsep.THIS_EXP };\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (ch === Jsep.OPAREN_CODE) { // open parenthesis\n\t\t\t\tnode = this.gobbleGroup();\n\t\t\t}\n\t\t}\n\n\t\tif (!node) {\n\t\t\treturn this.runHook('after-token', false);\n\t\t}\n\n\t\tnode = this.gobbleTokenProperty(node);\n\t\treturn this.runHook('after-token', node);\n\t}\n\n\t/**\n\t * Gobble properties of of identifiers/strings/arrays/groups.\n\t * e.g. `foo`, `bar.baz`, `foo['bar'].baz`\n\t * It also gobbles function calls:\n\t * e.g. `Math.acos(obj.angle)`\n\t * @param {jsep.Expression} node\n\t * @returns {jsep.Expression}\n\t */\n\tgobbleTokenProperty(node) {\n\t\tthis.gobbleSpaces();\n\n\t\tlet ch = this.code;\n\t\twhile (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {\n\t\t\tlet optional;\n\t\t\tif (ch === Jsep.QUMARK_CODE) {\n\t\t\t\tif (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\toptional = true;\n\t\t\t\tthis.index += 2;\n\t\t\t\tthis.gobbleSpaces();\n\t\t\t\tch = this.code;\n\t\t\t}\n\t\t\tthis.index++;\n\n\t\t\tif (ch === Jsep.OBRACK_CODE) {\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.MEMBER_EXP,\n\t\t\t\t\tcomputed: true,\n\t\t\t\t\tobject: node,\n\t\t\t\t\tproperty: this.gobbleExpression()\n\t\t\t\t};\n\t\t\t\tthis.gobbleSpaces();\n\t\t\t\tch = this.code;\n\t\t\t\tif (ch !== Jsep.CBRACK_CODE) {\n\t\t\t\t\tthis.throwError('Unclosed [');\n\t\t\t\t}\n\t\t\t\tthis.index++;\n\t\t\t}\n\t\t\telse if (ch === Jsep.OPAREN_CODE) {\n\t\t\t\t// A function call is being made; gobble all the arguments\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.CALL_EXP,\n\t\t\t\t\t'arguments': this.gobbleArguments(Jsep.CPAREN_CODE),\n\t\t\t\t\tcallee: node\n\t\t\t\t};\n\t\t\t}\n\t\t\telse if (ch === Jsep.PERIOD_CODE || optional) {\n\t\t\t\tif (optional) {\n\t\t\t\t\tthis.index--;\n\t\t\t\t}\n\t\t\t\tthis.gobbleSpaces();\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.MEMBER_EXP,\n\t\t\t\t\tcomputed: false,\n\t\t\t\t\tobject: node,\n\t\t\t\t\tproperty: this.gobbleIdentifier(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (optional) {\n\t\t\t\tnode.optional = true;\n\t\t\t} // else leave undefined for compatibility with esprima\n\n\t\t\tthis.gobbleSpaces();\n\t\t\tch = this.code;\n\t\t}\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to\n\t * keep track of everything in the numeric literal and then calling `parseFloat` on that string\n\t * @returns {jsep.Literal}\n\t */\n\tgobbleNumericLiteral() {\n\t\tlet number = '', ch, chCode;\n\n\t\twhile (Jsep.isDecimalDigit(this.code)) {\n\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t}\n\n\t\tif (this.code === Jsep.PERIOD_CODE) { // can start with a decimal marker\n\t\t\tnumber += this.expr.charAt(this.index++);\n\n\t\t\twhile (Jsep.isDecimalDigit(this.code)) {\n\t\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\t}\n\t\t}\n\n\t\tch = this.char;\n\n\t\tif (ch === 'e' || ch === 'E') { // exponent marker\n\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\tch = this.char;\n\n\t\t\tif (ch === '+' || ch === '-') { // exponent sign\n\t\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\t}\n\n\t\t\twhile (Jsep.isDecimalDigit(this.code)) { // exponent itself\n\t\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\t}\n\n\t\t\tif (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1)) ) {\n\t\t\t\tthis.throwError('Expected exponent (' + number + this.char + ')');\n\t\t\t}\n\t\t}\n\n\t\tchCode = this.code;\n\n\t\t// Check to make sure this isn't a variable name that start with a number (123abc)\n\t\tif (Jsep.isIdentifierStart(chCode)) {\n\t\t\tthis.throwError('Variable names cannot start with a number (' +\n\t\t\t\tnumber + this.char + ')');\n\t\t}\n\t\telse if (chCode === Jsep.PERIOD_CODE || (number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE)) {\n\t\t\tthis.throwError('Unexpected period');\n\t\t}\n\n\t\treturn {\n\t\t\ttype: Jsep.LITERAL,\n\t\t\tvalue: parseFloat(number),\n\t\t\traw: number\n\t\t};\n\t}\n\n\t/**\n\t * Parses a string literal, staring with single or double quotes with basic support for escape codes\n\t * e.g. `\"hello world\"`, `'this is\\nJSEP'`\n\t * @returns {jsep.Literal}\n\t */\n\tgobbleStringLiteral() {\n\t\tlet str = '';\n\t\tconst startIndex = this.index;\n\t\tconst quote = this.expr.charAt(this.index++);\n\t\tlet closed = false;\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tlet ch = this.expr.charAt(this.index++);\n\n\t\t\tif (ch === quote) {\n\t\t\t\tclosed = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (ch === '\\\\') {\n\t\t\t\t// Check for all of the common escape codes\n\t\t\t\tch = this.expr.charAt(this.index++);\n\n\t\t\t\tswitch (ch) {\n\t\t\t\t\tcase 'n': str += '\\n'; break;\n\t\t\t\t\tcase 'r': str += '\\r'; break;\n\t\t\t\t\tcase 't': str += '\\t'; break;\n\t\t\t\t\tcase 'b': str += '\\b'; break;\n\t\t\t\t\tcase 'f': str += '\\f'; break;\n\t\t\t\t\tcase 'v': str += '\\x0B'; break;\n\t\t\t\t\tdefault : str += ch;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tstr += ch;\n\t\t\t}\n\t\t}\n\n\t\tif (!closed) {\n\t\t\tthis.throwError('Unclosed quote after \"' + str + '\"');\n\t\t}\n\n\t\treturn {\n\t\t\ttype: Jsep.LITERAL,\n\t\t\tvalue: str,\n\t\t\traw: this.expr.substring(startIndex, this.index),\n\t\t};\n\t}\n\n\t/**\n\t * Gobbles only identifiers\n\t * e.g.: `foo`, `_value`, `$x1`\n\t * Also, this function checks if that identifier is a literal:\n\t * (e.g. `true`, `false`, `null`) or `this`\n\t * @returns {jsep.Identifier}\n\t */\n\tgobbleIdentifier() {\n\t\tlet ch = this.code, start = this.index;\n\n\t\tif (Jsep.isIdentifierStart(ch)) {\n\t\t\tthis.index++;\n\t\t}\n\t\telse {\n\t\t\tthis.throwError('Unexpected ' + this.char);\n\t\t}\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tch = this.code;\n\n\t\t\tif (Jsep.isIdentifierPart(ch)) {\n\t\t\t\tthis.index++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\ttype: Jsep.IDENTIFIER,\n\t\t\tname: this.expr.slice(start, this.index),\n\t\t};\n\t}\n\n\t/**\n\t * Gobbles a list of arguments within the context of a function call\n\t * or array literal. This function also assumes that the opening character\n\t * `(` or `[` has already been gobbled, and gobbles expressions and commas\n\t * until the terminator character `)` or `]` is encountered.\n\t * e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`\n\t * @param {number} termination\n\t * @returns {jsep.Expression[]}\n\t */\n\tgobbleArguments(termination) {\n\t\tconst args = [];\n\t\tlet closed = false;\n\t\tlet separator_count = 0;\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tthis.gobbleSpaces();\n\t\t\tlet ch_i = this.code;\n\n\t\t\tif (ch_i === termination) { // done parsing\n\t\t\t\tclosed = true;\n\t\t\t\tthis.index++;\n\n\t\t\t\tif (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length){\n\t\t\t\t\tthis.throwError('Unexpected token ' + String.fromCharCode(termination));\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (ch_i === Jsep.COMMA_CODE) { // between expressions\n\t\t\t\tthis.index++;\n\t\t\t\tseparator_count++;\n\n\t\t\t\tif (separator_count !== args.length) { // missing argument\n\t\t\t\t\tif (termination === Jsep.CPAREN_CODE) {\n\t\t\t\t\t\tthis.throwError('Unexpected token ,');\n\t\t\t\t\t}\n\t\t\t\t\telse if (termination === Jsep.CBRACK_CODE) {\n\t\t\t\t\t\tfor (let arg = args.length; arg < separator_count; arg++) {\n\t\t\t\t\t\t\targs.push(null);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (args.length !== separator_count && separator_count !== 0) {\n\t\t\t\t// NOTE: `&& separator_count !== 0` allows for either all commas, or all spaces as arguments\n\t\t\t\tthis.throwError('Expected comma');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconst node = this.gobbleExpression();\n\n\t\t\t\tif (!node || node.type === Jsep.COMPOUND) {\n\t\t\t\t\tthis.throwError('Expected comma');\n\t\t\t\t}\n\n\t\t\t\targs.push(node);\n\t\t\t}\n\t\t}\n\n\t\tif (!closed) {\n\t\t\tthis.throwError('Expected ' + String.fromCharCode(termination));\n\t\t}\n\n\t\treturn args;\n\t}\n\n\t/**\n\t * Responsible for parsing a group of things within parentheses `()`\n\t * that have no identifier in front (so not a function call)\n\t * This function assumes that it needs to gobble the opening parenthesis\n\t * and then tries to gobble everything within that parenthesis, assuming\n\t * that the next thing it should see is the close parenthesis. If not,\n\t * then the expression probably doesn't have a `)`\n\t * @returns {boolean|jsep.Expression}\n\t */\n\tgobbleGroup() {\n\t\tthis.index++;\n\t\tlet nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);\n\t\tif (this.code === Jsep.CPAREN_CODE) {\n\t\t\tthis.index++;\n\t\t\tif (nodes.length === 1) {\n\t\t\t\treturn nodes[0];\n\t\t\t}\n\t\t\telse if (!nodes.length) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn {\n\t\t\t\t\ttype: Jsep.SEQUENCE_EXP,\n\t\t\t\t\texpressions: nodes,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tthis.throwError('Unclosed (');\n\t\t}\n\t}\n\n\t/**\n\t * Responsible for parsing Array literals `[1, 2, 3]`\n\t * This function assumes that it needs to gobble the opening bracket\n\t * and then tries to gobble the expressions as arguments.\n\t * @returns {jsep.ArrayExpression}\n\t */\n\tgobbleArray() {\n\t\tthis.index++;\n\n\t\treturn {\n\t\t\ttype: Jsep.ARRAY_EXP,\n\t\t\telements: this.gobbleArguments(Jsep.CBRACK_CODE)\n\t\t};\n\t}\n}\n\n// Static fields:\nconst hooks = new Hooks();\nObject.assign(Jsep, {\n\thooks,\n\tplugins: new Plugins(Jsep),\n\n\t// Node Types\n\t// ----------\n\t// This is the full set of types that any JSEP node can be.\n\t// Store them here to save space when minified\n\tCOMPOUND: 'Compound',\n\tSEQUENCE_EXP: 'SequenceExpression',\n\tIDENTIFIER: 'Identifier',\n\tMEMBER_EXP: 'MemberExpression',\n\tLITERAL: 'Literal',\n\tTHIS_EXP: 'ThisExpression',\n\tCALL_EXP: 'CallExpression',\n\tUNARY_EXP: 'UnaryExpression',\n\tBINARY_EXP: 'BinaryExpression',\n\tARRAY_EXP: 'ArrayExpression',\n\n\tTAB_CODE: 9,\n\tLF_CODE: 10,\n\tCR_CODE: 13,\n\tSPACE_CODE: 32,\n\tPERIOD_CODE: 46, // '.'\n\tCOMMA_CODE: 44, // ','\n\tSQUOTE_CODE: 39, // single quote\n\tDQUOTE_CODE: 34, // double quotes\n\tOPAREN_CODE: 40, // (\n\tCPAREN_CODE: 41, // )\n\tOBRACK_CODE: 91, // [\n\tCBRACK_CODE: 93, // ]\n\tQUMARK_CODE: 63, // ?\n\tSEMCOL_CODE: 59, // ;\n\tCOLON_CODE: 58, // :\n\n\n\t// Operations\n\t// ----------\n\t// Use a quickly-accessible map to store all of the unary operators\n\t// Values are set to `1` (it really doesn't matter)\n\tunary_ops: {\n\t\t'-': 1,\n\t\t'!': 1,\n\t\t'~': 1,\n\t\t'+': 1\n\t},\n\n\t// Also use a map for the binary operations but set their values to their\n\t// binary precedence for quick reference (higher number = higher precedence)\n\t// see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)\n\tbinary_ops: {\n\t\t'||': 1, '&&': 2, '|': 3, '^': 4, '&': 5,\n\t\t'==': 6, '!=': 6, '===': 6, '!==': 6,\n\t\t'<': 7, '>': 7, '<=': 7, '>=': 7,\n\t\t'<<': 8, '>>': 8, '>>>': 8,\n\t\t'+': 9, '-': 9,\n\t\t'*': 10, '/': 10, '%': 10\n\t},\n\n\t// sets specific binary_ops as right-associative\n\tright_associative: new Set(),\n\n\t// Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char)\n\tadditional_identifier_chars: new Set(['$', '_']),\n\n\t// Literals\n\t// ----------\n\t// Store the values to return for the various literals we may encounter\n\tliterals: {\n\t\t'true': true,\n\t\t'false': false,\n\t\t'null': null\n\t},\n\n\t// Except for `this`, which is special. This could be changed to something like `'self'` as well\n\tthis_str: 'this',\n});\nJsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);\nJsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);\n\n// Backward Compatibility:\nconst jsep = expr => (new Jsep(expr)).parse();\nconst staticMethods = Object.getOwnPropertyNames(Jsep);\nstaticMethods\n\t.forEach((m) => {\n\t\tif (jsep[m] === undefined && m !== 'prototype') {\n\t\t\tjsep[m] = Jsep[m];\n\t\t}\n\t});\njsep.Jsep = Jsep; // allows for const { Jsep } = require('jsep');\n\nconst CONDITIONAL_EXP = 'ConditionalExpression';\n\nvar ternary = {\n\tname: 'ternary',\n\n\tinit(jsep) {\n\t\t// Ternary expression: test ? consequent : alternate\n\t\tjsep.hooks.add('after-expression', function gobbleTernary(env) {\n\t\t\tif (env.node && this.code === jsep.QUMARK_CODE) {\n\t\t\t\tthis.index++;\n\t\t\t\tconst test = env.node;\n\t\t\t\tconst consequent = this.gobbleExpression();\n\n\t\t\t\tif (!consequent) {\n\t\t\t\t\tthis.throwError('Expected expression');\n\t\t\t\t}\n\n\t\t\t\tthis.gobbleSpaces();\n\n\t\t\t\tif (this.code === jsep.COLON_CODE) {\n\t\t\t\t\tthis.index++;\n\t\t\t\t\tconst alternate = this.gobbleExpression();\n\n\t\t\t\t\tif (!alternate) {\n\t\t\t\t\t\tthis.throwError('Expected expression');\n\t\t\t\t\t}\n\t\t\t\t\tenv.node = {\n\t\t\t\t\t\ttype: CONDITIONAL_EXP,\n\t\t\t\t\t\ttest,\n\t\t\t\t\t\tconsequent,\n\t\t\t\t\t\talternate,\n\t\t\t\t\t};\n\n\t\t\t\t\t// check for operators of higher priority than ternary (i.e. assignment)\n\t\t\t\t\t// jsep sets || at 1, and assignment at 0.9, and conditional should be between them\n\t\t\t\t\tif (test.operator && jsep.binary_ops[test.operator] <= 0.9) {\n\t\t\t\t\t\tlet newTest = test;\n\t\t\t\t\t\twhile (newTest.right.operator && jsep.binary_ops[newTest.right.operator] <= 0.9) {\n\t\t\t\t\t\t\tnewTest = newTest.right;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tenv.node.test = newTest.right;\n\t\t\t\t\t\tnewTest.right = env.node;\n\t\t\t\t\t\tenv.node = test;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis.throwError('Expected :');\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t},\n};\n\n// Add default plugins:\n\njsep.plugins.register(ternary);\n\nexport { Jsep, jsep as default };\n","const FSLASH_CODE = 47; // '/'\nconst BSLASH_CODE = 92; // '\\\\'\n\nvar index = {\n\tname: 'regex',\n\n\tinit(jsep) {\n\t\t// Regex literal: /abc123/ig\n\t\tjsep.hooks.add('gobble-token', function gobbleRegexLiteral(env) {\n\t\t\tif (this.code === FSLASH_CODE) {\n\t\t\t\tconst patternIndex = ++this.index;\n\n\t\t\t\tlet inCharSet = false;\n\t\t\t\twhile (this.index < this.expr.length) {\n\t\t\t\t\tif (this.code === FSLASH_CODE && !inCharSet) {\n\t\t\t\t\t\tconst pattern = this.expr.slice(patternIndex, this.index);\n\n\t\t\t\t\t\tlet flags = '';\n\t\t\t\t\t\twhile (++this.index < this.expr.length) {\n\t\t\t\t\t\t\tconst code = this.code;\n\t\t\t\t\t\t\tif ((code >= 97 && code <= 122) // a...z\n\t\t\t\t\t\t\t\t|| (code >= 65 && code <= 90) // A...Z\n\t\t\t\t\t\t\t\t|| (code >= 48 && code <= 57)) { // 0-9\n\t\t\t\t\t\t\t\tflags += this.char;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet value;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tvalue = new RegExp(pattern, flags);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\t\tthis.throwError(e.message);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tenv.node = {\n\t\t\t\t\t\t\ttype: jsep.LITERAL,\n\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\traw: this.expr.slice(patternIndex - 1, this.index),\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// allow . [] and () after regex: /regex/.test(a)\n\t\t\t\t\t\tenv.node = this.gobbleTokenProperty(env.node);\n\t\t\t\t\t\treturn env.node;\n\t\t\t\t\t}\n\t\t\t\t\tif (this.code === jsep.OBRACK_CODE) {\n\t\t\t\t\t\tinCharSet = true;\n\t\t\t\t\t}\n\t\t\t\t\telse if (inCharSet && this.code === jsep.CBRACK_CODE) {\n\t\t\t\t\t\tinCharSet = false;\n\t\t\t\t\t}\n\t\t\t\t\tthis.index += this.code === BSLASH_CODE ? 2 : 1;\n\t\t\t\t}\n\t\t\t\tthis.throwError('Unclosed Regex');\n\t\t\t}\n\t\t});\n\t},\n};\n\nexport { index as default };\n","const {hasOwnProperty: hasOwnProp} = Object.prototype;\n\n/**\n * @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject\n */\n\n/**\n * @typedef {any} AnyItem\n */\n\n/**\n * @typedef {any} AnyResult\n */\n\n/**\n * Copies array and then pushes item into it.\n * @param {GenericArray} arr Array to copy and into which to push\n * @param {AnyItem} item Array item to add (to end)\n * @returns {GenericArray} Copy of the original array\n */\nfunction push (arr, item) {\n arr = arr.slice();\n arr.push(item);\n return arr;\n}\n/**\n * Copies array and then unshifts item into it.\n * @param {AnyItem} item Array item to add (to beginning)\n * @param {GenericArray} arr Array to copy and into which to unshift\n * @returns {GenericArray} Copy of the original array\n */\nfunction unshift (item, arr) {\n arr = arr.slice();\n arr.unshift(item);\n return arr;\n}\n\n/**\n * Caught when JSONPath is used without `new` but rethrown if with `new`\n * @extends Error\n */\nclass NewError extends Error {\n /**\n * @param {AnyResult} value The evaluated scalar value\n */\n constructor (value) {\n super(\n 'JSONPath should not be called with \"new\" (it prevents return ' +\n 'of (unwrapped) scalar values)'\n );\n this.avoidNew = true;\n this.value = value;\n this.name = 'NewError';\n }\n}\n\n/**\n* @typedef {PlainObject} ReturnObject\n* @property {string} path\n* @property {JSONObject} value\n* @property {PlainObject|GenericArray} parent\n* @property {string} parentProperty\n*/\n\n/**\n* @callback JSONPathCallback\n* @param {string|PlainObject} preferredOutput\n* @param {\"value\"|\"property\"} type\n* @param {ReturnObject} fullRetObj\n* @returns {void}\n*/\n\n/**\n* @callback OtherTypeCallback\n* @param {JSONObject} val\n* @param {string} path\n* @param {PlainObject|GenericArray} parent\n* @param {string} parentPropName\n* @returns {boolean}\n*/\n\n/* eslint-disable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */\n/**\n * @typedef {PlainObject} JSONPathOptions\n * @property {JSON} json\n * @property {string|string[]} path\n * @property {\"value\"|\"path\"|\"pointer\"|\"parent\"|\"parentProperty\"|\"all\"} [resultType=\"value\"]\n * @property {boolean} [flatten=false]\n * @property {boolean} [wrap=true]\n * @property {PlainObject} [sandbox={}]\n * @property {boolean} [preventEval=false]\n * @property {\"safe\"|\"native\"|\"none\"} [evalType='safe']\n * @property {PlainObject|GenericArray|null} [parent=null]\n * @property {string|null} [parentProperty=null]\n * @property {JSONPathCallback} [callback]\n * @property {OtherTypeCallback} [otherTypeCallback] Defaults to\n * function which throws on encountering `@other`\n * @property {boolean} [autostart=true]\n */\n/* eslint-enable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */\n\n/**\n * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`\n * @param {string} [expr] JSON path to evaluate\n * @param {JSON} [obj] JSON object to evaluate against\n * @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload\n * per `resultType`, 2) `\"value\"|\"property\"`, 3) Full returned object with\n * all payloads\n * @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end\n * of one's query, this will be invoked with the value of the item, its\n * path, its parent, and its parent's property name, and it should return\n * a boolean indicating whether the supplied value belongs to the \"other\"\n * type or not (or it may handle transformations and return `false`).\n * @returns {JSONPath}\n * @class\n */\nfunction JSONPath (opts, expr, obj, callback, otherTypeCallback) {\n // eslint-disable-next-line no-restricted-syntax\n if (!(this instanceof JSONPath)) {\n try {\n return new JSONPath(opts, expr, obj, callback, otherTypeCallback);\n } catch (e) {\n if (!e.avoidNew) {\n throw e;\n }\n return e.value;\n }\n }\n\n if (typeof opts === 'string') {\n otherTypeCallback = callback;\n callback = obj;\n obj = expr;\n expr = opts;\n opts = null;\n }\n const optObj = opts && typeof opts === 'object';\n opts = opts || {};\n this.json = opts.json || obj;\n this.path = opts.path || expr;\n this.resultType = opts.resultType || 'value';\n this.flatten = opts.flatten || false;\n this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;\n this.sandbox = opts.sandbox || {};\n this.preventEval = opts.preventEval || false;\n this.evalType = opts.evalType || 'safe';\n this.parent = opts.parent || null;\n this.parentProperty = opts.parentProperty || null;\n this.callback = opts.callback || callback || null;\n this.otherTypeCallback = opts.otherTypeCallback ||\n otherTypeCallback ||\n function () {\n throw new TypeError(\n 'You must supply an otherTypeCallback callback option ' +\n 'with the @other() operator.'\n );\n };\n\n if (opts.autostart !== false) {\n const args = {\n path: (optObj ? opts.path : expr)\n };\n if (!optObj) {\n args.json = obj;\n } else if ('json' in opts) {\n args.json = opts.json;\n }\n const ret = this.evaluate(args);\n if (!ret || typeof ret !== 'object') {\n throw new NewError(ret);\n }\n return ret;\n }\n}\n\n// PUBLIC METHODS\nJSONPath.prototype.evaluate = function (\n expr, json, callback, otherTypeCallback\n) {\n let currParent = this.parent,\n currParentProperty = this.parentProperty;\n let {flatten, wrap} = this;\n\n this.currResultType = this.resultType;\n this.currPreventEval = this.preventEval;\n this.currEvalType = this.evalType;\n this.currSandbox = this.sandbox;\n callback = callback || this.callback;\n this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;\n\n json = json || this.json;\n expr = expr || this.path;\n if (expr && typeof expr === 'object' && !Array.isArray(expr)) {\n if (!expr.path && expr.path !== '') {\n throw new TypeError(\n 'You must supply a \"path\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n if (!(hasOwnProp.call(expr, 'json'))) {\n throw new TypeError(\n 'You must supply a \"json\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n ({json} = expr);\n flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;\n this.currResultType = hasOwnProp.call(expr, 'resultType')\n ? expr.resultType\n : this.currResultType;\n this.currSandbox = hasOwnProp.call(expr, 'sandbox')\n ? expr.sandbox\n : this.currSandbox;\n wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;\n this.currPreventEval = hasOwnProp.call(expr, 'preventEval')\n ? expr.preventEval\n : this.currPreventEval;\n this.currEvalType = hasOwnProp.call(expr, 'evalType')\n ? expr.evalType\n : this.currEvalType;\n callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;\n this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback')\n ? expr.otherTypeCallback\n : this.currOtherTypeCallback;\n currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;\n currParentProperty = hasOwnProp.call(expr, 'parentProperty')\n ? expr.parentProperty\n : currParentProperty;\n expr = expr.path;\n }\n currParent = currParent || null;\n currParentProperty = currParentProperty || null;\n\n if (Array.isArray(expr)) {\n expr = JSONPath.toPathString(expr);\n }\n if ((!expr && expr !== '') || !json) {\n return undefined;\n }\n\n const exprList = JSONPath.toPathArray(expr);\n if (exprList[0] === '$' && exprList.length > 1) { exprList.shift(); }\n this._hasParentSelector = null;\n const result = this\n ._trace(\n exprList, json, ['$'], currParent, currParentProperty, callback\n )\n .filter(function (ea) { return ea && !ea.isParentSelector; });\n\n if (!result.length) { return wrap ? [] : undefined; }\n if (!wrap && result.length === 1 && !result[0].hasArrExpr) {\n return this._getPreferredOutput(result[0]);\n }\n return result.reduce((rslt, ea) => {\n const valOrPath = this._getPreferredOutput(ea);\n if (flatten && Array.isArray(valOrPath)) {\n rslt = rslt.concat(valOrPath);\n } else {\n rslt.push(valOrPath);\n }\n return rslt;\n }, []);\n};\n\n// PRIVATE METHODS\n\nJSONPath.prototype._getPreferredOutput = function (ea) {\n const resultType = this.currResultType;\n switch (resultType) {\n case 'all': {\n const path = Array.isArray(ea.path)\n ? ea.path\n : JSONPath.toPathArray(ea.path);\n ea.pointer = JSONPath.toPointer(path);\n ea.path = typeof ea.path === 'string'\n ? ea.path\n : JSONPath.toPathString(ea.path);\n return ea;\n } case 'value': case 'parent': case 'parentProperty':\n return ea[resultType];\n case 'path':\n return JSONPath.toPathString(ea[resultType]);\n case 'pointer':\n return JSONPath.toPointer(ea.path);\n default:\n throw new TypeError('Unknown result type');\n }\n};\n\nJSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {\n if (callback) {\n const preferredOutput = this._getPreferredOutput(fullRetObj);\n fullRetObj.path = typeof fullRetObj.path === 'string'\n ? fullRetObj.path\n : JSONPath.toPathString(fullRetObj.path);\n // eslint-disable-next-line n/callback-return\n callback(preferredOutput, type, fullRetObj);\n }\n};\n\n/**\n *\n * @param {string} expr\n * @param {JSONObject} val\n * @param {string} path\n * @param {PlainObject|GenericArray} parent\n * @param {string} parentPropName\n * @param {JSONPathCallback} callback\n * @param {boolean} hasArrExpr\n * @param {boolean} literalPriority\n * @returns {ReturnObject|ReturnObject[]}\n */\nJSONPath.prototype._trace = function (\n expr, val, path, parent, parentPropName, callback, hasArrExpr,\n literalPriority\n) {\n // No expr to follow? return path and value as the result of\n // this trace branch\n let retObj;\n if (!expr.length) {\n retObj = {\n path,\n value: val,\n parent,\n parentProperty: parentPropName,\n hasArrExpr\n };\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n\n const loc = expr[0], x = expr.slice(1);\n\n // We need to gather the return value of recursive trace calls in order to\n // do the parent sel computation.\n const ret = [];\n /**\n *\n * @param {ReturnObject|ReturnObject[]} elems\n * @returns {void}\n */\n function addRet (elems) {\n if (Array.isArray(elems)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test:\n // `ret.push(...elems);`\n elems.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(elems);\n }\n }\n if ((typeof loc !== 'string' || literalPriority) && val &&\n hasOwnProp.call(val, loc)\n ) { // simple case--directly follow property\n addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback,\n hasArrExpr));\n // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`\n } else if (loc === '*') { // all child properties\n this._walk(val, (m) => {\n addRet(this._trace(\n x, val[m], push(path, m), val, m, callback, true, true\n ));\n });\n } else if (loc === '..') { // all descendent parent properties\n // Check remaining expression with val's immediate children\n addRet(\n this._trace(x, val, path, parent, parentPropName, callback,\n hasArrExpr)\n );\n this._walk(val, (m) => {\n // We don't join m and x here because we only want parents,\n // not scalar values\n if (typeof val[m] === 'object') {\n // Keep going with recursive descent on val's\n // object children\n addRet(this._trace(\n expr.slice(), val[m], push(path, m), val, m, callback, true\n ));\n }\n });\n // The parent sel computation is handled in the frame above using the\n // ancestor object of val\n } else if (loc === '^') {\n // This is not a final endpoint, so we do not invoke the callback here\n this._hasParentSelector = true;\n return {\n path: path.slice(0, -1),\n expr: x,\n isParentSelector: true\n };\n } else if (loc === '~') { // property name\n retObj = {\n path: push(path, loc),\n value: parentPropName,\n parent,\n parentProperty: null\n };\n this._handleCallback(retObj, callback, 'property');\n return retObj;\n } else if (loc === '$') { // root only\n addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));\n } else if ((/^(-?\\d*):(-?\\d*):?(\\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax\n addRet(\n this._slice(loc, x, val, path, parent, parentPropName, callback)\n );\n } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering)\n if (this.currPreventEval || this.currEvalType === 'none') {\n throw new Error('Eval [?(expr)] prevented in JSONPath expression.');\n }\n const safeLoc = loc.replace(/^\\?\\((.*?)\\)$/u, '$1');\n this._walk(val, (m) => {\n if (this._eval(safeLoc, val[m], m, path, parent, parentPropName)) {\n addRet(this._trace(x, val[m], push(path, m), val, m, callback,\n true));\n }\n });\n } else if (loc[0] === '(') { // [(expr)] (dynamic property/index)\n if (this.currPreventEval || this.currEvalType === 'none') {\n throw new Error('Eval [(expr)] prevented in JSONPath expression.');\n }\n // As this will resolve to a property name (but we don't know it\n // yet), property and parent information is relative to the\n // parent of the property to which this expression will resolve\n addRet(this._trace(unshift(\n this._eval(\n loc, val, path[path.length - 1],\n path.slice(0, -1), parent, parentPropName\n ),\n x\n ), val, path, parent, parentPropName, callback, hasArrExpr));\n } else if (loc[0] === '@') { // value type: @boolean(), etc.\n let addType = false;\n const valueType = loc.slice(1, -2);\n switch (valueType) {\n case 'scalar':\n if (!val || !(['object', 'function'].includes(typeof val))) {\n addType = true;\n }\n break;\n case 'boolean': case 'string': case 'undefined': case 'function':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType) {\n addType = true;\n }\n break;\n case 'integer':\n if (Number.isFinite(val) && !(val % 1)) {\n addType = true;\n }\n break;\n case 'number':\n if (Number.isFinite(val)) {\n addType = true;\n }\n break;\n case 'nonFinite':\n if (typeof val === 'number' && !Number.isFinite(val)) {\n addType = true;\n }\n break;\n case 'object':\n // eslint-disable-next-line valid-typeof\n if (val && typeof val === valueType) {\n addType = true;\n }\n break;\n case 'array':\n if (Array.isArray(val)) {\n addType = true;\n }\n break;\n case 'other':\n addType = this.currOtherTypeCallback(\n val, path, parent, parentPropName\n );\n break;\n case 'null':\n if (val === null) {\n addType = true;\n }\n break;\n /* c8 ignore next 2 */\n default:\n throw new TypeError('Unknown value type ' + valueType);\n }\n if (addType) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n // `-escaped property\n } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {\n const locProp = loc.slice(1);\n addRet(this._trace(\n x, val[locProp], push(path, locProp), val, locProp, callback,\n hasArrExpr, true\n ));\n } else if (loc.includes(',')) { // [name1,name2,...]\n const parts = loc.split(',');\n for (const part of parts) {\n addRet(this._trace(\n unshift(part, x), val, path, parent, parentPropName, callback,\n true\n ));\n }\n // simple case--directly follow property\n } else if (\n !literalPriority && val && hasOwnProp.call(val, loc)\n ) {\n addRet(\n this._trace(x, val[loc], push(path, loc), val, loc, callback,\n hasArrExpr, true)\n );\n }\n\n // We check the resulting values for parent selections. For parent\n // selections we discard the value object and continue the trace with the\n // current val object\n if (this._hasParentSelector) {\n for (let t = 0; t < ret.length; t++) {\n const rett = ret[t];\n if (rett && rett.isParentSelector) {\n const tmp = this._trace(\n rett.expr, val, rett.path, parent, parentPropName, callback,\n hasArrExpr\n );\n if (Array.isArray(tmp)) {\n ret[t] = tmp[0];\n const tl = tmp.length;\n for (let tt = 1; tt < tl; tt++) {\n t++;\n ret.splice(t, 0, tmp[tt]);\n }\n } else {\n ret[t] = tmp;\n }\n }\n }\n }\n return ret;\n};\n\nJSONPath.prototype._walk = function (val, f) {\n if (Array.isArray(val)) {\n const n = val.length;\n for (let i = 0; i < n; i++) {\n f(i);\n }\n } else if (val && typeof val === 'object') {\n Object.keys(val).forEach((m) => {\n f(m);\n });\n }\n};\n\nJSONPath.prototype._slice = function (\n loc, expr, val, path, parent, parentPropName, callback\n) {\n if (!Array.isArray(val)) { return undefined; }\n const len = val.length, parts = loc.split(':'),\n step = (parts[2] && Number.parseInt(parts[2])) || 1;\n let start = (parts[0] && Number.parseInt(parts[0])) || 0,\n end = (parts[1] && Number.parseInt(parts[1])) || len;\n start = (start < 0) ? Math.max(0, start + len) : Math.min(len, start);\n end = (end < 0) ? Math.max(0, end + len) : Math.min(len, end);\n const ret = [];\n for (let i = start; i < end; i += step) {\n const tmp = this._trace(\n unshift(i, expr), val, path, parent, parentPropName, callback, true\n );\n // Should only be possible to be an array here since first part of\n // ``unshift(i, expr)` passed in above would not be empty, nor `~`,\n // nor begin with `@` (as could return objects)\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test: `ret.push(...tmp);`\n tmp.forEach((t) => {\n ret.push(t);\n });\n }\n return ret;\n};\n\nJSONPath.prototype._eval = function (\n code, _v, _vname, path, parent, parentPropName\n) {\n this.currSandbox._$_parentProperty = parentPropName;\n this.currSandbox._$_parent = parent;\n this.currSandbox._$_property = _vname;\n this.currSandbox._$_root = this.json;\n this.currSandbox._$_v = _v;\n\n const containsPath = code.includes('@path');\n if (containsPath) {\n this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));\n }\n\n const scriptCacheKey = this.currEvalType + 'Script:' + code;\n if (!JSONPath.cache[scriptCacheKey]) {\n let script = code\n .replace(/@parentProperty/gu, '_$_parentProperty')\n .replace(/@parent/gu, '_$_parent')\n .replace(/@property/gu, '_$_property')\n .replace(/@root/gu, '_$_root')\n .replace(/@([.\\s)[])/gu, '_$_v$1');\n if (containsPath) {\n script = script.replace(/@path/gu, '_$_path');\n }\n if (this.currEvalType === 'safe') {\n JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);\n } else if (this.currEvalType === 'native') {\n JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);\n }\n }\n\n try {\n return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);\n } catch (e) {\n throw new Error('jsonPath: ' + e.message + ': ' + code);\n }\n};\n\n// PUBLIC CLASS PROPERTIES AND METHODS\n\n// Could store the cache object itself\nJSONPath.cache = {};\n\n/**\n * @param {string[]} pathArr Array to convert\n * @returns {string} The path string\n */\nJSONPath.toPathString = function (pathArr) {\n const x = pathArr, n = x.length;\n let p = '$';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += (/^[0-9*]+$/u).test(x[i]) ? ('[' + x[i] + ']') : (\"['\" + x[i] + \"']\");\n }\n }\n return p;\n};\n\n/**\n * @param {string} pointer JSON Path\n * @returns {string} JSON Pointer\n */\nJSONPath.toPointer = function (pointer) {\n const x = pointer, n = x.length;\n let p = '';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += '/' + x[i].toString()\n .replace(/~/gu, '~0')\n .replace(/\\//gu, '~1');\n }\n }\n return p;\n};\n\n/**\n * @param {string} expr Expression to convert\n * @returns {string[]}\n */\nJSONPath.toPathArray = function (expr) {\n const {cache} = JSONPath;\n if (cache[expr]) { return cache[expr].concat(); }\n const subx = [];\n const normalized = expr\n // Properties\n .replace(\n /@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\\(\\)/gu,\n ';$&;'\n )\n // Parenthetical evaluations (filtering and otherwise), directly\n // within brackets or single quotes\n .replace(/[['](\\??\\(.*?\\))[\\]']/gu, function ($0, $1) {\n return '[#' + (subx.push($1) - 1) + ']';\n })\n // Escape periods and tildes within properties\n .replace(/\\[['\"]([^'\\]]*)['\"]\\]/gu, function ($0, prop) {\n return \"['\" + prop\n .replace(/\\./gu, '%@%')\n .replace(/~/gu, '%%@@%%') +\n \"']\";\n })\n // Properties operator\n .replace(/~/gu, ';~;')\n // Split by property boundaries\n .replace(/['\"]?\\.['\"]?(?![^[]*\\])|\\[['\"]?/gu, ';')\n // Reinsert periods within properties\n .replace(/%@%/gu, '.')\n // Reinsert tildes within properties\n .replace(/%%@@%%/gu, '~')\n // Parent\n .replace(/(?:;)?(\\^+)(?:;)?/gu, function ($0, ups) {\n return ';' + ups.split('').join(';') + ';';\n })\n // Descendents\n .replace(/;;;|;;/gu, ';..;')\n // Remove trailing\n .replace(/;$|'?\\]|'$/gu, '');\n\n const exprList = normalized.split(';').map(function (exp) {\n const match = exp.match(/#(\\d+)/u);\n return !match || !match[1] ? exp : subx[match[1]];\n });\n cache[expr] = exprList;\n return cache[expr].concat();\n};\n\nexport {JSONPath};\n","/* eslint-disable no-bitwise */\nimport jsep from 'jsep';\nimport jsepRegex from '@jsep-plugin/regex';\nimport {JSONPath} from './jsonpath.js';\n\n/**\n * @typedef {any} ContextItem\n */\n\n/**\n * @typedef {any} EvaluatedResult\n */\n\n/**\n * @callback ConditionCallback\n * @param {ContextItem} item\n * @returns {boolean}\n */\n\n/**\n * Copy items out of one array into another.\n * @param {GenericArray} source Array with items to copy\n * @param {GenericArray} target Array to which to copy\n * @param {ConditionCallback} conditionCb Callback passed the current item;\n * will move item if evaluates to `true`\n * @returns {void}\n */\nconst moveToAnotherArray = function (source, target, conditionCb) {\n const il = source.length;\n for (let i = 0; i < il; i++) {\n const item = source[i];\n if (conditionCb(item)) {\n target.push(source.splice(i--, 1)[0]);\n }\n }\n};\n\n// register plugins\njsep.plugins.register(jsepRegex);\n\nconst SafeEval = {\n eval (code, substitions = {}) {\n const ast = jsep(code);\n return SafeEval.evalAst(ast, substitions);\n },\n /**\n * @param {jsep.Expression} ast\n * @param {Record} subs\n */\n evalAst (ast, subs) {\n switch (ast.type) {\n case 'BinaryExpression':\n case 'LogicalExpression':\n return SafeEval.evalBinaryExpression(ast, subs);\n case 'Compound':\n return SafeEval.evalCompound(ast, subs);\n case 'ConditionalExpression':\n return SafeEval.evalConditionalExpression(ast, subs);\n case 'Identifier':\n return SafeEval.evalIdentifier(ast, subs);\n case 'Literal':\n return SafeEval.evalLiteral(ast, subs);\n case 'MemberExpression':\n return SafeEval.evalMemberExpression(ast, subs);\n case 'UnaryExpression':\n return SafeEval.evalUnaryExpression(ast, subs);\n case 'ArrayExpression':\n return SafeEval.evalArrayExpression(ast, subs);\n case 'CallExpression':\n return SafeEval.evalCallExpression(ast, subs);\n default:\n throw SyntaxError('Unexpected expression', ast);\n }\n },\n evalBinaryExpression (ast, subs) {\n const result = ({\n '||': (a, b) => a || b(),\n '&&': (a, b) => a && b(),\n '|': (a, b) => a | b(),\n '^': (a, b) => a ^ b(),\n '&': (a, b) => a & b(),\n // eslint-disable-next-line eqeqeq\n '==': (a, b) => a == b(),\n // eslint-disable-next-line eqeqeq\n '!=': (a, b) => a != b(),\n '===': (a, b) => a === b(),\n '!==': (a, b) => a !== b(),\n '<': (a, b) => a < b(),\n '>': (a, b) => a > b(),\n '<=': (a, b) => a <= b(),\n '>=': (a, b) => a >= b(),\n '<<': (a, b) => a << b(),\n '>>': (a, b) => a >> b(),\n '>>>': (a, b) => a >>> b(),\n '+': (a, b) => a + b(),\n '-': (a, b) => a - b(),\n '*': (a, b) => a * b(),\n '/': (a, b) => a / b(),\n '%': (a, b) => a % b()\n })[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));\n return result;\n },\n evalCompound (ast, subs) {\n let last;\n for (const expr of ast.body) {\n last = this.evalAst(expr, subs);\n }\n return last;\n },\n evalConditionalExpression (ast, subs) {\n if (SafeEval.evalAst(ast.test, subs)) {\n return SafeEval.evalAst(ast.consequent, subs);\n }\n return SafeEval.evalAst(ast.alternate, subs);\n },\n evalIdentifier (ast, subs) {\n if (ast.name in subs) {\n return subs[ast.name];\n }\n throw ReferenceError(`${ast.name} is not defined`);\n },\n evalLiteral (ast, subs) {\n return ast.value;\n },\n evalMemberExpression (ast, subs) {\n const prop = ast.computed\n ? SafeEval.evalAst(ast.property) // `object[property]`\n : ast.property.name; // `object.property` property is identifier\n const obj = SafeEval.evalAst(ast.object, subs);\n const result = obj[prop];\n if (typeof result === 'function') {\n return result.bind(obj); // arrow functions aren't affected by bind.\n }\n return result;\n },\n evalUnaryExpression (ast, subs) {\n const result = ({\n '-': (a) => -SafeEval.evalAst(a),\n '!': (a) => !SafeEval.evalAst(a),\n '~': (a) => ~SafeEval.evalAst(a),\n // eslint-disable-next-line no-implicit-coercion\n '+': (a) => +SafeEval.evalAst(a)\n })[ast.operator](ast.argument);\n return result;\n },\n evalArrayExpression (ast, subs) {\n return ast.elements.map((el) => SafeEval.evalAst(el, subs));\n },\n evalCallExpression (ast, subs) {\n const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));\n const func = SafeEval.evalAst(ast.callee, subs);\n return func(...args);\n }\n};\n\n/**\n * In-browser replacement for NodeJS' VM.Script.\n */\nclass SafeScript {\n /**\n * @param {string} expr Expression to evaluate\n */\n constructor (expr) {\n this.code = expr;\n }\n\n /**\n * @param {PlainObject} context Object whose items will be added\n * to evaluation\n * @returns {EvaluatedResult} Result of evaluated code\n */\n runInNewContext (context) {\n const keyMap = {...context};\n return SafeEval.eval(this.code, keyMap);\n }\n}\n\n/**\n * In-browser replacement for NodeJS' VM.Script.\n */\nclass Script {\n /**\n * @param {string} expr Expression to evaluate\n */\n constructor (expr) {\n this.code = expr;\n }\n\n /**\n * @param {PlainObject} context Object whose items will be added\n * to evaluation\n * @returns {EvaluatedResult} Result of evaluated code\n */\n runInNewContext (context) {\n let expr = this.code;\n const keys = Object.keys(context);\n const funcs = [];\n moveToAnotherArray(keys, funcs, (key) => {\n return typeof context[key] === 'function';\n });\n const values = keys.map((vr, i) => {\n return context[vr];\n });\n\n const funcString = funcs.reduce((s, func) => {\n let fString = context[func].toString();\n if (!(/function/u).test(fString)) {\n fString = 'function ' + fString;\n }\n return 'var ' + func + '=' + fString + ';' + s;\n }, '');\n\n expr = funcString + expr;\n\n // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function\n if (!(/(['\"])use strict\\1/u).test(expr) &&\n !keys.includes('arguments')\n ) {\n expr = 'var arguments = undefined;' + expr;\n }\n\n // Remove last semi so `return` will be inserted before\n // the previous one instead, allowing for the return\n // of a bare ending expression\n expr = expr.replace(/;\\s*$/u, '');\n\n // Insert `return`\n const lastStatementEnd = expr.lastIndexOf(';');\n const code = (lastStatementEnd > -1\n ? expr.slice(0, lastStatementEnd + 1) +\n ' return ' + expr.slice(lastStatementEnd + 1)\n : ' return ' + expr);\n\n // eslint-disable-next-line no-new-func\n return (new Function(...keys, code))(...values);\n }\n}\n\nJSONPath.prototype.vm = {\n Script\n};\n\nJSONPath.prototype.safeVm = {\n Script: SafeScript\n};\n\nexport {JSONPath};\n"],"names":["Hooks","name","callback","first","arguments","this","add","Array","isArray","forEach","env","call","context","Plugins","jsep","_classCallCheck","registered","_this","_len","length","plugins","_key","plugin","_typeof","init","Error","Jsep","expr","index","get","charAt","charCodeAt","message","error","description","node","hooks","run","value","find","ch","code","SPACE_CODE","TAB_CODE","LF_CODE","CR_CODE","runHook","nodes","gobbleExpressions","type","COMPOUND","body","untilICode","ch_i","SEMCOL_CODE","COMMA_CODE","gobbleExpression","push","throwError","searchHook","gobbleBinaryExpression","gobbleSpaces","to_check","substr","max_binop_len","tc_len","binary_ops","hasOwnProperty","isIdentifierStart","isIdentifierPart","biop","prec","stack","biop_info","left","right","i","cur_biop","prev","gobbleToken","gobbleBinaryOp","binaryPrecedence","right_a","right_associative","has","pop","BINARY_EXP","operator","isDecimalDigit","PERIOD_CODE","gobbleNumericLiteral","SQUOTE_CODE","DQUOTE_CODE","gobbleStringLiteral","OBRACK_CODE","gobbleArray","max_unop_len","unary_ops","argument","UNARY_EXP","prefix","gobbleIdentifier","literals","LITERAL","raw","this_str","THIS_EXP","OPAREN_CODE","gobbleGroup","gobbleTokenProperty","QUMARK_CODE","optional","MEMBER_EXP","computed","object","property","CBRACK_CODE","CALL_EXP","gobbleArguments","CPAREN_CODE","callee","chCode","number","parseFloat","str","startIndex","quote","closed","substring","start","IDENTIFIER","slice","termination","args","separator_count","String","fromCharCode","arg","SEQUENCE_EXP","expressions","ARRAY_EXP","elements","version","op_name","Math","max","precedence","isRightAssociative","char","additional_identifier_chars","literal_name","literal_value","getMaxKeyLen","parse","obj","concat","_toConsumableArray","Object","keys","map","k","op_val","assign","COLON_CODE","Set","true","false","null","getOwnPropertyNames","m","undefined","ternary","test","consequent","alternate","newTest","register","patternIndex","inCharSet","pattern","flags","RegExp","e","hasOwnProp","prototype","arr","item","unshift","NewError","_super","avoidNew","JSONPath","opts","otherTypeCallback","optObj","json","path","resultType","flatten","wrap","sandbox","preventEval","evalType","parent","parentProperty","TypeError","autostart","ret","evaluate","_this2","currParent","currParentProperty","currResultType","currPreventEval","currEvalType","currSandbox","currOtherTypeCallback","toPathString","exprList","toPathArray","shift","_hasParentSelector","result","_trace","filter","ea","isParentSelector","hasArrExpr","reduce","rslt","valOrPath","_getPreferredOutput","pointer","toPointer","_handleCallback","fullRetObj","preferredOutput","val","parentPropName","literalPriority","retObj","_this3","loc","x","addRet","elems","t","_walk","_slice","indexOf","safeLoc","replace","_eval","addType","valueType","includes","Number","isFinite","locProp","_step","_iterator","_createForOfIteratorHelper","split","s","n","done","part","err","f","rett","tmp","tl","tt","splice","len","parts","step","parseInt","end","min","_v","_vname","_$_parentProperty","_$_parent","_$_property","_$_root","_$_v","containsPath","_$_path","scriptCacheKey","cache","script","safeVm","Script","vm","runInNewContext","pathArr","p","toString","subx","$0","$1","prop","ups","join","exp","match","jsepRegex","SafeEval","eval","substitions","ast","evalAst","subs","evalBinaryExpression","evalCompound","evalConditionalExpression","evalIdentifier","evalLiteral","evalMemberExpression","evalUnaryExpression","evalArrayExpression","evalCallExpression","SyntaxError","a","b","last","ReferenceError","bind","el","apply","SafeScript","keyMap","funcs","source","target","conditionCb","il","moveToAnotherArray","key","values","vr","funcString","func","fString","lastStatementEnd","lastIndexOf","_construct","Function"],"mappings":"wwHAGMA,iEAmBL,SAAIC,EAAMC,EAAUC,GACnB,GAA2B,iBAAhBC,UAAU,GAEpB,IAAK,IAAIH,KAAQG,UAAU,GAC1BC,KAAKC,IAAIL,EAAMG,UAAU,GAAGH,GAAOG,UAAU,SAI7CG,MAAMC,QAAQP,GAAQA,EAAO,CAACA,IAAOQ,SAAQ,SAAUR,GACvDI,KAAKJ,GAAQI,KAAKJ,IAAS,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EAAKiG,SAAS,eAEfpO,EAAO,6BAA+BA,GAS1C,IAAM8T,GAHN9T,EAAOA,EAAKgO,QAAQ,yEAAU,KAGA+F,YAAY,KACpCjT,EAAQgT,GAAoB,EAC5B9T,EAAKwG,MAAM,EAAGsN,EAAmB,GAC/B,WAAa9T,EAAKwG,MAAMsN,EAAmB,GAC7C,WAAa9T,EAGnB,OAAOgU,EAAKC,SAAY9L,UAAMrH,KAAvBiS,WAAA,EAAA9K,EAAiCwL,GAC3C,UAGLrJ,EAASP,UAAU8G,GAAK,CACpBD,OAAAA,GAGJtG,EAASP,UAAU4G,OAAS,CACxBC,OAAQsC"} \ No newline at end of file diff --git a/dist/index-browser-umd.cjs b/dist/index-browser-umd.cjs index ba77064..8f7026d 100644 --- a/dist/index-browser-umd.cjs +++ b/dist/index-browser-umd.cjs @@ -4,6 +4,32 @@ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONPath = {})); })(this, (function (exports) { 'use strict'; + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + function _typeof(obj) { "@babel/helpers - typeof"; @@ -39,6 +65,21 @@ return Constructor; } + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); @@ -267,6 +308,1341 @@ }; } + /** + * @implements {IHooks} + */ + var Hooks = /*#__PURE__*/function () { + function Hooks() { + _classCallCheck(this, Hooks); + } + + _createClass(Hooks, [{ + key: "add", + value: + /** + * @callback HookCallback + * @this {*|Jsep} this + * @param {Jsep} env + * @returns: void + */ + + /** + * Adds the given callback to the list of callbacks for the given hook. + * + * The callback will be invoked when the hook it is registered for is run. + * + * One callback function can be registered to multiple hooks and the same hook multiple times. + * + * @param {string|object} name The name of the hook, or an object of callbacks keyed by name + * @param {HookCallback|boolean} callback The callback function which is given environment variables. + * @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom) + * @public + */ + function add(name, callback, first) { + if (typeof arguments[0] != 'string') { + // Multiple hook callbacks, keyed by name + for (var _name in arguments[0]) { + this.add(_name, arguments[0][_name], arguments[1]); + } + } else { + (Array.isArray(name) ? name : [name]).forEach(function (name) { + this[name] = this[name] || []; + + if (callback) { + this[name][first ? 'unshift' : 'push'](callback); + } + }, this); + } + } + /** + * Runs a hook invoking all registered callbacks with the given environment variables. + * + * Callbacks will be invoked synchronously and in the order in which they were registered. + * + * @param {string} name The name of the hook. + * @param {Object} env The environment variables of the hook passed to all callbacks registered. + * @public + */ + + }, { + key: "run", + value: function run(name, env) { + this[name] = this[name] || []; + this[name].forEach(function (callback) { + callback.call(env && env.context ? env.context : env, env); + }); + } + }]); + + return Hooks; + }(); + /** + * @implements {IPlugins} + */ + + + var Plugins = /*#__PURE__*/function () { + function Plugins(jsep) { + _classCallCheck(this, Plugins); + + this.jsep = jsep; + this.registered = {}; + } + /** + * @callback PluginSetup + * @this {Jsep} jsep + * @returns: void + */ + + /** + * Adds the given plugin(s) to the registry + * + * @param {object} plugins + * @param {string} plugins.name The name of the plugin + * @param {PluginSetup} plugins.init The init function + * @public + */ + + + _createClass(Plugins, [{ + key: "register", + value: function register() { + var _this = this; + + for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) { + plugins[_key] = arguments[_key]; + } + + plugins.forEach(function (plugin) { + if (_typeof(plugin) !== 'object' || !plugin.name || !plugin.init) { + throw new Error('Invalid JSEP plugin format'); + } + + if (_this.registered[plugin.name]) { + // already registered. Ignore. + return; + } + + plugin.init(_this.jsep); + _this.registered[plugin.name] = plugin; + }); + } + }]); + + return Plugins; + }(); // JavaScript Expression Parser (JSEP) 1.3.8 + + + var Jsep = /*#__PURE__*/function () { + /** + * @param {string} expr a string with the passed in express + * @returns Jsep + */ + function Jsep(expr) { + _classCallCheck(this, Jsep); + + // `index` stores the character number we are currently at + // All of the gobbles below will modify `index` as we move along + this.expr = expr; + this.index = 0; + } + /** + * static top-level parser + * @returns {jsep.Expression} + */ + + + _createClass(Jsep, [{ + key: "char", + get: // ==================== END CONFIG ============================ + + /** + * @returns {string} + */ + function get() { + return this.expr.charAt(this.index); + } + /** + * @returns {number} + */ + + }, { + key: "code", + get: function get() { + return this.expr.charCodeAt(this.index); + } + }, { + key: "throwError", + value: + /** + * throw error at index of the expression + * @param {string} message + * @throws + */ + function throwError(message) { + var error = new Error(message + ' at character ' + this.index); + error.index = this.index; + error.description = message; + throw error; + } + /** + * Run a given hook + * @param {string} name + * @param {jsep.Expression|false} [node] + * @returns {?jsep.Expression} + */ + + }, { + key: "runHook", + value: function runHook(name, node) { + if (Jsep.hooks[name]) { + var env = { + context: this, + node: node + }; + Jsep.hooks.run(name, env); + return env.node; + } + + return node; + } + /** + * Runs a given hook until one returns a node + * @param {string} name + * @returns {?jsep.Expression} + */ + + }, { + key: "searchHook", + value: function searchHook(name) { + if (Jsep.hooks[name]) { + var env = { + context: this + }; + Jsep.hooks[name].find(function (callback) { + callback.call(env.context, env); + return env.node; + }); + return env.node; + } + } + /** + * Push `index` up to the next non-space character + */ + + }, { + key: "gobbleSpaces", + value: function gobbleSpaces() { + var ch = this.code; // Whitespace + + while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) { + ch = this.expr.charCodeAt(++this.index); + } + + this.runHook('gobble-spaces'); + } + /** + * Top-level method to parse all expressions and returns compound or single node + * @returns {jsep.Expression} + */ + + }, { + key: "parse", + value: function parse() { + this.runHook('before-all'); + var nodes = this.gobbleExpressions(); // If there's only one expression just try returning the expression + + var node = nodes.length === 1 ? nodes[0] : { + type: Jsep.COMPOUND, + body: nodes + }; + return this.runHook('after-all', node); + } + /** + * top-level parser (but can be reused within as well) + * @param {number} [untilICode] + * @returns {jsep.Expression[]} + */ + + }, { + key: "gobbleExpressions", + value: function gobbleExpressions(untilICode) { + var nodes = [], + ch_i, + node; + + while (this.index < this.expr.length) { + ch_i = this.code; // Expressions can be separated by semicolons, commas, or just inferred without any + // separators + + if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) { + this.index++; // ignore separators + } else { + // Try to gobble each expression individually + if (node = this.gobbleExpression()) { + nodes.push(node); // If we weren't able to find a binary expression and are out of room, then + // the expression passed in probably has too much + } else if (this.index < this.expr.length) { + if (ch_i === untilICode) { + break; + } + + this.throwError('Unexpected "' + this["char"] + '"'); + } + } + } + + return nodes; + } + /** + * The main parsing function. + * @returns {?jsep.Expression} + */ + + }, { + key: "gobbleExpression", + value: function gobbleExpression() { + var node = this.searchHook('gobble-expression') || this.gobbleBinaryExpression(); + this.gobbleSpaces(); + return this.runHook('after-expression', node); + } + /** + * Search for the operation portion of the string (e.g. `+`, `===`) + * Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`) + * and move down from 3 to 2 to 1 character until a matching binary operation is found + * then, return that binary operation + * @returns {string|boolean} + */ + + }, { + key: "gobbleBinaryOp", + value: function gobbleBinaryOp() { + this.gobbleSpaces(); + var to_check = this.expr.substr(this.index, Jsep.max_binop_len); + var tc_len = to_check.length; + + while (tc_len > 0) { + // Don't accept a binary op when it is an identifier. + // Binary ops that start with a identifier-valid character must be followed + // by a non identifier-part valid character + if (Jsep.binary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) { + this.index += tc_len; + return to_check; + } + + to_check = to_check.substr(0, --tc_len); + } + + return false; + } + /** + * This function is responsible for gobbling an individual expression, + * e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)` + * @returns {?jsep.BinaryExpression} + */ + + }, { + key: "gobbleBinaryExpression", + value: function gobbleBinaryExpression() { + var node, biop, prec, stack, biop_info, left, right, i, cur_biop; // First, try to get the leftmost thing + // Then, check to see if there's a binary operator operating on that leftmost thing + // Don't gobbleBinaryOp without a left-hand-side + + left = this.gobbleToken(); + + if (!left) { + return left; + } + + biop = this.gobbleBinaryOp(); // If there wasn't a binary operator, just return the leftmost node + + if (!biop) { + return left; + } // Otherwise, we need to start a stack to properly place the binary operations in their + // precedence structure + + + biop_info = { + value: biop, + prec: Jsep.binaryPrecedence(biop), + right_a: Jsep.right_associative.has(biop) + }; + right = this.gobbleToken(); + + if (!right) { + this.throwError("Expected expression after " + biop); + } + + stack = [left, biop_info, right]; // Properly deal with precedence using [recursive descent](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm) + + while (biop = this.gobbleBinaryOp()) { + prec = Jsep.binaryPrecedence(biop); + + if (prec === 0) { + this.index -= biop.length; + break; + } + + biop_info = { + value: biop, + prec: prec, + right_a: Jsep.right_associative.has(biop) + }; + cur_biop = biop; // Reduce: make a binary expression from the three topmost entries. + + var comparePrev = function comparePrev(prev) { + return biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec; + }; + + while (stack.length > 2 && comparePrev(stack[stack.length - 2])) { + right = stack.pop(); + biop = stack.pop().value; + left = stack.pop(); + node = { + type: Jsep.BINARY_EXP, + operator: biop, + left: left, + right: right + }; + stack.push(node); + } + + node = this.gobbleToken(); + + if (!node) { + this.throwError("Expected expression after " + cur_biop); + } + + stack.push(biop_info, node); + } + + i = stack.length - 1; + node = stack[i]; + + while (i > 1) { + node = { + type: Jsep.BINARY_EXP, + operator: stack[i - 1].value, + left: stack[i - 2], + right: node + }; + i -= 2; + } + + return node; + } + /** + * An individual part of a binary expression: + * e.g. `foo.bar(baz)`, `1`, `"abc"`, `(a % 2)` (because it's in parenthesis) + * @returns {boolean|jsep.Expression} + */ + + }, { + key: "gobbleToken", + value: function gobbleToken() { + var ch, to_check, tc_len, node; + this.gobbleSpaces(); + node = this.searchHook('gobble-token'); + + if (node) { + return this.runHook('after-token', node); + } + + ch = this.code; + + if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) { + // Char code 46 is a dot `.` which can start off a numeric literal + return this.gobbleNumericLiteral(); + } + + if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) { + // Single or double quotes + node = this.gobbleStringLiteral(); + } else if (ch === Jsep.OBRACK_CODE) { + node = this.gobbleArray(); + } else { + to_check = this.expr.substr(this.index, Jsep.max_unop_len); + tc_len = to_check.length; + + while (tc_len > 0) { + // Don't accept an unary op when it is an identifier. + // Unary ops that start with a identifier-valid character must be followed + // by a non identifier-part valid character + if (Jsep.unary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) { + this.index += tc_len; + var argument = this.gobbleToken(); + + if (!argument) { + this.throwError('missing unaryOp argument'); + } + + return this.runHook('after-token', { + type: Jsep.UNARY_EXP, + operator: to_check, + argument: argument, + prefix: true + }); + } + + to_check = to_check.substr(0, --tc_len); + } + + if (Jsep.isIdentifierStart(ch)) { + node = this.gobbleIdentifier(); + + if (Jsep.literals.hasOwnProperty(node.name)) { + node = { + type: Jsep.LITERAL, + value: Jsep.literals[node.name], + raw: node.name + }; + } else if (node.name === Jsep.this_str) { + node = { + type: Jsep.THIS_EXP + }; + } + } else if (ch === Jsep.OPAREN_CODE) { + // open parenthesis + node = this.gobbleGroup(); + } + } + + if (!node) { + return this.runHook('after-token', false); + } + + node = this.gobbleTokenProperty(node); + return this.runHook('after-token', node); + } + /** + * Gobble properties of of identifiers/strings/arrays/groups. + * e.g. `foo`, `bar.baz`, `foo['bar'].baz` + * It also gobbles function calls: + * e.g. `Math.acos(obj.angle)` + * @param {jsep.Expression} node + * @returns {jsep.Expression} + */ + + }, { + key: "gobbleTokenProperty", + value: function gobbleTokenProperty(node) { + this.gobbleSpaces(); + var ch = this.code; + + while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) { + var optional = void 0; + + if (ch === Jsep.QUMARK_CODE) { + if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) { + break; + } + + optional = true; + this.index += 2; + this.gobbleSpaces(); + ch = this.code; + } + + this.index++; + + if (ch === Jsep.OBRACK_CODE) { + node = { + type: Jsep.MEMBER_EXP, + computed: true, + object: node, + property: this.gobbleExpression() + }; + this.gobbleSpaces(); + ch = this.code; + + if (ch !== Jsep.CBRACK_CODE) { + this.throwError('Unclosed ['); + } + + this.index++; + } else if (ch === Jsep.OPAREN_CODE) { + // A function call is being made; gobble all the arguments + node = { + type: Jsep.CALL_EXP, + 'arguments': this.gobbleArguments(Jsep.CPAREN_CODE), + callee: node + }; + } else if (ch === Jsep.PERIOD_CODE || optional) { + if (optional) { + this.index--; + } + + this.gobbleSpaces(); + node = { + type: Jsep.MEMBER_EXP, + computed: false, + object: node, + property: this.gobbleIdentifier() + }; + } + + if (optional) { + node.optional = true; + } // else leave undefined for compatibility with esprima + + + this.gobbleSpaces(); + ch = this.code; + } + + return node; + } + /** + * Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to + * keep track of everything in the numeric literal and then calling `parseFloat` on that string + * @returns {jsep.Literal} + */ + + }, { + key: "gobbleNumericLiteral", + value: function gobbleNumericLiteral() { + var number = '', + ch, + chCode; + + while (Jsep.isDecimalDigit(this.code)) { + number += this.expr.charAt(this.index++); + } + + if (this.code === Jsep.PERIOD_CODE) { + // can start with a decimal marker + number += this.expr.charAt(this.index++); + + while (Jsep.isDecimalDigit(this.code)) { + number += this.expr.charAt(this.index++); + } + } + + ch = this["char"]; + + if (ch === 'e' || ch === 'E') { + // exponent marker + number += this.expr.charAt(this.index++); + ch = this["char"]; + + if (ch === '+' || ch === '-') { + // exponent sign + number += this.expr.charAt(this.index++); + } + + while (Jsep.isDecimalDigit(this.code)) { + // exponent itself + number += this.expr.charAt(this.index++); + } + + if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) { + this.throwError('Expected exponent (' + number + this["char"] + ')'); + } + } + + chCode = this.code; // Check to make sure this isn't a variable name that start with a number (123abc) + + if (Jsep.isIdentifierStart(chCode)) { + this.throwError('Variable names cannot start with a number (' + number + this["char"] + ')'); + } else if (chCode === Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE) { + this.throwError('Unexpected period'); + } + + return { + type: Jsep.LITERAL, + value: parseFloat(number), + raw: number + }; + } + /** + * Parses a string literal, staring with single or double quotes with basic support for escape codes + * e.g. `"hello world"`, `'this is\nJSEP'` + * @returns {jsep.Literal} + */ + + }, { + key: "gobbleStringLiteral", + value: function gobbleStringLiteral() { + var str = ''; + var startIndex = this.index; + var quote = this.expr.charAt(this.index++); + var closed = false; + + while (this.index < this.expr.length) { + var ch = this.expr.charAt(this.index++); + + if (ch === quote) { + closed = true; + break; + } else if (ch === '\\') { + // Check for all of the common escape codes + ch = this.expr.charAt(this.index++); + + switch (ch) { + case 'n': + str += '\n'; + break; + + case 'r': + str += '\r'; + break; + + case 't': + str += '\t'; + break; + + case 'b': + str += '\b'; + break; + + case 'f': + str += '\f'; + break; + + case 'v': + str += '\x0B'; + break; + + default: + str += ch; + } + } else { + str += ch; + } + } + + if (!closed) { + this.throwError('Unclosed quote after "' + str + '"'); + } + + return { + type: Jsep.LITERAL, + value: str, + raw: this.expr.substring(startIndex, this.index) + }; + } + /** + * Gobbles only identifiers + * e.g.: `foo`, `_value`, `$x1` + * Also, this function checks if that identifier is a literal: + * (e.g. `true`, `false`, `null`) or `this` + * @returns {jsep.Identifier} + */ + + }, { + key: "gobbleIdentifier", + value: function gobbleIdentifier() { + var ch = this.code, + start = this.index; + + if (Jsep.isIdentifierStart(ch)) { + this.index++; + } else { + this.throwError('Unexpected ' + this["char"]); + } + + while (this.index < this.expr.length) { + ch = this.code; + + if (Jsep.isIdentifierPart(ch)) { + this.index++; + } else { + break; + } + } + + return { + type: Jsep.IDENTIFIER, + name: this.expr.slice(start, this.index) + }; + } + /** + * Gobbles a list of arguments within the context of a function call + * or array literal. This function also assumes that the opening character + * `(` or `[` has already been gobbled, and gobbles expressions and commas + * until the terminator character `)` or `]` is encountered. + * e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]` + * @param {number} termination + * @returns {jsep.Expression[]} + */ + + }, { + key: "gobbleArguments", + value: function gobbleArguments(termination) { + var args = []; + var closed = false; + var separator_count = 0; + + while (this.index < this.expr.length) { + this.gobbleSpaces(); + var ch_i = this.code; + + if (ch_i === termination) { + // done parsing + closed = true; + this.index++; + + if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) { + this.throwError('Unexpected token ' + String.fromCharCode(termination)); + } + + break; + } else if (ch_i === Jsep.COMMA_CODE) { + // between expressions + this.index++; + separator_count++; + + if (separator_count !== args.length) { + // missing argument + if (termination === Jsep.CPAREN_CODE) { + this.throwError('Unexpected token ,'); + } else if (termination === Jsep.CBRACK_CODE) { + for (var arg = args.length; arg < separator_count; arg++) { + args.push(null); + } + } + } + } else if (args.length !== separator_count && separator_count !== 0) { + // NOTE: `&& separator_count !== 0` allows for either all commas, or all spaces as arguments + this.throwError('Expected comma'); + } else { + var node = this.gobbleExpression(); + + if (!node || node.type === Jsep.COMPOUND) { + this.throwError('Expected comma'); + } + + args.push(node); + } + } + + if (!closed) { + this.throwError('Expected ' + String.fromCharCode(termination)); + } + + return args; + } + /** + * Responsible for parsing a group of things within parentheses `()` + * that have no identifier in front (so not a function call) + * This function assumes that it needs to gobble the opening parenthesis + * and then tries to gobble everything within that parenthesis, assuming + * that the next thing it should see is the close parenthesis. If not, + * then the expression probably doesn't have a `)` + * @returns {boolean|jsep.Expression} + */ + + }, { + key: "gobbleGroup", + value: function gobbleGroup() { + this.index++; + var nodes = this.gobbleExpressions(Jsep.CPAREN_CODE); + + if (this.code === Jsep.CPAREN_CODE) { + this.index++; + + if (nodes.length === 1) { + return nodes[0]; + } else if (!nodes.length) { + return false; + } else { + return { + type: Jsep.SEQUENCE_EXP, + expressions: nodes + }; + } + } else { + this.throwError('Unclosed ('); + } + } + /** + * Responsible for parsing Array literals `[1, 2, 3]` + * This function assumes that it needs to gobble the opening bracket + * and then tries to gobble the expressions as arguments. + * @returns {jsep.ArrayExpression} + */ + + }, { + key: "gobbleArray", + value: function gobbleArray() { + this.index++; + return { + type: Jsep.ARRAY_EXP, + elements: this.gobbleArguments(Jsep.CBRACK_CODE) + }; + } + }], [{ + key: "version", + get: + /** + * @returns {string} + */ + function get() { + // To be filled in by the template + return '1.3.8'; + } + /** + * @returns {string} + */ + + }, { + key: "toString", + value: function toString() { + return 'JavaScript Expression Parser (JSEP) v' + Jsep.version; + } + }, { + key: "addUnaryOp", + value: // ==================== CONFIG ================================ + + /** + * @method addUnaryOp + * @param {string} op_name The name of the unary op to add + * @returns {Jsep} + */ + function addUnaryOp(op_name) { + Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len); + Jsep.unary_ops[op_name] = 1; + return Jsep; + } + /** + * @method jsep.addBinaryOp + * @param {string} op_name The name of the binary op to add + * @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence + * @param {boolean} [isRightAssociative=false] whether operator is right-associative + * @returns {Jsep} + */ + + }, { + key: "addBinaryOp", + value: function addBinaryOp(op_name, precedence, isRightAssociative) { + Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len); + Jsep.binary_ops[op_name] = precedence; + + if (isRightAssociative) { + Jsep.right_associative.add(op_name); + } else { + Jsep.right_associative["delete"](op_name); + } + + return Jsep; + } + /** + * @method addIdentifierChar + * @param {string} char The additional character to treat as a valid part of an identifier + * @returns {Jsep} + */ + + }, { + key: "addIdentifierChar", + value: function addIdentifierChar(_char) { + Jsep.additional_identifier_chars.add(_char); + return Jsep; + } + /** + * @method addLiteral + * @param {string} literal_name The name of the literal to add + * @param {*} literal_value The value of the literal + * @returns {Jsep} + */ + + }, { + key: "addLiteral", + value: function addLiteral(literal_name, literal_value) { + Jsep.literals[literal_name] = literal_value; + return Jsep; + } + /** + * @method removeUnaryOp + * @param {string} op_name The name of the unary op to remove + * @returns {Jsep} + */ + + }, { + key: "removeUnaryOp", + value: function removeUnaryOp(op_name) { + delete Jsep.unary_ops[op_name]; + + if (op_name.length === Jsep.max_unop_len) { + Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops); + } + + return Jsep; + } + /** + * @method removeAllUnaryOps + * @returns {Jsep} + */ + + }, { + key: "removeAllUnaryOps", + value: function removeAllUnaryOps() { + Jsep.unary_ops = {}; + Jsep.max_unop_len = 0; + return Jsep; + } + /** + * @method removeIdentifierChar + * @param {string} char The additional character to stop treating as a valid part of an identifier + * @returns {Jsep} + */ + + }, { + key: "removeIdentifierChar", + value: function removeIdentifierChar(_char2) { + Jsep.additional_identifier_chars["delete"](_char2); + return Jsep; + } + /** + * @method removeBinaryOp + * @param {string} op_name The name of the binary op to remove + * @returns {Jsep} + */ + + }, { + key: "removeBinaryOp", + value: function removeBinaryOp(op_name) { + delete Jsep.binary_ops[op_name]; + + if (op_name.length === Jsep.max_binop_len) { + Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops); + } + + Jsep.right_associative["delete"](op_name); + return Jsep; + } + /** + * @method removeAllBinaryOps + * @returns {Jsep} + */ + + }, { + key: "removeAllBinaryOps", + value: function removeAllBinaryOps() { + Jsep.binary_ops = {}; + Jsep.max_binop_len = 0; + return Jsep; + } + /** + * @method removeLiteral + * @param {string} literal_name The name of the literal to remove + * @returns {Jsep} + */ + + }, { + key: "removeLiteral", + value: function removeLiteral(literal_name) { + delete Jsep.literals[literal_name]; + return Jsep; + } + /** + * @method removeAllLiterals + * @returns {Jsep} + */ + + }, { + key: "removeAllLiterals", + value: function removeAllLiterals() { + Jsep.literals = {}; + return Jsep; + } + }, { + key: "parse", + value: function parse(expr) { + return new Jsep(expr).parse(); + } + /** + * Get the longest key length of any object + * @param {object} obj + * @returns {number} + */ + + }, { + key: "getMaxKeyLen", + value: function getMaxKeyLen(obj) { + return Math.max.apply(Math, [0].concat(_toConsumableArray(Object.keys(obj).map(function (k) { + return k.length; + })))); + } + /** + * `ch` is a character code in the next three functions + * @param {number} ch + * @returns {boolean} + */ + + }, { + key: "isDecimalDigit", + value: function isDecimalDigit(ch) { + return ch >= 48 && ch <= 57; // 0...9 + } + /** + * Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float. + * @param {string} op_val + * @returns {number} + */ + + }, { + key: "binaryPrecedence", + value: function binaryPrecedence(op_val) { + return Jsep.binary_ops[op_val] || 0; + } + /** + * Looks for start of identifier + * @param {number} ch + * @returns {boolean} + */ + + }, { + key: "isIdentifierStart", + value: function isIdentifierStart(ch) { + return ch >= 65 && ch <= 90 || // A...Z + ch >= 97 && ch <= 122 || // a...z + ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)] || // any non-ASCII that is not an operator + Jsep.additional_identifier_chars.has(String.fromCharCode(ch)); // additional characters + } + /** + * @param {number} ch + * @returns {boolean} + */ + + }, { + key: "isIdentifierPart", + value: function isIdentifierPart(ch) { + return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch); + } + }]); + + return Jsep; + }(); // Static fields: + + + var hooks = new Hooks(); + Object.assign(Jsep, { + hooks: hooks, + plugins: new Plugins(Jsep), + // Node Types + // ---------- + // This is the full set of types that any JSEP node can be. + // Store them here to save space when minified + COMPOUND: 'Compound', + SEQUENCE_EXP: 'SequenceExpression', + IDENTIFIER: 'Identifier', + MEMBER_EXP: 'MemberExpression', + LITERAL: 'Literal', + THIS_EXP: 'ThisExpression', + CALL_EXP: 'CallExpression', + UNARY_EXP: 'UnaryExpression', + BINARY_EXP: 'BinaryExpression', + ARRAY_EXP: 'ArrayExpression', + TAB_CODE: 9, + LF_CODE: 10, + CR_CODE: 13, + SPACE_CODE: 32, + PERIOD_CODE: 46, + // '.' + COMMA_CODE: 44, + // ',' + SQUOTE_CODE: 39, + // single quote + DQUOTE_CODE: 34, + // double quotes + OPAREN_CODE: 40, + // ( + CPAREN_CODE: 41, + // ) + OBRACK_CODE: 91, + // [ + CBRACK_CODE: 93, + // ] + QUMARK_CODE: 63, + // ? + SEMCOL_CODE: 59, + // ; + COLON_CODE: 58, + // : + // Operations + // ---------- + // Use a quickly-accessible map to store all of the unary operators + // Values are set to `1` (it really doesn't matter) + unary_ops: { + '-': 1, + '!': 1, + '~': 1, + '+': 1 + }, + // Also use a map for the binary operations but set their values to their + // binary precedence for quick reference (higher number = higher precedence) + // see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) + binary_ops: { + '||': 1, + '&&': 2, + '|': 3, + '^': 4, + '&': 5, + '==': 6, + '!=': 6, + '===': 6, + '!==': 6, + '<': 7, + '>': 7, + '<=': 7, + '>=': 7, + '<<': 8, + '>>': 8, + '>>>': 8, + '+': 9, + '-': 9, + '*': 10, + '/': 10, + '%': 10 + }, + // sets specific binary_ops as right-associative + right_associative: new Set(), + // Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char) + additional_identifier_chars: new Set(['$', '_']), + // Literals + // ---------- + // Store the values to return for the various literals we may encounter + literals: { + 'true': true, + 'false': false, + 'null': null + }, + // Except for `this`, which is special. This could be changed to something like `'self'` as well + this_str: 'this' + }); + Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops); + Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops); // Backward Compatibility: + + var jsep = function jsep(expr) { + return new Jsep(expr).parse(); + }; + + var staticMethods = Object.getOwnPropertyNames(Jsep); + staticMethods.forEach(function (m) { + if (jsep[m] === undefined && m !== 'prototype') { + jsep[m] = Jsep[m]; + } + }); + jsep.Jsep = Jsep; // allows for const { Jsep } = require('jsep'); + + var CONDITIONAL_EXP = 'ConditionalExpression'; + var ternary = { + name: 'ternary', + init: function init(jsep) { + // Ternary expression: test ? consequent : alternate + jsep.hooks.add('after-expression', function gobbleTernary(env) { + if (env.node && this.code === jsep.QUMARK_CODE) { + this.index++; + var test = env.node; + var consequent = this.gobbleExpression(); + + if (!consequent) { + this.throwError('Expected expression'); + } + + this.gobbleSpaces(); + + if (this.code === jsep.COLON_CODE) { + this.index++; + var alternate = this.gobbleExpression(); + + if (!alternate) { + this.throwError('Expected expression'); + } + + env.node = { + type: CONDITIONAL_EXP, + test: test, + consequent: consequent, + alternate: alternate + }; // check for operators of higher priority than ternary (i.e. assignment) + // jsep sets || at 1, and assignment at 0.9, and conditional should be between them + + if (test.operator && jsep.binary_ops[test.operator] <= 0.9) { + var newTest = test; + + while (newTest.right.operator && jsep.binary_ops[newTest.right.operator] <= 0.9) { + newTest = newTest.right; + } + + env.node.test = newTest.right; + newTest.right = env.node; + env.node = test; + } + } else { + this.throwError('Expected :'); + } + } + }); + } + }; // Add default plugins: + + jsep.plugins.register(ternary); + + var FSLASH_CODE = 47; // '/' + + var BSLASH_CODE = 92; // '\\' + + var index = { + name: 'regex', + init: function init(jsep) { + // Regex literal: /abc123/ig + jsep.hooks.add('gobble-token', function gobbleRegexLiteral(env) { + if (this.code === FSLASH_CODE) { + var patternIndex = ++this.index; + var inCharSet = false; + + while (this.index < this.expr.length) { + if (this.code === FSLASH_CODE && !inCharSet) { + var pattern = this.expr.slice(patternIndex, this.index); + var flags = ''; + + while (++this.index < this.expr.length) { + var code = this.code; + + if (code >= 97 && code <= 122 // a...z + || code >= 65 && code <= 90 // A...Z + || code >= 48 && code <= 57) { + // 0-9 + flags += this["char"]; + } else { + break; + } + } + + var value = void 0; + + try { + value = new RegExp(pattern, flags); + } catch (e) { + this.throwError(e.message); + } + + env.node = { + type: jsep.LITERAL, + value: value, + raw: this.expr.slice(patternIndex - 1, this.index) + }; // allow . [] and () after regex: /regex/.test(a) + + env.node = this.gobbleTokenProperty(env.node); + return env.node; + } + + if (this.code === jsep.OBRACK_CODE) { + inCharSet = true; + } else if (inCharSet && this.code === jsep.CBRACK_CODE) { + inCharSet = false; + } + + this.index += this.code === BSLASH_CODE ? 2 : 1; + } + + this.throwError('Unclosed Regex'); + } + }); + } + }; + var hasOwnProp = Object.prototype.hasOwnProperty; /** * @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject @@ -369,6 +1745,7 @@ * @property {boolean} [wrap=true] * @property {PlainObject} [sandbox={}] * @property {boolean} [preventEval=false] + * @property {"safe"|"native"|"none"} [evalType='safe'] * @property {PlainObject|GenericArray|null} [parent=null] * @property {string|null} [parentProperty=null] * @property {JSONPathCallback} [callback] @@ -427,6 +1804,7 @@ this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true; this.sandbox = opts.sandbox || {}; this.preventEval = opts.preventEval || false; + this.evalType = opts.evalType || 'safe'; this.parent = opts.parent || null; this.parentProperty = opts.parentProperty || null; this.callback = opts.callback || callback || null; @@ -466,6 +1844,7 @@ wrap = this.wrap; this.currResultType = this.resultType; this.currPreventEval = this.preventEval; + this.currEvalType = this.evalType; this.currSandbox = this.sandbox; callback = callback || this.callback; this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback; @@ -488,6 +1867,7 @@ this.currSandbox = hasOwnProp.call(expr, 'sandbox') ? expr.sandbox : this.currSandbox; wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap; this.currPreventEval = hasOwnProp.call(expr, 'preventEval') ? expr.preventEval : this.currPreventEval; + this.currEvalType = hasOwnProp.call(expr, 'evalType') ? expr.evalType : this.currEvalType; callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback; this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback') ? expr.otherTypeCallback : this.currOtherTypeCallback; currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent; @@ -688,7 +2068,7 @@ addRet(this._slice(loc, x, val, path, parent, parentPropName, callback)); } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [?(expr)] prevented in JSONPath expression.'); } @@ -701,7 +2081,7 @@ }); } else if (loc[0] === '(') { // [(expr)] (dynamic property/index) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [(expr)] prevented in JSONPath expression.'); } // As this will resolve to a property name (but we don't know it // yet), property and parent information is relative to the @@ -908,7 +2288,7 @@ this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname])); } - var scriptCacheKey = 'script:' + code; + var scriptCacheKey = this.currEvalType + 'Script:' + code; if (!JSONPath.cache[scriptCacheKey]) { var script = code.replace(/@parentProperty/g, '_$_parentProperty').replace(/@parent/g, '_$_parent').replace(/@property/g, '_$_property').replace(/@root/g, '_$_root').replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g, '_$_v$1'); @@ -917,7 +2297,11 @@ script = script.replace(/@path/g, '_$_path'); } - JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + if (this.currEvalType === 'safe') { + JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script); + } else if (this.currEvalType === 'native') { + JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + } } try { @@ -1040,11 +2424,242 @@ target.push(source.splice(i--, 1)[0]); } } + }; // register plugins + + + jsep.plugins.register(index); + var SafeEval = { + eval: function _eval(code) { + var substitions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var ast = jsep(code); + return SafeEval.evalAst(ast, substitions); + }, + + /** + * @param {jsep.Expression} ast + * @param {Record} subs + */ + evalAst: function evalAst(ast, subs) { + switch (ast.type) { + case 'BinaryExpression': + case 'LogicalExpression': + return SafeEval.evalBinaryExpression(ast, subs); + + case 'Compound': + return SafeEval.evalCompound(ast, subs); + + case 'ConditionalExpression': + return SafeEval.evalConditionalExpression(ast, subs); + + case 'Identifier': + return SafeEval.evalIdentifier(ast, subs); + + case 'Literal': + return SafeEval.evalLiteral(ast, subs); + + case 'MemberExpression': + return SafeEval.evalMemberExpression(ast, subs); + + case 'UnaryExpression': + return SafeEval.evalUnaryExpression(ast, subs); + + case 'ArrayExpression': + return SafeEval.evalArrayExpression(ast, subs); + + case 'CallExpression': + return SafeEval.evalCallExpression(ast, subs); + + default: + throw SyntaxError('Unexpected expression', ast); + } + }, + evalBinaryExpression: function evalBinaryExpression(ast, subs) { + var result = { + '||': function _(a, b) { + return a || b(); + }, + '&&': function _(a, b) { + return a && b(); + }, + '|': function _(a, b) { + return a | b(); + }, + '^': function _(a, b) { + return a ^ b(); + }, + '&': function _(a, b) { + return a & b(); + }, + // eslint-disable-next-line eqeqeq + '==': function _(a, b) { + return a == b(); + }, + // eslint-disable-next-line eqeqeq + '!=': function _(a, b) { + return a != b(); + }, + '===': function _(a, b) { + return a === b(); + }, + '!==': function _(a, b) { + return a !== b(); + }, + '<': function _(a, b) { + return a < b(); + }, + '>': function _(a, b) { + return a > b(); + }, + '<=': function _(a, b) { + return a <= b(); + }, + '>=': function _(a, b) { + return a >= b(); + }, + '<<': function _(a, b) { + return a << b(); + }, + '>>': function _(a, b) { + return a >> b(); + }, + '>>>': function _(a, b) { + return a >>> b(); + }, + '+': function _(a, b) { + return a + b(); + }, + '-': function _(a, b) { + return a - b(); + }, + '*': function _(a, b) { + return a * b(); + }, + '/': function _(a, b) { + return a / b(); + }, + '%': function _(a, b) { + return a % b(); + } + }[ast.operator](SafeEval.evalAst(ast.left, subs), function () { + return SafeEval.evalAst(ast.right, subs); + }); + return result; + }, + evalCompound: function evalCompound(ast, subs) { + var last; + + var _iterator = _createForOfIteratorHelper(ast.body), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var expr = _step.value; + last = this.evalAst(expr, subs); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return last; + }, + evalConditionalExpression: function evalConditionalExpression(ast, subs) { + if (SafeEval.evalAst(ast.test, subs)) { + return SafeEval.evalAst(ast.consequent, subs); + } + + return SafeEval.evalAst(ast.alternate, subs); + }, + evalIdentifier: function evalIdentifier(ast, subs) { + if (ast.name in subs) { + return subs[ast.name]; + } + + throw ReferenceError("".concat(ast.name, " is not defined")); + }, + evalLiteral: function evalLiteral(ast, subs) { + return ast.value; + }, + evalMemberExpression: function evalMemberExpression(ast, subs) { + var prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]` + : ast.property.name; // `object.property` property is identifier + + var obj = SafeEval.evalAst(ast.object, subs); + var result = obj[prop]; + + if (typeof result === 'function') { + return result.bind(obj); // arrow functions aren't affected by bind. + } + + return result; + }, + evalUnaryExpression: function evalUnaryExpression(ast, subs) { + var result = { + '-': function _(a) { + return -SafeEval.evalAst(a); + }, + '!': function _(a) { + return !SafeEval.evalAst(a); + }, + '~': function _(a) { + return ~SafeEval.evalAst(a); + }, + // eslint-disable-next-line no-implicit-coercion + '+': function _(a) { + return +SafeEval.evalAst(a); + } + }[ast.operator](ast.argument); + return result; + }, + evalArrayExpression: function evalArrayExpression(ast, subs) { + return ast.elements.map(function (el) { + return SafeEval.evalAst(el, subs); + }); + }, + evalCallExpression: function evalCallExpression(ast, subs) { + var args = ast.arguments.map(function (arg) { + return SafeEval.evalAst(arg, subs); + }); + var func = SafeEval.evalAst(ast.callee, subs); + return func.apply(void 0, _toConsumableArray(args)); + } }; /** * In-browser replacement for NodeJS' VM.Script. */ + var SafeScript = /*#__PURE__*/function () { + /** + * @param {string} expr Expression to evaluate + */ + function SafeScript(expr) { + _classCallCheck(this, SafeScript); + + this.code = expr; + } + /** + * @param {PlainObject} context Object whose items will be added + * to evaluation + * @returns {EvaluatedResult} Result of evaluated code + */ + + + _createClass(SafeScript, [{ + key: "runInNewContext", + value: function runInNewContext(context) { + var keyMap = _objectSpread2({}, context); + + return SafeEval.eval(this.code, keyMap); + } + }]); + + return SafeScript; + }(); + /** + * In-browser replacement for NodeJS' VM.Script. + */ + var Script = /*#__PURE__*/function () { /** @@ -1107,6 +2722,9 @@ JSONPath.prototype.vm = { Script: Script }; + JSONPath.prototype.safeVm = { + Script: SafeScript + }; exports.JSONPath = JSONPath; diff --git a/dist/index-browser-umd.min.cjs b/dist/index-browser-umd.min.cjs index 2cbae9e..da7028e 100644 --- a/dist/index-browser-umd.min.cjs +++ b/dist/index-browser-umd.min.cjs @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JSONPath={})}(this,(function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,n=new Array(e);r1&&s.shift(),this._hasParentSelector=null;var p=this._trace(s,r,["$"],u,i,n).filter((function(t){return t&&!t.isParentSelector}));return p.length?l||1!==p.length||p[0].hasArrExpr?p.reduce((function(t,e){var r=o._getPreferredOutput(e);return c&&Array.isArray(r)?t=t.concat(r):t.push(r),t}),[]):this._getPreferredOutput(p[0]):l?[]:void 0}},d.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){case"all":var r=Array.isArray(t.path)?t.path:d.toPathArray(t.path);return t.pointer=d.toPointer(r),t.path="string"==typeof t.path?t.path:d.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return d.toPathString(t[e]);case"pointer":return d.toPointer(t.path);default:throw new TypeError("Unknown result type")}},d.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:d.toPathString(t.path),e(n,r,t)}},d.prototype._trace=function(t,r,n,a,o,u,i,c){var l,s=this;if(!t.length)return l={path:n,value:r,parent:a,parentProperty:o,hasArrExpr:i},this._handleCallback(l,u,"value"),l;var p=t[0],h=t.slice(1),F=[];function d(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof p||c)&&r&&y.call(r,p))d(this._trace(h,r[p],v(n,p),r,p,u,i));else if("*"===p)this._walk(r,(function(t){d(s._trace(h,r[t],v(n,t),r,t,u,!0,!0))}));else if(".."===p)d(this._trace(h,r,n,a,o,u,i)),this._walk(r,(function(a){"object"===e(r[a])&&d(s._trace(t.slice(),r[a],v(n,a),r,a,u,!0))}));else{if("^"===p)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:h,isParentSelector:!0};if("~"===p)return l={path:v(n,p),value:o,parent:a,parentProperty:null},this._handleCallback(l,u,"property"),l;if("$"===p)d(this._trace(h,r,n,null,null,u,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(p))d(this._slice(p,h,r,n,a,o,u));else if(0===p.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");var g=p.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1");this._walk(r,(function(t){s._eval(g,r[t],t,n,a,o)&&d(s._trace(h,r[t],v(n,t),r,t,u,!0))}))}else if("("===p[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");d(this._trace(b(this._eval(p,r,n[n.length-1],n.slice(0,-1),a,o),h),r,n,a,o,u,i))}else if("@"===p[0]){var w=!1,_=p.slice(1,-2);switch(_){case"scalar":r&&["object","function"].includes(e(r))||(w=!0);break;case"boolean":case"string":case"undefined":case"function":e(r)===_&&(w=!0);break;case"integer":!Number.isFinite(r)||r%1||(w=!0);break;case"number":Number.isFinite(r)&&(w=!0);break;case"nonFinite":"number"!=typeof r||Number.isFinite(r)||(w=!0);break;case"object":r&&e(r)===_&&(w=!0);break;case"array":Array.isArray(r)&&(w=!0);break;case"other":w=this.currOtherTypeCallback(r,n,a,o);break;case"null":null===r&&(w=!0);break;default:throw new TypeError("Unknown value type "+_)}if(w)return l={path:n,value:r,parent:a,parentProperty:o},this._handleCallback(l,u,"value"),l}else if("`"===p[0]&&r&&y.call(r,p.slice(1))){var m=p.slice(1);d(this._trace(h,r[m],v(n,m),r,m,u,i,!0))}else if(p.includes(",")){var P,D=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=f(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,a=function(){};return{s:a,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,i=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){i=!0,o=t},f:function(){try{u||null==r.return||r.return()}finally{if(i)throw o}}}}(p.split(","));try{for(D.s();!(P=D.n()).done;){var S=P.value;d(this._trace(b(S,h),r,n,a,o,u,!0))}}catch(t){D.e(t)}finally{D.f()}}else!c&&r&&y.call(r,p)&&d(this._trace(h,r[p],v(n,p),r,p,u,i,!0))}if(this._hasParentSelector)for(var x=0;x-1?e.slice(0,u+1)+" return "+e.slice(u+1):" return "+e;return c(Function,r.concat([i])).apply(void 0,p(a))}}]),t}();d.prototype.vm={Script:g},t.JSONPath=d,Object.defineProperty(t,"__esModule",{value:!0})})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).JSONPath={})}(this,(function(e){"use strict";function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;re.length)&&(t=e.length);for(var r=0,n=new Array(t);r=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}var v=function(){function e(){n(this,e)}return o(e,[{key:"add",value:function(e,t,r){if("string"!=typeof arguments[0])for(var n in arguments[0])this.add(n,arguments[0][n],arguments[1]);else(Array.isArray(e)?e:[e]).forEach((function(e){this[e]=this[e]||[],t&&this[e][r?"unshift":"push"](t)}),this)}},{key:"run",value:function(e,t){this[e]=this[e]||[],this[e].forEach((function(e){e.call(t&&t.context?t.context:t,t)}))}}]),e}(),E=function(){function e(t){n(this,e),this.jsep=t,this.registered={}}return o(e,[{key:"register",value:function(){for(var e=this,t=arguments.length,n=new Array(t),i=0;i0;){if(e.binary_ops.hasOwnProperty(t)&&(!e.isIdentifierStart(this.code)||this.index+t.length2&&(l=i[i.length-2],o.right_a&&l.right_a?n>l.prec:n<=l.prec);)s=i.pop(),r=i.pop().value,a=i.pop(),t={type:e.BINARY_EXP,operator:r,left:a,right:s},i.push(t);(t=this.gobbleToken())||this.throwError("Expected expression after "+c),i.push(o,t)}for(t=i[u=i.length-1];u>1;)t={type:e.BINARY_EXP,operator:i[u-1].value,left:i[u-2],right:t},u-=2;return t}},{key:"gobbleToken",value:function(){var t,r,n,i;if(this.gobbleSpaces(),i=this.searchHook("gobble-token"))return this.runHook("after-token",i);if(t=this.code,e.isDecimalDigit(t)||t===e.PERIOD_CODE)return this.gobbleNumericLiteral();if(t===e.SQUOTE_CODE||t===e.DQUOTE_CODE)i=this.gobbleStringLiteral();else if(t===e.OBRACK_CODE)i=this.gobbleArray();else{for(n=(r=this.expr.substr(this.index,e.max_unop_len)).length;n>0;){if(e.unary_ops.hasOwnProperty(r)&&(!e.isIdentifierStart(this.code)||this.index+r.length=r.length&&this.throwError("Unexpected token "+String.fromCharCode(t));break}if(o===e.COMMA_CODE){if(this.index++,++i!==r.length)if(t===e.CPAREN_CODE)this.throwError("Unexpected token ,");else if(t===e.CBRACK_CODE)for(var a=r.length;a=48&&e<=57}},{key:"binaryPrecedence",value:function(t){return e.binary_ops[t]||0}},{key:"isIdentifierStart",value:function(t){return t>=65&&t<=90||t>=97&&t<=122||t>=128&&!e.binary_ops[String.fromCharCode(t)]||e.additional_identifier_chars.has(String.fromCharCode(t))}},{key:"isIdentifierPart",value:function(t){return e.isIdentifierStart(t)||e.isDecimalDigit(t)}}]),e}(),x=new v;Object.assign(g,{hooks:x,plugins:new E(g),COMPOUND:"Compound",SEQUENCE_EXP:"SequenceExpression",IDENTIFIER:"Identifier",MEMBER_EXP:"MemberExpression",LITERAL:"Literal",THIS_EXP:"ThisExpression",CALL_EXP:"CallExpression",UNARY_EXP:"UnaryExpression",BINARY_EXP:"BinaryExpression",ARRAY_EXP:"ArrayExpression",TAB_CODE:9,LF_CODE:10,CR_CODE:13,SPACE_CODE:32,PERIOD_CODE:46,COMMA_CODE:44,SQUOTE_CODE:39,DQUOTE_CODE:34,OPAREN_CODE:40,CPAREN_CODE:41,OBRACK_CODE:91,CBRACK_CODE:93,QUMARK_CODE:63,SEMCOL_CODE:59,COLON_CODE:58,unary_ops:{"-":1,"!":1,"~":1,"+":1},binary_ops:{"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},right_associative:new Set,additional_identifier_chars:new Set(["$","_"]),literals:{true:!0,false:!1,null:null},this_str:"this"}),g.max_unop_len=g.getMaxKeyLen(g.unary_ops),g.max_binop_len=g.getMaxKeyLen(g.binary_ops);var _=function(e){return new g(e).parse()};Object.getOwnPropertyNames(g).forEach((function(e){void 0===_[e]&&"prototype"!==e&&(_[e]=g[e])})),_.Jsep=g;var O={name:"ternary",init:function(e){e.hooks.add("after-expression",(function(t){if(t.node&&this.code===e.QUMARK_CODE){this.index++;var r=t.node,n=this.gobbleExpression();if(n||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===e.COLON_CODE){this.index++;var i=this.gobbleExpression();if(i||this.throwError("Expected expression"),t.node={type:"ConditionalExpression",test:r,consequent:n,alternate:i},r.operator&&e.binary_ops[r.operator]<=.9){for(var o=r;o.right.operator&&e.binary_ops[o.right.operator]<=.9;)o=o.right;t.node.test=o.right,o.right=t.node,t.node=r}}else this.throwError("Expected :")}}))}};_.plugins.register(O);var m={name:"regex",init:function(e){e.hooks.add("gobble-token",(function(t){if(47===this.code){for(var r=++this.index,n=!1;this.index=97&&a<=122||a>=65&&a<=90||a>=48&&a<=57))break;o+=this.char}var s=void 0;try{s=new RegExp(i,o)}catch(e){this.throwError(e.message)}return t.node={type:e.LITERAL,value:s,raw:this.expr.slice(r-1,this.index)},t.node=this.gobbleTokenProperty(t.node),t.node}this.code===e.OBRACK_CODE?n=!0:n&&this.code===e.CBRACK_CODE&&(n=!1),this.index+=92===this.code?2:1}this.throwError("Unclosed Regex")}}))}},C=Object.prototype.hasOwnProperty;function D(e,t){return(e=e.slice()).push(t),e}function A(e,t){return(t=t.slice()).unshift(e),t}var k=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}(a,e);var t,r,i=(t=a,r=c(),function(){var e,n=s(t);if(r){var i=s(this).constructor;e=Reflect.construct(n,arguments,i)}else e=n.apply(this,arguments);return p(this,e)});function a(e){var t;return n(this,a),(t=i.call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)')).avoidNew=!0,t.value=e,t.name="NewError",t}return o(a)}(h(Error));function w(e,t,n,i,o){if(!(this instanceof w))try{return new w(e,t,n,i,o)}catch(e){if(!e.avoidNew)throw e;return e.value}"string"==typeof e&&(o=i,i=n,n=t,t=e,e=null);var a=e&&"object"===r(e);if(e=e||{},this.json=e.json||n,this.path=e.path||t,this.resultType=e.resultType||"value",this.flatten=e.flatten||!1,this.wrap=!C.call(e,"wrap")||e.wrap,this.sandbox=e.sandbox||{},this.preventEval=e.preventEval||!1,this.evalType=e.evalType||"safe",this.parent=e.parent||null,this.parentProperty=e.parentProperty||null,this.callback=e.callback||i||null,this.otherTypeCallback=e.otherTypeCallback||o||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==e.autostart){var s={path:a?e.path:t};a?"json"in e&&(s.json=e.json):s.json=n;var u=this.evaluate(s);if(!u||"object"!==r(u))throw new k(u);return u}}w.prototype.evaluate=function(e,t,n,i){var o=this,a=this.parent,s=this.parentProperty,u=this.flatten,c=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currEvalType=this.evalType,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=i||this.otherTypeCallback,t=t||this.json,(e=e||this.path)&&"object"===r(e)&&!Array.isArray(e)){if(!e.path&&""!==e.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!C.call(e,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');t=e.json,u=C.call(e,"flatten")?e.flatten:u,this.currResultType=C.call(e,"resultType")?e.resultType:this.currResultType,this.currSandbox=C.call(e,"sandbox")?e.sandbox:this.currSandbox,c=C.call(e,"wrap")?e.wrap:c,this.currPreventEval=C.call(e,"preventEval")?e.preventEval:this.currPreventEval,this.currEvalType=C.call(e,"evalType")?e.evalType:this.currEvalType,n=C.call(e,"callback")?e.callback:n,this.currOtherTypeCallback=C.call(e,"otherTypeCallback")?e.otherTypeCallback:this.currOtherTypeCallback,a=C.call(e,"parent")?e.parent:a,s=C.call(e,"parentProperty")?e.parentProperty:s,e=e.path}if(a=a||null,s=s||null,Array.isArray(e)&&(e=w.toPathString(e)),(e||""===e)&&t){var l=w.toPathArray(e);"$"===l[0]&&l.length>1&&l.shift(),this._hasParentSelector=null;var h=this._trace(l,t,["$"],a,s,n).filter((function(e){return e&&!e.isParentSelector}));return h.length?c||1!==h.length||h[0].hasArrExpr?h.reduce((function(e,t){var r=o._getPreferredOutput(t);return u&&Array.isArray(r)?e=e.concat(r):e.push(r),e}),[]):this._getPreferredOutput(h[0]):c?[]:void 0}},w.prototype._getPreferredOutput=function(e){var t=this.currResultType;switch(t){case"all":var r=Array.isArray(e.path)?e.path:w.toPathArray(e.path);return e.pointer=w.toPointer(r),e.path="string"==typeof e.path?e.path:w.toPathString(e.path),e;case"value":case"parent":case"parentProperty":return e[t];case"path":return w.toPathString(e[t]);case"pointer":return w.toPointer(e.path);default:throw new TypeError("Unknown result type")}},w.prototype._handleCallback=function(e,t,r){if(t){var n=this._getPreferredOutput(e);e.path="string"==typeof e.path?e.path:w.toPathString(e.path),t(n,r,e)}},w.prototype._trace=function(e,t,n,i,o,a,s,u){var c,l=this;if(!e.length)return c={path:n,value:t,parent:i,parentProperty:o,hasArrExpr:s},this._handleCallback(c,a,"value"),c;var h=e[0],p=e.slice(1),f=[];function y(e){Array.isArray(e)?e.forEach((function(e){f.push(e)})):f.push(e)}if(("string"!=typeof h||u)&&t&&C.call(t,h))y(this._trace(p,t[h],D(n,h),t,h,a,s));else if("*"===h)this._walk(t,(function(e){y(l._trace(p,t[e],D(n,e),t,e,a,!0,!0))}));else if(".."===h)y(this._trace(p,t,n,i,o,a,s)),this._walk(t,(function(i){"object"===r(t[i])&&y(l._trace(e.slice(),t[i],D(n,i),t,i,a,!0))}));else{if("^"===h)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:p,isParentSelector:!0};if("~"===h)return c={path:D(n,h),value:o,parent:i,parentProperty:null},this._handleCallback(c,a,"property"),c;if("$"===h)y(this._trace(p,t,n,null,null,a,s));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(h))y(this._slice(h,p,t,n,i,o,a));else if(0===h.indexOf("?(")){if(this.currPreventEval||"none"===this.currEvalType)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");var d=h.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1");this._walk(t,(function(e){l._eval(d,t[e],e,n,i,o)&&y(l._trace(p,t[e],D(n,e),t,e,a,!0))}))}else if("("===h[0]){if(this.currPreventEval||"none"===this.currEvalType)throw new Error("Eval [(expr)] prevented in JSONPath expression.");y(this._trace(A(this._eval(h,t,n[n.length-1],n.slice(0,-1),i,o),p),t,n,i,o,a,s))}else if("@"===h[0]){var v=!1,E=h.slice(1,-2);switch(E){case"scalar":t&&["object","function"].includes(r(t))||(v=!0);break;case"boolean":case"string":case"undefined":case"function":r(t)===E&&(v=!0);break;case"integer":!Number.isFinite(t)||t%1||(v=!0);break;case"number":Number.isFinite(t)&&(v=!0);break;case"nonFinite":"number"!=typeof t||Number.isFinite(t)||(v=!0);break;case"object":t&&r(t)===E&&(v=!0);break;case"array":Array.isArray(t)&&(v=!0);break;case"other":v=this.currOtherTypeCallback(t,n,i,o);break;case"null":null===t&&(v=!0);break;default:throw new TypeError("Unknown value type "+E)}if(v)return c={path:n,value:t,parent:i,parentProperty:o},this._handleCallback(c,a,"value"),c}else if("`"===h[0]&&t&&C.call(t,h.slice(1))){var g=h.slice(1);y(this._trace(p,t[g],D(n,g),t,g,a,s,!0))}else if(h.includes(",")){var x,_=b(h.split(","));try{for(_.s();!(x=_.n()).done;){var O=x.value;y(this._trace(A(O,p),t,n,i,o,a,!0))}}catch(e){_.e(e)}finally{_.f()}}else!u&&t&&C.call(t,h)&&y(this._trace(p,t[h],D(n,h),t,h,a,s,!0))}if(this._hasParentSelector)for(var m=0;m1&&void 0!==arguments[1]?arguments[1]:{},r=_(e);return P.evalAst(r,t)},evalAst:function(e,t){switch(e.type){case"BinaryExpression":case"LogicalExpression":return P.evalBinaryExpression(e,t);case"Compound":return P.evalCompound(e,t);case"ConditionalExpression":return P.evalConditionalExpression(e,t);case"Identifier":return P.evalIdentifier(e,t);case"Literal":return P.evalLiteral(e,t);case"MemberExpression":return P.evalMemberExpression(e,t);case"UnaryExpression":return P.evalUnaryExpression(e,t);case"ArrayExpression":return P.evalArrayExpression(e,t);case"CallExpression":return P.evalCallExpression(e,t);default:throw SyntaxError("Unexpected expression",e)}},evalBinaryExpression:function(e,t){return{"||":function(e,t){return e||t()},"&&":function(e,t){return e&&t()},"|":function(e,t){return e|t()},"^":function(e,t){return e^t()},"&":function(e,t){return e&t()},"==":function(e,t){return e==t()},"!=":function(e,t){return e!=t()},"===":function(e,t){return e===t()},"!==":function(e,t){return e!==t()},"<":function(e,t){return e":function(e,t){return e>t()},"<=":function(e,t){return e<=t()},">=":function(e,t){return e>=t()},"<<":function(e,t){return e<>":function(e,t){return e>>t()},">>>":function(e,t){return e>>>t()},"+":function(e,t){return e+t()},"-":function(e,t){return e-t()},"*":function(e,t){return e*t()},"/":function(e,t){return e/t()},"%":function(e,t){return e%t()}}[e.operator](P.evalAst(e.left,t),(function(){return P.evalAst(e.right,t)}))},evalCompound:function(e,t){var r,n,i=b(e.body);try{for(i.s();!(n=i.n()).done;){var o=n.value;r=this.evalAst(o,t)}}catch(e){i.e(e)}finally{i.f()}return r},evalConditionalExpression:function(e,t){return P.evalAst(e.test,t)?P.evalAst(e.consequent,t):P.evalAst(e.alternate,t)},evalIdentifier:function(e,t){if(e.name in t)return t[e.name];throw ReferenceError("".concat(e.name," is not defined"))},evalLiteral:function(e,t){return e.value},evalMemberExpression:function(e,t){var r=e.computed?P.evalAst(e.property):e.property.name,n=P.evalAst(e.object,t),i=n[r];return"function"==typeof i?i.bind(n):i},evalUnaryExpression:function(e,t){return{"-":function(e){return-P.evalAst(e)},"!":function(e){return!P.evalAst(e)},"~":function(e){return~P.evalAst(e)},"+":function(e){return+P.evalAst(e)}}[e.operator](e.argument)},evalArrayExpression:function(e,t){return e.elements.map((function(e){return P.evalAst(e,t)}))},evalCallExpression:function(e,t){var r=e.arguments.map((function(e){return P.evalAst(e,t)}));return P.evalAst(e.callee,t).apply(void 0,f(r))}},F=function(){function e(t){n(this,e),this.code=t}return o(e,[{key:"runInNewContext",value:function(e){var r=function(e){for(var r=1;r-1?t.slice(0,a+1)+" return "+t.slice(a+1):" return "+t;return l(Function,r.concat([s])).apply(void 0,f(i))}}]),e}();w.prototype.vm={Script:S},w.prototype.safeVm={Script:F},e.JSONPath=w,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=index-browser-umd.min.cjs.map diff --git a/dist/index-browser-umd.min.cjs.map b/dist/index-browser-umd.min.cjs.map index ad9f0af..791229e 100644 --- a/dist/index-browser-umd.min.cjs.map +++ b/dist/index-browser-umd.min.cjs.map @@ -1 +1 @@ -{"version":3,"file":"index-browser-umd.min.cjs","sources":["../src/jsonpath.js","../src/jsonpath-browser.js"],"sourcesContent":["const {hasOwnProperty: hasOwnProp} = Object.prototype;\n\n/**\n * @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject\n */\n\n/**\n * @typedef {any} AnyItem\n */\n\n/**\n * @typedef {any} AnyResult\n */\n\n/**\n * Copies array and then pushes item into it.\n * @param {GenericArray} arr Array to copy and into which to push\n * @param {AnyItem} item Array item to add (to end)\n * @returns {GenericArray} Copy of the original array\n */\nfunction push (arr, item) {\n arr = arr.slice();\n arr.push(item);\n return arr;\n}\n/**\n * Copies array and then unshifts item into it.\n * @param {AnyItem} item Array item to add (to beginning)\n * @param {GenericArray} arr Array to copy and into which to unshift\n * @returns {GenericArray} Copy of the original array\n */\nfunction unshift (item, arr) {\n arr = arr.slice();\n arr.unshift(item);\n return arr;\n}\n\n/**\n * Caught when JSONPath is used without `new` but rethrown if with `new`\n * @extends Error\n */\nclass NewError extends Error {\n /**\n * @param {AnyResult} value The evaluated scalar value\n */\n constructor (value) {\n super(\n 'JSONPath should not be called with \"new\" (it prevents return ' +\n 'of (unwrapped) scalar values)'\n );\n this.avoidNew = true;\n this.value = value;\n this.name = 'NewError';\n }\n}\n\n/**\n* @typedef {PlainObject} ReturnObject\n* @property {string} path\n* @property {JSONObject} value\n* @property {PlainObject|GenericArray} parent\n* @property {string} parentProperty\n*/\n\n/**\n* @callback JSONPathCallback\n* @param {string|PlainObject} preferredOutput\n* @param {\"value\"|\"property\"} type\n* @param {ReturnObject} fullRetObj\n* @returns {void}\n*/\n\n/**\n* @callback OtherTypeCallback\n* @param {JSONObject} val\n* @param {string} path\n* @param {PlainObject|GenericArray} parent\n* @param {string} parentPropName\n* @returns {boolean}\n*/\n\n/* eslint-disable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */\n/**\n * @typedef {PlainObject} JSONPathOptions\n * @property {JSON} json\n * @property {string|string[]} path\n * @property {\"value\"|\"path\"|\"pointer\"|\"parent\"|\"parentProperty\"|\"all\"} [resultType=\"value\"]\n * @property {boolean} [flatten=false]\n * @property {boolean} [wrap=true]\n * @property {PlainObject} [sandbox={}]\n * @property {boolean} [preventEval=false]\n * @property {PlainObject|GenericArray|null} [parent=null]\n * @property {string|null} [parentProperty=null]\n * @property {JSONPathCallback} [callback]\n * @property {OtherTypeCallback} [otherTypeCallback] Defaults to\n * function which throws on encountering `@other`\n * @property {boolean} [autostart=true]\n */\n/* eslint-enable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */\n\n/**\n * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`\n * @param {string} [expr] JSON path to evaluate\n * @param {JSON} [obj] JSON object to evaluate against\n * @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload\n * per `resultType`, 2) `\"value\"|\"property\"`, 3) Full returned object with\n * all payloads\n * @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end\n * of one's query, this will be invoked with the value of the item, its\n * path, its parent, and its parent's property name, and it should return\n * a boolean indicating whether the supplied value belongs to the \"other\"\n * type or not (or it may handle transformations and return `false`).\n * @returns {JSONPath}\n * @class\n */\nfunction JSONPath (opts, expr, obj, callback, otherTypeCallback) {\n // eslint-disable-next-line no-restricted-syntax\n if (!(this instanceof JSONPath)) {\n try {\n return new JSONPath(opts, expr, obj, callback, otherTypeCallback);\n } catch (e) {\n if (!e.avoidNew) {\n throw e;\n }\n return e.value;\n }\n }\n\n if (typeof opts === 'string') {\n otherTypeCallback = callback;\n callback = obj;\n obj = expr;\n expr = opts;\n opts = null;\n }\n const optObj = opts && typeof opts === 'object';\n opts = opts || {};\n this.json = opts.json || obj;\n this.path = opts.path || expr;\n this.resultType = opts.resultType || 'value';\n this.flatten = opts.flatten || false;\n this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;\n this.sandbox = opts.sandbox || {};\n this.preventEval = opts.preventEval || false;\n this.parent = opts.parent || null;\n this.parentProperty = opts.parentProperty || null;\n this.callback = opts.callback || callback || null;\n this.otherTypeCallback = opts.otherTypeCallback ||\n otherTypeCallback ||\n function () {\n throw new TypeError(\n 'You must supply an otherTypeCallback callback option ' +\n 'with the @other() operator.'\n );\n };\n\n if (opts.autostart !== false) {\n const args = {\n path: (optObj ? opts.path : expr)\n };\n if (!optObj) {\n args.json = obj;\n } else if ('json' in opts) {\n args.json = opts.json;\n }\n const ret = this.evaluate(args);\n if (!ret || typeof ret !== 'object') {\n throw new NewError(ret);\n }\n return ret;\n }\n}\n\n// PUBLIC METHODS\nJSONPath.prototype.evaluate = function (\n expr, json, callback, otherTypeCallback\n) {\n let currParent = this.parent,\n currParentProperty = this.parentProperty;\n let {flatten, wrap} = this;\n\n this.currResultType = this.resultType;\n this.currPreventEval = this.preventEval;\n this.currSandbox = this.sandbox;\n callback = callback || this.callback;\n this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;\n\n json = json || this.json;\n expr = expr || this.path;\n if (expr && typeof expr === 'object' && !Array.isArray(expr)) {\n if (!expr.path && expr.path !== '') {\n throw new TypeError(\n 'You must supply a \"path\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n if (!(hasOwnProp.call(expr, 'json'))) {\n throw new TypeError(\n 'You must supply a \"json\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n ({json} = expr);\n flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;\n this.currResultType = hasOwnProp.call(expr, 'resultType')\n ? expr.resultType\n : this.currResultType;\n this.currSandbox = hasOwnProp.call(expr, 'sandbox')\n ? expr.sandbox\n : this.currSandbox;\n wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;\n this.currPreventEval = hasOwnProp.call(expr, 'preventEval')\n ? expr.preventEval\n : this.currPreventEval;\n callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;\n this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback')\n ? expr.otherTypeCallback\n : this.currOtherTypeCallback;\n currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;\n currParentProperty = hasOwnProp.call(expr, 'parentProperty')\n ? expr.parentProperty\n : currParentProperty;\n expr = expr.path;\n }\n currParent = currParent || null;\n currParentProperty = currParentProperty || null;\n\n if (Array.isArray(expr)) {\n expr = JSONPath.toPathString(expr);\n }\n if ((!expr && expr !== '') || !json) {\n return undefined;\n }\n\n const exprList = JSONPath.toPathArray(expr);\n if (exprList[0] === '$' && exprList.length > 1) { exprList.shift(); }\n this._hasParentSelector = null;\n const result = this\n ._trace(\n exprList, json, ['$'], currParent, currParentProperty, callback\n )\n .filter(function (ea) { return ea && !ea.isParentSelector; });\n\n if (!result.length) { return wrap ? [] : undefined; }\n if (!wrap && result.length === 1 && !result[0].hasArrExpr) {\n return this._getPreferredOutput(result[0]);\n }\n return result.reduce((rslt, ea) => {\n const valOrPath = this._getPreferredOutput(ea);\n if (flatten && Array.isArray(valOrPath)) {\n rslt = rslt.concat(valOrPath);\n } else {\n rslt.push(valOrPath);\n }\n return rslt;\n }, []);\n};\n\n// PRIVATE METHODS\n\nJSONPath.prototype._getPreferredOutput = function (ea) {\n const resultType = this.currResultType;\n switch (resultType) {\n case 'all': {\n const path = Array.isArray(ea.path)\n ? ea.path\n : JSONPath.toPathArray(ea.path);\n ea.pointer = JSONPath.toPointer(path);\n ea.path = typeof ea.path === 'string'\n ? ea.path\n : JSONPath.toPathString(ea.path);\n return ea;\n } case 'value': case 'parent': case 'parentProperty':\n return ea[resultType];\n case 'path':\n return JSONPath.toPathString(ea[resultType]);\n case 'pointer':\n return JSONPath.toPointer(ea.path);\n default:\n throw new TypeError('Unknown result type');\n }\n};\n\nJSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {\n if (callback) {\n const preferredOutput = this._getPreferredOutput(fullRetObj);\n fullRetObj.path = typeof fullRetObj.path === 'string'\n ? fullRetObj.path\n : JSONPath.toPathString(fullRetObj.path);\n // eslint-disable-next-line n/callback-return\n callback(preferredOutput, type, fullRetObj);\n }\n};\n\n/**\n *\n * @param {string} expr\n * @param {JSONObject} val\n * @param {string} path\n * @param {PlainObject|GenericArray} parent\n * @param {string} parentPropName\n * @param {JSONPathCallback} callback\n * @param {boolean} hasArrExpr\n * @param {boolean} literalPriority\n * @returns {ReturnObject|ReturnObject[]}\n */\nJSONPath.prototype._trace = function (\n expr, val, path, parent, parentPropName, callback, hasArrExpr,\n literalPriority\n) {\n // No expr to follow? return path and value as the result of\n // this trace branch\n let retObj;\n if (!expr.length) {\n retObj = {\n path,\n value: val,\n parent,\n parentProperty: parentPropName,\n hasArrExpr\n };\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n\n const loc = expr[0], x = expr.slice(1);\n\n // We need to gather the return value of recursive trace calls in order to\n // do the parent sel computation.\n const ret = [];\n /**\n *\n * @param {ReturnObject|ReturnObject[]} elems\n * @returns {void}\n */\n function addRet (elems) {\n if (Array.isArray(elems)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test:\n // `ret.push(...elems);`\n elems.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(elems);\n }\n }\n if ((typeof loc !== 'string' || literalPriority) && val &&\n hasOwnProp.call(val, loc)\n ) { // simple case--directly follow property\n addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback,\n hasArrExpr));\n // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`\n } else if (loc === '*') { // all child properties\n this._walk(val, (m) => {\n addRet(this._trace(\n x, val[m], push(path, m), val, m, callback, true, true\n ));\n });\n } else if (loc === '..') { // all descendent parent properties\n // Check remaining expression with val's immediate children\n addRet(\n this._trace(x, val, path, parent, parentPropName, callback,\n hasArrExpr)\n );\n this._walk(val, (m) => {\n // We don't join m and x here because we only want parents,\n // not scalar values\n if (typeof val[m] === 'object') {\n // Keep going with recursive descent on val's\n // object children\n addRet(this._trace(\n expr.slice(), val[m], push(path, m), val, m, callback, true\n ));\n }\n });\n // The parent sel computation is handled in the frame above using the\n // ancestor object of val\n } else if (loc === '^') {\n // This is not a final endpoint, so we do not invoke the callback here\n this._hasParentSelector = true;\n return {\n path: path.slice(0, -1),\n expr: x,\n isParentSelector: true\n };\n } else if (loc === '~') { // property name\n retObj = {\n path: push(path, loc),\n value: parentPropName,\n parent,\n parentProperty: null\n };\n this._handleCallback(retObj, callback, 'property');\n return retObj;\n } else if (loc === '$') { // root only\n addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));\n } else if ((/^(-?\\d*):(-?\\d*):?(\\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax\n addRet(\n this._slice(loc, x, val, path, parent, parentPropName, callback)\n );\n } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering)\n if (this.currPreventEval) {\n throw new Error('Eval [?(expr)] prevented in JSONPath expression.');\n }\n const safeLoc = loc.replace(/^\\?\\((.*?)\\)$/u, '$1');\n this._walk(val, (m) => {\n if (this._eval(safeLoc, val[m], m, path, parent, parentPropName)) {\n addRet(this._trace(x, val[m], push(path, m), val, m, callback,\n true));\n }\n });\n } else if (loc[0] === '(') { // [(expr)] (dynamic property/index)\n if (this.currPreventEval) {\n throw new Error('Eval [(expr)] prevented in JSONPath expression.');\n }\n // As this will resolve to a property name (but we don't know it\n // yet), property and parent information is relative to the\n // parent of the property to which this expression will resolve\n addRet(this._trace(unshift(\n this._eval(\n loc, val, path[path.length - 1],\n path.slice(0, -1), parent, parentPropName\n ),\n x\n ), val, path, parent, parentPropName, callback, hasArrExpr));\n } else if (loc[0] === '@') { // value type: @boolean(), etc.\n let addType = false;\n const valueType = loc.slice(1, -2);\n switch (valueType) {\n case 'scalar':\n if (!val || !(['object', 'function'].includes(typeof val))) {\n addType = true;\n }\n break;\n case 'boolean': case 'string': case 'undefined': case 'function':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType) {\n addType = true;\n }\n break;\n case 'integer':\n if (Number.isFinite(val) && !(val % 1)) {\n addType = true;\n }\n break;\n case 'number':\n if (Number.isFinite(val)) {\n addType = true;\n }\n break;\n case 'nonFinite':\n if (typeof val === 'number' && !Number.isFinite(val)) {\n addType = true;\n }\n break;\n case 'object':\n // eslint-disable-next-line valid-typeof\n if (val && typeof val === valueType) {\n addType = true;\n }\n break;\n case 'array':\n if (Array.isArray(val)) {\n addType = true;\n }\n break;\n case 'other':\n addType = this.currOtherTypeCallback(\n val, path, parent, parentPropName\n );\n break;\n case 'null':\n if (val === null) {\n addType = true;\n }\n break;\n /* c8 ignore next 2 */\n default:\n throw new TypeError('Unknown value type ' + valueType);\n }\n if (addType) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n // `-escaped property\n } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {\n const locProp = loc.slice(1);\n addRet(this._trace(\n x, val[locProp], push(path, locProp), val, locProp, callback,\n hasArrExpr, true\n ));\n } else if (loc.includes(',')) { // [name1,name2,...]\n const parts = loc.split(',');\n for (const part of parts) {\n addRet(this._trace(\n unshift(part, x), val, path, parent, parentPropName, callback,\n true\n ));\n }\n // simple case--directly follow property\n } else if (\n !literalPriority && val && hasOwnProp.call(val, loc)\n ) {\n addRet(\n this._trace(x, val[loc], push(path, loc), val, loc, callback,\n hasArrExpr, true)\n );\n }\n\n // We check the resulting values for parent selections. For parent\n // selections we discard the value object and continue the trace with the\n // current val object\n if (this._hasParentSelector) {\n for (let t = 0; t < ret.length; t++) {\n const rett = ret[t];\n if (rett && rett.isParentSelector) {\n const tmp = this._trace(\n rett.expr, val, rett.path, parent, parentPropName, callback,\n hasArrExpr\n );\n if (Array.isArray(tmp)) {\n ret[t] = tmp[0];\n const tl = tmp.length;\n for (let tt = 1; tt < tl; tt++) {\n t++;\n ret.splice(t, 0, tmp[tt]);\n }\n } else {\n ret[t] = tmp;\n }\n }\n }\n }\n return ret;\n};\n\nJSONPath.prototype._walk = function (val, f) {\n if (Array.isArray(val)) {\n const n = val.length;\n for (let i = 0; i < n; i++) {\n f(i);\n }\n } else if (val && typeof val === 'object') {\n Object.keys(val).forEach((m) => {\n f(m);\n });\n }\n};\n\nJSONPath.prototype._slice = function (\n loc, expr, val, path, parent, parentPropName, callback\n) {\n if (!Array.isArray(val)) { return undefined; }\n const len = val.length, parts = loc.split(':'),\n step = (parts[2] && Number.parseInt(parts[2])) || 1;\n let start = (parts[0] && Number.parseInt(parts[0])) || 0,\n end = (parts[1] && Number.parseInt(parts[1])) || len;\n start = (start < 0) ? Math.max(0, start + len) : Math.min(len, start);\n end = (end < 0) ? Math.max(0, end + len) : Math.min(len, end);\n const ret = [];\n for (let i = start; i < end; i += step) {\n const tmp = this._trace(\n unshift(i, expr), val, path, parent, parentPropName, callback, true\n );\n // Should only be possible to be an array here since first part of\n // ``unshift(i, expr)` passed in above would not be empty, nor `~`,\n // nor begin with `@` (as could return objects)\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test: `ret.push(...tmp);`\n tmp.forEach((t) => {\n ret.push(t);\n });\n }\n return ret;\n};\n\nJSONPath.prototype._eval = function (\n code, _v, _vname, path, parent, parentPropName\n) {\n this.currSandbox._$_parentProperty = parentPropName;\n this.currSandbox._$_parent = parent;\n this.currSandbox._$_property = _vname;\n this.currSandbox._$_root = this.json;\n this.currSandbox._$_v = _v;\n\n const containsPath = code.includes('@path');\n if (containsPath) {\n this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));\n }\n\n const scriptCacheKey = 'script:' + code;\n if (!JSONPath.cache[scriptCacheKey]) {\n let script = code\n .replace(/@parentProperty/gu, '_$_parentProperty')\n .replace(/@parent/gu, '_$_parent')\n .replace(/@property/gu, '_$_property')\n .replace(/@root/gu, '_$_root')\n .replace(/@([.\\s)[])/gu, '_$_v$1');\n if (containsPath) {\n script = script.replace(/@path/gu, '_$_path');\n }\n\n JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);\n }\n\n try {\n return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);\n } catch (e) {\n throw new Error('jsonPath: ' + e.message + ': ' + code);\n }\n};\n\n// PUBLIC CLASS PROPERTIES AND METHODS\n\n// Could store the cache object itself\nJSONPath.cache = {};\n\n/**\n * @param {string[]} pathArr Array to convert\n * @returns {string} The path string\n */\nJSONPath.toPathString = function (pathArr) {\n const x = pathArr, n = x.length;\n let p = '$';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += (/^[0-9*]+$/u).test(x[i]) ? ('[' + x[i] + ']') : (\"['\" + x[i] + \"']\");\n }\n }\n return p;\n};\n\n/**\n * @param {string} pointer JSON Path\n * @returns {string} JSON Pointer\n */\nJSONPath.toPointer = function (pointer) {\n const x = pointer, n = x.length;\n let p = '';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += '/' + x[i].toString()\n .replace(/~/gu, '~0')\n .replace(/\\//gu, '~1');\n }\n }\n return p;\n};\n\n/**\n * @param {string} expr Expression to convert\n * @returns {string[]}\n */\nJSONPath.toPathArray = function (expr) {\n const {cache} = JSONPath;\n if (cache[expr]) { return cache[expr].concat(); }\n const subx = [];\n const normalized = expr\n // Properties\n .replace(\n /@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\\(\\)/gu,\n ';$&;'\n )\n // Parenthetical evaluations (filtering and otherwise), directly\n // within brackets or single quotes\n .replace(/[['](\\??\\(.*?\\))[\\]']/gu, function ($0, $1) {\n return '[#' + (subx.push($1) - 1) + ']';\n })\n // Escape periods and tildes within properties\n .replace(/\\[['\"]([^'\\]]*)['\"]\\]/gu, function ($0, prop) {\n return \"['\" + prop\n .replace(/\\./gu, '%@%')\n .replace(/~/gu, '%%@@%%') +\n \"']\";\n })\n // Properties operator\n .replace(/~/gu, ';~;')\n // Split by property boundaries\n .replace(/['\"]?\\.['\"]?(?![^[]*\\])|\\[['\"]?/gu, ';')\n // Reinsert periods within properties\n .replace(/%@%/gu, '.')\n // Reinsert tildes within properties\n .replace(/%%@@%%/gu, '~')\n // Parent\n .replace(/(?:;)?(\\^+)(?:;)?/gu, function ($0, ups) {\n return ';' + ups.split('').join(';') + ';';\n })\n // Descendents\n .replace(/;;;|;;/gu, ';..;')\n // Remove trailing\n .replace(/;$|'?\\]|'$/gu, '');\n\n const exprList = normalized.split(';').map(function (exp) {\n const match = exp.match(/#(\\d+)/u);\n return !match || !match[1] ? exp : subx[match[1]];\n });\n cache[expr] = exprList;\n return cache[expr].concat();\n};\n\nexport {JSONPath};\n","import {JSONPath} from './jsonpath.js';\n\n/**\n * @typedef {any} ContextItem\n */\n\n/**\n * @typedef {any} EvaluatedResult\n */\n\n/**\n * @callback ConditionCallback\n * @param {ContextItem} item\n * @returns {boolean}\n */\n\n/**\n * Copy items out of one array into another.\n * @param {GenericArray} source Array with items to copy\n * @param {GenericArray} target Array to which to copy\n * @param {ConditionCallback} conditionCb Callback passed the current item;\n * will move item if evaluates to `true`\n * @returns {void}\n */\nconst moveToAnotherArray = function (source, target, conditionCb) {\n const il = source.length;\n for (let i = 0; i < il; i++) {\n const item = source[i];\n if (conditionCb(item)) {\n target.push(source.splice(i--, 1)[0]);\n }\n }\n};\n\n/**\n * In-browser replacement for NodeJS' VM.Script.\n */\nclass Script {\n /**\n * @param {string} expr Expression to evaluate\n */\n constructor (expr) {\n this.code = expr;\n }\n\n /**\n * @param {PlainObject} context Object whose items will be added\n * to evaluation\n * @returns {EvaluatedResult} Result of evaluated code\n */\n runInNewContext (context) {\n let expr = this.code;\n const keys = Object.keys(context);\n const funcs = [];\n moveToAnotherArray(keys, funcs, (key) => {\n return typeof context[key] === 'function';\n });\n const values = keys.map((vr, i) => {\n return context[vr];\n });\n\n const funcString = funcs.reduce((s, func) => {\n let fString = context[func].toString();\n if (!(/function/u).test(fString)) {\n fString = 'function ' + fString;\n }\n return 'var ' + func + '=' + fString + ';' + s;\n }, '');\n\n expr = funcString + expr;\n\n // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function\n if (!(/(['\"])use strict\\1/u).test(expr) &&\n !keys.includes('arguments')\n ) {\n expr = 'var arguments = undefined;' + expr;\n }\n\n // Remove last semi so `return` will be inserted before\n // the previous one instead, allowing for the return\n // of a bare ending expression\n expr = expr.replace(/;\\s*$/u, '');\n\n // Insert `return`\n const lastStatementEnd = expr.lastIndexOf(';');\n const code = (lastStatementEnd > -1\n ? expr.slice(0, lastStatementEnd + 1) +\n ' return ' + expr.slice(lastStatementEnd + 1)\n : ' return ' + expr);\n\n // eslint-disable-next-line no-new-func\n return (new Function(...keys, code))(...values);\n }\n}\n\nJSONPath.prototype.vm = {\n Script\n};\n\nexport {JSONPath};\n"],"names":["hasOwnProp","Object","prototype","hasOwnProperty","push","arr","item","slice","unshift","NewError","value","_this","_classCallCheck","this","_super","call","avoidNew","name","Error","JSONPath","opts","expr","obj","callback","otherTypeCallback","e","optObj","_typeof","json","path","resultType","flatten","wrap","sandbox","preventEval","parent","parentProperty","TypeError","autostart","args","ret","evaluate","_this2","currParent","currParentProperty","currResultType","currPreventEval","currSandbox","currOtherTypeCallback","Array","isArray","toPathString","exprList","toPathArray","length","shift","_hasParentSelector","result","_trace","filter","ea","isParentSelector","hasArrExpr","reduce","rslt","valOrPath","_getPreferredOutput","concat","undefined","pointer","toPointer","_handleCallback","fullRetObj","type","preferredOutput","val","parentPropName","literalPriority","retObj","_this3","loc","x","addRet","elems","forEach","t","_walk","m","test","_slice","indexOf","safeLoc","replace","_eval","addType","valueType","includes","Number","isFinite","locProp","_step","_iterator","_createForOfIteratorHelper","split","s","n","done","part","err","f","rett","tmp","tl","tt","splice","i","keys","len","parts","step","parseInt","start","end","Math","max","min","code","_v","_vname","_$_parentProperty","_$_parent","_$_property","_$_root","_$_v","containsPath","_$_path","scriptCacheKey","cache","script","vm","Script","runInNewContext","message","pathArr","p","toString","subx","$0","$1","prop","ups","join","map","exp","match","context","funcs","source","target","conditionCb","il","moveToAnotherArray","key","values","vr","funcString","func","fString","lastStatementEnd","lastIndexOf","_construct","Function","apply","_toConsumableArray"],"mappings":"4hGAAA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7C,EAAMwC,GAAO,SAACM,GAC7B,MAA+B,mBAAjBP,EAAQO,EACzB,IACD,IAAMC,EAAS/C,EAAKoC,KAAI,SAACY,EAAIjD,GACzB,OAAOwC,EAAQS,EAClB,IAEKC,EAAaT,EAAM7F,QAAO,SAACyC,EAAG8D,GAChC,IAAIC,EAAUZ,EAAQW,GAAMrB,WAI5B,MAHM,WAAazD,KAAK+E,KACpBA,EAAU,YAAcA,GAErB,OAASD,EAAO,IAAMC,EAAU,IAAM/D,CAL9B,GAMhB,IAKG,qBAAuBhB,KAH7BnE,EAAOgJ,EAAahJ,IAIf+F,EAAKpB,SAAS,eAEf3E,EAAO,6BAA+BA,GAS1C,IAAMmJ,GAHNnJ,EAAOA,EAAKuE,QAAQ,yEAAU,KAGA6E,YAAY,KACpC3C,EAAQ0C,GAAoB,EAC5BnJ,EAAKd,MAAM,EAAGiK,EAAmB,GAC/B,WAAanJ,EAAKd,MAAMiK,EAAmB,GAC7C,WAAanJ,EAGnB,OAAOqJ,EAAKC,SAAYvD,UAAMU,KAAvB8C,WAAA,EAAAC,EAAiCV,GAC3C,UAGLhJ,EAASjB,UAAUyI,GAAK,CACpBC,OAAAA"} \ No newline at end of file +{"version":3,"file":"index-browser-umd.min.cjs","sources":["../node_modules/.pnpm/jsep@1.3.8/node_modules/jsep/dist/jsep.js","../node_modules/.pnpm/@jsep-plugin+regex@1.0.3_jsep@1.3.8/node_modules/@jsep-plugin/regex/dist/index.js","../src/jsonpath.js","../src/jsonpath-browser.js"],"sourcesContent":["/**\n * @implements {IHooks}\n */\nclass Hooks {\n\t/**\n\t * @callback HookCallback\n\t * @this {*|Jsep} this\n\t * @param {Jsep} env\n\t * @returns: void\n\t */\n\t/**\n\t * Adds the given callback to the list of callbacks for the given hook.\n\t *\n\t * The callback will be invoked when the hook it is registered for is run.\n\t *\n\t * One callback function can be registered to multiple hooks and the same hook multiple times.\n\t *\n\t * @param {string|object} name The name of the hook, or an object of callbacks keyed by name\n\t * @param {HookCallback|boolean} callback The callback function which is given environment variables.\n\t * @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom)\n\t * @public\n\t */\n\tadd(name, callback, first) {\n\t\tif (typeof arguments[0] != 'string') {\n\t\t\t// Multiple hook callbacks, keyed by name\n\t\t\tfor (let name in arguments[0]) {\n\t\t\t\tthis.add(name, arguments[0][name], arguments[1]);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t(Array.isArray(name) ? name : [name]).forEach(function (name) {\n\t\t\t\tthis[name] = this[name] || [];\n\n\t\t\t\tif (callback) {\n\t\t\t\t\tthis[name][first ? 'unshift' : 'push'](callback);\n\t\t\t\t}\n\t\t\t}, this);\n\t\t}\n\t}\n\n\t/**\n\t * Runs a hook invoking all registered callbacks with the given environment variables.\n\t *\n\t * Callbacks will be invoked synchronously and in the order in which they were registered.\n\t *\n\t * @param {string} name The name of the hook.\n\t * @param {Object} env The environment variables of the hook passed to all callbacks registered.\n\t * @public\n\t */\n\trun(name, env) {\n\t\tthis[name] = this[name] || [];\n\t\tthis[name].forEach(function (callback) {\n\t\t\tcallback.call(env && env.context ? env.context : env, env);\n\t\t});\n\t}\n}\n\n/**\n * @implements {IPlugins}\n */\nclass Plugins {\n\tconstructor(jsep) {\n\t\tthis.jsep = jsep;\n\t\tthis.registered = {};\n\t}\n\n\t/**\n\t * @callback PluginSetup\n\t * @this {Jsep} jsep\n\t * @returns: void\n\t */\n\t/**\n\t * Adds the given plugin(s) to the registry\n\t *\n\t * @param {object} plugins\n\t * @param {string} plugins.name The name of the plugin\n\t * @param {PluginSetup} plugins.init The init function\n\t * @public\n\t */\n\tregister(...plugins) {\n\t\tplugins.forEach((plugin) => {\n\t\t\tif (typeof plugin !== 'object' || !plugin.name || !plugin.init) {\n\t\t\t\tthrow new Error('Invalid JSEP plugin format');\n\t\t\t}\n\t\t\tif (this.registered[plugin.name]) {\n\t\t\t\t// already registered. Ignore.\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tplugin.init(this.jsep);\n\t\t\tthis.registered[plugin.name] = plugin;\n\t\t});\n\t}\n}\n\n// JavaScript Expression Parser (JSEP) 1.3.8\n\nclass Jsep {\n\t/**\n\t * @returns {string}\n\t */\n\tstatic get version() {\n\t\t// To be filled in by the template\n\t\treturn '1.3.8';\n\t}\n\n\t/**\n\t * @returns {string}\n\t */\n\tstatic toString() {\n\t\treturn 'JavaScript Expression Parser (JSEP) v' + Jsep.version;\n\t};\n\n\t// ==================== CONFIG ================================\n\t/**\n\t * @method addUnaryOp\n\t * @param {string} op_name The name of the unary op to add\n\t * @returns {Jsep}\n\t */\n\tstatic addUnaryOp(op_name) {\n\t\tJsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);\n\t\tJsep.unary_ops[op_name] = 1;\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method jsep.addBinaryOp\n\t * @param {string} op_name The name of the binary op to add\n\t * @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence\n\t * @param {boolean} [isRightAssociative=false] whether operator is right-associative\n\t * @returns {Jsep}\n\t */\n\tstatic addBinaryOp(op_name, precedence, isRightAssociative) {\n\t\tJsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);\n\t\tJsep.binary_ops[op_name] = precedence;\n\t\tif (isRightAssociative) {\n\t\t\tJsep.right_associative.add(op_name);\n\t\t}\n\t\telse {\n\t\t\tJsep.right_associative.delete(op_name);\n\t\t}\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method addIdentifierChar\n\t * @param {string} char The additional character to treat as a valid part of an identifier\n\t * @returns {Jsep}\n\t */\n\tstatic addIdentifierChar(char) {\n\t\tJsep.additional_identifier_chars.add(char);\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method addLiteral\n\t * @param {string} literal_name The name of the literal to add\n\t * @param {*} literal_value The value of the literal\n\t * @returns {Jsep}\n\t */\n\tstatic addLiteral(literal_name, literal_value) {\n\t\tJsep.literals[literal_name] = literal_value;\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeUnaryOp\n\t * @param {string} op_name The name of the unary op to remove\n\t * @returns {Jsep}\n\t */\n\tstatic removeUnaryOp(op_name) {\n\t\tdelete Jsep.unary_ops[op_name];\n\t\tif (op_name.length === Jsep.max_unop_len) {\n\t\t\tJsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);\n\t\t}\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeAllUnaryOps\n\t * @returns {Jsep}\n\t */\n\tstatic removeAllUnaryOps() {\n\t\tJsep.unary_ops = {};\n\t\tJsep.max_unop_len = 0;\n\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeIdentifierChar\n\t * @param {string} char The additional character to stop treating as a valid part of an identifier\n\t * @returns {Jsep}\n\t */\n\tstatic removeIdentifierChar(char) {\n\t\tJsep.additional_identifier_chars.delete(char);\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeBinaryOp\n\t * @param {string} op_name The name of the binary op to remove\n\t * @returns {Jsep}\n\t */\n\tstatic removeBinaryOp(op_name) {\n\t\tdelete Jsep.binary_ops[op_name];\n\n\t\tif (op_name.length === Jsep.max_binop_len) {\n\t\t\tJsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);\n\t\t}\n\t\tJsep.right_associative.delete(op_name);\n\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeAllBinaryOps\n\t * @returns {Jsep}\n\t */\n\tstatic removeAllBinaryOps() {\n\t\tJsep.binary_ops = {};\n\t\tJsep.max_binop_len = 0;\n\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeLiteral\n\t * @param {string} literal_name The name of the literal to remove\n\t * @returns {Jsep}\n\t */\n\tstatic removeLiteral(literal_name) {\n\t\tdelete Jsep.literals[literal_name];\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeAllLiterals\n\t * @returns {Jsep}\n\t */\n\tstatic removeAllLiterals() {\n\t\tJsep.literals = {};\n\n\t\treturn Jsep;\n\t}\n\t// ==================== END CONFIG ============================\n\n\n\t/**\n\t * @returns {string}\n\t */\n\tget char() {\n\t\treturn this.expr.charAt(this.index);\n\t}\n\n\t/**\n\t * @returns {number}\n\t */\n\tget code() {\n\t\treturn this.expr.charCodeAt(this.index);\n\t};\n\n\n\t/**\n\t * @param {string} expr a string with the passed in express\n\t * @returns Jsep\n\t */\n\tconstructor(expr) {\n\t\t// `index` stores the character number we are currently at\n\t\t// All of the gobbles below will modify `index` as we move along\n\t\tthis.expr = expr;\n\t\tthis.index = 0;\n\t}\n\n\t/**\n\t * static top-level parser\n\t * @returns {jsep.Expression}\n\t */\n\tstatic parse(expr) {\n\t\treturn (new Jsep(expr)).parse();\n\t}\n\n\t/**\n\t * Get the longest key length of any object\n\t * @param {object} obj\n\t * @returns {number}\n\t */\n\tstatic getMaxKeyLen(obj) {\n\t\treturn Math.max(0, ...Object.keys(obj).map(k => k.length));\n\t}\n\n\t/**\n\t * `ch` is a character code in the next three functions\n\t * @param {number} ch\n\t * @returns {boolean}\n\t */\n\tstatic isDecimalDigit(ch) {\n\t\treturn (ch >= 48 && ch <= 57); // 0...9\n\t}\n\n\t/**\n\t * Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float.\n\t * @param {string} op_val\n\t * @returns {number}\n\t */\n\tstatic binaryPrecedence(op_val) {\n\t\treturn Jsep.binary_ops[op_val] || 0;\n\t}\n\n\t/**\n\t * Looks for start of identifier\n\t * @param {number} ch\n\t * @returns {boolean}\n\t */\n\tstatic isIdentifierStart(ch) {\n\t\treturn (ch >= 65 && ch <= 90) || // A...Z\n\t\t\t(ch >= 97 && ch <= 122) || // a...z\n\t\t\t(ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)]) || // any non-ASCII that is not an operator\n\t\t\t(Jsep.additional_identifier_chars.has(String.fromCharCode(ch))); // additional characters\n\t}\n\n\t/**\n\t * @param {number} ch\n\t * @returns {boolean}\n\t */\n\tstatic isIdentifierPart(ch) {\n\t\treturn Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);\n\t}\n\n\t/**\n\t * throw error at index of the expression\n\t * @param {string} message\n\t * @throws\n\t */\n\tthrowError(message) {\n\t\tconst error = new Error(message + ' at character ' + this.index);\n\t\terror.index = this.index;\n\t\terror.description = message;\n\t\tthrow error;\n\t}\n\n\t/**\n\t * Run a given hook\n\t * @param {string} name\n\t * @param {jsep.Expression|false} [node]\n\t * @returns {?jsep.Expression}\n\t */\n\trunHook(name, node) {\n\t\tif (Jsep.hooks[name]) {\n\t\t\tconst env = { context: this, node };\n\t\t\tJsep.hooks.run(name, env);\n\t\t\treturn env.node;\n\t\t}\n\t\treturn node;\n\t}\n\n\t/**\n\t * Runs a given hook until one returns a node\n\t * @param {string} name\n\t * @returns {?jsep.Expression}\n\t */\n\tsearchHook(name) {\n\t\tif (Jsep.hooks[name]) {\n\t\t\tconst env = { context: this };\n\t\t\tJsep.hooks[name].find(function (callback) {\n\t\t\t\tcallback.call(env.context, env);\n\t\t\t\treturn env.node;\n\t\t\t});\n\t\t\treturn env.node;\n\t\t}\n\t}\n\n\t/**\n\t * Push `index` up to the next non-space character\n\t */\n\tgobbleSpaces() {\n\t\tlet ch = this.code;\n\t\t// Whitespace\n\t\twhile (ch === Jsep.SPACE_CODE\n\t\t|| ch === Jsep.TAB_CODE\n\t\t|| ch === Jsep.LF_CODE\n\t\t|| ch === Jsep.CR_CODE) {\n\t\t\tch = this.expr.charCodeAt(++this.index);\n\t\t}\n\t\tthis.runHook('gobble-spaces');\n\t}\n\n\t/**\n\t * Top-level method to parse all expressions and returns compound or single node\n\t * @returns {jsep.Expression}\n\t */\n\tparse() {\n\t\tthis.runHook('before-all');\n\t\tconst nodes = this.gobbleExpressions();\n\n\t\t// If there's only one expression just try returning the expression\n\t\tconst node = nodes.length === 1\n\t\t ? nodes[0]\n\t\t\t: {\n\t\t\t\ttype: Jsep.COMPOUND,\n\t\t\t\tbody: nodes\n\t\t\t};\n\t\treturn this.runHook('after-all', node);\n\t}\n\n\t/**\n\t * top-level parser (but can be reused within as well)\n\t * @param {number} [untilICode]\n\t * @returns {jsep.Expression[]}\n\t */\n\tgobbleExpressions(untilICode) {\n\t\tlet nodes = [], ch_i, node;\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tch_i = this.code;\n\n\t\t\t// Expressions can be separated by semicolons, commas, or just inferred without any\n\t\t\t// separators\n\t\t\tif (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {\n\t\t\t\tthis.index++; // ignore separators\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// Try to gobble each expression individually\n\t\t\t\tif (node = this.gobbleExpression()) {\n\t\t\t\t\tnodes.push(node);\n\t\t\t\t\t// If we weren't able to find a binary expression and are out of room, then\n\t\t\t\t\t// the expression passed in probably has too much\n\t\t\t\t}\n\t\t\t\telse if (this.index < this.expr.length) {\n\t\t\t\t\tif (ch_i === untilICode) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tthis.throwError('Unexpected \"' + this.char + '\"');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn nodes;\n\t}\n\n\t/**\n\t * The main parsing function.\n\t * @returns {?jsep.Expression}\n\t */\n\tgobbleExpression() {\n\t\tconst node = this.searchHook('gobble-expression') || this.gobbleBinaryExpression();\n\t\tthis.gobbleSpaces();\n\n\t\treturn this.runHook('after-expression', node);\n\t}\n\n\t/**\n\t * Search for the operation portion of the string (e.g. `+`, `===`)\n\t * Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)\n\t * and move down from 3 to 2 to 1 character until a matching binary operation is found\n\t * then, return that binary operation\n\t * @returns {string|boolean}\n\t */\n\tgobbleBinaryOp() {\n\t\tthis.gobbleSpaces();\n\t\tlet to_check = this.expr.substr(this.index, Jsep.max_binop_len);\n\t\tlet tc_len = to_check.length;\n\n\t\twhile (tc_len > 0) {\n\t\t\t// Don't accept a binary op when it is an identifier.\n\t\t\t// Binary ops that start with a identifier-valid character must be followed\n\t\t\t// by a non identifier-part valid character\n\t\t\tif (Jsep.binary_ops.hasOwnProperty(to_check) && (\n\t\t\t\t!Jsep.isIdentifierStart(this.code) ||\n\t\t\t\t(this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))\n\t\t\t)) {\n\t\t\t\tthis.index += tc_len;\n\t\t\t\treturn to_check;\n\t\t\t}\n\t\t\tto_check = to_check.substr(0, --tc_len);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * This function is responsible for gobbling an individual expression,\n\t * e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`\n\t * @returns {?jsep.BinaryExpression}\n\t */\n\tgobbleBinaryExpression() {\n\t\tlet node, biop, prec, stack, biop_info, left, right, i, cur_biop;\n\n\t\t// First, try to get the leftmost thing\n\t\t// Then, check to see if there's a binary operator operating on that leftmost thing\n\t\t// Don't gobbleBinaryOp without a left-hand-side\n\t\tleft = this.gobbleToken();\n\t\tif (!left) {\n\t\t\treturn left;\n\t\t}\n\t\tbiop = this.gobbleBinaryOp();\n\n\t\t// If there wasn't a binary operator, just return the leftmost node\n\t\tif (!biop) {\n\t\t\treturn left;\n\t\t}\n\n\t\t// Otherwise, we need to start a stack to properly place the binary operations in their\n\t\t// precedence structure\n\t\tbiop_info = { value: biop, prec: Jsep.binaryPrecedence(biop), right_a: Jsep.right_associative.has(biop) };\n\n\t\tright = this.gobbleToken();\n\n\t\tif (!right) {\n\t\t\tthis.throwError(\"Expected expression after \" + biop);\n\t\t}\n\n\t\tstack = [left, biop_info, right];\n\n\t\t// Properly deal with precedence using [recursive descent](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm)\n\t\twhile ((biop = this.gobbleBinaryOp())) {\n\t\t\tprec = Jsep.binaryPrecedence(biop);\n\n\t\t\tif (prec === 0) {\n\t\t\t\tthis.index -= biop.length;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tbiop_info = { value: biop, prec, right_a: Jsep.right_associative.has(biop) };\n\n\t\t\tcur_biop = biop;\n\n\t\t\t// Reduce: make a binary expression from the three topmost entries.\n\t\t\tconst comparePrev = prev => biop_info.right_a && prev.right_a\n\t\t\t\t? prec > prev.prec\n\t\t\t\t: prec <= prev.prec;\n\t\t\twhile ((stack.length > 2) && comparePrev(stack[stack.length - 2])) {\n\t\t\t\tright = stack.pop();\n\t\t\t\tbiop = stack.pop().value;\n\t\t\t\tleft = stack.pop();\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.BINARY_EXP,\n\t\t\t\t\toperator: biop,\n\t\t\t\t\tleft,\n\t\t\t\t\tright\n\t\t\t\t};\n\t\t\t\tstack.push(node);\n\t\t\t}\n\n\t\t\tnode = this.gobbleToken();\n\n\t\t\tif (!node) {\n\t\t\t\tthis.throwError(\"Expected expression after \" + cur_biop);\n\t\t\t}\n\n\t\t\tstack.push(biop_info, node);\n\t\t}\n\n\t\ti = stack.length - 1;\n\t\tnode = stack[i];\n\n\t\twhile (i > 1) {\n\t\t\tnode = {\n\t\t\t\ttype: Jsep.BINARY_EXP,\n\t\t\t\toperator: stack[i - 1].value,\n\t\t\t\tleft: stack[i - 2],\n\t\t\t\tright: node\n\t\t\t};\n\t\t\ti -= 2;\n\t\t}\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * An individual part of a binary expression:\n\t * e.g. `foo.bar(baz)`, `1`, `\"abc\"`, `(a % 2)` (because it's in parenthesis)\n\t * @returns {boolean|jsep.Expression}\n\t */\n\tgobbleToken() {\n\t\tlet ch, to_check, tc_len, node;\n\n\t\tthis.gobbleSpaces();\n\t\tnode = this.searchHook('gobble-token');\n\t\tif (node) {\n\t\t\treturn this.runHook('after-token', node);\n\t\t}\n\n\t\tch = this.code;\n\n\t\tif (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {\n\t\t\t// Char code 46 is a dot `.` which can start off a numeric literal\n\t\t\treturn this.gobbleNumericLiteral();\n\t\t}\n\n\t\tif (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {\n\t\t\t// Single or double quotes\n\t\t\tnode = this.gobbleStringLiteral();\n\t\t}\n\t\telse if (ch === Jsep.OBRACK_CODE) {\n\t\t\tnode = this.gobbleArray();\n\t\t}\n\t\telse {\n\t\t\tto_check = this.expr.substr(this.index, Jsep.max_unop_len);\n\t\t\ttc_len = to_check.length;\n\n\t\t\twhile (tc_len > 0) {\n\t\t\t\t// Don't accept an unary op when it is an identifier.\n\t\t\t\t// Unary ops that start with a identifier-valid character must be followed\n\t\t\t\t// by a non identifier-part valid character\n\t\t\t\tif (Jsep.unary_ops.hasOwnProperty(to_check) && (\n\t\t\t\t\t!Jsep.isIdentifierStart(this.code) ||\n\t\t\t\t\t(this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))\n\t\t\t\t)) {\n\t\t\t\t\tthis.index += tc_len;\n\t\t\t\t\tconst argument = this.gobbleToken();\n\t\t\t\t\tif (!argument) {\n\t\t\t\t\t\tthis.throwError('missing unaryOp argument');\n\t\t\t\t\t}\n\t\t\t\t\treturn this.runHook('after-token', {\n\t\t\t\t\t\ttype: Jsep.UNARY_EXP,\n\t\t\t\t\t\toperator: to_check,\n\t\t\t\t\t\targument,\n\t\t\t\t\t\tprefix: true\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tto_check = to_check.substr(0, --tc_len);\n\t\t\t}\n\n\t\t\tif (Jsep.isIdentifierStart(ch)) {\n\t\t\t\tnode = this.gobbleIdentifier();\n\t\t\t\tif (Jsep.literals.hasOwnProperty(node.name)) {\n\t\t\t\t\tnode = {\n\t\t\t\t\t\ttype: Jsep.LITERAL,\n\t\t\t\t\t\tvalue: Jsep.literals[node.name],\n\t\t\t\t\t\traw: node.name,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (node.name === Jsep.this_str) {\n\t\t\t\t\tnode = { type: Jsep.THIS_EXP };\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (ch === Jsep.OPAREN_CODE) { // open parenthesis\n\t\t\t\tnode = this.gobbleGroup();\n\t\t\t}\n\t\t}\n\n\t\tif (!node) {\n\t\t\treturn this.runHook('after-token', false);\n\t\t}\n\n\t\tnode = this.gobbleTokenProperty(node);\n\t\treturn this.runHook('after-token', node);\n\t}\n\n\t/**\n\t * Gobble properties of of identifiers/strings/arrays/groups.\n\t * e.g. `foo`, `bar.baz`, `foo['bar'].baz`\n\t * It also gobbles function calls:\n\t * e.g. `Math.acos(obj.angle)`\n\t * @param {jsep.Expression} node\n\t * @returns {jsep.Expression}\n\t */\n\tgobbleTokenProperty(node) {\n\t\tthis.gobbleSpaces();\n\n\t\tlet ch = this.code;\n\t\twhile (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {\n\t\t\tlet optional;\n\t\t\tif (ch === Jsep.QUMARK_CODE) {\n\t\t\t\tif (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\toptional = true;\n\t\t\t\tthis.index += 2;\n\t\t\t\tthis.gobbleSpaces();\n\t\t\t\tch = this.code;\n\t\t\t}\n\t\t\tthis.index++;\n\n\t\t\tif (ch === Jsep.OBRACK_CODE) {\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.MEMBER_EXP,\n\t\t\t\t\tcomputed: true,\n\t\t\t\t\tobject: node,\n\t\t\t\t\tproperty: this.gobbleExpression()\n\t\t\t\t};\n\t\t\t\tthis.gobbleSpaces();\n\t\t\t\tch = this.code;\n\t\t\t\tif (ch !== Jsep.CBRACK_CODE) {\n\t\t\t\t\tthis.throwError('Unclosed [');\n\t\t\t\t}\n\t\t\t\tthis.index++;\n\t\t\t}\n\t\t\telse if (ch === Jsep.OPAREN_CODE) {\n\t\t\t\t// A function call is being made; gobble all the arguments\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.CALL_EXP,\n\t\t\t\t\t'arguments': this.gobbleArguments(Jsep.CPAREN_CODE),\n\t\t\t\t\tcallee: node\n\t\t\t\t};\n\t\t\t}\n\t\t\telse if (ch === Jsep.PERIOD_CODE || optional) {\n\t\t\t\tif (optional) {\n\t\t\t\t\tthis.index--;\n\t\t\t\t}\n\t\t\t\tthis.gobbleSpaces();\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.MEMBER_EXP,\n\t\t\t\t\tcomputed: false,\n\t\t\t\t\tobject: node,\n\t\t\t\t\tproperty: this.gobbleIdentifier(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (optional) {\n\t\t\t\tnode.optional = true;\n\t\t\t} // else leave undefined for compatibility with esprima\n\n\t\t\tthis.gobbleSpaces();\n\t\t\tch = this.code;\n\t\t}\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to\n\t * keep track of everything in the numeric literal and then calling `parseFloat` on that string\n\t * @returns {jsep.Literal}\n\t */\n\tgobbleNumericLiteral() {\n\t\tlet number = '', ch, chCode;\n\n\t\twhile (Jsep.isDecimalDigit(this.code)) {\n\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t}\n\n\t\tif (this.code === Jsep.PERIOD_CODE) { // can start with a decimal marker\n\t\t\tnumber += this.expr.charAt(this.index++);\n\n\t\t\twhile (Jsep.isDecimalDigit(this.code)) {\n\t\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\t}\n\t\t}\n\n\t\tch = this.char;\n\n\t\tif (ch === 'e' || ch === 'E') { // exponent marker\n\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\tch = this.char;\n\n\t\t\tif (ch === '+' || ch === '-') { // exponent sign\n\t\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\t}\n\n\t\t\twhile (Jsep.isDecimalDigit(this.code)) { // exponent itself\n\t\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\t}\n\n\t\t\tif (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1)) ) {\n\t\t\t\tthis.throwError('Expected exponent (' + number + this.char + ')');\n\t\t\t}\n\t\t}\n\n\t\tchCode = this.code;\n\n\t\t// Check to make sure this isn't a variable name that start with a number (123abc)\n\t\tif (Jsep.isIdentifierStart(chCode)) {\n\t\t\tthis.throwError('Variable names cannot start with a number (' +\n\t\t\t\tnumber + this.char + ')');\n\t\t}\n\t\telse if (chCode === Jsep.PERIOD_CODE || (number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE)) {\n\t\t\tthis.throwError('Unexpected period');\n\t\t}\n\n\t\treturn {\n\t\t\ttype: Jsep.LITERAL,\n\t\t\tvalue: parseFloat(number),\n\t\t\traw: number\n\t\t};\n\t}\n\n\t/**\n\t * Parses a string literal, staring with single or double quotes with basic support for escape codes\n\t * e.g. `\"hello world\"`, `'this is\\nJSEP'`\n\t * @returns {jsep.Literal}\n\t */\n\tgobbleStringLiteral() {\n\t\tlet str = '';\n\t\tconst startIndex = this.index;\n\t\tconst quote = this.expr.charAt(this.index++);\n\t\tlet closed = false;\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tlet ch = this.expr.charAt(this.index++);\n\n\t\t\tif (ch === quote) {\n\t\t\t\tclosed = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (ch === '\\\\') {\n\t\t\t\t// Check for all of the common escape codes\n\t\t\t\tch = this.expr.charAt(this.index++);\n\n\t\t\t\tswitch (ch) {\n\t\t\t\t\tcase 'n': str += '\\n'; break;\n\t\t\t\t\tcase 'r': str += '\\r'; break;\n\t\t\t\t\tcase 't': str += '\\t'; break;\n\t\t\t\t\tcase 'b': str += '\\b'; break;\n\t\t\t\t\tcase 'f': str += '\\f'; break;\n\t\t\t\t\tcase 'v': str += '\\x0B'; break;\n\t\t\t\t\tdefault : str += ch;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tstr += ch;\n\t\t\t}\n\t\t}\n\n\t\tif (!closed) {\n\t\t\tthis.throwError('Unclosed quote after \"' + str + '\"');\n\t\t}\n\n\t\treturn {\n\t\t\ttype: Jsep.LITERAL,\n\t\t\tvalue: str,\n\t\t\traw: this.expr.substring(startIndex, this.index),\n\t\t};\n\t}\n\n\t/**\n\t * Gobbles only identifiers\n\t * e.g.: `foo`, `_value`, `$x1`\n\t * Also, this function checks if that identifier is a literal:\n\t * (e.g. `true`, `false`, `null`) or `this`\n\t * @returns {jsep.Identifier}\n\t */\n\tgobbleIdentifier() {\n\t\tlet ch = this.code, start = this.index;\n\n\t\tif (Jsep.isIdentifierStart(ch)) {\n\t\t\tthis.index++;\n\t\t}\n\t\telse {\n\t\t\tthis.throwError('Unexpected ' + this.char);\n\t\t}\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tch = this.code;\n\n\t\t\tif (Jsep.isIdentifierPart(ch)) {\n\t\t\t\tthis.index++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\ttype: Jsep.IDENTIFIER,\n\t\t\tname: this.expr.slice(start, this.index),\n\t\t};\n\t}\n\n\t/**\n\t * Gobbles a list of arguments within the context of a function call\n\t * or array literal. This function also assumes that the opening character\n\t * `(` or `[` has already been gobbled, and gobbles expressions and commas\n\t * until the terminator character `)` or `]` is encountered.\n\t * e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`\n\t * @param {number} termination\n\t * @returns {jsep.Expression[]}\n\t */\n\tgobbleArguments(termination) {\n\t\tconst args = [];\n\t\tlet closed = false;\n\t\tlet separator_count = 0;\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tthis.gobbleSpaces();\n\t\t\tlet ch_i = this.code;\n\n\t\t\tif (ch_i === termination) { // done parsing\n\t\t\t\tclosed = true;\n\t\t\t\tthis.index++;\n\n\t\t\t\tif (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length){\n\t\t\t\t\tthis.throwError('Unexpected token ' + String.fromCharCode(termination));\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (ch_i === Jsep.COMMA_CODE) { // between expressions\n\t\t\t\tthis.index++;\n\t\t\t\tseparator_count++;\n\n\t\t\t\tif (separator_count !== args.length) { // missing argument\n\t\t\t\t\tif (termination === Jsep.CPAREN_CODE) {\n\t\t\t\t\t\tthis.throwError('Unexpected token ,');\n\t\t\t\t\t}\n\t\t\t\t\telse if (termination === Jsep.CBRACK_CODE) {\n\t\t\t\t\t\tfor (let arg = args.length; arg < separator_count; arg++) {\n\t\t\t\t\t\t\targs.push(null);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (args.length !== separator_count && separator_count !== 0) {\n\t\t\t\t// NOTE: `&& separator_count !== 0` allows for either all commas, or all spaces as arguments\n\t\t\t\tthis.throwError('Expected comma');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconst node = this.gobbleExpression();\n\n\t\t\t\tif (!node || node.type === Jsep.COMPOUND) {\n\t\t\t\t\tthis.throwError('Expected comma');\n\t\t\t\t}\n\n\t\t\t\targs.push(node);\n\t\t\t}\n\t\t}\n\n\t\tif (!closed) {\n\t\t\tthis.throwError('Expected ' + String.fromCharCode(termination));\n\t\t}\n\n\t\treturn args;\n\t}\n\n\t/**\n\t * Responsible for parsing a group of things within parentheses `()`\n\t * that have no identifier in front (so not a function call)\n\t * This function assumes that it needs to gobble the opening parenthesis\n\t * and then tries to gobble everything within that parenthesis, assuming\n\t * that the next thing it should see is the close parenthesis. If not,\n\t * then the expression probably doesn't have a `)`\n\t * @returns {boolean|jsep.Expression}\n\t */\n\tgobbleGroup() {\n\t\tthis.index++;\n\t\tlet nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);\n\t\tif (this.code === Jsep.CPAREN_CODE) {\n\t\t\tthis.index++;\n\t\t\tif (nodes.length === 1) {\n\t\t\t\treturn nodes[0];\n\t\t\t}\n\t\t\telse if (!nodes.length) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn {\n\t\t\t\t\ttype: Jsep.SEQUENCE_EXP,\n\t\t\t\t\texpressions: nodes,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tthis.throwError('Unclosed (');\n\t\t}\n\t}\n\n\t/**\n\t * Responsible for parsing Array literals `[1, 2, 3]`\n\t * This function assumes that it needs to gobble the opening bracket\n\t * and then tries to gobble the expressions as arguments.\n\t * @returns {jsep.ArrayExpression}\n\t */\n\tgobbleArray() {\n\t\tthis.index++;\n\n\t\treturn {\n\t\t\ttype: Jsep.ARRAY_EXP,\n\t\t\telements: this.gobbleArguments(Jsep.CBRACK_CODE)\n\t\t};\n\t}\n}\n\n// Static fields:\nconst hooks = new Hooks();\nObject.assign(Jsep, {\n\thooks,\n\tplugins: new Plugins(Jsep),\n\n\t// Node Types\n\t// ----------\n\t// This is the full set of types that any JSEP node can be.\n\t// Store them here to save space when minified\n\tCOMPOUND: 'Compound',\n\tSEQUENCE_EXP: 'SequenceExpression',\n\tIDENTIFIER: 'Identifier',\n\tMEMBER_EXP: 'MemberExpression',\n\tLITERAL: 'Literal',\n\tTHIS_EXP: 'ThisExpression',\n\tCALL_EXP: 'CallExpression',\n\tUNARY_EXP: 'UnaryExpression',\n\tBINARY_EXP: 'BinaryExpression',\n\tARRAY_EXP: 'ArrayExpression',\n\n\tTAB_CODE: 9,\n\tLF_CODE: 10,\n\tCR_CODE: 13,\n\tSPACE_CODE: 32,\n\tPERIOD_CODE: 46, // '.'\n\tCOMMA_CODE: 44, // ','\n\tSQUOTE_CODE: 39, // single quote\n\tDQUOTE_CODE: 34, // double quotes\n\tOPAREN_CODE: 40, // (\n\tCPAREN_CODE: 41, // )\n\tOBRACK_CODE: 91, // [\n\tCBRACK_CODE: 93, // ]\n\tQUMARK_CODE: 63, // ?\n\tSEMCOL_CODE: 59, // ;\n\tCOLON_CODE: 58, // :\n\n\n\t// Operations\n\t// ----------\n\t// Use a quickly-accessible map to store all of the unary operators\n\t// Values are set to `1` (it really doesn't matter)\n\tunary_ops: {\n\t\t'-': 1,\n\t\t'!': 1,\n\t\t'~': 1,\n\t\t'+': 1\n\t},\n\n\t// Also use a map for the binary operations but set their values to their\n\t// binary precedence for quick reference (higher number = higher precedence)\n\t// see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)\n\tbinary_ops: {\n\t\t'||': 1, '&&': 2, '|': 3, '^': 4, '&': 5,\n\t\t'==': 6, '!=': 6, '===': 6, '!==': 6,\n\t\t'<': 7, '>': 7, '<=': 7, '>=': 7,\n\t\t'<<': 8, '>>': 8, '>>>': 8,\n\t\t'+': 9, '-': 9,\n\t\t'*': 10, '/': 10, '%': 10\n\t},\n\n\t// sets specific binary_ops as right-associative\n\tright_associative: new Set(),\n\n\t// Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char)\n\tadditional_identifier_chars: new Set(['$', '_']),\n\n\t// Literals\n\t// ----------\n\t// Store the values to return for the various literals we may encounter\n\tliterals: {\n\t\t'true': true,\n\t\t'false': false,\n\t\t'null': null\n\t},\n\n\t// Except for `this`, which is special. This could be changed to something like `'self'` as well\n\tthis_str: 'this',\n});\nJsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);\nJsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);\n\n// Backward Compatibility:\nconst jsep = expr => (new Jsep(expr)).parse();\nconst staticMethods = Object.getOwnPropertyNames(Jsep);\nstaticMethods\n\t.forEach((m) => {\n\t\tif (jsep[m] === undefined && m !== 'prototype') {\n\t\t\tjsep[m] = Jsep[m];\n\t\t}\n\t});\njsep.Jsep = Jsep; // allows for const { Jsep } = require('jsep');\n\nconst CONDITIONAL_EXP = 'ConditionalExpression';\n\nvar ternary = {\n\tname: 'ternary',\n\n\tinit(jsep) {\n\t\t// Ternary expression: test ? consequent : alternate\n\t\tjsep.hooks.add('after-expression', function gobbleTernary(env) {\n\t\t\tif (env.node && this.code === jsep.QUMARK_CODE) {\n\t\t\t\tthis.index++;\n\t\t\t\tconst test = env.node;\n\t\t\t\tconst consequent = this.gobbleExpression();\n\n\t\t\t\tif (!consequent) {\n\t\t\t\t\tthis.throwError('Expected expression');\n\t\t\t\t}\n\n\t\t\t\tthis.gobbleSpaces();\n\n\t\t\t\tif (this.code === jsep.COLON_CODE) {\n\t\t\t\t\tthis.index++;\n\t\t\t\t\tconst alternate = this.gobbleExpression();\n\n\t\t\t\t\tif (!alternate) {\n\t\t\t\t\t\tthis.throwError('Expected expression');\n\t\t\t\t\t}\n\t\t\t\t\tenv.node = {\n\t\t\t\t\t\ttype: CONDITIONAL_EXP,\n\t\t\t\t\t\ttest,\n\t\t\t\t\t\tconsequent,\n\t\t\t\t\t\talternate,\n\t\t\t\t\t};\n\n\t\t\t\t\t// check for operators of higher priority than ternary (i.e. assignment)\n\t\t\t\t\t// jsep sets || at 1, and assignment at 0.9, and conditional should be between them\n\t\t\t\t\tif (test.operator && jsep.binary_ops[test.operator] <= 0.9) {\n\t\t\t\t\t\tlet newTest = test;\n\t\t\t\t\t\twhile (newTest.right.operator && jsep.binary_ops[newTest.right.operator] <= 0.9) {\n\t\t\t\t\t\t\tnewTest = newTest.right;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tenv.node.test = newTest.right;\n\t\t\t\t\t\tnewTest.right = env.node;\n\t\t\t\t\t\tenv.node = test;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis.throwError('Expected :');\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t},\n};\n\n// Add default plugins:\n\njsep.plugins.register(ternary);\n\nexport { Jsep, jsep as default };\n","const FSLASH_CODE = 47; // '/'\nconst BSLASH_CODE = 92; // '\\\\'\n\nvar index = {\n\tname: 'regex',\n\n\tinit(jsep) {\n\t\t// Regex literal: /abc123/ig\n\t\tjsep.hooks.add('gobble-token', function gobbleRegexLiteral(env) {\n\t\t\tif (this.code === FSLASH_CODE) {\n\t\t\t\tconst patternIndex = ++this.index;\n\n\t\t\t\tlet inCharSet = false;\n\t\t\t\twhile (this.index < this.expr.length) {\n\t\t\t\t\tif (this.code === FSLASH_CODE && !inCharSet) {\n\t\t\t\t\t\tconst pattern = this.expr.slice(patternIndex, this.index);\n\n\t\t\t\t\t\tlet flags = '';\n\t\t\t\t\t\twhile (++this.index < this.expr.length) {\n\t\t\t\t\t\t\tconst code = this.code;\n\t\t\t\t\t\t\tif ((code >= 97 && code <= 122) // a...z\n\t\t\t\t\t\t\t\t|| (code >= 65 && code <= 90) // A...Z\n\t\t\t\t\t\t\t\t|| (code >= 48 && code <= 57)) { // 0-9\n\t\t\t\t\t\t\t\tflags += this.char;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet value;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tvalue = new RegExp(pattern, flags);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\t\tthis.throwError(e.message);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tenv.node = {\n\t\t\t\t\t\t\ttype: jsep.LITERAL,\n\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\traw: this.expr.slice(patternIndex - 1, this.index),\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// allow . [] and () after regex: /regex/.test(a)\n\t\t\t\t\t\tenv.node = this.gobbleTokenProperty(env.node);\n\t\t\t\t\t\treturn env.node;\n\t\t\t\t\t}\n\t\t\t\t\tif (this.code === jsep.OBRACK_CODE) {\n\t\t\t\t\t\tinCharSet = true;\n\t\t\t\t\t}\n\t\t\t\t\telse if (inCharSet && this.code === jsep.CBRACK_CODE) {\n\t\t\t\t\t\tinCharSet = false;\n\t\t\t\t\t}\n\t\t\t\t\tthis.index += this.code === BSLASH_CODE ? 2 : 1;\n\t\t\t\t}\n\t\t\t\tthis.throwError('Unclosed Regex');\n\t\t\t}\n\t\t});\n\t},\n};\n\nexport { index as default };\n","const {hasOwnProperty: hasOwnProp} = Object.prototype;\n\n/**\n * @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject\n */\n\n/**\n * @typedef {any} AnyItem\n */\n\n/**\n * @typedef {any} AnyResult\n */\n\n/**\n * Copies array and then pushes item into it.\n * @param {GenericArray} arr Array to copy and into which to push\n * @param {AnyItem} item Array item to add (to end)\n * @returns {GenericArray} Copy of the original array\n */\nfunction push (arr, item) {\n arr = arr.slice();\n arr.push(item);\n return arr;\n}\n/**\n * Copies array and then unshifts item into it.\n * @param {AnyItem} item Array item to add (to beginning)\n * @param {GenericArray} arr Array to copy and into which to unshift\n * @returns {GenericArray} Copy of the original array\n */\nfunction unshift (item, arr) {\n arr = arr.slice();\n arr.unshift(item);\n return arr;\n}\n\n/**\n * Caught when JSONPath is used without `new` but rethrown if with `new`\n * @extends Error\n */\nclass NewError extends Error {\n /**\n * @param {AnyResult} value The evaluated scalar value\n */\n constructor (value) {\n super(\n 'JSONPath should not be called with \"new\" (it prevents return ' +\n 'of (unwrapped) scalar values)'\n );\n this.avoidNew = true;\n this.value = value;\n this.name = 'NewError';\n }\n}\n\n/**\n* @typedef {PlainObject} ReturnObject\n* @property {string} path\n* @property {JSONObject} value\n* @property {PlainObject|GenericArray} parent\n* @property {string} parentProperty\n*/\n\n/**\n* @callback JSONPathCallback\n* @param {string|PlainObject} preferredOutput\n* @param {\"value\"|\"property\"} type\n* @param {ReturnObject} fullRetObj\n* @returns {void}\n*/\n\n/**\n* @callback OtherTypeCallback\n* @param {JSONObject} val\n* @param {string} path\n* @param {PlainObject|GenericArray} parent\n* @param {string} parentPropName\n* @returns {boolean}\n*/\n\n/* eslint-disable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */\n/**\n * @typedef {PlainObject} JSONPathOptions\n * @property {JSON} json\n * @property {string|string[]} path\n * @property {\"value\"|\"path\"|\"pointer\"|\"parent\"|\"parentProperty\"|\"all\"} [resultType=\"value\"]\n * @property {boolean} [flatten=false]\n * @property {boolean} [wrap=true]\n * @property {PlainObject} [sandbox={}]\n * @property {boolean} [preventEval=false]\n * @property {\"safe\"|\"native\"|\"none\"} [evalType='safe']\n * @property {PlainObject|GenericArray|null} [parent=null]\n * @property {string|null} [parentProperty=null]\n * @property {JSONPathCallback} [callback]\n * @property {OtherTypeCallback} [otherTypeCallback] Defaults to\n * function which throws on encountering `@other`\n * @property {boolean} [autostart=true]\n */\n/* eslint-enable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */\n\n/**\n * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`\n * @param {string} [expr] JSON path to evaluate\n * @param {JSON} [obj] JSON object to evaluate against\n * @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload\n * per `resultType`, 2) `\"value\"|\"property\"`, 3) Full returned object with\n * all payloads\n * @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end\n * of one's query, this will be invoked with the value of the item, its\n * path, its parent, and its parent's property name, and it should return\n * a boolean indicating whether the supplied value belongs to the \"other\"\n * type or not (or it may handle transformations and return `false`).\n * @returns {JSONPath}\n * @class\n */\nfunction JSONPath (opts, expr, obj, callback, otherTypeCallback) {\n // eslint-disable-next-line no-restricted-syntax\n if (!(this instanceof JSONPath)) {\n try {\n return new JSONPath(opts, expr, obj, callback, otherTypeCallback);\n } catch (e) {\n if (!e.avoidNew) {\n throw e;\n }\n return e.value;\n }\n }\n\n if (typeof opts === 'string') {\n otherTypeCallback = callback;\n callback = obj;\n obj = expr;\n expr = opts;\n opts = null;\n }\n const optObj = opts && typeof opts === 'object';\n opts = opts || {};\n this.json = opts.json || obj;\n this.path = opts.path || expr;\n this.resultType = opts.resultType || 'value';\n this.flatten = opts.flatten || false;\n this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;\n this.sandbox = opts.sandbox || {};\n this.preventEval = opts.preventEval || false;\n this.evalType = opts.evalType || 'safe';\n this.parent = opts.parent || null;\n this.parentProperty = opts.parentProperty || null;\n this.callback = opts.callback || callback || null;\n this.otherTypeCallback = opts.otherTypeCallback ||\n otherTypeCallback ||\n function () {\n throw new TypeError(\n 'You must supply an otherTypeCallback callback option ' +\n 'with the @other() operator.'\n );\n };\n\n if (opts.autostart !== false) {\n const args = {\n path: (optObj ? opts.path : expr)\n };\n if (!optObj) {\n args.json = obj;\n } else if ('json' in opts) {\n args.json = opts.json;\n }\n const ret = this.evaluate(args);\n if (!ret || typeof ret !== 'object') {\n throw new NewError(ret);\n }\n return ret;\n }\n}\n\n// PUBLIC METHODS\nJSONPath.prototype.evaluate = function (\n expr, json, callback, otherTypeCallback\n) {\n let currParent = this.parent,\n currParentProperty = this.parentProperty;\n let {flatten, wrap} = this;\n\n this.currResultType = this.resultType;\n this.currPreventEval = this.preventEval;\n this.currEvalType = this.evalType;\n this.currSandbox = this.sandbox;\n callback = callback || this.callback;\n this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;\n\n json = json || this.json;\n expr = expr || this.path;\n if (expr && typeof expr === 'object' && !Array.isArray(expr)) {\n if (!expr.path && expr.path !== '') {\n throw new TypeError(\n 'You must supply a \"path\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n if (!(hasOwnProp.call(expr, 'json'))) {\n throw new TypeError(\n 'You must supply a \"json\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n ({json} = expr);\n flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;\n this.currResultType = hasOwnProp.call(expr, 'resultType')\n ? expr.resultType\n : this.currResultType;\n this.currSandbox = hasOwnProp.call(expr, 'sandbox')\n ? expr.sandbox\n : this.currSandbox;\n wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;\n this.currPreventEval = hasOwnProp.call(expr, 'preventEval')\n ? expr.preventEval\n : this.currPreventEval;\n this.currEvalType = hasOwnProp.call(expr, 'evalType')\n ? expr.evalType\n : this.currEvalType;\n callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;\n this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback')\n ? expr.otherTypeCallback\n : this.currOtherTypeCallback;\n currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;\n currParentProperty = hasOwnProp.call(expr, 'parentProperty')\n ? expr.parentProperty\n : currParentProperty;\n expr = expr.path;\n }\n currParent = currParent || null;\n currParentProperty = currParentProperty || null;\n\n if (Array.isArray(expr)) {\n expr = JSONPath.toPathString(expr);\n }\n if ((!expr && expr !== '') || !json) {\n return undefined;\n }\n\n const exprList = JSONPath.toPathArray(expr);\n if (exprList[0] === '$' && exprList.length > 1) { exprList.shift(); }\n this._hasParentSelector = null;\n const result = this\n ._trace(\n exprList, json, ['$'], currParent, currParentProperty, callback\n )\n .filter(function (ea) { return ea && !ea.isParentSelector; });\n\n if (!result.length) { return wrap ? [] : undefined; }\n if (!wrap && result.length === 1 && !result[0].hasArrExpr) {\n return this._getPreferredOutput(result[0]);\n }\n return result.reduce((rslt, ea) => {\n const valOrPath = this._getPreferredOutput(ea);\n if (flatten && Array.isArray(valOrPath)) {\n rslt = rslt.concat(valOrPath);\n } else {\n rslt.push(valOrPath);\n }\n return rslt;\n }, []);\n};\n\n// PRIVATE METHODS\n\nJSONPath.prototype._getPreferredOutput = function (ea) {\n const resultType = this.currResultType;\n switch (resultType) {\n case 'all': {\n const path = Array.isArray(ea.path)\n ? ea.path\n : JSONPath.toPathArray(ea.path);\n ea.pointer = JSONPath.toPointer(path);\n ea.path = typeof ea.path === 'string'\n ? ea.path\n : JSONPath.toPathString(ea.path);\n return ea;\n } case 'value': case 'parent': case 'parentProperty':\n return ea[resultType];\n case 'path':\n return JSONPath.toPathString(ea[resultType]);\n case 'pointer':\n return JSONPath.toPointer(ea.path);\n default:\n throw new TypeError('Unknown result type');\n }\n};\n\nJSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {\n if (callback) {\n const preferredOutput = this._getPreferredOutput(fullRetObj);\n fullRetObj.path = typeof fullRetObj.path === 'string'\n ? fullRetObj.path\n : JSONPath.toPathString(fullRetObj.path);\n // eslint-disable-next-line n/callback-return\n callback(preferredOutput, type, fullRetObj);\n }\n};\n\n/**\n *\n * @param {string} expr\n * @param {JSONObject} val\n * @param {string} path\n * @param {PlainObject|GenericArray} parent\n * @param {string} parentPropName\n * @param {JSONPathCallback} callback\n * @param {boolean} hasArrExpr\n * @param {boolean} literalPriority\n * @returns {ReturnObject|ReturnObject[]}\n */\nJSONPath.prototype._trace = function (\n expr, val, path, parent, parentPropName, callback, hasArrExpr,\n literalPriority\n) {\n // No expr to follow? return path and value as the result of\n // this trace branch\n let retObj;\n if (!expr.length) {\n retObj = {\n path,\n value: val,\n parent,\n parentProperty: parentPropName,\n hasArrExpr\n };\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n\n const loc = expr[0], x = expr.slice(1);\n\n // We need to gather the return value of recursive trace calls in order to\n // do the parent sel computation.\n const ret = [];\n /**\n *\n * @param {ReturnObject|ReturnObject[]} elems\n * @returns {void}\n */\n function addRet (elems) {\n if (Array.isArray(elems)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test:\n // `ret.push(...elems);`\n elems.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(elems);\n }\n }\n if ((typeof loc !== 'string' || literalPriority) && val &&\n hasOwnProp.call(val, loc)\n ) { // simple case--directly follow property\n addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback,\n hasArrExpr));\n // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`\n } else if (loc === '*') { // all child properties\n this._walk(val, (m) => {\n addRet(this._trace(\n x, val[m], push(path, m), val, m, callback, true, true\n ));\n });\n } else if (loc === '..') { // all descendent parent properties\n // Check remaining expression with val's immediate children\n addRet(\n this._trace(x, val, path, parent, parentPropName, callback,\n hasArrExpr)\n );\n this._walk(val, (m) => {\n // We don't join m and x here because we only want parents,\n // not scalar values\n if (typeof val[m] === 'object') {\n // Keep going with recursive descent on val's\n // object children\n addRet(this._trace(\n expr.slice(), val[m], push(path, m), val, m, callback, true\n ));\n }\n });\n // The parent sel computation is handled in the frame above using the\n // ancestor object of val\n } else if (loc === '^') {\n // This is not a final endpoint, so we do not invoke the callback here\n this._hasParentSelector = true;\n return {\n path: path.slice(0, -1),\n expr: x,\n isParentSelector: true\n };\n } else if (loc === '~') { // property name\n retObj = {\n path: push(path, loc),\n value: parentPropName,\n parent,\n parentProperty: null\n };\n this._handleCallback(retObj, callback, 'property');\n return retObj;\n } else if (loc === '$') { // root only\n addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));\n } else if ((/^(-?\\d*):(-?\\d*):?(\\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax\n addRet(\n this._slice(loc, x, val, path, parent, parentPropName, callback)\n );\n } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering)\n if (this.currPreventEval || this.currEvalType === 'none') {\n throw new Error('Eval [?(expr)] prevented in JSONPath expression.');\n }\n const safeLoc = loc.replace(/^\\?\\((.*?)\\)$/u, '$1');\n this._walk(val, (m) => {\n if (this._eval(safeLoc, val[m], m, path, parent, parentPropName)) {\n addRet(this._trace(x, val[m], push(path, m), val, m, callback,\n true));\n }\n });\n } else if (loc[0] === '(') { // [(expr)] (dynamic property/index)\n if (this.currPreventEval || this.currEvalType === 'none') {\n throw new Error('Eval [(expr)] prevented in JSONPath expression.');\n }\n // As this will resolve to a property name (but we don't know it\n // yet), property and parent information is relative to the\n // parent of the property to which this expression will resolve\n addRet(this._trace(unshift(\n this._eval(\n loc, val, path[path.length - 1],\n path.slice(0, -1), parent, parentPropName\n ),\n x\n ), val, path, parent, parentPropName, callback, hasArrExpr));\n } else if (loc[0] === '@') { // value type: @boolean(), etc.\n let addType = false;\n const valueType = loc.slice(1, -2);\n switch (valueType) {\n case 'scalar':\n if (!val || !(['object', 'function'].includes(typeof val))) {\n addType = true;\n }\n break;\n case 'boolean': case 'string': case 'undefined': case 'function':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType) {\n addType = true;\n }\n break;\n case 'integer':\n if (Number.isFinite(val) && !(val % 1)) {\n addType = true;\n }\n break;\n case 'number':\n if (Number.isFinite(val)) {\n addType = true;\n }\n break;\n case 'nonFinite':\n if (typeof val === 'number' && !Number.isFinite(val)) {\n addType = true;\n }\n break;\n case 'object':\n // eslint-disable-next-line valid-typeof\n if (val && typeof val === valueType) {\n addType = true;\n }\n break;\n case 'array':\n if (Array.isArray(val)) {\n addType = true;\n }\n break;\n case 'other':\n addType = this.currOtherTypeCallback(\n val, path, parent, parentPropName\n );\n break;\n case 'null':\n if (val === null) {\n addType = true;\n }\n break;\n /* c8 ignore next 2 */\n default:\n throw new TypeError('Unknown value type ' + valueType);\n }\n if (addType) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n // `-escaped property\n } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {\n const locProp = loc.slice(1);\n addRet(this._trace(\n x, val[locProp], push(path, locProp), val, locProp, callback,\n hasArrExpr, true\n ));\n } else if (loc.includes(',')) { // [name1,name2,...]\n const parts = loc.split(',');\n for (const part of parts) {\n addRet(this._trace(\n unshift(part, x), val, path, parent, parentPropName, callback,\n true\n ));\n }\n // simple case--directly follow property\n } else if (\n !literalPriority && val && hasOwnProp.call(val, loc)\n ) {\n addRet(\n this._trace(x, val[loc], push(path, loc), val, loc, callback,\n hasArrExpr, true)\n );\n }\n\n // We check the resulting values for parent selections. For parent\n // selections we discard the value object and continue the trace with the\n // current val object\n if (this._hasParentSelector) {\n for (let t = 0; t < ret.length; t++) {\n const rett = ret[t];\n if (rett && rett.isParentSelector) {\n const tmp = this._trace(\n rett.expr, val, rett.path, parent, parentPropName, callback,\n hasArrExpr\n );\n if (Array.isArray(tmp)) {\n ret[t] = tmp[0];\n const tl = tmp.length;\n for (let tt = 1; tt < tl; tt++) {\n t++;\n ret.splice(t, 0, tmp[tt]);\n }\n } else {\n ret[t] = tmp;\n }\n }\n }\n }\n return ret;\n};\n\nJSONPath.prototype._walk = function (val, f) {\n if (Array.isArray(val)) {\n const n = val.length;\n for (let i = 0; i < n; i++) {\n f(i);\n }\n } else if (val && typeof val === 'object') {\n Object.keys(val).forEach((m) => {\n f(m);\n });\n }\n};\n\nJSONPath.prototype._slice = function (\n loc, expr, val, path, parent, parentPropName, callback\n) {\n if (!Array.isArray(val)) { return undefined; }\n const len = val.length, parts = loc.split(':'),\n step = (parts[2] && Number.parseInt(parts[2])) || 1;\n let start = (parts[0] && Number.parseInt(parts[0])) || 0,\n end = (parts[1] && Number.parseInt(parts[1])) || len;\n start = (start < 0) ? Math.max(0, start + len) : Math.min(len, start);\n end = (end < 0) ? Math.max(0, end + len) : Math.min(len, end);\n const ret = [];\n for (let i = start; i < end; i += step) {\n const tmp = this._trace(\n unshift(i, expr), val, path, parent, parentPropName, callback, true\n );\n // Should only be possible to be an array here since first part of\n // ``unshift(i, expr)` passed in above would not be empty, nor `~`,\n // nor begin with `@` (as could return objects)\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test: `ret.push(...tmp);`\n tmp.forEach((t) => {\n ret.push(t);\n });\n }\n return ret;\n};\n\nJSONPath.prototype._eval = function (\n code, _v, _vname, path, parent, parentPropName\n) {\n this.currSandbox._$_parentProperty = parentPropName;\n this.currSandbox._$_parent = parent;\n this.currSandbox._$_property = _vname;\n this.currSandbox._$_root = this.json;\n this.currSandbox._$_v = _v;\n\n const containsPath = code.includes('@path');\n if (containsPath) {\n this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));\n }\n\n const scriptCacheKey = this.currEvalType + 'Script:' + code;\n if (!JSONPath.cache[scriptCacheKey]) {\n let script = code\n .replace(/@parentProperty/gu, '_$_parentProperty')\n .replace(/@parent/gu, '_$_parent')\n .replace(/@property/gu, '_$_property')\n .replace(/@root/gu, '_$_root')\n .replace(/@([.\\s)[])/gu, '_$_v$1');\n if (containsPath) {\n script = script.replace(/@path/gu, '_$_path');\n }\n if (this.currEvalType === 'safe') {\n JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);\n } else if (this.currEvalType === 'native') {\n JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);\n }\n }\n\n try {\n return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);\n } catch (e) {\n throw new Error('jsonPath: ' + e.message + ': ' + code);\n }\n};\n\n// PUBLIC CLASS PROPERTIES AND METHODS\n\n// Could store the cache object itself\nJSONPath.cache = {};\n\n/**\n * @param {string[]} pathArr Array to convert\n * @returns {string} The path string\n */\nJSONPath.toPathString = function (pathArr) {\n const x = pathArr, n = x.length;\n let p = '$';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += (/^[0-9*]+$/u).test(x[i]) ? ('[' + x[i] + ']') : (\"['\" + x[i] + \"']\");\n }\n }\n return p;\n};\n\n/**\n * @param {string} pointer JSON Path\n * @returns {string} JSON Pointer\n */\nJSONPath.toPointer = function (pointer) {\n const x = pointer, n = x.length;\n let p = '';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += '/' + x[i].toString()\n .replace(/~/gu, '~0')\n .replace(/\\//gu, '~1');\n }\n }\n return p;\n};\n\n/**\n * @param {string} expr Expression to convert\n * @returns {string[]}\n */\nJSONPath.toPathArray = function (expr) {\n const {cache} = JSONPath;\n if (cache[expr]) { return cache[expr].concat(); }\n const subx = [];\n const normalized = expr\n // Properties\n .replace(\n /@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\\(\\)/gu,\n ';$&;'\n )\n // Parenthetical evaluations (filtering and otherwise), directly\n // within brackets or single quotes\n .replace(/[['](\\??\\(.*?\\))[\\]']/gu, function ($0, $1) {\n return '[#' + (subx.push($1) - 1) + ']';\n })\n // Escape periods and tildes within properties\n .replace(/\\[['\"]([^'\\]]*)['\"]\\]/gu, function ($0, prop) {\n return \"['\" + prop\n .replace(/\\./gu, '%@%')\n .replace(/~/gu, '%%@@%%') +\n \"']\";\n })\n // Properties operator\n .replace(/~/gu, ';~;')\n // Split by property boundaries\n .replace(/['\"]?\\.['\"]?(?![^[]*\\])|\\[['\"]?/gu, ';')\n // Reinsert periods within properties\n .replace(/%@%/gu, '.')\n // Reinsert tildes within properties\n .replace(/%%@@%%/gu, '~')\n // Parent\n .replace(/(?:;)?(\\^+)(?:;)?/gu, function ($0, ups) {\n return ';' + ups.split('').join(';') + ';';\n })\n // Descendents\n .replace(/;;;|;;/gu, ';..;')\n // Remove trailing\n .replace(/;$|'?\\]|'$/gu, '');\n\n const exprList = normalized.split(';').map(function (exp) {\n const match = exp.match(/#(\\d+)/u);\n return !match || !match[1] ? exp : subx[match[1]];\n });\n cache[expr] = exprList;\n return cache[expr].concat();\n};\n\nexport {JSONPath};\n","/* eslint-disable no-bitwise */\nimport jsep from 'jsep';\nimport jsepRegex from '@jsep-plugin/regex';\nimport {JSONPath} from './jsonpath.js';\n\n/**\n * @typedef {any} ContextItem\n */\n\n/**\n * @typedef {any} EvaluatedResult\n */\n\n/**\n * @callback ConditionCallback\n * @param {ContextItem} item\n * @returns {boolean}\n */\n\n/**\n * Copy items out of one array into another.\n * @param {GenericArray} source Array with items to copy\n * @param {GenericArray} target Array to which to copy\n * @param {ConditionCallback} conditionCb Callback passed the current item;\n * will move item if evaluates to `true`\n * @returns {void}\n */\nconst moveToAnotherArray = function (source, target, conditionCb) {\n const il = source.length;\n for (let i = 0; i < il; i++) {\n const item = source[i];\n if (conditionCb(item)) {\n target.push(source.splice(i--, 1)[0]);\n }\n }\n};\n\n// register plugins\njsep.plugins.register(jsepRegex);\n\nconst SafeEval = {\n eval (code, substitions = {}) {\n const ast = jsep(code);\n return SafeEval.evalAst(ast, substitions);\n },\n /**\n * @param {jsep.Expression} ast\n * @param {Record} subs\n */\n evalAst (ast, subs) {\n switch (ast.type) {\n case 'BinaryExpression':\n case 'LogicalExpression':\n return SafeEval.evalBinaryExpression(ast, subs);\n case 'Compound':\n return SafeEval.evalCompound(ast, subs);\n case 'ConditionalExpression':\n return SafeEval.evalConditionalExpression(ast, subs);\n case 'Identifier':\n return SafeEval.evalIdentifier(ast, subs);\n case 'Literal':\n return SafeEval.evalLiteral(ast, subs);\n case 'MemberExpression':\n return SafeEval.evalMemberExpression(ast, subs);\n case 'UnaryExpression':\n return SafeEval.evalUnaryExpression(ast, subs);\n case 'ArrayExpression':\n return SafeEval.evalArrayExpression(ast, subs);\n case 'CallExpression':\n return SafeEval.evalCallExpression(ast, subs);\n default:\n throw SyntaxError('Unexpected expression', ast);\n }\n },\n evalBinaryExpression (ast, subs) {\n const result = ({\n '||': (a, b) => a || b(),\n '&&': (a, b) => a && b(),\n '|': (a, b) => a | b(),\n '^': (a, b) => a ^ b(),\n '&': (a, b) => a & b(),\n // eslint-disable-next-line eqeqeq\n '==': (a, b) => a == b(),\n // eslint-disable-next-line eqeqeq\n '!=': (a, b) => a != b(),\n '===': (a, b) => a === b(),\n '!==': (a, b) => a !== b(),\n '<': (a, b) => a < b(),\n '>': (a, b) => a > b(),\n '<=': (a, b) => a <= b(),\n '>=': (a, b) => a >= b(),\n '<<': (a, b) => a << b(),\n '>>': (a, b) => a >> b(),\n '>>>': (a, b) => a >>> b(),\n '+': (a, b) => a + b(),\n '-': (a, b) => a - b(),\n '*': (a, b) => a * b(),\n '/': (a, b) => a / b(),\n '%': (a, b) => a % b()\n })[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));\n return result;\n },\n evalCompound (ast, subs) {\n let last;\n for (const expr of ast.body) {\n last = this.evalAst(expr, subs);\n }\n return last;\n },\n evalConditionalExpression (ast, subs) {\n if (SafeEval.evalAst(ast.test, subs)) {\n return SafeEval.evalAst(ast.consequent, subs);\n }\n return SafeEval.evalAst(ast.alternate, subs);\n },\n evalIdentifier (ast, subs) {\n if (ast.name in subs) {\n return subs[ast.name];\n }\n throw ReferenceError(`${ast.name} is not defined`);\n },\n evalLiteral (ast, subs) {\n return ast.value;\n },\n evalMemberExpression (ast, subs) {\n const prop = ast.computed\n ? SafeEval.evalAst(ast.property) // `object[property]`\n : ast.property.name; // `object.property` property is identifier\n const obj = SafeEval.evalAst(ast.object, subs);\n const result = obj[prop];\n if (typeof result === 'function') {\n return result.bind(obj); // arrow functions aren't affected by bind.\n }\n return result;\n },\n evalUnaryExpression (ast, subs) {\n const result = ({\n '-': (a) => -SafeEval.evalAst(a),\n '!': (a) => !SafeEval.evalAst(a),\n '~': (a) => ~SafeEval.evalAst(a),\n // eslint-disable-next-line no-implicit-coercion\n '+': (a) => +SafeEval.evalAst(a)\n })[ast.operator](ast.argument);\n return result;\n },\n evalArrayExpression (ast, subs) {\n return ast.elements.map((el) => SafeEval.evalAst(el, subs));\n },\n evalCallExpression (ast, subs) {\n const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));\n const func = SafeEval.evalAst(ast.callee, subs);\n return func(...args);\n }\n};\n\n/**\n * In-browser replacement for NodeJS' VM.Script.\n */\nclass SafeScript {\n /**\n * @param {string} expr Expression to evaluate\n */\n constructor (expr) {\n this.code = expr;\n }\n\n /**\n * @param {PlainObject} context Object whose items will be added\n * to evaluation\n * @returns {EvaluatedResult} Result of evaluated code\n */\n runInNewContext (context) {\n const keyMap = {...context};\n return SafeEval.eval(this.code, keyMap);\n }\n}\n\n/**\n * In-browser replacement for NodeJS' VM.Script.\n */\nclass Script {\n /**\n * @param {string} expr Expression to evaluate\n */\n constructor (expr) {\n this.code = expr;\n }\n\n /**\n * @param {PlainObject} context Object whose items will be added\n * to evaluation\n * @returns {EvaluatedResult} Result of evaluated code\n */\n runInNewContext (context) {\n let expr = this.code;\n const keys = Object.keys(context);\n const funcs = [];\n moveToAnotherArray(keys, funcs, (key) => {\n return typeof context[key] === 'function';\n });\n const values = keys.map((vr, i) => {\n return context[vr];\n });\n\n const funcString = funcs.reduce((s, func) => {\n let fString = context[func].toString();\n if (!(/function/u).test(fString)) {\n fString = 'function ' + fString;\n }\n return 'var ' + func + '=' + fString + ';' + s;\n }, '');\n\n expr = funcString + expr;\n\n // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function\n if (!(/(['\"])use strict\\1/u).test(expr) &&\n !keys.includes('arguments')\n ) {\n expr = 'var arguments = undefined;' + expr;\n }\n\n // Remove last semi so `return` will be inserted before\n // the previous one instead, allowing for the return\n // of a bare ending expression\n expr = expr.replace(/;\\s*$/u, '');\n\n // Insert `return`\n const lastStatementEnd = expr.lastIndexOf(';');\n const code = (lastStatementEnd > -1\n ? expr.slice(0, lastStatementEnd + 1) +\n ' return ' + expr.slice(lastStatementEnd + 1)\n : ' return ' + expr);\n\n // eslint-disable-next-line no-new-func\n return (new Function(...keys, code))(...values);\n }\n}\n\nJSONPath.prototype.vm = {\n Script\n};\n\nJSONPath.prototype.safeVm = {\n Script: SafeScript\n};\n\nexport {JSONPath};\n"],"names":["Hooks","name","callback","first","arguments","this","add","Array","isArray","forEach","env","call","context","Plugins","jsep","_classCallCheck","registered","_this","_len","length","plugins","_key","plugin","_typeof","init","Error","Jsep","expr","index","get","charAt","charCodeAt","message","error","description","node","hooks","run","value","find","ch","code","SPACE_CODE","TAB_CODE","LF_CODE","CR_CODE","runHook","nodes","gobbleExpressions","type","COMPOUND","body","untilICode","ch_i","SEMCOL_CODE","COMMA_CODE","gobbleExpression","push","throwError","searchHook","gobbleBinaryExpression","gobbleSpaces","to_check","substr","max_binop_len","tc_len","binary_ops","hasOwnProperty","isIdentifierStart","isIdentifierPart","biop","prec","stack","biop_info","left","right","i","cur_biop","prev","gobbleToken","gobbleBinaryOp","binaryPrecedence","right_a","right_associative","has","pop","BINARY_EXP","operator","isDecimalDigit","PERIOD_CODE","gobbleNumericLiteral","SQUOTE_CODE","DQUOTE_CODE","gobbleStringLiteral","OBRACK_CODE","gobbleArray","max_unop_len","unary_ops","argument","UNARY_EXP","prefix","gobbleIdentifier","literals","LITERAL","raw","this_str","THIS_EXP","OPAREN_CODE","gobbleGroup","gobbleTokenProperty","QUMARK_CODE","optional","MEMBER_EXP","computed","object","property","CBRACK_CODE","CALL_EXP","gobbleArguments","CPAREN_CODE","callee","chCode","number","parseFloat","str","startIndex","quote","closed","substring","start","IDENTIFIER","slice","termination","args","separator_count","String","fromCharCode","arg","SEQUENCE_EXP","expressions","ARRAY_EXP","elements","version","op_name","Math","max","precedence","isRightAssociative","char","additional_identifier_chars","literal_name","literal_value","getMaxKeyLen","parse","obj","concat","_toConsumableArray","Object","keys","map","k","op_val","assign","COLON_CODE","Set","true","false","null","getOwnPropertyNames","m","undefined","ternary","test","consequent","alternate","newTest","register","patternIndex","inCharSet","pattern","flags","RegExp","e","hasOwnProp","prototype","arr","item","unshift","NewError","_super","avoidNew","JSONPath","opts","otherTypeCallback","optObj","json","path","resultType","flatten","wrap","sandbox","preventEval","evalType","parent","parentProperty","TypeError","autostart","ret","evaluate","_this2","currParent","currParentProperty","currResultType","currPreventEval","currEvalType","currSandbox","currOtherTypeCallback","toPathString","exprList","toPathArray","shift","_hasParentSelector","result","_trace","filter","ea","isParentSelector","hasArrExpr","reduce","rslt","valOrPath","_getPreferredOutput","pointer","toPointer","_handleCallback","fullRetObj","preferredOutput","val","parentPropName","literalPriority","retObj","_this3","loc","x","addRet","elems","t","_walk","_slice","indexOf","safeLoc","replace","_eval","addType","valueType","includes","Number","isFinite","locProp","_step","_iterator","_createForOfIteratorHelper","split","s","n","done","part","err","f","rett","tmp","tl","tt","splice","len","parts","step","parseInt","end","min","_v","_vname","_$_parentProperty","_$_parent","_$_property","_$_root","_$_v","containsPath","_$_path","scriptCacheKey","cache","script","safeVm","Script","vm","runInNewContext","pathArr","p","toString","subx","$0","$1","prop","ups","join","exp","match","jsepRegex","SafeEval","eval","substitions","ast","evalAst","subs","evalBinaryExpression","evalCompound","evalConditionalExpression","evalIdentifier","evalLiteral","evalMemberExpression","evalUnaryExpression","evalArrayExpression","evalCallExpression","SyntaxError","a","b","last","ReferenceError","bind","el","apply","SafeScript","keyMap","funcs","source","target","conditionCb","il","moveToAnotherArray","key","values","vr","funcString","func","fString","lastStatementEnd","lastIndexOf","_construct","Function"],"mappings":"w/HAGMA,iEAmBL,SAAIC,EAAMC,EAAUC,GACnB,GAA2B,iBAAhBC,UAAU,GAEpB,IAAK,IAAIH,KAAQG,UAAU,GAC1BC,KAAKC,IAAIL,EAAMG,UAAU,GAAGH,GAAOG,UAAU,SAI7CG,MAAMC,QAAQP,GAAQA,EAAO,CAACA,IAAOQ,SAAQ,SAAUR,GACvDI,KAAKJ,GAAQI,KAAKJ,IAAS,GAEvBC,GACHG,KAAKJ,GAAME,EAAQ,UAAY,QAAQD,EAJzC,GAMGG,KAEJ,oBAWD,SAAIJ,EAAMS,GACTL,KAAKJ,GAAQI,KAAKJ,IAAS,GAC3BI,KAAKJ,GAAMQ,SAAQ,SAAUP,GAC5BA,EAASS,KAAKD,GAAOA,EAAIE,QAAUF,EAAIE,QAAUF,EAAKA,KAEvD,UAMIG,aACL,SAAAA,EAAYC,GAAMC,EAAAV,KAAAQ,GACjBR,KAAKS,KAAOA,EACZT,KAAKW,WAAa,EAClB,mCAeD,WAAqB,IAAA,IAAAC,EAAAZ,KAAAa,EAAAd,UAAAe,OAATC,EAAS,IAAAb,MAAAW,GAAAG,EAAA,EAAAA,EAAAH,EAAAG,IAATD,EAASC,GAAAjB,UAAAiB,GACpBD,EAAQX,SAAQ,SAACa,GAChB,GAAsB,WAAlBC,EAAOD,KAAwBA,EAAOrB,OAASqB,EAAOE,KACzD,MAAM,IAAIC,MAAM,8BAEbR,EAAKD,WAAWM,EAAOrB,QAI3BqB,EAAOE,KAAKP,EAAKH,MACjBG,EAAKD,WAAWM,EAAOrB,MAAQqB,KAEhC,MAGF,IAEMI,aA0KL,SAAAA,EAAYC,GAAMZ,EAAAV,KAAAqB,GA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hBmQ,EAAOtR,KAAKqR,EAAO7D,OAAOrM,IAAK,GAAG,GAG7C,CAkKOsQ,CAAmBpL,EAAM+K,GAAO,SAACM,GAC7B,MAA+B,mBAAjBvU,EAAQuU,EACzB,IACD,IAAMC,EAAStL,EAAKC,KAAI,SAACsL,EAAIzQ,GACzB,OAAOhE,EAAQyU,EAClB,IAEKC,EAAaT,EAAMzG,QAAO,SAACmC,EAAGgF,GAChC,IAAIC,EAAU5U,EAAQ2U,GAAM7C,WAI5B,MAHM,WAAa9H,KAAK4K,KACpBA,EAAU,YAAcA,GAErB,OAASD,EAAO,IAAMC,EAAU,IAAMjF,CAL9B,GAMhB,IAKG,qBAAuB3F,KAH7BjJ,EAAO2T,EAAa3T,IAIfmI,EAAKiG,SAAS,eAEfpO,EAAO,6BAA+BA,GAS1C,IAAM8T,GAHN9T,EAAOA,EAAKgO,QAAQ,yEAAU,KAGA+F,YAAY,KACpCjT,EAAQgT,GAAoB,EAC5B9T,EAAKwG,MAAM,EAAGsN,EAAmB,GAC/B,WAAa9T,EAAKwG,MAAMsN,EAAmB,GAC7C,WAAa9T,EAGnB,OAAOgU,EAAKC,SAAY9L,UAAMrH,KAAvBiS,WAAA,EAAA9K,EAAiCwL,GAC3C,UAGLrJ,EAASP,UAAU8G,GAAK,CACpBD,OAAAA,GAGJtG,EAASP,UAAU4G,OAAS,CACxBC,OAAQsC"} \ No newline at end of file diff --git a/dist/index-node-cjs.cjs b/dist/index-node-cjs.cjs index a36c67d..b84c3a9 100644 --- a/dist/index-node-cjs.cjs +++ b/dist/index-node-cjs.cjs @@ -102,6 +102,7 @@ class NewError extends Error { * @property {boolean} [wrap=true] * @property {PlainObject} [sandbox={}] * @property {boolean} [preventEval=false] + * @property {"safe"|"native"|"none"} [evalType='safe'] * @property {PlainObject|GenericArray|null} [parent=null] * @property {string|null} [parentProperty=null] * @property {JSONPathCallback} [callback] @@ -160,6 +161,7 @@ function JSONPath(opts, expr, obj, callback, otherTypeCallback) { this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true; this.sandbox = opts.sandbox || {}; this.preventEval = opts.preventEval || false; + this.evalType = opts.evalType || 'safe'; this.parent = opts.parent || null; this.parentProperty = opts.parentProperty || null; this.callback = opts.callback || callback || null; @@ -199,6 +201,7 @@ JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) } = this; this.currResultType = this.resultType; this.currPreventEval = this.preventEval; + this.currEvalType = this.evalType; this.currSandbox = this.sandbox; callback = callback || this.callback; this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback; @@ -222,6 +225,7 @@ JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) this.currSandbox = hasOwnProp.call(expr, 'sandbox') ? expr.sandbox : this.currSandbox; wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap; this.currPreventEval = hasOwnProp.call(expr, 'preventEval') ? expr.preventEval : this.currPreventEval; + this.currEvalType = hasOwnProp.call(expr, 'evalType') ? expr.evalType : this.currEvalType; callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback; this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback') ? expr.otherTypeCallback : this.currOtherTypeCallback; currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent; @@ -420,7 +424,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c addRet(this._slice(loc, x, val, path, parent, parentPropName, callback)); } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [?(expr)] prevented in JSONPath expression.'); } @@ -433,7 +437,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c }); } else if (loc[0] === '(') { // [(expr)] (dynamic property/index) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [(expr)] prevented in JSONPath expression.'); } // As this will resolve to a property name (but we don't know it // yet), property and parent information is relative to the @@ -630,7 +634,7 @@ JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropN this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname])); } - const scriptCacheKey = 'script:' + code; + const scriptCacheKey = this.currEvalType + 'Script:' + code; if (!JSONPath.cache[scriptCacheKey]) { let script = code.replace(/@parentProperty/gu, '_$_parentProperty').replace(/@parent/gu, '_$_parent').replace(/@property/gu, '_$_property').replace(/@root/gu, '_$_root').replace(/@([.\s)[])/gu, '_$_v$1'); @@ -639,7 +643,11 @@ JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropN script = script.replace(/@path/gu, '_$_path'); } - JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + if (this.currEvalType === 'safe') { + JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script); + } else if (this.currEvalType === 'native') { + JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + } } try { @@ -732,5 +740,6 @@ JSONPath.toPathArray = function (expr) { }; JSONPath.prototype.vm = vm__default["default"]; +JSONPath.prototype.safeVm = vm__default["default"]; exports.JSONPath = JSONPath; diff --git a/dist/index-node-esm.js b/dist/index-node-esm.js index 821e932..804a7c2 100644 --- a/dist/index-node-esm.js +++ b/dist/index-node-esm.js @@ -94,6 +94,7 @@ class NewError extends Error { * @property {boolean} [wrap=true] * @property {PlainObject} [sandbox={}] * @property {boolean} [preventEval=false] + * @property {"safe"|"native"|"none"} [evalType='safe'] * @property {PlainObject|GenericArray|null} [parent=null] * @property {string|null} [parentProperty=null] * @property {JSONPathCallback} [callback] @@ -152,6 +153,7 @@ function JSONPath(opts, expr, obj, callback, otherTypeCallback) { this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true; this.sandbox = opts.sandbox || {}; this.preventEval = opts.preventEval || false; + this.evalType = opts.evalType || 'safe'; this.parent = opts.parent || null; this.parentProperty = opts.parentProperty || null; this.callback = opts.callback || callback || null; @@ -191,6 +193,7 @@ JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) } = this; this.currResultType = this.resultType; this.currPreventEval = this.preventEval; + this.currEvalType = this.evalType; this.currSandbox = this.sandbox; callback = callback || this.callback; this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback; @@ -214,6 +217,7 @@ JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) this.currSandbox = hasOwnProp.call(expr, 'sandbox') ? expr.sandbox : this.currSandbox; wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap; this.currPreventEval = hasOwnProp.call(expr, 'preventEval') ? expr.preventEval : this.currPreventEval; + this.currEvalType = hasOwnProp.call(expr, 'evalType') ? expr.evalType : this.currEvalType; callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback; this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback') ? expr.otherTypeCallback : this.currOtherTypeCallback; currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent; @@ -412,7 +416,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c addRet(this._slice(loc, x, val, path, parent, parentPropName, callback)); } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [?(expr)] prevented in JSONPath expression.'); } @@ -425,7 +429,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c }); } else if (loc[0] === '(') { // [(expr)] (dynamic property/index) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [(expr)] prevented in JSONPath expression.'); } // As this will resolve to a property name (but we don't know it // yet), property and parent information is relative to the @@ -622,7 +626,7 @@ JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropN this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname])); } - const scriptCacheKey = 'script:' + code; + const scriptCacheKey = this.currEvalType + 'Script:' + code; if (!JSONPath.cache[scriptCacheKey]) { let script = code.replace(/@parentProperty/gu, '_$_parentProperty').replace(/@parent/gu, '_$_parent').replace(/@property/gu, '_$_property').replace(/@root/gu, '_$_root').replace(/@([.\s)[])/gu, '_$_v$1'); @@ -631,7 +635,11 @@ JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropN script = script.replace(/@path/gu, '_$_path'); } - JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + if (this.currEvalType === 'safe') { + JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script); + } else if (this.currEvalType === 'native') { + JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + } } try { @@ -724,5 +732,6 @@ JSONPath.toPathArray = function (expr) { }; JSONPath.prototype.vm = vm; +JSONPath.prototype.safeVm = vm; export { JSONPath }; diff --git a/package.json b/package.json index a60ff7e..57cbd2b 100644 --- a/package.json +++ b/package.json @@ -59,12 +59,16 @@ "vm": false }, "dependencies": { + "@jsep-plugin/regex": "^1.0.3", + "jsep": "^1.3.8" }, "devDependencies": { "@babel/core": "^7.18.13", + "@babel/eslint-parser": "^7.19.1", "@babel/preset-env": "^7.18.10", "@brettz9/eslint-plugin": "^1.0.4", "@rollup/plugin-babel": "^5.3.1", + "@rollup/plugin-node-resolve": "^15.0.1", "c8": "^7.12.0", "chai": "^4.3.6", "core-js-bundle": "^3.25.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e55075e..503cec9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,9 +2,12 @@ lockfileVersion: 5.4 specifiers: '@babel/core': ^7.18.13 + '@babel/eslint-parser': ^7.19.1 '@babel/preset-env': ^7.18.10 '@brettz9/eslint-plugin': ^1.0.4 + '@jsep-plugin/regex': ^1.0.3 '@rollup/plugin-babel': ^5.3.1 + '@rollup/plugin-node-resolve': ^15.0.1 c8: ^7.12.0 chai: ^4.3.6 core-js-bundle: ^3.25.0 @@ -29,6 +32,7 @@ specifiers: eslint-plugin-standard: ^4.1.0 eslint-plugin-unicorn: ^43.0.2 http-server: ^14.1.1 + jsep: ^1.3.8 license-badger: ^0.19.0 mocha: ^10.0.0 mocha-badge-generator: ^0.9.0 @@ -39,11 +43,17 @@ specifiers: typedoc: ^0.23.13 typescript: ^4.8.2 +dependencies: + '@jsep-plugin/regex': 1.0.3_jsep@1.3.8 + jsep: 1.3.8 + devDependencies: '@babel/core': 7.18.13 + '@babel/eslint-parser': 7.19.1_f6qngz4m6vfa3g3bk2x4qa2a2q '@babel/preset-env': 7.18.10_@babel+core@7.18.13 '@brettz9/eslint-plugin': 1.0.4_eslint@8.23.0 '@rollup/plugin-babel': 5.3.1_qa5xd24o3tymwictiiptlhxtom + '@rollup/plugin-node-resolve': 15.0.1_rollup@2.79.0 c8: 7.12.0 chai: 4.3.6 core-js-bundle: 3.25.0 @@ -123,6 +133,20 @@ packages: - supports-color dev: true + /@babel/eslint-parser/7.19.1_f6qngz4m6vfa3g3bk2x4qa2a2q: + resolution: {integrity: sha512-AqNf2QWt1rtu2/1rLswy6CDP7H9Oh3mMhk177Y67Rg8d7RD9WfOLLv8CGn6tisFvS2htm86yIe1yLF6I1UDaGQ==} + engines: {node: ^10.13.0 || ^12.13.0 || >=14.0.0} + peerDependencies: + '@babel/core': '>=7.11.0' + eslint: ^7.5.0 || ^8.0.0 + dependencies: + '@babel/core': 7.18.13 + '@nicolo-ribaudo/eslint-scope-5-internals': 5.1.1-v1 + eslint: 8.23.0 + eslint-visitor-keys: 2.1.0 + semver: 6.3.0 + dev: true + /@babel/generator/7.18.13: resolution: {integrity: sha512-CkPg8ySSPuHTYPJYo7IRALdqyjM9HCbt/3uOBEFbzyGVP6Mn8bwFPB0jX6982JVNBlYzM1nnPkfjuXSOPtQeEQ==} engines: {node: '>=6.9.0'} @@ -1364,6 +1388,15 @@ packages: '@jridgewell/sourcemap-codec': 1.4.14 dev: true + /@jsep-plugin/regex/1.0.3_jsep@1.3.8: + resolution: {integrity: sha512-XfZgry4DwEZvSFtS/6Y+R48D7qJYJK6R9/yJFyUFHCIUMEEHuJ4X95TDgJp5QkmzfLYvapMPzskV5HpIDrREug==} + engines: {node: '>= 10.16.0'} + peerDependencies: + jsep: ^0.4.0||^1.0.0 + dependencies: + jsep: 1.3.8 + dev: false + /@mdn/browser-compat-data/3.3.14: resolution: {integrity: sha512-n2RC9d6XatVbWFdHLimzzUJxJ1KY8LdjqrW6YvGPiRmsHkhOUx74/Ct10x5Yo7bC/Jvqx7cDEW8IMPv/+vwEzA==} dev: true @@ -1372,6 +1405,12 @@ packages: resolution: {integrity: sha512-EWUguj2kd7ldmrF9F+vI5hUOralPd+sdsUnYbRy33vZTuZkduC1shE9TtEMEjAQwyfyMb4ole5KtjF8MsnQOlA==} dev: true + /@nicolo-ribaudo/eslint-scope-5-internals/5.1.1-v1: + resolution: {integrity: sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==} + dependencies: + eslint-scope: 5.1.1 + dev: true + /@nodelib/fs.scandir/2.1.5: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -1410,6 +1449,24 @@ packages: rollup: 2.79.0 dev: true + /@rollup/plugin-node-resolve/15.0.1_rollup@2.79.0: + resolution: {integrity: sha512-ReY88T7JhJjeRVbfCyNj+NXAG3IIsVMsX9b5/9jC98dRP8/yxlZdz7mHZbHk5zHr24wZZICS5AcXsFZAXYUQEg==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.78.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 5.0.2_rollup@2.79.0 + '@types/resolve': 1.20.2 + deepmerge: 4.2.2 + is-builtin-module: 3.2.0 + is-module: 1.0.0 + resolve: 1.22.1 + rollup: 2.79.0 + dev: true + /@rollup/pluginutils/3.1.0_rollup@2.79.0: resolution: {integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==} engines: {node: '>= 8.0.0'} @@ -1422,6 +1479,21 @@ packages: rollup: 2.79.0 dev: true + /@rollup/pluginutils/5.0.2_rollup@2.79.0: + resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@types/estree': 1.0.0 + estree-walker: 2.0.2 + picomatch: 2.3.1 + rollup: 2.79.0 + dev: true + /@sindresorhus/is/0.14.0: resolution: {integrity: sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==} engines: {node: '>=6'} @@ -1447,6 +1519,10 @@ packages: resolution: {integrity: sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==} dev: true + /@types/estree/1.0.0: + resolution: {integrity: sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==} + dev: true + /@types/istanbul-lib-coverage/2.0.4: resolution: {integrity: sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==} dev: true @@ -1483,6 +1559,10 @@ packages: resolution: {integrity: sha512-L28j2FcJfSZOnL1WBjDYp2vUHCeIFlyYI/53EwD/rKUBQ7MtUUfbQWiyKJGpcnv4/WgrhWsFKrcPstcAt/J0tQ==} dev: true + /@types/resolve/1.20.2: + resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} + dev: true + /@types/responselike/1.0.0: resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==} dependencies: @@ -2306,6 +2386,11 @@ packages: resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} dev: true + /deepmerge/4.2.2: + resolution: {integrity: sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==} + engines: {node: '>=0.10.0'} + dev: true + /defer-to-connect/1.1.3: resolution: {integrity: sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==} dev: true @@ -2896,6 +2981,14 @@ packages: strip-indent: 3.0.0 dev: true + /eslint-scope/5.1.1: + resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==} + engines: {node: '>=8.0.0'} + dependencies: + esrecurse: 4.3.0 + estraverse: 4.3.0 + dev: true + /eslint-scope/7.1.1: resolution: {integrity: sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -3020,6 +3113,11 @@ packages: estraverse: 5.3.0 dev: true + /estraverse/4.3.0: + resolution: {integrity: sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==} + engines: {node: '>=4.0'} + dev: true + /estraverse/5.3.0: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} @@ -3029,6 +3127,10 @@ packages: resolution: {integrity: sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==} dev: true + /estree-walker/2.0.2: + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + dev: true + /esutils/2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} @@ -3684,6 +3786,10 @@ packages: js-types: 1.0.0 dev: true + /is-module/1.0.0: + resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==} + dev: true + /is-negative-zero/2.0.2: resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==} engines: {node: '>= 0.4'} @@ -3873,6 +3979,11 @@ packages: engines: {node: '>=12.0.0'} dev: true + /jsep/1.3.8: + resolution: {integrity: sha512-qofGylTGgYj9gZFsHuyWAN4jr35eJ66qJCK4eKDnldohuUoQFbU3iZn2zjvEbd9wOAhP9Wx5DsAAduTyE1PSWQ==} + engines: {node: '>= 10.16.0'} + dev: false + /jsesc/0.5.0: resolution: {integrity: sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==} hasBin: true diff --git a/rollup.config.js b/rollup.config.js index 7883e2e..6d519d0 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,5 @@ import {babel} from '@rollup/plugin-babel'; +import {nodeResolve} from '@rollup/plugin-node-resolve'; import {terser} from 'rollup-plugin-terser'; import pkg from './package.json'; @@ -50,7 +51,8 @@ function getRollupObject ({ : ['@babel/preset-env'] ], babelHelpers: 'bundled' - }) + }), + nodeResolve() ] }; if (minifying) { diff --git a/src/jsonpath-browser.js b/src/jsonpath-browser.js index b91c78c..5d081ff 100644 --- a/src/jsonpath-browser.js +++ b/src/jsonpath-browser.js @@ -1,3 +1,6 @@ +/* eslint-disable no-bitwise */ +import jsep from 'jsep'; +import jsepRegex from '@jsep-plugin/regex'; import {JSONPath} from './jsonpath.js'; /** @@ -32,6 +35,146 @@ const moveToAnotherArray = function (source, target, conditionCb) { } }; +// register plugins +jsep.plugins.register(jsepRegex); + +const SafeEval = { + eval (code, substitions = {}) { + const ast = jsep(code); + return SafeEval.evalAst(ast, substitions); + }, + /** + * @param {jsep.Expression} ast + * @param {Record} subs + */ + evalAst (ast, subs) { + switch (ast.type) { + case 'BinaryExpression': + case 'LogicalExpression': + return SafeEval.evalBinaryExpression(ast, subs); + case 'Compound': + return SafeEval.evalCompound(ast, subs); + case 'ConditionalExpression': + return SafeEval.evalConditionalExpression(ast, subs); + case 'Identifier': + return SafeEval.evalIdentifier(ast, subs); + case 'Literal': + return SafeEval.evalLiteral(ast, subs); + case 'MemberExpression': + return SafeEval.evalMemberExpression(ast, subs); + case 'UnaryExpression': + return SafeEval.evalUnaryExpression(ast, subs); + case 'ArrayExpression': + return SafeEval.evalArrayExpression(ast, subs); + case 'CallExpression': + return SafeEval.evalCallExpression(ast, subs); + default: + throw SyntaxError('Unexpected expression', ast); + } + }, + evalBinaryExpression (ast, subs) { + const result = ({ + '||': (a, b) => a || b(), + '&&': (a, b) => a && b(), + '|': (a, b) => a | b(), + '^': (a, b) => a ^ b(), + '&': (a, b) => a & b(), + // eslint-disable-next-line eqeqeq + '==': (a, b) => a == b(), + // eslint-disable-next-line eqeqeq + '!=': (a, b) => a != b(), + '===': (a, b) => a === b(), + '!==': (a, b) => a !== b(), + '<': (a, b) => a < b(), + '>': (a, b) => a > b(), + '<=': (a, b) => a <= b(), + '>=': (a, b) => a >= b(), + '<<': (a, b) => a << b(), + '>>': (a, b) => a >> b(), + '>>>': (a, b) => a >>> b(), + '+': (a, b) => a + b(), + '-': (a, b) => a - b(), + '*': (a, b) => a * b(), + '/': (a, b) => a / b(), + '%': (a, b) => a % b() + })[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs)); + return result; + }, + evalCompound (ast, subs) { + let last; + for (const expr of ast.body) { + last = this.evalAst(expr, subs); + } + return last; + }, + evalConditionalExpression (ast, subs) { + if (SafeEval.evalAst(ast.test, subs)) { + return SafeEval.evalAst(ast.consequent, subs); + } + return SafeEval.evalAst(ast.alternate, subs); + }, + evalIdentifier (ast, subs) { + if (ast.name in subs) { + return subs[ast.name]; + } + throw ReferenceError(`${ast.name} is not defined`); + }, + evalLiteral (ast, subs) { + return ast.value; + }, + evalMemberExpression (ast, subs) { + const prop = ast.computed + ? SafeEval.evalAst(ast.property) // `object[property]` + : ast.property.name; // `object.property` property is identifier + const obj = SafeEval.evalAst(ast.object, subs); + const result = obj[prop]; + if (typeof result === 'function') { + return result.bind(obj); // arrow functions aren't affected by bind. + } + return result; + }, + evalUnaryExpression (ast, subs) { + const result = ({ + '-': (a) => -SafeEval.evalAst(a), + '!': (a) => !SafeEval.evalAst(a), + '~': (a) => ~SafeEval.evalAst(a), + // eslint-disable-next-line no-implicit-coercion + '+': (a) => +SafeEval.evalAst(a) + })[ast.operator](ast.argument); + return result; + }, + evalArrayExpression (ast, subs) { + return ast.elements.map((el) => SafeEval.evalAst(el, subs)); + }, + evalCallExpression (ast, subs) { + const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs)); + const func = SafeEval.evalAst(ast.callee, subs); + return func(...args); + } +}; + +/** + * In-browser replacement for NodeJS' VM.Script. + */ +class SafeScript { + /** + * @param {string} expr Expression to evaluate + */ + constructor (expr) { + this.code = expr; + } + + /** + * @param {PlainObject} context Object whose items will be added + * to evaluation + * @returns {EvaluatedResult} Result of evaluated code + */ + runInNewContext (context) { + const keyMap = {...context}; + return SafeEval.eval(this.code, keyMap); + } +} + /** * In-browser replacement for NodeJS' VM.Script. */ @@ -97,4 +240,8 @@ JSONPath.prototype.vm = { Script }; +JSONPath.prototype.safeVm = { + Script: SafeScript +}; + export {JSONPath}; diff --git a/src/jsonpath-node.js b/src/jsonpath-node.js index b45650b..4144971 100644 --- a/src/jsonpath-node.js +++ b/src/jsonpath-node.js @@ -2,5 +2,6 @@ import vm from 'vm'; import {JSONPath} from './jsonpath.js'; JSONPath.prototype.vm = vm; +JSONPath.prototype.safeVm = vm; export {JSONPath}; diff --git a/src/jsonpath.js b/src/jsonpath.js index 54e27bf..5c531ad 100644 --- a/src/jsonpath.js +++ b/src/jsonpath.js @@ -89,6 +89,7 @@ class NewError extends Error { * @property {boolean} [wrap=true] * @property {PlainObject} [sandbox={}] * @property {boolean} [preventEval=false] + * @property {"safe"|"native"|"none"} [evalType='safe'] * @property {PlainObject|GenericArray|null} [parent=null] * @property {string|null} [parentProperty=null] * @property {JSONPathCallback} [callback] @@ -142,6 +143,7 @@ function JSONPath (opts, expr, obj, callback, otherTypeCallback) { this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true; this.sandbox = opts.sandbox || {}; this.preventEval = opts.preventEval || false; + this.evalType = opts.evalType || 'safe'; this.parent = opts.parent || null; this.parentProperty = opts.parentProperty || null; this.callback = opts.callback || callback || null; @@ -181,6 +183,7 @@ JSONPath.prototype.evaluate = function ( this.currResultType = this.resultType; this.currPreventEval = this.preventEval; + this.currEvalType = this.evalType; this.currSandbox = this.sandbox; callback = callback || this.callback; this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback; @@ -212,6 +215,9 @@ JSONPath.prototype.evaluate = function ( this.currPreventEval = hasOwnProp.call(expr, 'preventEval') ? expr.preventEval : this.currPreventEval; + this.currEvalType = hasOwnProp.call(expr, 'evalType') + ? expr.evalType + : this.currEvalType; callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback; this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback') ? expr.otherTypeCallback @@ -400,7 +406,7 @@ JSONPath.prototype._trace = function ( this._slice(loc, x, val, path, parent, parentPropName, callback) ); } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [?(expr)] prevented in JSONPath expression.'); } const safeLoc = loc.replace(/^\?\((.*?)\)$/u, '$1'); @@ -411,7 +417,7 @@ JSONPath.prototype._trace = function ( } }); } else if (loc[0] === '(') { // [(expr)] (dynamic property/index) - if (this.currPreventEval) { + if (this.currPreventEval || this.currEvalType === 'none') { throw new Error('Eval [(expr)] prevented in JSONPath expression.'); } // As this will resolve to a property name (but we don't know it @@ -590,7 +596,7 @@ JSONPath.prototype._eval = function ( this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname])); } - const scriptCacheKey = 'script:' + code; + const scriptCacheKey = this.currEvalType + 'Script:' + code; if (!JSONPath.cache[scriptCacheKey]) { let script = code .replace(/@parentProperty/gu, '_$_parentProperty') @@ -601,8 +607,11 @@ JSONPath.prototype._eval = function ( if (containsPath) { script = script.replace(/@path/gu, '_$_path'); } - - JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + if (this.currEvalType === 'safe') { + JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script); + } else if (this.currEvalType === 'native') { + JSONPath.cache[scriptCacheKey] = new this.vm.Script(script); + } } try { diff --git a/test/index.html b/test/index.html index dbd236b..855b4a4 100644 --- a/test/index.html +++ b/test/index.html @@ -20,7 +20,7 @@

JSONPath Tests