Skip to content

Commit d6d44e1

Browse files
committed
Refactor and update change log
1 parent 25841b6 commit d6d44e1

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# JSON P3 Change Log
22

3+
## Version 2.1.0 (unreleased)
4+
5+
**Changes**
6+
7+
- Fixed `JSONPathQuery` serialization. `JSONPathQuery.toString()` was not handling name selectors containing `'` or `\`, and was a bit vague about the format serialized paths would use. `JSONPathQuery.toString()` now accepts an options object with a single `form` option. `form` can be one of `"pretty"` (the default) or `"canonical"`. The canonical format uses bracket notation and single quotes, whereas the pretty format uses shorthand notation where possible and double quotes. See [issue #30](https://github.com/jg-rp/json-p3/issues/30) and [PR #32](https://github.com/jg-rp/json-p3/pull/32).
8+
- Added `JSONPathNode.getPath(options?)`, which returns a string representation of the node's location. As above, the `form` option can be one of `"pretty"` (the default) or `"canonical"`.
9+
- Deprecated `JSONPathNode.path` in favour of `JSONPathNode.getPath(options?)`.
10+
- Changed the string representation of _filter selectors_. Both canonical and pretty formats now only include parentheses where necessary.
11+
312
## Version 2.0.0
413

514
**Breaking changes**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-p3",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"author": "James Prior",
55
"license": "MIT",
66
"description": "JSONPath, JSON Pointer and JSON Patch",

src/path/expression.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ export class LogicalExpression extends FilterExpression {
194194
expression: FilterExpression,
195195
parentPrecedence: number,
196196
): string {
197-
let precedence: number;
198-
let op: string;
199-
let left: string;
200-
let right: string;
201-
202197
if (expression instanceof InfixExpression) {
198+
let precedence: number;
199+
let op: string;
200+
let left: string;
201+
let right: string;
202+
203203
if (expression.operator === "&&") {
204204
precedence = PRECEDENCE_LOGICAL_AND;
205205
op = "&&";
@@ -213,16 +213,18 @@ export class LogicalExpression extends FilterExpression {
213213
} else {
214214
return expression.toString(options);
215215
}
216-
} else if (expression instanceof PrefixExpression) {
216+
217+
const expr = `${left} ${op} ${right}`;
218+
return precedence < parentPrecedence ? `(${expr})` : expr;
219+
}
220+
221+
if (expression instanceof PrefixExpression) {
217222
const operand = _toString(expression.right, PRECEDENCE_PREFIX);
218223
const expr = `!${operand}`;
219224
return parentPrecedence > PRECEDENCE_PREFIX ? `(${expr})` : expr;
220-
} else {
221-
return expression.toString(options);
222225
}
223226

224-
const expr = `${left} ${op} ${right}`;
225-
return precedence < parentPrecedence ? `(${expr})` : expr;
227+
return expression.toString(options);
226228
}
227229

228230
return _toString(this.expression, 0);

0 commit comments

Comments
 (0)