From 4aaf0407408cbdca88011efab4e5c95fe34f0339 Mon Sep 17 00:00:00 2001 From: Simon Scherzinger Date: Wed, 12 Sep 2018 16:11:37 +0200 Subject: [PATCH] fix: detect node on react-native environments --- lib/jsonpath.js | 21 +++++++++++---------- package.json | 3 +++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/jsonpath.js b/lib/jsonpath.js index 8b4b6e0..ae2052f 100644 --- a/lib/jsonpath.js +++ b/lib/jsonpath.js @@ -10,8 +10,9 @@ var module; (function (glbl, require) {'use strict'; // Make sure to know if we are in real node or not (the `require` variable -// could actually be require.js, for example. -var isNode = module && !!module.exports; +// could actually be require.js, for example). Will also check if we are +// in react-native +var isNode = module && !!module.exports && !(typeof navigator !== 'undefined' && navigator.product === 'ReactNative'); var allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all']; @@ -248,8 +249,8 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c // The parent sel computation is handled in the frame above using the // ancestor object of val else if (loc === '^') { - // This is not a final endpoint, so we do not invoke the callback here - this._hasParentSelector = true; + // This is not a final endpoint, so we do not invoke the callback here + this._hasParentSelector = true; return path.length ? { path: path.slice(0, -1), expr: x, @@ -354,11 +355,11 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c // We check the resulting values for parent selections. For parent // selections we discard the value object and continue the trace with the - // current val object - if (this._hasParentSelector) { - for (var t = 0; t < ret.length; t++) { + // current val object + if (this._hasParentSelector) { + for (var t = 0; t < ret.length; t++) { var rett = ret[t]; - if (rett.isParentSelector) { + if (rett.isParentSelector) { var tmp = self._trace(rett.expr, val, rett.path, parent, parentPropName, callback); if (Array.isArray(tmp)) { ret[t] = tmp[0]; @@ -370,10 +371,10 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c ret[t] = tmp; } } - } + } } return ret; -}; +}; JSONPath.prototype._walk = function (loc, expr, val, path, parent, parentPropName, callback, f) { var i, n, m; diff --git a/package.json b/package.json index dcbc434..e776411 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,9 @@ "engines": { "node": ">=0.8" }, + "react-native": { + "vm": false + }, "devDependencies": { "eslint": "^1.10.3", "eslint-config-standard": "^4.4.0",