Skip to content

Commit

Permalink
chore: bump to 7.2.0 and update build files
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Sep 3, 2022
1 parent aaee241 commit 1f1b382
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 49 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGES for jsonpath-plus

## 7.2.0

- perf: optimize walk method by 10%-34% (@jacobroschen)
- chore: add types to exports field (@awlayton)

## 7.1.0

- perf: improve evaluation speed of conditional queries (@jacobroschen)

## 7.0.0

- Breaking change: Bump `engines` to 12
Expand Down
24 changes: 13 additions & 11 deletions dist/index-browser-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,21 +635,21 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`
} else if (loc === '*') {
// all child properties
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
addRet(_this3._trace(unshift(m, _x), v, p, par, pr, cb, true, true));
this._walk(val, function (m) {
addRet(_this3._trace(x, val[m], push(path, m), val, m, callback, true, true));
});
} else if (loc === '..') {
// all descendent parent properties
// Check remaining expression with val's immediate children
addRet(this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr));

this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
this._walk(val, function (m) {
// We don't join m and x here because we only want parents,
// not scalar values
if (_typeof(v[m]) === 'object') {
if (_typeof(val[m]) === 'object') {
// Keep going with recursive descent on val's
// object children
addRet(_this3._trace(unshift(l, _x), v[m], push(p, m), v, m, cb, true));
addRet(_this3._trace(expr.slice(), val[m], push(path, m), val, m, callback, true));
}
}); // The parent sel computation is handled in the frame above using the
// ancestor object of val
Expand Down Expand Up @@ -686,9 +686,11 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c
throw new Error('Eval [?(expr)] prevented in JSONPath expression.');
}

this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
if (_this3._eval(l.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/, '$1'), v[m], m, p, par, pr)) {
addRet(_this3._trace(unshift(m, _x), v, p, par, pr, cb, true));
var safeLoc = loc.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(val, function (m) {
if (_this3._eval(safeLoc, val[m], m, path, parent, parentPropName)) {
addRet(_this3._trace(x, val[m], push(path, m), val, m, callback, true));
}
});
} else if (loc[0] === '(') {
Expand Down Expand Up @@ -844,16 +846,16 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c
return ret;
};

JSONPath.prototype._walk = function (loc, expr, val, path, parent, parentPropName, callback, f) {
JSONPath.prototype._walk = function (val, f) {
if (Array.isArray(val)) {
var n = val.length;

for (var i = 0; i < n; i++) {
f(i, loc, expr, val, path, parent, parentPropName, callback);
f(i);
}
} else if (val && _typeof(val) === 'object') {
Object.keys(val).forEach(function (m) {
f(m, loc, expr, val, path, parent, parentPropName, callback);
f(m);
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/index-browser-esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-browser-esm.min.js.map

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions dist/index-browser-umd.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -641,21 +641,21 @@
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`
} else if (loc === '*') {
// all child properties
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
addRet(_this3._trace(unshift(m, _x), v, p, par, pr, cb, true, true));
this._walk(val, function (m) {
addRet(_this3._trace(x, val[m], push(path, m), val, m, callback, true, true));
});
} else if (loc === '..') {
// all descendent parent properties
// Check remaining expression with val's immediate children
addRet(this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr));

this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
this._walk(val, function (m) {
// We don't join m and x here because we only want parents,
// not scalar values
if (_typeof(v[m]) === 'object') {
if (_typeof(val[m]) === 'object') {
// Keep going with recursive descent on val's
// object children
addRet(_this3._trace(unshift(l, _x), v[m], push(p, m), v, m, cb, true));
addRet(_this3._trace(expr.slice(), val[m], push(path, m), val, m, callback, true));
}
}); // The parent sel computation is handled in the frame above using the
// ancestor object of val
Expand Down Expand Up @@ -692,9 +692,11 @@
throw new Error('Eval [?(expr)] prevented in JSONPath expression.');
}

this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
if (_this3._eval(l.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/, '$1'), v[m], m, p, par, pr)) {
addRet(_this3._trace(unshift(m, _x), v, p, par, pr, cb, true));
var safeLoc = loc.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(val, function (m) {
if (_this3._eval(safeLoc, val[m], m, path, parent, parentPropName)) {
addRet(_this3._trace(x, val[m], push(path, m), val, m, callback, true));
}
});
} else if (loc[0] === '(') {
Expand Down Expand Up @@ -850,16 +852,16 @@
return ret;
};

JSONPath.prototype._walk = function (loc, expr, val, path, parent, parentPropName, callback, f) {
JSONPath.prototype._walk = function (val, f) {
if (Array.isArray(val)) {
var n = val.length;

for (var i = 0; i < n; i++) {
f(i, loc, expr, val, path, parent, parentPropName, callback);
f(i);
}
} else if (val && _typeof(val) === 'object') {
Object.keys(val).forEach(function (m) {
f(m, loc, expr, val, path, parent, parentPropName, callback);
f(m);
});
}
};
Expand Down
Loading

0 comments on commit 1f1b382

Please sign in to comment.