@gabrielbryk/jq-ts 1.3.5 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +30 -23
- package/dist/index.mjs +30 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -279,7 +279,7 @@ const lex = (text) => {
|
|
|
279
279
|
const raw = text.slice(start, pos);
|
|
280
280
|
const keyword = keywordKinds[raw];
|
|
281
281
|
if (keyword === "Null" || keyword === "True" || keyword === "False") pushToken(keyword, start, pos);
|
|
282
|
-
else if (keyword) pushToken(keyword, start, pos);
|
|
282
|
+
else if (keyword) pushToken(keyword, start, pos, raw);
|
|
283
283
|
else pushToken("Identifier", start, pos, raw);
|
|
284
284
|
continue;
|
|
285
285
|
}
|
|
@@ -623,16 +623,6 @@ var Parser = class {
|
|
|
623
623
|
return expr;
|
|
624
624
|
}
|
|
625
625
|
parseUnary() {
|
|
626
|
-
if (this.match("Not")) {
|
|
627
|
-
const op = this.previous();
|
|
628
|
-
const expr = this.parseUnary();
|
|
629
|
-
return {
|
|
630
|
-
kind: "Unary",
|
|
631
|
-
op: "Not",
|
|
632
|
-
expr,
|
|
633
|
-
span: spanBetween(op.span, expr.span)
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
626
|
if (this.match("Minus")) {
|
|
637
627
|
const op = this.previous();
|
|
638
628
|
const expr = this.parseUnary();
|
|
@@ -749,11 +739,8 @@ var Parser = class {
|
|
|
749
739
|
kind: "Recurse",
|
|
750
740
|
span: this.previous().span
|
|
751
741
|
};
|
|
752
|
-
if (this.match("DotDot")) return {
|
|
753
|
-
kind: "Recurse",
|
|
754
|
-
span: this.previous().span
|
|
755
|
-
};
|
|
756
742
|
if (this.match("Break")) return this.parseBreak(this.previous());
|
|
743
|
+
if (this.match("Not")) return this.finishIdentifier(this.previous());
|
|
757
744
|
throw this.error(this.peek(), "Unexpected token");
|
|
758
745
|
}
|
|
759
746
|
parseBreak(start) {
|
|
@@ -1307,7 +1294,10 @@ const emit$1 = (value, span, tracker) => {
|
|
|
1307
1294
|
return value;
|
|
1308
1295
|
};
|
|
1309
1296
|
const ensureIndex = (val) => {
|
|
1310
|
-
if (typeof val === "number"
|
|
1297
|
+
if (typeof val === "number") {
|
|
1298
|
+
if (!Number.isFinite(val)) return void 0;
|
|
1299
|
+
return Math.trunc(val);
|
|
1300
|
+
}
|
|
1311
1301
|
if (typeof val === "string" && /^-?\d+$/.test(val)) return parseInt(val, 10);
|
|
1312
1302
|
};
|
|
1313
1303
|
const stableStringify = (value) => {
|
|
@@ -1379,6 +1369,13 @@ const stdBuiltins = [
|
|
|
1379
1369
|
yield emit$1(isTruthy(input), span, tracker);
|
|
1380
1370
|
}
|
|
1381
1371
|
},
|
|
1372
|
+
{
|
|
1373
|
+
name: "not",
|
|
1374
|
+
arity: 0,
|
|
1375
|
+
apply: function* (input, _args, _env, tracker, _eval, span) {
|
|
1376
|
+
yield emit$1(!isTruthy(input), span, tracker);
|
|
1377
|
+
}
|
|
1378
|
+
},
|
|
1382
1379
|
{
|
|
1383
1380
|
name: "walk",
|
|
1384
1381
|
arity: 1,
|
|
@@ -3099,15 +3096,21 @@ const emit = (value, span, tracker) => {
|
|
|
3099
3096
|
return value;
|
|
3100
3097
|
};
|
|
3101
3098
|
/**
|
|
3102
|
-
*
|
|
3099
|
+
* Converts a value to an array index.
|
|
3100
|
+
* Truncates floats to integers. Returns null if input is null.
|
|
3101
|
+
* Throws a RuntimeError for non-numeric types.
|
|
3103
3102
|
*
|
|
3104
|
-
* @param value - The value to
|
|
3103
|
+
* @param value - The value to convert.
|
|
3105
3104
|
* @param span - To report error.
|
|
3106
|
-
* @returns The integer
|
|
3105
|
+
* @returns The integer index or null.
|
|
3107
3106
|
*/
|
|
3108
|
-
const
|
|
3109
|
-
if (
|
|
3110
|
-
|
|
3107
|
+
const toIndex = (value, span) => {
|
|
3108
|
+
if (value === null) return null;
|
|
3109
|
+
if (typeof value === "number") {
|
|
3110
|
+
if (!Number.isFinite(value)) return null;
|
|
3111
|
+
return Math.trunc(value);
|
|
3112
|
+
}
|
|
3113
|
+
throw new RuntimeError("Expected numeric index", span);
|
|
3111
3114
|
};
|
|
3112
3115
|
|
|
3113
3116
|
//#endregion
|
|
@@ -3335,7 +3338,11 @@ const evalIndex = function* (node, input, env, tracker, evaluate$1) {
|
|
|
3335
3338
|
}
|
|
3336
3339
|
if (isValueArray(container)) {
|
|
3337
3340
|
for (const idxValue of indexValues) {
|
|
3338
|
-
const index =
|
|
3341
|
+
const index = toIndex(idxValue, node.span);
|
|
3342
|
+
if (index === null) {
|
|
3343
|
+
yield emit(null, node.span, tracker);
|
|
3344
|
+
continue;
|
|
3345
|
+
}
|
|
3339
3346
|
const resolved = index < 0 ? container.length + index : index;
|
|
3340
3347
|
if (resolved < 0 || resolved >= container.length) yield emit(null, node.span, tracker);
|
|
3341
3348
|
else yield emit(container[resolved], node.span, tracker);
|
package/dist/index.mjs
CHANGED
|
@@ -278,7 +278,7 @@ const lex = (text) => {
|
|
|
278
278
|
const raw = text.slice(start, pos);
|
|
279
279
|
const keyword = keywordKinds[raw];
|
|
280
280
|
if (keyword === "Null" || keyword === "True" || keyword === "False") pushToken(keyword, start, pos);
|
|
281
|
-
else if (keyword) pushToken(keyword, start, pos);
|
|
281
|
+
else if (keyword) pushToken(keyword, start, pos, raw);
|
|
282
282
|
else pushToken("Identifier", start, pos, raw);
|
|
283
283
|
continue;
|
|
284
284
|
}
|
|
@@ -622,16 +622,6 @@ var Parser = class {
|
|
|
622
622
|
return expr;
|
|
623
623
|
}
|
|
624
624
|
parseUnary() {
|
|
625
|
-
if (this.match("Not")) {
|
|
626
|
-
const op = this.previous();
|
|
627
|
-
const expr = this.parseUnary();
|
|
628
|
-
return {
|
|
629
|
-
kind: "Unary",
|
|
630
|
-
op: "Not",
|
|
631
|
-
expr,
|
|
632
|
-
span: spanBetween(op.span, expr.span)
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
625
|
if (this.match("Minus")) {
|
|
636
626
|
const op = this.previous();
|
|
637
627
|
const expr = this.parseUnary();
|
|
@@ -748,11 +738,8 @@ var Parser = class {
|
|
|
748
738
|
kind: "Recurse",
|
|
749
739
|
span: this.previous().span
|
|
750
740
|
};
|
|
751
|
-
if (this.match("DotDot")) return {
|
|
752
|
-
kind: "Recurse",
|
|
753
|
-
span: this.previous().span
|
|
754
|
-
};
|
|
755
741
|
if (this.match("Break")) return this.parseBreak(this.previous());
|
|
742
|
+
if (this.match("Not")) return this.finishIdentifier(this.previous());
|
|
756
743
|
throw this.error(this.peek(), "Unexpected token");
|
|
757
744
|
}
|
|
758
745
|
parseBreak(start) {
|
|
@@ -1306,7 +1293,10 @@ const emit$1 = (value, span, tracker) => {
|
|
|
1306
1293
|
return value;
|
|
1307
1294
|
};
|
|
1308
1295
|
const ensureIndex = (val) => {
|
|
1309
|
-
if (typeof val === "number"
|
|
1296
|
+
if (typeof val === "number") {
|
|
1297
|
+
if (!Number.isFinite(val)) return void 0;
|
|
1298
|
+
return Math.trunc(val);
|
|
1299
|
+
}
|
|
1310
1300
|
if (typeof val === "string" && /^-?\d+$/.test(val)) return parseInt(val, 10);
|
|
1311
1301
|
};
|
|
1312
1302
|
const stableStringify = (value) => {
|
|
@@ -1378,6 +1368,13 @@ const stdBuiltins = [
|
|
|
1378
1368
|
yield emit$1(isTruthy(input), span, tracker);
|
|
1379
1369
|
}
|
|
1380
1370
|
},
|
|
1371
|
+
{
|
|
1372
|
+
name: "not",
|
|
1373
|
+
arity: 0,
|
|
1374
|
+
apply: function* (input, _args, _env, tracker, _eval, span) {
|
|
1375
|
+
yield emit$1(!isTruthy(input), span, tracker);
|
|
1376
|
+
}
|
|
1377
|
+
},
|
|
1381
1378
|
{
|
|
1382
1379
|
name: "walk",
|
|
1383
1380
|
arity: 1,
|
|
@@ -3098,15 +3095,21 @@ const emit = (value, span, tracker) => {
|
|
|
3098
3095
|
return value;
|
|
3099
3096
|
};
|
|
3100
3097
|
/**
|
|
3101
|
-
*
|
|
3098
|
+
* Converts a value to an array index.
|
|
3099
|
+
* Truncates floats to integers. Returns null if input is null.
|
|
3100
|
+
* Throws a RuntimeError for non-numeric types.
|
|
3102
3101
|
*
|
|
3103
|
-
* @param value - The value to
|
|
3102
|
+
* @param value - The value to convert.
|
|
3104
3103
|
* @param span - To report error.
|
|
3105
|
-
* @returns The integer
|
|
3104
|
+
* @returns The integer index or null.
|
|
3106
3105
|
*/
|
|
3107
|
-
const
|
|
3108
|
-
if (
|
|
3109
|
-
|
|
3106
|
+
const toIndex = (value, span) => {
|
|
3107
|
+
if (value === null) return null;
|
|
3108
|
+
if (typeof value === "number") {
|
|
3109
|
+
if (!Number.isFinite(value)) return null;
|
|
3110
|
+
return Math.trunc(value);
|
|
3111
|
+
}
|
|
3112
|
+
throw new RuntimeError("Expected numeric index", span);
|
|
3110
3113
|
};
|
|
3111
3114
|
|
|
3112
3115
|
//#endregion
|
|
@@ -3334,7 +3337,11 @@ const evalIndex = function* (node, input, env, tracker, evaluate$1) {
|
|
|
3334
3337
|
}
|
|
3335
3338
|
if (isValueArray(container)) {
|
|
3336
3339
|
for (const idxValue of indexValues) {
|
|
3337
|
-
const index =
|
|
3340
|
+
const index = toIndex(idxValue, node.span);
|
|
3341
|
+
if (index === null) {
|
|
3342
|
+
yield emit(null, node.span, tracker);
|
|
3343
|
+
continue;
|
|
3344
|
+
}
|
|
3338
3345
|
const resolved = index < 0 ? container.length + index : index;
|
|
3339
3346
|
if (resolved < 0 || resolved >= container.length) yield emit(null, node.span, tracker);
|
|
3340
3347
|
else yield emit(container[resolved], node.span, tracker);
|