jtlt 0.24.0 → 0.24.1
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/CHANGES.md +5 -0
- package/demo/codemirror.esm.js +3 -1
- package/dist/AbstractJoiningTransformer.d.ts.map +1 -1
- package/dist/DOMJoiningTransformer.d.ts.map +1 -1
- package/dist/JSONJoiningTransformer.d.ts.map +1 -1
- package/dist/JSONPathTransformer.d.ts.map +1 -1
- package/dist/JSONPathTransformerContext.d.ts.map +1 -1
- package/dist/StringJoiningTransformer.d.ts.map +1 -1
- package/dist/XPathTransformer.d.ts.map +1 -1
- package/dist/XPathTransformerContext.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/indexedDB.d.ts.map +1 -1
- package/dist/jsonTemplate.d.ts.map +1 -1
- package/package.json +18 -18
- package/pnpm-workspace.yaml +3 -1
- package/src/AbstractJoiningTransformer.js +15 -15
- package/src/DOMJoiningTransformer.js +13 -11
- package/src/JSONJoiningTransformer.js +21 -21
- package/src/JSONPathTransformer.js +3 -4
- package/src/JSONPathTransformerContext.js +43 -64
- package/src/StringJoiningTransformer.js +9 -7
- package/src/XPathTransformer.js +3 -4
- package/src/XPathTransformerContext.js +79 -91
- package/src/index.js +1 -0
- package/src/indexedDB.js +5 -6
- package/src/jsonTemplate.js +58 -53
- package/tsconfig-prod.json +1 -7
|
@@ -488,10 +488,9 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
488
488
|
// If children provided as array, copy (may be primitives or nested JML)
|
|
489
489
|
if (Array.isArray(childNodes) && childNodes.length) {
|
|
490
490
|
jmlChildren.push(...childNodes.map((childNode) => {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
return childNode;
|
|
491
|
+
return typeof childNode === 'string'
|
|
492
|
+
? this._replaceCharacterMaps(childNode)
|
|
493
|
+
: childNode;
|
|
495
494
|
}));
|
|
496
495
|
}
|
|
497
496
|
|
|
@@ -537,7 +536,7 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
537
536
|
standalone
|
|
538
537
|
};
|
|
539
538
|
}
|
|
540
|
-
/* c8 ignore stop */
|
|
539
|
+
/* c8 ignore stop -- See above */
|
|
541
540
|
|
|
542
541
|
const doc = {$document: {
|
|
543
542
|
...(xmlDeclaration ? {xmlDeclaration} : {}),
|
|
@@ -641,20 +640,22 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
641
640
|
}
|
|
642
641
|
|
|
643
642
|
const pending = this._pendingNamespaceMap.get(prefix);
|
|
644
|
-
if (pending) {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
if (!attsObj.xmlns) {
|
|
649
|
-
attsObj.xmlns = {};
|
|
650
|
-
}
|
|
643
|
+
if (!pending) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
651
646
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
this._replaceCharacterMaps(pending.namespaceURI);
|
|
647
|
+
const top = /** @type {ElementInfo} */ (this._elementStack.at(-1));
|
|
648
|
+
const {attsObj} = top;
|
|
655
649
|
|
|
656
|
-
|
|
650
|
+
if (!attsObj.xmlns) {
|
|
651
|
+
attsObj.xmlns = {};
|
|
657
652
|
}
|
|
653
|
+
|
|
654
|
+
/** @type {Record<string, string>} */
|
|
655
|
+
(attsObj.xmlns)[pending.prefix === '#default' ? '' : pending.prefix] =
|
|
656
|
+
this._replaceCharacterMaps(pending.namespaceURI);
|
|
657
|
+
|
|
658
|
+
this._pendingNamespaceMap.delete(prefix);
|
|
658
659
|
}
|
|
659
660
|
/**
|
|
660
661
|
* Adds/updates an attribute for the most recently open element built via
|
|
@@ -882,7 +883,7 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
882
883
|
standalone
|
|
883
884
|
};
|
|
884
885
|
}
|
|
885
|
-
/* c8 ignore stop */
|
|
886
|
+
/* c8 ignore stop -- See above */
|
|
886
887
|
|
|
887
888
|
resultDoc = {$document: {
|
|
888
889
|
...(xmlDeclaration ? {xmlDeclaration} : {}),
|
|
@@ -921,10 +922,9 @@ class JSONJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
921
922
|
*/
|
|
922
923
|
_usePropertySets (obj, psName) {
|
|
923
924
|
// Merge the named property set (if present) into the provided object
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
return obj;
|
|
925
|
+
return Object.hasOwn(this.propertySets, psName)
|
|
926
|
+
? Object.assign(obj, this.propertySets[psName])
|
|
927
|
+
: obj;
|
|
928
928
|
}
|
|
929
929
|
}
|
|
930
930
|
|
|
@@ -34,10 +34,9 @@ class JSONPathTransformer {
|
|
|
34
34
|
*/
|
|
35
35
|
template (value) {
|
|
36
36
|
// Emit property names for the current object context
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return '';
|
|
37
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
38
|
+
? Object.keys(value).join('')
|
|
39
|
+
: '';
|
|
41
40
|
}
|
|
42
41
|
},
|
|
43
42
|
transformObjects: {
|
|
@@ -319,10 +319,8 @@ class JSONPathTransformerContext {
|
|
|
319
319
|
/* const results = */ this._getJoiningTransformer();
|
|
320
320
|
const modeMatchedTemplates = this._templates.filter((templateObj) => {
|
|
321
321
|
// Exclude named-only templates (those with name but no path)
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
return ((mode && mode === templateObj.mode) ||
|
|
322
|
+
return (!templateObj.name || templateObj.path) &&
|
|
323
|
+
((mode && mode === templateObj.mode) ||
|
|
326
324
|
(!mode && !templateObj.mode));
|
|
327
325
|
});
|
|
328
326
|
|
|
@@ -382,10 +380,7 @@ class JSONPathTransformerContext {
|
|
|
382
380
|
if (Number.isNaN(an)) {
|
|
383
381
|
return Number(order);
|
|
384
382
|
}
|
|
385
|
-
|
|
386
|
-
return -order;
|
|
387
|
-
}
|
|
388
|
-
return (an - bn) * order;
|
|
383
|
+
return Number.isNaN(bn) ? -order : (an - bn) * order;
|
|
389
384
|
}
|
|
390
385
|
// text
|
|
391
386
|
/* c8 ignore next 2 -- all null/undefined tested; OR short-circuit */
|
|
@@ -460,7 +455,7 @@ class JSONPathTransformerContext {
|
|
|
460
455
|
if (!templateObj.path) {
|
|
461
456
|
return false;
|
|
462
457
|
}
|
|
463
|
-
/* c8 ignore stop */
|
|
458
|
+
/* c8 ignore stop -- See above */
|
|
464
459
|
const queryResult = /** @type {any[]} */ (
|
|
465
460
|
(/** @type {any} */ (jsonpath))({
|
|
466
461
|
path: JSONPathTransformer.makeJSONPathAbsolute(
|
|
@@ -554,7 +549,7 @@ class JSONPathTransformerContext {
|
|
|
554
549
|
: (that._config.specificityPriorityResolver && b.path
|
|
555
550
|
? that._config.specificityPriorityResolver(b.path)
|
|
556
551
|
: 0);
|
|
557
|
-
/* c8 ignore stop */
|
|
552
|
+
/* c8 ignore stop -- See above */
|
|
558
553
|
|
|
559
554
|
if (aPriority === bPriority) {
|
|
560
555
|
that._triggerEqualPriorityError();
|
|
@@ -676,13 +671,13 @@ class JSONPathTransformerContext {
|
|
|
676
671
|
// @ts-expect-error -- _openTagState: StringJoiningTransformer
|
|
677
672
|
joiner._openTagState = false;
|
|
678
673
|
}
|
|
679
|
-
/* c8 ignore stop */
|
|
674
|
+
/* c8 ignore stop -- See above */
|
|
680
675
|
joiner.append(resolvedRet);
|
|
681
676
|
}
|
|
682
677
|
that._parent = parent;
|
|
683
678
|
// Matches reached here always carry a parentProperty; the sync
|
|
684
679
|
// path covers the root-node fallback.
|
|
685
|
-
/* c8 ignore next */
|
|
680
|
+
/* c8 ignore next -- See comment just above */
|
|
686
681
|
that._parentProperty = (parentProperty ?? that._parentProperty);
|
|
687
682
|
that._currPath = _oldPath;
|
|
688
683
|
return undefined;
|
|
@@ -700,7 +695,7 @@ class JSONPathTransformerContext {
|
|
|
700
695
|
// @ts-expect-error -- _openTagState only on StringJoiningTransformer
|
|
701
696
|
joiner._openTagState = false;
|
|
702
697
|
}
|
|
703
|
-
/* c8 ignore stop */
|
|
698
|
+
/* c8 ignore stop -- See above */
|
|
704
699
|
joiner.append(
|
|
705
700
|
/** @type {string|Node|*} */ (ret)
|
|
706
701
|
);
|
|
@@ -910,10 +905,7 @@ class JSONPathTransformerContext {
|
|
|
910
905
|
if (Number.isNaN(an)) {
|
|
911
906
|
return Number(order);
|
|
912
907
|
}
|
|
913
|
-
|
|
914
|
-
return -order;
|
|
915
|
-
}
|
|
916
|
-
return (an - bn) * order;
|
|
908
|
+
return Number.isNaN(bn) ? -order : (an - bn) * order;
|
|
917
909
|
}
|
|
918
910
|
/* c8 ignore next 2 -- all null/undefined tested; OR short-circuit */
|
|
919
911
|
const aStr = aVal === null || aVal === undefined ? '' : String(aVal);
|
|
@@ -1257,23 +1249,25 @@ class JSONPathTransformerContext {
|
|
|
1257
1249
|
currentGroup.push(m.value);
|
|
1258
1250
|
const endMatch = evalInContext(groupEndingWith, m.value);
|
|
1259
1251
|
|
|
1260
|
-
if (endMatch) {
|
|
1261
|
-
|
|
1262
|
-
const prevParams = this._params;
|
|
1263
|
-
const prevVars = this.vars;
|
|
1264
|
-
this.vars = {};
|
|
1265
|
-
try {
|
|
1266
|
-
this._contextObj = currentGroup;
|
|
1267
|
-
/** @type {any} */ (this)._currentGroup = currentGroup;
|
|
1268
|
-
cb.call(this, null, currentGroup, this);
|
|
1269
|
-
} finally {
|
|
1270
|
-
this._contextObj = prevContext;
|
|
1271
|
-
this._params = prevParams;
|
|
1272
|
-
this.vars = prevVars;
|
|
1273
|
-
delete /** @type {any} */ (this)._currentGroup;
|
|
1274
|
-
}
|
|
1275
|
-
currentGroup = [];
|
|
1252
|
+
if (!endMatch) {
|
|
1253
|
+
continue;
|
|
1276
1254
|
}
|
|
1255
|
+
|
|
1256
|
+
const prevContext = this._contextObj;
|
|
1257
|
+
const prevParams = this._params;
|
|
1258
|
+
const prevVars = this.vars;
|
|
1259
|
+
this.vars = {};
|
|
1260
|
+
try {
|
|
1261
|
+
this._contextObj = currentGroup;
|
|
1262
|
+
/** @type {any} */ (this)._currentGroup = currentGroup;
|
|
1263
|
+
cb.call(this, null, currentGroup, this);
|
|
1264
|
+
} finally {
|
|
1265
|
+
this._contextObj = prevContext;
|
|
1266
|
+
this._params = prevParams;
|
|
1267
|
+
this.vars = prevVars;
|
|
1268
|
+
delete /** @type {any} */ (this)._currentGroup;
|
|
1269
|
+
}
|
|
1270
|
+
currentGroup = [];
|
|
1277
1271
|
}
|
|
1278
1272
|
|
|
1279
1273
|
// Process last group if not ended
|
|
@@ -1341,10 +1335,7 @@ class JSONPathTransformerContext {
|
|
|
1341
1335
|
if (Number.isNaN(an)) {
|
|
1342
1336
|
return order;
|
|
1343
1337
|
}
|
|
1344
|
-
|
|
1345
|
-
return -order;
|
|
1346
|
-
}
|
|
1347
|
-
return (an - bn) * order;
|
|
1338
|
+
return Number.isNaN(bn) ? -order : (an - bn) * order;
|
|
1348
1339
|
}
|
|
1349
1340
|
/* c8 ignore next 2 -- all null/undefined tested; OR short-circuit */
|
|
1350
1341
|
const aStr = aVal === null || aVal === undefined ? '' : String(aVal);
|
|
@@ -1642,12 +1633,11 @@ class JSONPathTransformerContext {
|
|
|
1642
1633
|
* @returns {string} - Captured group or empty string
|
|
1643
1634
|
*/
|
|
1644
1635
|
const getRegexGroup = (groupNumber) => {
|
|
1645
|
-
|
|
1636
|
+
return !currentCapturedGroups ||
|
|
1646
1637
|
groupNumber < 0 ||
|
|
1647
|
-
groupNumber >= currentCapturedGroups.length
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
return currentCapturedGroups[groupNumber] || '';
|
|
1638
|
+
groupNumber >= currentCapturedGroups.length
|
|
1639
|
+
? ''
|
|
1640
|
+
: currentCapturedGroups[groupNumber] || '';
|
|
1651
1641
|
};
|
|
1652
1642
|
|
|
1653
1643
|
// Save previous context to restore later
|
|
@@ -1750,7 +1740,7 @@ class JSONPathTransformerContext {
|
|
|
1750
1740
|
// For non-functions, attempting structuredClone again would rethrow;
|
|
1751
1741
|
// use shallow clone to retain non-serializable props like Symbols.
|
|
1752
1742
|
clone = Array.isArray(val) ? [...val] : {...val};
|
|
1753
|
-
/* c8 ignore stop */
|
|
1743
|
+
/* c8 ignore stop -- See above */
|
|
1754
1744
|
}
|
|
1755
1745
|
} else {
|
|
1756
1746
|
// Primitives/functions copied by value/reference semantics naturally.
|
|
@@ -1782,7 +1772,7 @@ class JSONPathTransformerContext {
|
|
|
1782
1772
|
}
|
|
1783
1773
|
} else { /* c8 ignore start -- primitive branch attribution variance */
|
|
1784
1774
|
clone = src; // Primitive/function - nothing to shallow clone
|
|
1785
|
-
} /* c8 ignore stop */
|
|
1775
|
+
} /* c8 ignore stop -- See above */
|
|
1786
1776
|
this._getJoiningTransformer().append(clone);
|
|
1787
1777
|
return this;
|
|
1788
1778
|
}
|
|
@@ -1841,10 +1831,9 @@ class JSONPathTransformerContext {
|
|
|
1841
1831
|
if (Object.hasOwn(this.vars, name)) {
|
|
1842
1832
|
return {has: true, value: this.vars[name]};
|
|
1843
1833
|
}
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
return {has: false, value: undefined};
|
|
1834
|
+
return Object.hasOwn(this._runtimeParams, name)
|
|
1835
|
+
? {has: true, value: this._runtimeParams[name]}
|
|
1836
|
+
: {has: false, value: undefined};
|
|
1848
1837
|
}
|
|
1849
1838
|
|
|
1850
1839
|
/**
|
|
@@ -2778,15 +2767,9 @@ class JSONPathTransformerContext {
|
|
|
2778
2767
|
}
|
|
2779
2768
|
// Single item; apply scalar truthiness
|
|
2780
2769
|
const single = val[0];
|
|
2781
|
-
|
|
2782
|
-
return true;
|
|
2783
|
-
}
|
|
2784
|
-
return Boolean(single);
|
|
2770
|
+
return single && typeof single === 'object' ? true : Boolean(single);
|
|
2785
2771
|
}
|
|
2786
|
-
|
|
2787
|
-
return true;
|
|
2788
|
-
}
|
|
2789
|
-
return Boolean(val);
|
|
2772
|
+
return val && typeof val === 'object' ? true : Boolean(val);
|
|
2790
2773
|
}
|
|
2791
2774
|
|
|
2792
2775
|
/**
|
|
@@ -2837,10 +2820,9 @@ class JSONPathTransformerContext {
|
|
|
2837
2820
|
return null;
|
|
2838
2821
|
}
|
|
2839
2822
|
const right = this._parseLiteral(m.groups.right.trim());
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
return {left: m.groups.left, op: m.groups.op, right: right.value};
|
|
2823
|
+
return !right
|
|
2824
|
+
? null
|
|
2825
|
+
: {left: m.groups.left, op: m.groups.op, right: right.value};
|
|
2844
2826
|
}
|
|
2845
2827
|
|
|
2846
2828
|
/**
|
|
@@ -2871,10 +2853,7 @@ class JSONPathTransformerContext {
|
|
|
2871
2853
|
if (str === 'null') {
|
|
2872
2854
|
return {value: null};
|
|
2873
2855
|
}
|
|
2874
|
-
|
|
2875
|
-
return {value: undefined};
|
|
2876
|
-
}
|
|
2877
|
-
return null;
|
|
2856
|
+
return str === 'undefined' ? {value: undefined} : null;
|
|
2878
2857
|
}
|
|
2879
2858
|
|
|
2880
2859
|
/**
|
|
@@ -562,7 +562,7 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
562
562
|
standalone ? ` standalone="yes"` : ''
|
|
563
563
|
}?>\n`;
|
|
564
564
|
}
|
|
565
|
-
/* c8 ignore stop */
|
|
565
|
+
/* c8 ignore stop -- See above */
|
|
566
566
|
|
|
567
567
|
const doctype = bareDoctype ||
|
|
568
568
|
doctypePublic !== undefined || doctypeSystem !== undefined
|
|
@@ -733,13 +733,15 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
733
733
|
*/
|
|
734
734
|
_flushPendingNamespace (prefix) {
|
|
735
735
|
const pending = this._pendingNamespaceMap.get(prefix);
|
|
736
|
-
if (pending) {
|
|
737
|
-
|
|
738
|
-
pending.prefix === '#default' ? 'xmlns' : 'xmlns:' + pending.prefix
|
|
739
|
-
) + '="' +
|
|
740
|
-
this._replaceCharacterMaps(pending.namespaceURI) + '"');
|
|
741
|
-
this._pendingNamespaceMap.delete(prefix);
|
|
736
|
+
if (!pending) {
|
|
737
|
+
return;
|
|
742
738
|
}
|
|
739
|
+
|
|
740
|
+
this.append(' ' + (
|
|
741
|
+
pending.prefix === '#default' ? 'xmlns' : 'xmlns:' + pending.prefix
|
|
742
|
+
) + '="' +
|
|
743
|
+
this._replaceCharacterMaps(pending.namespaceURI) + '"');
|
|
744
|
+
this._pendingNamespaceMap.delete(prefix);
|
|
743
745
|
}
|
|
744
746
|
|
|
745
747
|
/**
|
package/src/XPathTransformer.js
CHANGED
|
@@ -50,10 +50,9 @@ class XPathTransformer {
|
|
|
50
50
|
return {path: template[0], template: template[1]};
|
|
51
51
|
}
|
|
52
52
|
// Normalize 'match' to 'path' for XSLT compatibility
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return template;
|
|
53
|
+
return template.match && !template.path
|
|
54
|
+
? {...template, path: template.match}
|
|
55
|
+
: template;
|
|
57
56
|
});
|
|
58
57
|
this.templates.forEach((template) => {
|
|
59
58
|
if ('name' in template && template.name &&
|