@gct-paas/word 0.1.39 → 0.1.41
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/core/data/DataManager.d.ts +2 -2
- package/dist/index.es.js +1861 -120
- package/dist/runtime/_register_/runtime/SuiteRuntime.d.ts +4 -0
- package/dist/runtime/interface/change-diff.d.ts +2 -0
- package/dist/sdk/doc-runtime/composables/useDocOperations.d.ts +2 -0
- package/dist/sdk/engine/index.d.ts +0 -1
- package/dist/sdk/types/field-model-query.d.ts +2 -0
- package/dist/sdk/types/index.d.ts +16 -7
- package/dist/utils/func/render.d.ts +11 -3
- package/package.json +5 -4
package/dist/index.es.js
CHANGED
|
@@ -16765,7 +16765,7 @@ function speedometer(samplesCount, min) {
|
|
|
16765
16765
|
let tail = 0;
|
|
16766
16766
|
let firstSampleTS;
|
|
16767
16767
|
min = min !== void 0 ? min : 1e3;
|
|
16768
|
-
return function
|
|
16768
|
+
return function push2(chunkLength) {
|
|
16769
16769
|
const now2 = Date.now();
|
|
16770
16770
|
const startedAt = timestamps[tail];
|
|
16771
16771
|
if (!firstSampleTS) {
|
|
@@ -18618,7 +18618,7 @@ function setupPlatformAdapters(options) {
|
|
|
18618
18618
|
triggerUtil.register({
|
|
18619
18619
|
handle: triggerHandler
|
|
18620
18620
|
});
|
|
18621
|
-
plugins?.forEach((
|
|
18621
|
+
plugins?.forEach((plugin2) => plugin2.install());
|
|
18622
18622
|
}
|
|
18623
18623
|
function setupVueRuntime(options) {
|
|
18624
18624
|
const { app } = options;
|
|
@@ -35239,7 +35239,7 @@ var ResizeObserver$1 = (
|
|
|
35239
35239
|
return (_a = observers.get(this))[method4].apply(_a, arguments);
|
|
35240
35240
|
};
|
|
35241
35241
|
});
|
|
35242
|
-
var index = (function() {
|
|
35242
|
+
var index$1 = (function() {
|
|
35243
35243
|
if (typeof global$1.ResizeObserver !== "undefined") {
|
|
35244
35244
|
return global$1.ResizeObserver;
|
|
35245
35245
|
}
|
|
@@ -35260,7 +35260,7 @@ function addResizeListener(element, fn) {
|
|
|
35260
35260
|
if (isServer) return;
|
|
35261
35261
|
if (!element.__resizeListeners__) {
|
|
35262
35262
|
element.__resizeListeners__ = [];
|
|
35263
|
-
element.__ro__ = new index(resizeHandler);
|
|
35263
|
+
element.__ro__ = new index$1(resizeHandler);
|
|
35264
35264
|
element.__ro__.observe(element);
|
|
35265
35265
|
}
|
|
35266
35266
|
element.__resizeListeners__.push(fn);
|
|
@@ -47621,14 +47621,16 @@ class DataManager {
|
|
|
47621
47621
|
this.syncSubTableRowsToLayout();
|
|
47622
47622
|
}
|
|
47623
47623
|
/**
|
|
47624
|
-
*
|
|
47625
|
-
*
|
|
47624
|
+
* 补齐二维/检验表的关联轴子表(如 f_ewblink / f_jianyan2)到动态关联铺砖槽位数。
|
|
47625
|
+
* 不处理主体轴(如 f_ewb / f_jianyan1),避免覆盖接口行或误扩纵向轴。
|
|
47626
47626
|
*/
|
|
47627
47627
|
syncSubTableRowsToLayout() {
|
|
47628
47628
|
const listSubTables = this.doc?.model?.getSubTableInfoList;
|
|
47629
47629
|
if (typeof listSubTables !== "function") return;
|
|
47630
|
-
for (const info of listSubTables.call(this.doc
|
|
47631
|
-
if (info.
|
|
47630
|
+
for (const info of listSubTables.call(this.doc?.model)) {
|
|
47631
|
+
if (!info.field || !["check-table-2d-link", "sub-table-2d-link"].includes(info.subType)) {
|
|
47632
|
+
continue;
|
|
47633
|
+
}
|
|
47632
47634
|
const linkFieldKey = info.field;
|
|
47633
47635
|
const layoutRows = this.doc?.model?.getSubTableLayoutSlotCount(linkFieldKey) ?? 0;
|
|
47634
47636
|
if (layoutRows <= 0) continue;
|
|
@@ -50303,13 +50305,15 @@ class DocModel {
|
|
|
50303
50305
|
};
|
|
50304
50306
|
});
|
|
50305
50307
|
const table2DRegions = tables.filter((w2) => w2.has2DTable).flatMap((w2) => w2._2DTable).map((item) => {
|
|
50308
|
+
const crossKey = item.subFieldKey && item.linkFieldKey ? `${item.subFieldKey}:${item.linkFieldKey}` : void 0;
|
|
50306
50309
|
const result = [];
|
|
50307
50310
|
if (item.subFieldKey) {
|
|
50308
50311
|
result.push({
|
|
50309
50312
|
field: item.subFieldKey,
|
|
50310
50313
|
key: "dyn",
|
|
50311
50314
|
name: "二维表",
|
|
50312
|
-
subType: "sub-table-2d"
|
|
50315
|
+
subType: "sub-table-2d",
|
|
50316
|
+
crossKey
|
|
50313
50317
|
});
|
|
50314
50318
|
}
|
|
50315
50319
|
if (item.linkFieldKey) {
|
|
@@ -50317,19 +50321,22 @@ class DocModel {
|
|
|
50317
50321
|
field: item.linkFieldKey,
|
|
50318
50322
|
key: "newfixed",
|
|
50319
50323
|
name: "二维表-关联",
|
|
50320
|
-
subType: "sub-table-2d-link"
|
|
50324
|
+
subType: "sub-table-2d-link",
|
|
50325
|
+
crossKey
|
|
50321
50326
|
});
|
|
50322
50327
|
}
|
|
50323
50328
|
return result;
|
|
50324
50329
|
}).flat();
|
|
50325
50330
|
const checkTableRegions = tables.filter((w2) => w2.hasCheckTable).flatMap((w2) => w2.checkTable).map((item) => {
|
|
50331
|
+
const crossKey = item.subFieldKey && item.linkFieldKey ? `${item.subFieldKey}:${item.linkFieldKey}` : void 0;
|
|
50326
50332
|
const result = [];
|
|
50327
50333
|
if (item.subFieldKey) {
|
|
50328
50334
|
result.push({
|
|
50329
50335
|
field: item.subFieldKey,
|
|
50330
50336
|
key: "newfixed",
|
|
50331
50337
|
name: "检验表-动态",
|
|
50332
|
-
subType: "check-table-2d"
|
|
50338
|
+
subType: "check-table-2d",
|
|
50339
|
+
crossKey
|
|
50333
50340
|
});
|
|
50334
50341
|
}
|
|
50335
50342
|
if (item.linkFieldKey) {
|
|
@@ -50337,7 +50344,8 @@ class DocModel {
|
|
|
50337
50344
|
field: item.linkFieldKey,
|
|
50338
50345
|
key: "newfixed",
|
|
50339
50346
|
name: "检验表-关联",
|
|
50340
|
-
subType: "check-table-2d-link"
|
|
50347
|
+
subType: "check-table-2d-link",
|
|
50348
|
+
crossKey
|
|
50341
50349
|
});
|
|
50342
50350
|
}
|
|
50343
50351
|
return result;
|
|
@@ -50362,7 +50370,7 @@ class DocModel {
|
|
|
50362
50370
|
const fillDirection = region.widgetMeta?.props?.fillDirection ?? "x";
|
|
50363
50371
|
max = Math.max(max, countDataGroupSlots(region, region.itemRegion, fillDirection));
|
|
50364
50372
|
}
|
|
50365
|
-
for (const region of table.checkTable) {
|
|
50373
|
+
for (const region of [...table.checkTable, ...table._2DTable]) {
|
|
50366
50374
|
if (!region.itemRegion) continue;
|
|
50367
50375
|
const range3 = expandDataGroupRowRange(region, region.itemRegion);
|
|
50368
50376
|
const fillDirection = region.widgetMeta?.props?.fillDirection ?? "x";
|
|
@@ -50374,17 +50382,6 @@ class DocModel {
|
|
|
50374
50382
|
isLinkSubTableSubAxisOnly = true;
|
|
50375
50383
|
}
|
|
50376
50384
|
}
|
|
50377
|
-
for (const region of table._2DTable) {
|
|
50378
|
-
if (!region.itemRegion) continue;
|
|
50379
|
-
const range3 = expandDataGroupRowRange(region, region.itemRegion);
|
|
50380
|
-
const slots = countDataGroupSlots(range3, region.itemRegion);
|
|
50381
|
-
if (region.linkFieldKey === subFieldKey) {
|
|
50382
|
-
max = Math.max(max, slots);
|
|
50383
|
-
}
|
|
50384
|
-
if (region.subFieldKey === subFieldKey) {
|
|
50385
|
-
isLinkSubTableSubAxisOnly = true;
|
|
50386
|
-
}
|
|
50387
|
-
}
|
|
50388
50385
|
}
|
|
50389
50386
|
if (max > 0) return max;
|
|
50390
50387
|
if (isLinkSubTableSubAxisOnly) return 0;
|
|
@@ -51786,63 +51783,48 @@ function transformSourceDataList(data, dict = {}) {
|
|
|
51786
51783
|
return list || [];
|
|
51787
51784
|
}
|
|
51788
51785
|
function conversionFormState(payload) {
|
|
51789
|
-
const { interfaceData, masterSlaveList,
|
|
51786
|
+
const { interfaceData, masterSlaveList, subTableInfoList } = payload || {};
|
|
51790
51787
|
const formState = {};
|
|
51791
51788
|
if (interfaceData && interfaceData.data) {
|
|
51792
51789
|
merge(formState, transformSourceData(interfaceData.data, interfaceData.dict));
|
|
51793
51790
|
}
|
|
51794
|
-
|
|
51795
|
-
|
|
51796
|
-
const
|
|
51797
|
-
|
|
51798
|
-
|
|
51799
|
-
|
|
51800
|
-
|
|
51801
|
-
|
|
51802
|
-
|
|
51803
|
-
};
|
|
51804
|
-
|
|
51805
|
-
|
|
51806
|
-
|
|
51807
|
-
|
|
51808
|
-
|
|
51809
|
-
|
|
51810
|
-
|
|
51811
|
-
|
|
51812
|
-
|
|
51813
|
-
|
|
51814
|
-
|
|
51815
|
-
|
|
51816
|
-
|
|
51817
|
-
|
|
51818
|
-
|
|
51819
|
-
|
|
51820
|
-
|
|
51821
|
-
|
|
51822
|
-
|
|
51823
|
-
|
|
51824
|
-
|
|
51825
|
-
|
|
51826
|
-
|
|
51827
|
-
dict: parentState?.dict || []
|
|
51828
|
-
};
|
|
51829
|
-
const addedYUidList = [];
|
|
51830
|
-
formState[parentFieldKey] = {
|
|
51831
|
-
data: [],
|
|
51832
|
-
dict: formState[parentFieldKey]?.dict || []
|
|
51833
|
-
};
|
|
51834
|
-
parentState?.data.forEach((row) => {
|
|
51835
|
-
const yUid = row.group_.split(":")[0];
|
|
51836
|
-
if (addedYUidList.includes(yUid)) return;
|
|
51837
|
-
addedYUidList.push(yUid);
|
|
51838
|
-
formState[parentFieldKey].data.push({
|
|
51839
|
-
...row,
|
|
51840
|
-
__gw_y_uid: yUid
|
|
51841
|
-
});
|
|
51791
|
+
const crossKeyList = Array.from(new Set(subTableInfoList.map((o) => o.crossKey).filter(Boolean)));
|
|
51792
|
+
crossKeyList.forEach((crossKey) => {
|
|
51793
|
+
const [parentFieldKey, linkFieldKey] = crossKey.split(":");
|
|
51794
|
+
const parentState = formState[parentFieldKey];
|
|
51795
|
+
formState[linkFieldKey]?.data.forEach((row) => {
|
|
51796
|
+
row.__gw_x_uid = row.group_;
|
|
51797
|
+
});
|
|
51798
|
+
formState[crossKey] = {
|
|
51799
|
+
data: parentState?.data.map((row) => {
|
|
51800
|
+
const { group_ } = row;
|
|
51801
|
+
const _row = { ...row };
|
|
51802
|
+
if (group_) {
|
|
51803
|
+
const [yid, xid] = group_.split(":");
|
|
51804
|
+
_row.__gw_y_uid = yid;
|
|
51805
|
+
_row.__gw_x_uid = xid;
|
|
51806
|
+
}
|
|
51807
|
+
return _row;
|
|
51808
|
+
}) || [],
|
|
51809
|
+
dict: parentState?.dict || []
|
|
51810
|
+
};
|
|
51811
|
+
const addedYids = [];
|
|
51812
|
+
formState[parentFieldKey] = {
|
|
51813
|
+
data: [],
|
|
51814
|
+
dict: formState[parentFieldKey]?.dict || []
|
|
51815
|
+
};
|
|
51816
|
+
parentState?.data.forEach((row) => {
|
|
51817
|
+
if (!row.group_?.includes(":")) return;
|
|
51818
|
+
const yid = row.group_.split(":")[0];
|
|
51819
|
+
if (addedYids.includes(yid)) return;
|
|
51820
|
+
addedYids.push(yid);
|
|
51821
|
+
formState[parentFieldKey].data.push({
|
|
51822
|
+
...row,
|
|
51823
|
+
__gw_y_uid: yid
|
|
51842
51824
|
});
|
|
51843
51825
|
});
|
|
51844
|
-
}
|
|
51845
|
-
masterSlaveList.map((item) => item.key).concat(
|
|
51826
|
+
});
|
|
51827
|
+
masterSlaveList.map((item) => item.key).concat(crossKeyList).forEach((k) => {
|
|
51846
51828
|
const subFormData = formState[k];
|
|
51847
51829
|
if (subFormData) {
|
|
51848
51830
|
formState[k] = transformSourceDataList([...subFormData.data], subFormData.dict);
|
|
@@ -51850,38 +51832,38 @@ function conversionFormState(payload) {
|
|
|
51850
51832
|
});
|
|
51851
51833
|
return formState;
|
|
51852
51834
|
}
|
|
51853
|
-
function
|
|
51835
|
+
function resolveSubmitCrossKeys(formData, subTableInfoList) {
|
|
51836
|
+
if (subTableInfoList?.length) {
|
|
51837
|
+
const fromModel = [
|
|
51838
|
+
...new Set(
|
|
51839
|
+
subTableInfoList.map((item) => item.crossKey).filter((key) => typeof key === "string" && key.length > 0)
|
|
51840
|
+
)
|
|
51841
|
+
];
|
|
51842
|
+
if (fromModel.length) return fromModel;
|
|
51843
|
+
}
|
|
51844
|
+
return Object.keys(formData).filter((k) => k.includes(":"));
|
|
51845
|
+
}
|
|
51846
|
+
function getSubmitFormData(formData, subTableInfoList) {
|
|
51854
51847
|
const _formData = { ...formData };
|
|
51855
|
-
|
|
51856
|
-
const [subKey] =
|
|
51848
|
+
resolveSubmitCrossKeys(_formData, subTableInfoList).forEach((crossKey) => {
|
|
51849
|
+
const [subKey, linkKey] = crossKey.split(":");
|
|
51857
51850
|
const subData = _formData[subKey] || [];
|
|
51858
|
-
const
|
|
51859
|
-
|
|
51860
|
-
|
|
51861
|
-
|
|
51862
|
-
|
|
51863
|
-
|
|
51864
|
-
|
|
51865
|
-
const
|
|
51866
|
-
|
|
51867
|
-
|
|
51868
|
-
|
|
51869
|
-
|
|
51870
|
-
|
|
51871
|
-
Object.assign(existedRow, {
|
|
51872
|
-
...newRowInfo,
|
|
51873
|
-
group_
|
|
51874
|
-
});
|
|
51875
|
-
} else {
|
|
51876
|
-
_formData[subKey].push({
|
|
51877
|
-
...existedRow,
|
|
51878
|
-
...newRowInfo,
|
|
51879
|
-
group_
|
|
51880
|
-
});
|
|
51881
|
-
}
|
|
51851
|
+
const linkData = _formData[linkKey] || [];
|
|
51852
|
+
const crossData = _formData[crossKey] || [];
|
|
51853
|
+
_formData[subKey] = [];
|
|
51854
|
+
subData.forEach((subRow) => {
|
|
51855
|
+
const { __gw_y_uid: yid } = subRow;
|
|
51856
|
+
linkData.forEach((linkRow) => {
|
|
51857
|
+
const { __gw_x_uid: xid } = linkRow;
|
|
51858
|
+
const crossRow = crossData.find((row) => row.__gw_y_uid === yid && row.__gw_x_uid === xid) || {};
|
|
51859
|
+
_formData[subKey].push({
|
|
51860
|
+
...subRow,
|
|
51861
|
+
...omit(crossRow, FILTER_KEYS),
|
|
51862
|
+
group_: `${yid}:${xid}`
|
|
51863
|
+
});
|
|
51882
51864
|
});
|
|
51883
|
-
}
|
|
51884
|
-
delete _formData[
|
|
51865
|
+
});
|
|
51866
|
+
delete _formData[crossKey];
|
|
51885
51867
|
});
|
|
51886
51868
|
const realFormData = Object.keys(_formData).reduce((reducedData, fieldKey) => {
|
|
51887
51869
|
const fieldValue = _formData[fieldKey];
|
|
@@ -52661,6 +52643,1750 @@ async function loadDataValuesByAutofillRules(record, ctx, instances, autofillRul
|
|
|
52661
52643
|
{ needReplacePathIndexPlaceholder: true, sourceValuePath }
|
|
52662
52644
|
);
|
|
52663
52645
|
}
|
|
52646
|
+
class Hooks {
|
|
52647
|
+
/**
|
|
52648
|
+
* @callback HookCallback
|
|
52649
|
+
* @this {*|Jsep} this
|
|
52650
|
+
* @param {Jsep} env
|
|
52651
|
+
* @returns: void
|
|
52652
|
+
*/
|
|
52653
|
+
/**
|
|
52654
|
+
* Adds the given callback to the list of callbacks for the given hook.
|
|
52655
|
+
*
|
|
52656
|
+
* The callback will be invoked when the hook it is registered for is run.
|
|
52657
|
+
*
|
|
52658
|
+
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
52659
|
+
*
|
|
52660
|
+
* @param {string|object} name The name of the hook, or an object of callbacks keyed by name
|
|
52661
|
+
* @param {HookCallback|boolean} callback The callback function which is given environment variables.
|
|
52662
|
+
* @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom)
|
|
52663
|
+
* @public
|
|
52664
|
+
*/
|
|
52665
|
+
add(name2, callback, first) {
|
|
52666
|
+
if (typeof arguments[0] != "string") {
|
|
52667
|
+
for (let name3 in arguments[0]) {
|
|
52668
|
+
this.add(name3, arguments[0][name3], arguments[1]);
|
|
52669
|
+
}
|
|
52670
|
+
} else {
|
|
52671
|
+
(Array.isArray(name2) ? name2 : [name2]).forEach(function(name3) {
|
|
52672
|
+
this[name3] = this[name3] || [];
|
|
52673
|
+
if (callback) {
|
|
52674
|
+
this[name3][first ? "unshift" : "push"](callback);
|
|
52675
|
+
}
|
|
52676
|
+
}, this);
|
|
52677
|
+
}
|
|
52678
|
+
}
|
|
52679
|
+
/**
|
|
52680
|
+
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
52681
|
+
*
|
|
52682
|
+
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
52683
|
+
*
|
|
52684
|
+
* @param {string} name The name of the hook.
|
|
52685
|
+
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
52686
|
+
* @public
|
|
52687
|
+
*/
|
|
52688
|
+
run(name2, env) {
|
|
52689
|
+
this[name2] = this[name2] || [];
|
|
52690
|
+
this[name2].forEach(function(callback) {
|
|
52691
|
+
callback.call(env && env.context ? env.context : env, env);
|
|
52692
|
+
});
|
|
52693
|
+
}
|
|
52694
|
+
}
|
|
52695
|
+
class Plugins {
|
|
52696
|
+
constructor(jsep2) {
|
|
52697
|
+
this.jsep = jsep2;
|
|
52698
|
+
this.registered = {};
|
|
52699
|
+
}
|
|
52700
|
+
/**
|
|
52701
|
+
* @callback PluginSetup
|
|
52702
|
+
* @this {Jsep} jsep
|
|
52703
|
+
* @returns: void
|
|
52704
|
+
*/
|
|
52705
|
+
/**
|
|
52706
|
+
* Adds the given plugin(s) to the registry
|
|
52707
|
+
*
|
|
52708
|
+
* @param {object} plugins
|
|
52709
|
+
* @param {string} plugins.name The name of the plugin
|
|
52710
|
+
* @param {PluginSetup} plugins.init The init function
|
|
52711
|
+
* @public
|
|
52712
|
+
*/
|
|
52713
|
+
register() {
|
|
52714
|
+
for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
52715
|
+
plugins[_key] = arguments[_key];
|
|
52716
|
+
}
|
|
52717
|
+
plugins.forEach((plugin2) => {
|
|
52718
|
+
if (typeof plugin2 !== "object" || !plugin2.name || !plugin2.init) {
|
|
52719
|
+
throw new Error("Invalid JSEP plugin format");
|
|
52720
|
+
}
|
|
52721
|
+
if (this.registered[plugin2.name]) {
|
|
52722
|
+
return;
|
|
52723
|
+
}
|
|
52724
|
+
plugin2.init(this.jsep);
|
|
52725
|
+
this.registered[plugin2.name] = plugin2;
|
|
52726
|
+
});
|
|
52727
|
+
}
|
|
52728
|
+
}
|
|
52729
|
+
class Jsep {
|
|
52730
|
+
/**
|
|
52731
|
+
* @returns {string}
|
|
52732
|
+
*/
|
|
52733
|
+
static get version() {
|
|
52734
|
+
return "1.4.0";
|
|
52735
|
+
}
|
|
52736
|
+
/**
|
|
52737
|
+
* @returns {string}
|
|
52738
|
+
*/
|
|
52739
|
+
static toString() {
|
|
52740
|
+
return "JavaScript Expression Parser (JSEP) v" + Jsep.version;
|
|
52741
|
+
}
|
|
52742
|
+
// ==================== CONFIG ================================
|
|
52743
|
+
/**
|
|
52744
|
+
* @method addUnaryOp
|
|
52745
|
+
* @param {string} op_name The name of the unary op to add
|
|
52746
|
+
* @returns {Jsep}
|
|
52747
|
+
*/
|
|
52748
|
+
static addUnaryOp(op_name) {
|
|
52749
|
+
Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);
|
|
52750
|
+
Jsep.unary_ops[op_name] = 1;
|
|
52751
|
+
return Jsep;
|
|
52752
|
+
}
|
|
52753
|
+
/**
|
|
52754
|
+
* @method jsep.addBinaryOp
|
|
52755
|
+
* @param {string} op_name The name of the binary op to add
|
|
52756
|
+
* @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence
|
|
52757
|
+
* @param {boolean} [isRightAssociative=false] whether operator is right-associative
|
|
52758
|
+
* @returns {Jsep}
|
|
52759
|
+
*/
|
|
52760
|
+
static addBinaryOp(op_name, precedence, isRightAssociative) {
|
|
52761
|
+
Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);
|
|
52762
|
+
Jsep.binary_ops[op_name] = precedence;
|
|
52763
|
+
if (isRightAssociative) {
|
|
52764
|
+
Jsep.right_associative.add(op_name);
|
|
52765
|
+
} else {
|
|
52766
|
+
Jsep.right_associative.delete(op_name);
|
|
52767
|
+
}
|
|
52768
|
+
return Jsep;
|
|
52769
|
+
}
|
|
52770
|
+
/**
|
|
52771
|
+
* @method addIdentifierChar
|
|
52772
|
+
* @param {string} char The additional character to treat as a valid part of an identifier
|
|
52773
|
+
* @returns {Jsep}
|
|
52774
|
+
*/
|
|
52775
|
+
static addIdentifierChar(char) {
|
|
52776
|
+
Jsep.additional_identifier_chars.add(char);
|
|
52777
|
+
return Jsep;
|
|
52778
|
+
}
|
|
52779
|
+
/**
|
|
52780
|
+
* @method addLiteral
|
|
52781
|
+
* @param {string} literal_name The name of the literal to add
|
|
52782
|
+
* @param {*} literal_value The value of the literal
|
|
52783
|
+
* @returns {Jsep}
|
|
52784
|
+
*/
|
|
52785
|
+
static addLiteral(literal_name, literal_value) {
|
|
52786
|
+
Jsep.literals[literal_name] = literal_value;
|
|
52787
|
+
return Jsep;
|
|
52788
|
+
}
|
|
52789
|
+
/**
|
|
52790
|
+
* @method removeUnaryOp
|
|
52791
|
+
* @param {string} op_name The name of the unary op to remove
|
|
52792
|
+
* @returns {Jsep}
|
|
52793
|
+
*/
|
|
52794
|
+
static removeUnaryOp(op_name) {
|
|
52795
|
+
delete Jsep.unary_ops[op_name];
|
|
52796
|
+
if (op_name.length === Jsep.max_unop_len) {
|
|
52797
|
+
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
52798
|
+
}
|
|
52799
|
+
return Jsep;
|
|
52800
|
+
}
|
|
52801
|
+
/**
|
|
52802
|
+
* @method removeAllUnaryOps
|
|
52803
|
+
* @returns {Jsep}
|
|
52804
|
+
*/
|
|
52805
|
+
static removeAllUnaryOps() {
|
|
52806
|
+
Jsep.unary_ops = {};
|
|
52807
|
+
Jsep.max_unop_len = 0;
|
|
52808
|
+
return Jsep;
|
|
52809
|
+
}
|
|
52810
|
+
/**
|
|
52811
|
+
* @method removeIdentifierChar
|
|
52812
|
+
* @param {string} char The additional character to stop treating as a valid part of an identifier
|
|
52813
|
+
* @returns {Jsep}
|
|
52814
|
+
*/
|
|
52815
|
+
static removeIdentifierChar(char) {
|
|
52816
|
+
Jsep.additional_identifier_chars.delete(char);
|
|
52817
|
+
return Jsep;
|
|
52818
|
+
}
|
|
52819
|
+
/**
|
|
52820
|
+
* @method removeBinaryOp
|
|
52821
|
+
* @param {string} op_name The name of the binary op to remove
|
|
52822
|
+
* @returns {Jsep}
|
|
52823
|
+
*/
|
|
52824
|
+
static removeBinaryOp(op_name) {
|
|
52825
|
+
delete Jsep.binary_ops[op_name];
|
|
52826
|
+
if (op_name.length === Jsep.max_binop_len) {
|
|
52827
|
+
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
52828
|
+
}
|
|
52829
|
+
Jsep.right_associative.delete(op_name);
|
|
52830
|
+
return Jsep;
|
|
52831
|
+
}
|
|
52832
|
+
/**
|
|
52833
|
+
* @method removeAllBinaryOps
|
|
52834
|
+
* @returns {Jsep}
|
|
52835
|
+
*/
|
|
52836
|
+
static removeAllBinaryOps() {
|
|
52837
|
+
Jsep.binary_ops = {};
|
|
52838
|
+
Jsep.max_binop_len = 0;
|
|
52839
|
+
return Jsep;
|
|
52840
|
+
}
|
|
52841
|
+
/**
|
|
52842
|
+
* @method removeLiteral
|
|
52843
|
+
* @param {string} literal_name The name of the literal to remove
|
|
52844
|
+
* @returns {Jsep}
|
|
52845
|
+
*/
|
|
52846
|
+
static removeLiteral(literal_name) {
|
|
52847
|
+
delete Jsep.literals[literal_name];
|
|
52848
|
+
return Jsep;
|
|
52849
|
+
}
|
|
52850
|
+
/**
|
|
52851
|
+
* @method removeAllLiterals
|
|
52852
|
+
* @returns {Jsep}
|
|
52853
|
+
*/
|
|
52854
|
+
static removeAllLiterals() {
|
|
52855
|
+
Jsep.literals = {};
|
|
52856
|
+
return Jsep;
|
|
52857
|
+
}
|
|
52858
|
+
// ==================== END CONFIG ============================
|
|
52859
|
+
/**
|
|
52860
|
+
* @returns {string}
|
|
52861
|
+
*/
|
|
52862
|
+
get char() {
|
|
52863
|
+
return this.expr.charAt(this.index);
|
|
52864
|
+
}
|
|
52865
|
+
/**
|
|
52866
|
+
* @returns {number}
|
|
52867
|
+
*/
|
|
52868
|
+
get code() {
|
|
52869
|
+
return this.expr.charCodeAt(this.index);
|
|
52870
|
+
}
|
|
52871
|
+
/**
|
|
52872
|
+
* @param {string} expr a string with the passed in express
|
|
52873
|
+
* @returns Jsep
|
|
52874
|
+
*/
|
|
52875
|
+
constructor(expr) {
|
|
52876
|
+
this.expr = expr;
|
|
52877
|
+
this.index = 0;
|
|
52878
|
+
}
|
|
52879
|
+
/**
|
|
52880
|
+
* static top-level parser
|
|
52881
|
+
* @returns {jsep.Expression}
|
|
52882
|
+
*/
|
|
52883
|
+
static parse(expr) {
|
|
52884
|
+
return new Jsep(expr).parse();
|
|
52885
|
+
}
|
|
52886
|
+
/**
|
|
52887
|
+
* Get the longest key length of any object
|
|
52888
|
+
* @param {object} obj
|
|
52889
|
+
* @returns {number}
|
|
52890
|
+
*/
|
|
52891
|
+
static getMaxKeyLen(obj) {
|
|
52892
|
+
return Math.max(0, ...Object.keys(obj).map((k) => k.length));
|
|
52893
|
+
}
|
|
52894
|
+
/**
|
|
52895
|
+
* `ch` is a character code in the next three functions
|
|
52896
|
+
* @param {number} ch
|
|
52897
|
+
* @returns {boolean}
|
|
52898
|
+
*/
|
|
52899
|
+
static isDecimalDigit(ch) {
|
|
52900
|
+
return ch >= 48 && ch <= 57;
|
|
52901
|
+
}
|
|
52902
|
+
/**
|
|
52903
|
+
* Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float.
|
|
52904
|
+
* @param {string} op_val
|
|
52905
|
+
* @returns {number}
|
|
52906
|
+
*/
|
|
52907
|
+
static binaryPrecedence(op_val) {
|
|
52908
|
+
return Jsep.binary_ops[op_val] || 0;
|
|
52909
|
+
}
|
|
52910
|
+
/**
|
|
52911
|
+
* Looks for start of identifier
|
|
52912
|
+
* @param {number} ch
|
|
52913
|
+
* @returns {boolean}
|
|
52914
|
+
*/
|
|
52915
|
+
static isIdentifierStart(ch) {
|
|
52916
|
+
return ch >= 65 && ch <= 90 || // A...Z
|
|
52917
|
+
ch >= 97 && ch <= 122 || // a...z
|
|
52918
|
+
ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)] || // any non-ASCII that is not an operator
|
|
52919
|
+
Jsep.additional_identifier_chars.has(String.fromCharCode(ch));
|
|
52920
|
+
}
|
|
52921
|
+
/**
|
|
52922
|
+
* @param {number} ch
|
|
52923
|
+
* @returns {boolean}
|
|
52924
|
+
*/
|
|
52925
|
+
static isIdentifierPart(ch) {
|
|
52926
|
+
return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);
|
|
52927
|
+
}
|
|
52928
|
+
/**
|
|
52929
|
+
* throw error at index of the expression
|
|
52930
|
+
* @param {string} message
|
|
52931
|
+
* @throws
|
|
52932
|
+
*/
|
|
52933
|
+
throwError(message) {
|
|
52934
|
+
const error = new Error(message + " at character " + this.index);
|
|
52935
|
+
error.index = this.index;
|
|
52936
|
+
error.description = message;
|
|
52937
|
+
throw error;
|
|
52938
|
+
}
|
|
52939
|
+
/**
|
|
52940
|
+
* Run a given hook
|
|
52941
|
+
* @param {string} name
|
|
52942
|
+
* @param {jsep.Expression|false} [node]
|
|
52943
|
+
* @returns {?jsep.Expression}
|
|
52944
|
+
*/
|
|
52945
|
+
runHook(name2, node) {
|
|
52946
|
+
if (Jsep.hooks[name2]) {
|
|
52947
|
+
const env = {
|
|
52948
|
+
context: this,
|
|
52949
|
+
node
|
|
52950
|
+
};
|
|
52951
|
+
Jsep.hooks.run(name2, env);
|
|
52952
|
+
return env.node;
|
|
52953
|
+
}
|
|
52954
|
+
return node;
|
|
52955
|
+
}
|
|
52956
|
+
/**
|
|
52957
|
+
* Runs a given hook until one returns a node
|
|
52958
|
+
* @param {string} name
|
|
52959
|
+
* @returns {?jsep.Expression}
|
|
52960
|
+
*/
|
|
52961
|
+
searchHook(name2) {
|
|
52962
|
+
if (Jsep.hooks[name2]) {
|
|
52963
|
+
const env = {
|
|
52964
|
+
context: this
|
|
52965
|
+
};
|
|
52966
|
+
Jsep.hooks[name2].find(function(callback) {
|
|
52967
|
+
callback.call(env.context, env);
|
|
52968
|
+
return env.node;
|
|
52969
|
+
});
|
|
52970
|
+
return env.node;
|
|
52971
|
+
}
|
|
52972
|
+
}
|
|
52973
|
+
/**
|
|
52974
|
+
* Push `index` up to the next non-space character
|
|
52975
|
+
*/
|
|
52976
|
+
gobbleSpaces() {
|
|
52977
|
+
let ch = this.code;
|
|
52978
|
+
while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) {
|
|
52979
|
+
ch = this.expr.charCodeAt(++this.index);
|
|
52980
|
+
}
|
|
52981
|
+
this.runHook("gobble-spaces");
|
|
52982
|
+
}
|
|
52983
|
+
/**
|
|
52984
|
+
* Top-level method to parse all expressions and returns compound or single node
|
|
52985
|
+
* @returns {jsep.Expression}
|
|
52986
|
+
*/
|
|
52987
|
+
parse() {
|
|
52988
|
+
this.runHook("before-all");
|
|
52989
|
+
const nodes = this.gobbleExpressions();
|
|
52990
|
+
const node = nodes.length === 1 ? nodes[0] : {
|
|
52991
|
+
type: Jsep.COMPOUND,
|
|
52992
|
+
body: nodes
|
|
52993
|
+
};
|
|
52994
|
+
return this.runHook("after-all", node);
|
|
52995
|
+
}
|
|
52996
|
+
/**
|
|
52997
|
+
* top-level parser (but can be reused within as well)
|
|
52998
|
+
* @param {number} [untilICode]
|
|
52999
|
+
* @returns {jsep.Expression[]}
|
|
53000
|
+
*/
|
|
53001
|
+
gobbleExpressions(untilICode) {
|
|
53002
|
+
let nodes = [], ch_i, node;
|
|
53003
|
+
while (this.index < this.expr.length) {
|
|
53004
|
+
ch_i = this.code;
|
|
53005
|
+
if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {
|
|
53006
|
+
this.index++;
|
|
53007
|
+
} else {
|
|
53008
|
+
if (node = this.gobbleExpression()) {
|
|
53009
|
+
nodes.push(node);
|
|
53010
|
+
} else if (this.index < this.expr.length) {
|
|
53011
|
+
if (ch_i === untilICode) {
|
|
53012
|
+
break;
|
|
53013
|
+
}
|
|
53014
|
+
this.throwError('Unexpected "' + this.char + '"');
|
|
53015
|
+
}
|
|
53016
|
+
}
|
|
53017
|
+
}
|
|
53018
|
+
return nodes;
|
|
53019
|
+
}
|
|
53020
|
+
/**
|
|
53021
|
+
* The main parsing function.
|
|
53022
|
+
* @returns {?jsep.Expression}
|
|
53023
|
+
*/
|
|
53024
|
+
gobbleExpression() {
|
|
53025
|
+
const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
|
|
53026
|
+
this.gobbleSpaces();
|
|
53027
|
+
return this.runHook("after-expression", node);
|
|
53028
|
+
}
|
|
53029
|
+
/**
|
|
53030
|
+
* Search for the operation portion of the string (e.g. `+`, `===`)
|
|
53031
|
+
* Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)
|
|
53032
|
+
* and move down from 3 to 2 to 1 character until a matching binary operation is found
|
|
53033
|
+
* then, return that binary operation
|
|
53034
|
+
* @returns {string|boolean}
|
|
53035
|
+
*/
|
|
53036
|
+
gobbleBinaryOp() {
|
|
53037
|
+
this.gobbleSpaces();
|
|
53038
|
+
let to_check = this.expr.substr(this.index, Jsep.max_binop_len);
|
|
53039
|
+
let tc_len = to_check.length;
|
|
53040
|
+
while (tc_len > 0) {
|
|
53041
|
+
if (Jsep.binary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
|
|
53042
|
+
this.index += tc_len;
|
|
53043
|
+
return to_check;
|
|
53044
|
+
}
|
|
53045
|
+
to_check = to_check.substr(0, --tc_len);
|
|
53046
|
+
}
|
|
53047
|
+
return false;
|
|
53048
|
+
}
|
|
53049
|
+
/**
|
|
53050
|
+
* This function is responsible for gobbling an individual expression,
|
|
53051
|
+
* e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`
|
|
53052
|
+
* @returns {?jsep.BinaryExpression}
|
|
53053
|
+
*/
|
|
53054
|
+
gobbleBinaryExpression() {
|
|
53055
|
+
let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
|
|
53056
|
+
left = this.gobbleToken();
|
|
53057
|
+
if (!left) {
|
|
53058
|
+
return left;
|
|
53059
|
+
}
|
|
53060
|
+
biop = this.gobbleBinaryOp();
|
|
53061
|
+
if (!biop) {
|
|
53062
|
+
return left;
|
|
53063
|
+
}
|
|
53064
|
+
biop_info = {
|
|
53065
|
+
value: biop,
|
|
53066
|
+
prec: Jsep.binaryPrecedence(biop),
|
|
53067
|
+
right_a: Jsep.right_associative.has(biop)
|
|
53068
|
+
};
|
|
53069
|
+
right = this.gobbleToken();
|
|
53070
|
+
if (!right) {
|
|
53071
|
+
this.throwError("Expected expression after " + biop);
|
|
53072
|
+
}
|
|
53073
|
+
stack = [left, biop_info, right];
|
|
53074
|
+
while (biop = this.gobbleBinaryOp()) {
|
|
53075
|
+
prec = Jsep.binaryPrecedence(biop);
|
|
53076
|
+
if (prec === 0) {
|
|
53077
|
+
this.index -= biop.length;
|
|
53078
|
+
break;
|
|
53079
|
+
}
|
|
53080
|
+
biop_info = {
|
|
53081
|
+
value: biop,
|
|
53082
|
+
prec,
|
|
53083
|
+
right_a: Jsep.right_associative.has(biop)
|
|
53084
|
+
};
|
|
53085
|
+
cur_biop = biop;
|
|
53086
|
+
const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
|
|
53087
|
+
while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
|
|
53088
|
+
right = stack.pop();
|
|
53089
|
+
biop = stack.pop().value;
|
|
53090
|
+
left = stack.pop();
|
|
53091
|
+
node = {
|
|
53092
|
+
type: Jsep.BINARY_EXP,
|
|
53093
|
+
operator: biop,
|
|
53094
|
+
left,
|
|
53095
|
+
right
|
|
53096
|
+
};
|
|
53097
|
+
stack.push(node);
|
|
53098
|
+
}
|
|
53099
|
+
node = this.gobbleToken();
|
|
53100
|
+
if (!node) {
|
|
53101
|
+
this.throwError("Expected expression after " + cur_biop);
|
|
53102
|
+
}
|
|
53103
|
+
stack.push(biop_info, node);
|
|
53104
|
+
}
|
|
53105
|
+
i = stack.length - 1;
|
|
53106
|
+
node = stack[i];
|
|
53107
|
+
while (i > 1) {
|
|
53108
|
+
node = {
|
|
53109
|
+
type: Jsep.BINARY_EXP,
|
|
53110
|
+
operator: stack[i - 1].value,
|
|
53111
|
+
left: stack[i - 2],
|
|
53112
|
+
right: node
|
|
53113
|
+
};
|
|
53114
|
+
i -= 2;
|
|
53115
|
+
}
|
|
53116
|
+
return node;
|
|
53117
|
+
}
|
|
53118
|
+
/**
|
|
53119
|
+
* An individual part of a binary expression:
|
|
53120
|
+
* e.g. `foo.bar(baz)`, `1`, `"abc"`, `(a % 2)` (because it's in parenthesis)
|
|
53121
|
+
* @returns {boolean|jsep.Expression}
|
|
53122
|
+
*/
|
|
53123
|
+
gobbleToken() {
|
|
53124
|
+
let ch, to_check, tc_len, node;
|
|
53125
|
+
this.gobbleSpaces();
|
|
53126
|
+
node = this.searchHook("gobble-token");
|
|
53127
|
+
if (node) {
|
|
53128
|
+
return this.runHook("after-token", node);
|
|
53129
|
+
}
|
|
53130
|
+
ch = this.code;
|
|
53131
|
+
if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {
|
|
53132
|
+
return this.gobbleNumericLiteral();
|
|
53133
|
+
}
|
|
53134
|
+
if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {
|
|
53135
|
+
node = this.gobbleStringLiteral();
|
|
53136
|
+
} else if (ch === Jsep.OBRACK_CODE) {
|
|
53137
|
+
node = this.gobbleArray();
|
|
53138
|
+
} else {
|
|
53139
|
+
to_check = this.expr.substr(this.index, Jsep.max_unop_len);
|
|
53140
|
+
tc_len = to_check.length;
|
|
53141
|
+
while (tc_len > 0) {
|
|
53142
|
+
if (Jsep.unary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
|
|
53143
|
+
this.index += tc_len;
|
|
53144
|
+
const argument = this.gobbleToken();
|
|
53145
|
+
if (!argument) {
|
|
53146
|
+
this.throwError("missing unaryOp argument");
|
|
53147
|
+
}
|
|
53148
|
+
return this.runHook("after-token", {
|
|
53149
|
+
type: Jsep.UNARY_EXP,
|
|
53150
|
+
operator: to_check,
|
|
53151
|
+
argument,
|
|
53152
|
+
prefix: true
|
|
53153
|
+
});
|
|
53154
|
+
}
|
|
53155
|
+
to_check = to_check.substr(0, --tc_len);
|
|
53156
|
+
}
|
|
53157
|
+
if (Jsep.isIdentifierStart(ch)) {
|
|
53158
|
+
node = this.gobbleIdentifier();
|
|
53159
|
+
if (Jsep.literals.hasOwnProperty(node.name)) {
|
|
53160
|
+
node = {
|
|
53161
|
+
type: Jsep.LITERAL,
|
|
53162
|
+
value: Jsep.literals[node.name],
|
|
53163
|
+
raw: node.name
|
|
53164
|
+
};
|
|
53165
|
+
} else if (node.name === Jsep.this_str) {
|
|
53166
|
+
node = {
|
|
53167
|
+
type: Jsep.THIS_EXP
|
|
53168
|
+
};
|
|
53169
|
+
}
|
|
53170
|
+
} else if (ch === Jsep.OPAREN_CODE) {
|
|
53171
|
+
node = this.gobbleGroup();
|
|
53172
|
+
}
|
|
53173
|
+
}
|
|
53174
|
+
if (!node) {
|
|
53175
|
+
return this.runHook("after-token", false);
|
|
53176
|
+
}
|
|
53177
|
+
node = this.gobbleTokenProperty(node);
|
|
53178
|
+
return this.runHook("after-token", node);
|
|
53179
|
+
}
|
|
53180
|
+
/**
|
|
53181
|
+
* Gobble properties of of identifiers/strings/arrays/groups.
|
|
53182
|
+
* e.g. `foo`, `bar.baz`, `foo['bar'].baz`
|
|
53183
|
+
* It also gobbles function calls:
|
|
53184
|
+
* e.g. `Math.acos(obj.angle)`
|
|
53185
|
+
* @param {jsep.Expression} node
|
|
53186
|
+
* @returns {jsep.Expression}
|
|
53187
|
+
*/
|
|
53188
|
+
gobbleTokenProperty(node) {
|
|
53189
|
+
this.gobbleSpaces();
|
|
53190
|
+
let ch = this.code;
|
|
53191
|
+
while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {
|
|
53192
|
+
let optional;
|
|
53193
|
+
if (ch === Jsep.QUMARK_CODE) {
|
|
53194
|
+
if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {
|
|
53195
|
+
break;
|
|
53196
|
+
}
|
|
53197
|
+
optional = true;
|
|
53198
|
+
this.index += 2;
|
|
53199
|
+
this.gobbleSpaces();
|
|
53200
|
+
ch = this.code;
|
|
53201
|
+
}
|
|
53202
|
+
this.index++;
|
|
53203
|
+
if (ch === Jsep.OBRACK_CODE) {
|
|
53204
|
+
node = {
|
|
53205
|
+
type: Jsep.MEMBER_EXP,
|
|
53206
|
+
computed: true,
|
|
53207
|
+
object: node,
|
|
53208
|
+
property: this.gobbleExpression()
|
|
53209
|
+
};
|
|
53210
|
+
if (!node.property) {
|
|
53211
|
+
this.throwError('Unexpected "' + this.char + '"');
|
|
53212
|
+
}
|
|
53213
|
+
this.gobbleSpaces();
|
|
53214
|
+
ch = this.code;
|
|
53215
|
+
if (ch !== Jsep.CBRACK_CODE) {
|
|
53216
|
+
this.throwError("Unclosed [");
|
|
53217
|
+
}
|
|
53218
|
+
this.index++;
|
|
53219
|
+
} else if (ch === Jsep.OPAREN_CODE) {
|
|
53220
|
+
node = {
|
|
53221
|
+
type: Jsep.CALL_EXP,
|
|
53222
|
+
"arguments": this.gobbleArguments(Jsep.CPAREN_CODE),
|
|
53223
|
+
callee: node
|
|
53224
|
+
};
|
|
53225
|
+
} else if (ch === Jsep.PERIOD_CODE || optional) {
|
|
53226
|
+
if (optional) {
|
|
53227
|
+
this.index--;
|
|
53228
|
+
}
|
|
53229
|
+
this.gobbleSpaces();
|
|
53230
|
+
node = {
|
|
53231
|
+
type: Jsep.MEMBER_EXP,
|
|
53232
|
+
computed: false,
|
|
53233
|
+
object: node,
|
|
53234
|
+
property: this.gobbleIdentifier()
|
|
53235
|
+
};
|
|
53236
|
+
}
|
|
53237
|
+
if (optional) {
|
|
53238
|
+
node.optional = true;
|
|
53239
|
+
}
|
|
53240
|
+
this.gobbleSpaces();
|
|
53241
|
+
ch = this.code;
|
|
53242
|
+
}
|
|
53243
|
+
return node;
|
|
53244
|
+
}
|
|
53245
|
+
/**
|
|
53246
|
+
* Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to
|
|
53247
|
+
* keep track of everything in the numeric literal and then calling `parseFloat` on that string
|
|
53248
|
+
* @returns {jsep.Literal}
|
|
53249
|
+
*/
|
|
53250
|
+
gobbleNumericLiteral() {
|
|
53251
|
+
let number4 = "", ch, chCode;
|
|
53252
|
+
while (Jsep.isDecimalDigit(this.code)) {
|
|
53253
|
+
number4 += this.expr.charAt(this.index++);
|
|
53254
|
+
}
|
|
53255
|
+
if (this.code === Jsep.PERIOD_CODE) {
|
|
53256
|
+
number4 += this.expr.charAt(this.index++);
|
|
53257
|
+
while (Jsep.isDecimalDigit(this.code)) {
|
|
53258
|
+
number4 += this.expr.charAt(this.index++);
|
|
53259
|
+
}
|
|
53260
|
+
}
|
|
53261
|
+
ch = this.char;
|
|
53262
|
+
if (ch === "e" || ch === "E") {
|
|
53263
|
+
number4 += this.expr.charAt(this.index++);
|
|
53264
|
+
ch = this.char;
|
|
53265
|
+
if (ch === "+" || ch === "-") {
|
|
53266
|
+
number4 += this.expr.charAt(this.index++);
|
|
53267
|
+
}
|
|
53268
|
+
while (Jsep.isDecimalDigit(this.code)) {
|
|
53269
|
+
number4 += this.expr.charAt(this.index++);
|
|
53270
|
+
}
|
|
53271
|
+
if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
|
|
53272
|
+
this.throwError("Expected exponent (" + number4 + this.char + ")");
|
|
53273
|
+
}
|
|
53274
|
+
}
|
|
53275
|
+
chCode = this.code;
|
|
53276
|
+
if (Jsep.isIdentifierStart(chCode)) {
|
|
53277
|
+
this.throwError("Variable names cannot start with a number (" + number4 + this.char + ")");
|
|
53278
|
+
} else if (chCode === Jsep.PERIOD_CODE || number4.length === 1 && number4.charCodeAt(0) === Jsep.PERIOD_CODE) {
|
|
53279
|
+
this.throwError("Unexpected period");
|
|
53280
|
+
}
|
|
53281
|
+
return {
|
|
53282
|
+
type: Jsep.LITERAL,
|
|
53283
|
+
value: parseFloat(number4),
|
|
53284
|
+
raw: number4
|
|
53285
|
+
};
|
|
53286
|
+
}
|
|
53287
|
+
/**
|
|
53288
|
+
* Parses a string literal, staring with single or double quotes with basic support for escape codes
|
|
53289
|
+
* e.g. `"hello world"`, `'this is\nJSEP'`
|
|
53290
|
+
* @returns {jsep.Literal}
|
|
53291
|
+
*/
|
|
53292
|
+
gobbleStringLiteral() {
|
|
53293
|
+
let str = "";
|
|
53294
|
+
const startIndex = this.index;
|
|
53295
|
+
const quote = this.expr.charAt(this.index++);
|
|
53296
|
+
let closed = false;
|
|
53297
|
+
while (this.index < this.expr.length) {
|
|
53298
|
+
let ch = this.expr.charAt(this.index++);
|
|
53299
|
+
if (ch === quote) {
|
|
53300
|
+
closed = true;
|
|
53301
|
+
break;
|
|
53302
|
+
} else if (ch === "\\") {
|
|
53303
|
+
ch = this.expr.charAt(this.index++);
|
|
53304
|
+
switch (ch) {
|
|
53305
|
+
case "n":
|
|
53306
|
+
str += "\n";
|
|
53307
|
+
break;
|
|
53308
|
+
case "r":
|
|
53309
|
+
str += "\r";
|
|
53310
|
+
break;
|
|
53311
|
+
case "t":
|
|
53312
|
+
str += " ";
|
|
53313
|
+
break;
|
|
53314
|
+
case "b":
|
|
53315
|
+
str += "\b";
|
|
53316
|
+
break;
|
|
53317
|
+
case "f":
|
|
53318
|
+
str += "\f";
|
|
53319
|
+
break;
|
|
53320
|
+
case "v":
|
|
53321
|
+
str += "\v";
|
|
53322
|
+
break;
|
|
53323
|
+
default:
|
|
53324
|
+
str += ch;
|
|
53325
|
+
}
|
|
53326
|
+
} else {
|
|
53327
|
+
str += ch;
|
|
53328
|
+
}
|
|
53329
|
+
}
|
|
53330
|
+
if (!closed) {
|
|
53331
|
+
this.throwError('Unclosed quote after "' + str + '"');
|
|
53332
|
+
}
|
|
53333
|
+
return {
|
|
53334
|
+
type: Jsep.LITERAL,
|
|
53335
|
+
value: str,
|
|
53336
|
+
raw: this.expr.substring(startIndex, this.index)
|
|
53337
|
+
};
|
|
53338
|
+
}
|
|
53339
|
+
/**
|
|
53340
|
+
* Gobbles only identifiers
|
|
53341
|
+
* e.g.: `foo`, `_value`, `$x1`
|
|
53342
|
+
* Also, this function checks if that identifier is a literal:
|
|
53343
|
+
* (e.g. `true`, `false`, `null`) or `this`
|
|
53344
|
+
* @returns {jsep.Identifier}
|
|
53345
|
+
*/
|
|
53346
|
+
gobbleIdentifier() {
|
|
53347
|
+
let ch = this.code, start = this.index;
|
|
53348
|
+
if (Jsep.isIdentifierStart(ch)) {
|
|
53349
|
+
this.index++;
|
|
53350
|
+
} else {
|
|
53351
|
+
this.throwError("Unexpected " + this.char);
|
|
53352
|
+
}
|
|
53353
|
+
while (this.index < this.expr.length) {
|
|
53354
|
+
ch = this.code;
|
|
53355
|
+
if (Jsep.isIdentifierPart(ch)) {
|
|
53356
|
+
this.index++;
|
|
53357
|
+
} else {
|
|
53358
|
+
break;
|
|
53359
|
+
}
|
|
53360
|
+
}
|
|
53361
|
+
return {
|
|
53362
|
+
type: Jsep.IDENTIFIER,
|
|
53363
|
+
name: this.expr.slice(start, this.index)
|
|
53364
|
+
};
|
|
53365
|
+
}
|
|
53366
|
+
/**
|
|
53367
|
+
* Gobbles a list of arguments within the context of a function call
|
|
53368
|
+
* or array literal. This function also assumes that the opening character
|
|
53369
|
+
* `(` or `[` has already been gobbled, and gobbles expressions and commas
|
|
53370
|
+
* until the terminator character `)` or `]` is encountered.
|
|
53371
|
+
* e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`
|
|
53372
|
+
* @param {number} termination
|
|
53373
|
+
* @returns {jsep.Expression[]}
|
|
53374
|
+
*/
|
|
53375
|
+
gobbleArguments(termination) {
|
|
53376
|
+
const args = [];
|
|
53377
|
+
let closed = false;
|
|
53378
|
+
let separator_count = 0;
|
|
53379
|
+
while (this.index < this.expr.length) {
|
|
53380
|
+
this.gobbleSpaces();
|
|
53381
|
+
let ch_i = this.code;
|
|
53382
|
+
if (ch_i === termination) {
|
|
53383
|
+
closed = true;
|
|
53384
|
+
this.index++;
|
|
53385
|
+
if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
|
|
53386
|
+
this.throwError("Unexpected token " + String.fromCharCode(termination));
|
|
53387
|
+
}
|
|
53388
|
+
break;
|
|
53389
|
+
} else if (ch_i === Jsep.COMMA_CODE) {
|
|
53390
|
+
this.index++;
|
|
53391
|
+
separator_count++;
|
|
53392
|
+
if (separator_count !== args.length) {
|
|
53393
|
+
if (termination === Jsep.CPAREN_CODE) {
|
|
53394
|
+
this.throwError("Unexpected token ,");
|
|
53395
|
+
} else if (termination === Jsep.CBRACK_CODE) {
|
|
53396
|
+
for (let arg = args.length; arg < separator_count; arg++) {
|
|
53397
|
+
args.push(null);
|
|
53398
|
+
}
|
|
53399
|
+
}
|
|
53400
|
+
}
|
|
53401
|
+
} else if (args.length !== separator_count && separator_count !== 0) {
|
|
53402
|
+
this.throwError("Expected comma");
|
|
53403
|
+
} else {
|
|
53404
|
+
const node = this.gobbleExpression();
|
|
53405
|
+
if (!node || node.type === Jsep.COMPOUND) {
|
|
53406
|
+
this.throwError("Expected comma");
|
|
53407
|
+
}
|
|
53408
|
+
args.push(node);
|
|
53409
|
+
}
|
|
53410
|
+
}
|
|
53411
|
+
if (!closed) {
|
|
53412
|
+
this.throwError("Expected " + String.fromCharCode(termination));
|
|
53413
|
+
}
|
|
53414
|
+
return args;
|
|
53415
|
+
}
|
|
53416
|
+
/**
|
|
53417
|
+
* Responsible for parsing a group of things within parentheses `()`
|
|
53418
|
+
* that have no identifier in front (so not a function call)
|
|
53419
|
+
* This function assumes that it needs to gobble the opening parenthesis
|
|
53420
|
+
* and then tries to gobble everything within that parenthesis, assuming
|
|
53421
|
+
* that the next thing it should see is the close parenthesis. If not,
|
|
53422
|
+
* then the expression probably doesn't have a `)`
|
|
53423
|
+
* @returns {boolean|jsep.Expression}
|
|
53424
|
+
*/
|
|
53425
|
+
gobbleGroup() {
|
|
53426
|
+
this.index++;
|
|
53427
|
+
let nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);
|
|
53428
|
+
if (this.code === Jsep.CPAREN_CODE) {
|
|
53429
|
+
this.index++;
|
|
53430
|
+
if (nodes.length === 1) {
|
|
53431
|
+
return nodes[0];
|
|
53432
|
+
} else if (!nodes.length) {
|
|
53433
|
+
return false;
|
|
53434
|
+
} else {
|
|
53435
|
+
return {
|
|
53436
|
+
type: Jsep.SEQUENCE_EXP,
|
|
53437
|
+
expressions: nodes
|
|
53438
|
+
};
|
|
53439
|
+
}
|
|
53440
|
+
} else {
|
|
53441
|
+
this.throwError("Unclosed (");
|
|
53442
|
+
}
|
|
53443
|
+
}
|
|
53444
|
+
/**
|
|
53445
|
+
* Responsible for parsing Array literals `[1, 2, 3]`
|
|
53446
|
+
* This function assumes that it needs to gobble the opening bracket
|
|
53447
|
+
* and then tries to gobble the expressions as arguments.
|
|
53448
|
+
* @returns {jsep.ArrayExpression}
|
|
53449
|
+
*/
|
|
53450
|
+
gobbleArray() {
|
|
53451
|
+
this.index++;
|
|
53452
|
+
return {
|
|
53453
|
+
type: Jsep.ARRAY_EXP,
|
|
53454
|
+
elements: this.gobbleArguments(Jsep.CBRACK_CODE)
|
|
53455
|
+
};
|
|
53456
|
+
}
|
|
53457
|
+
}
|
|
53458
|
+
const hooks = new Hooks();
|
|
53459
|
+
Object.assign(Jsep, {
|
|
53460
|
+
hooks,
|
|
53461
|
+
plugins: new Plugins(Jsep),
|
|
53462
|
+
// Node Types
|
|
53463
|
+
// ----------
|
|
53464
|
+
// This is the full set of types that any JSEP node can be.
|
|
53465
|
+
// Store them here to save space when minified
|
|
53466
|
+
COMPOUND: "Compound",
|
|
53467
|
+
SEQUENCE_EXP: "SequenceExpression",
|
|
53468
|
+
IDENTIFIER: "Identifier",
|
|
53469
|
+
MEMBER_EXP: "MemberExpression",
|
|
53470
|
+
LITERAL: "Literal",
|
|
53471
|
+
THIS_EXP: "ThisExpression",
|
|
53472
|
+
CALL_EXP: "CallExpression",
|
|
53473
|
+
UNARY_EXP: "UnaryExpression",
|
|
53474
|
+
BINARY_EXP: "BinaryExpression",
|
|
53475
|
+
ARRAY_EXP: "ArrayExpression",
|
|
53476
|
+
TAB_CODE: 9,
|
|
53477
|
+
LF_CODE: 10,
|
|
53478
|
+
CR_CODE: 13,
|
|
53479
|
+
SPACE_CODE: 32,
|
|
53480
|
+
PERIOD_CODE: 46,
|
|
53481
|
+
// '.'
|
|
53482
|
+
COMMA_CODE: 44,
|
|
53483
|
+
// ','
|
|
53484
|
+
SQUOTE_CODE: 39,
|
|
53485
|
+
// single quote
|
|
53486
|
+
DQUOTE_CODE: 34,
|
|
53487
|
+
// double quotes
|
|
53488
|
+
OPAREN_CODE: 40,
|
|
53489
|
+
// (
|
|
53490
|
+
CPAREN_CODE: 41,
|
|
53491
|
+
// )
|
|
53492
|
+
OBRACK_CODE: 91,
|
|
53493
|
+
// [
|
|
53494
|
+
CBRACK_CODE: 93,
|
|
53495
|
+
// ]
|
|
53496
|
+
QUMARK_CODE: 63,
|
|
53497
|
+
// ?
|
|
53498
|
+
SEMCOL_CODE: 59,
|
|
53499
|
+
// ;
|
|
53500
|
+
COLON_CODE: 58,
|
|
53501
|
+
// :
|
|
53502
|
+
// Operations
|
|
53503
|
+
// ----------
|
|
53504
|
+
// Use a quickly-accessible map to store all of the unary operators
|
|
53505
|
+
// Values are set to `1` (it really doesn't matter)
|
|
53506
|
+
unary_ops: {
|
|
53507
|
+
"-": 1,
|
|
53508
|
+
"!": 1,
|
|
53509
|
+
"~": 1,
|
|
53510
|
+
"+": 1
|
|
53511
|
+
},
|
|
53512
|
+
// Also use a map for the binary operations but set their values to their
|
|
53513
|
+
// binary precedence for quick reference (higher number = higher precedence)
|
|
53514
|
+
// see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
|
|
53515
|
+
binary_ops: {
|
|
53516
|
+
"||": 1,
|
|
53517
|
+
"??": 1,
|
|
53518
|
+
"&&": 2,
|
|
53519
|
+
"|": 3,
|
|
53520
|
+
"^": 4,
|
|
53521
|
+
"&": 5,
|
|
53522
|
+
"==": 6,
|
|
53523
|
+
"!=": 6,
|
|
53524
|
+
"===": 6,
|
|
53525
|
+
"!==": 6,
|
|
53526
|
+
"<": 7,
|
|
53527
|
+
">": 7,
|
|
53528
|
+
"<=": 7,
|
|
53529
|
+
">=": 7,
|
|
53530
|
+
"<<": 8,
|
|
53531
|
+
">>": 8,
|
|
53532
|
+
">>>": 8,
|
|
53533
|
+
"+": 9,
|
|
53534
|
+
"-": 9,
|
|
53535
|
+
"*": 10,
|
|
53536
|
+
"/": 10,
|
|
53537
|
+
"%": 10,
|
|
53538
|
+
"**": 11
|
|
53539
|
+
},
|
|
53540
|
+
// sets specific binary_ops as right-associative
|
|
53541
|
+
right_associative: /* @__PURE__ */ new Set(["**"]),
|
|
53542
|
+
// Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char)
|
|
53543
|
+
additional_identifier_chars: /* @__PURE__ */ new Set(["$", "_"]),
|
|
53544
|
+
// Literals
|
|
53545
|
+
// ----------
|
|
53546
|
+
// Store the values to return for the various literals we may encounter
|
|
53547
|
+
literals: {
|
|
53548
|
+
"true": true,
|
|
53549
|
+
"false": false,
|
|
53550
|
+
"null": null
|
|
53551
|
+
},
|
|
53552
|
+
// Except for `this`, which is special. This could be changed to something like `'self'` as well
|
|
53553
|
+
this_str: "this"
|
|
53554
|
+
});
|
|
53555
|
+
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
53556
|
+
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
53557
|
+
const jsep = (expr) => new Jsep(expr).parse();
|
|
53558
|
+
const stdClassProps = Object.getOwnPropertyNames(class Test {
|
|
53559
|
+
});
|
|
53560
|
+
Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === void 0).forEach((m) => {
|
|
53561
|
+
jsep[m] = Jsep[m];
|
|
53562
|
+
});
|
|
53563
|
+
jsep.Jsep = Jsep;
|
|
53564
|
+
const CONDITIONAL_EXP = "ConditionalExpression";
|
|
53565
|
+
var ternary = {
|
|
53566
|
+
name: "ternary",
|
|
53567
|
+
init(jsep2) {
|
|
53568
|
+
jsep2.hooks.add("after-expression", function gobbleTernary(env) {
|
|
53569
|
+
if (env.node && this.code === jsep2.QUMARK_CODE) {
|
|
53570
|
+
this.index++;
|
|
53571
|
+
const test2 = env.node;
|
|
53572
|
+
const consequent = this.gobbleExpression();
|
|
53573
|
+
if (!consequent) {
|
|
53574
|
+
this.throwError("Expected expression");
|
|
53575
|
+
}
|
|
53576
|
+
this.gobbleSpaces();
|
|
53577
|
+
if (this.code === jsep2.COLON_CODE) {
|
|
53578
|
+
this.index++;
|
|
53579
|
+
const alternate = this.gobbleExpression();
|
|
53580
|
+
if (!alternate) {
|
|
53581
|
+
this.throwError("Expected expression");
|
|
53582
|
+
}
|
|
53583
|
+
env.node = {
|
|
53584
|
+
type: CONDITIONAL_EXP,
|
|
53585
|
+
test: test2,
|
|
53586
|
+
consequent,
|
|
53587
|
+
alternate
|
|
53588
|
+
};
|
|
53589
|
+
if (test2.operator && jsep2.binary_ops[test2.operator] <= 0.9) {
|
|
53590
|
+
let newTest = test2;
|
|
53591
|
+
while (newTest.right.operator && jsep2.binary_ops[newTest.right.operator] <= 0.9) {
|
|
53592
|
+
newTest = newTest.right;
|
|
53593
|
+
}
|
|
53594
|
+
env.node.test = newTest.right;
|
|
53595
|
+
newTest.right = env.node;
|
|
53596
|
+
env.node = test2;
|
|
53597
|
+
}
|
|
53598
|
+
} else {
|
|
53599
|
+
this.throwError("Expected :");
|
|
53600
|
+
}
|
|
53601
|
+
}
|
|
53602
|
+
});
|
|
53603
|
+
}
|
|
53604
|
+
};
|
|
53605
|
+
jsep.plugins.register(ternary);
|
|
53606
|
+
const FSLASH_CODE = 47;
|
|
53607
|
+
const BSLASH_CODE = 92;
|
|
53608
|
+
var index = {
|
|
53609
|
+
name: "regex",
|
|
53610
|
+
init(jsep2) {
|
|
53611
|
+
jsep2.hooks.add("gobble-token", function gobbleRegexLiteral(env) {
|
|
53612
|
+
if (this.code === FSLASH_CODE) {
|
|
53613
|
+
const patternIndex = ++this.index;
|
|
53614
|
+
let inCharSet = false;
|
|
53615
|
+
while (this.index < this.expr.length) {
|
|
53616
|
+
if (this.code === FSLASH_CODE && !inCharSet) {
|
|
53617
|
+
const pattern4 = this.expr.slice(patternIndex, this.index);
|
|
53618
|
+
let flags = "";
|
|
53619
|
+
while (++this.index < this.expr.length) {
|
|
53620
|
+
const code = this.code;
|
|
53621
|
+
if (code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57) {
|
|
53622
|
+
flags += this.char;
|
|
53623
|
+
} else {
|
|
53624
|
+
break;
|
|
53625
|
+
}
|
|
53626
|
+
}
|
|
53627
|
+
let value;
|
|
53628
|
+
try {
|
|
53629
|
+
value = new RegExp(pattern4, flags);
|
|
53630
|
+
} catch (e) {
|
|
53631
|
+
this.throwError(e.message);
|
|
53632
|
+
}
|
|
53633
|
+
env.node = {
|
|
53634
|
+
type: jsep2.LITERAL,
|
|
53635
|
+
value,
|
|
53636
|
+
raw: this.expr.slice(patternIndex - 1, this.index)
|
|
53637
|
+
};
|
|
53638
|
+
env.node = this.gobbleTokenProperty(env.node);
|
|
53639
|
+
return env.node;
|
|
53640
|
+
}
|
|
53641
|
+
if (this.code === jsep2.OBRACK_CODE) {
|
|
53642
|
+
inCharSet = true;
|
|
53643
|
+
} else if (inCharSet && this.code === jsep2.CBRACK_CODE) {
|
|
53644
|
+
inCharSet = false;
|
|
53645
|
+
}
|
|
53646
|
+
this.index += this.code === BSLASH_CODE ? 2 : 1;
|
|
53647
|
+
}
|
|
53648
|
+
this.throwError("Unclosed Regex");
|
|
53649
|
+
}
|
|
53650
|
+
});
|
|
53651
|
+
}
|
|
53652
|
+
};
|
|
53653
|
+
const PLUS_CODE = 43;
|
|
53654
|
+
const MINUS_CODE = 45;
|
|
53655
|
+
const plugin = {
|
|
53656
|
+
name: "assignment",
|
|
53657
|
+
assignmentOperators: /* @__PURE__ */ new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
|
|
53658
|
+
updateOperators: [PLUS_CODE, MINUS_CODE],
|
|
53659
|
+
assignmentPrecedence: 0.9,
|
|
53660
|
+
init(jsep2) {
|
|
53661
|
+
const updateNodeTypes = [jsep2.IDENTIFIER, jsep2.MEMBER_EXP];
|
|
53662
|
+
plugin.assignmentOperators.forEach((op) => jsep2.addBinaryOp(op, plugin.assignmentPrecedence, true));
|
|
53663
|
+
jsep2.hooks.add("gobble-token", function gobbleUpdatePrefix(env) {
|
|
53664
|
+
const code = this.code;
|
|
53665
|
+
if (plugin.updateOperators.some((c2) => c2 === code && c2 === this.expr.charCodeAt(this.index + 1))) {
|
|
53666
|
+
this.index += 2;
|
|
53667
|
+
env.node = {
|
|
53668
|
+
type: "UpdateExpression",
|
|
53669
|
+
operator: code === PLUS_CODE ? "++" : "--",
|
|
53670
|
+
argument: this.gobbleTokenProperty(this.gobbleIdentifier()),
|
|
53671
|
+
prefix: true
|
|
53672
|
+
};
|
|
53673
|
+
if (!env.node.argument || !updateNodeTypes.includes(env.node.argument.type)) {
|
|
53674
|
+
this.throwError(`Unexpected ${env.node.operator}`);
|
|
53675
|
+
}
|
|
53676
|
+
}
|
|
53677
|
+
});
|
|
53678
|
+
jsep2.hooks.add("after-token", function gobbleUpdatePostfix(env) {
|
|
53679
|
+
if (env.node) {
|
|
53680
|
+
const code = this.code;
|
|
53681
|
+
if (plugin.updateOperators.some((c2) => c2 === code && c2 === this.expr.charCodeAt(this.index + 1))) {
|
|
53682
|
+
if (!updateNodeTypes.includes(env.node.type)) {
|
|
53683
|
+
this.throwError(`Unexpected ${env.node.operator}`);
|
|
53684
|
+
}
|
|
53685
|
+
this.index += 2;
|
|
53686
|
+
env.node = {
|
|
53687
|
+
type: "UpdateExpression",
|
|
53688
|
+
operator: code === PLUS_CODE ? "++" : "--",
|
|
53689
|
+
argument: env.node,
|
|
53690
|
+
prefix: false
|
|
53691
|
+
};
|
|
53692
|
+
}
|
|
53693
|
+
}
|
|
53694
|
+
});
|
|
53695
|
+
jsep2.hooks.add("after-expression", function gobbleAssignment(env) {
|
|
53696
|
+
if (env.node) {
|
|
53697
|
+
updateBinariesToAssignments(env.node);
|
|
53698
|
+
}
|
|
53699
|
+
});
|
|
53700
|
+
function updateBinariesToAssignments(node) {
|
|
53701
|
+
if (plugin.assignmentOperators.has(node.operator)) {
|
|
53702
|
+
node.type = "AssignmentExpression";
|
|
53703
|
+
updateBinariesToAssignments(node.left);
|
|
53704
|
+
updateBinariesToAssignments(node.right);
|
|
53705
|
+
} else if (!node.operator) {
|
|
53706
|
+
Object.values(node).forEach((val) => {
|
|
53707
|
+
if (val && typeof val === "object") {
|
|
53708
|
+
updateBinariesToAssignments(val);
|
|
53709
|
+
}
|
|
53710
|
+
});
|
|
53711
|
+
}
|
|
53712
|
+
}
|
|
53713
|
+
}
|
|
53714
|
+
};
|
|
53715
|
+
jsep.plugins.register(index, plugin);
|
|
53716
|
+
jsep.addUnaryOp("typeof");
|
|
53717
|
+
jsep.addUnaryOp("void");
|
|
53718
|
+
jsep.addLiteral("null", null);
|
|
53719
|
+
jsep.addLiteral("undefined", void 0);
|
|
53720
|
+
const BLOCKED_PROTO_PROPERTIES = /* @__PURE__ */ new Set(["constructor", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
|
|
53721
|
+
const SafeEval = {
|
|
53722
|
+
/**
|
|
53723
|
+
* @param {jsep.Expression} ast
|
|
53724
|
+
* @param {Record<string, any>} subs
|
|
53725
|
+
*/
|
|
53726
|
+
evalAst(ast, subs) {
|
|
53727
|
+
switch (ast.type) {
|
|
53728
|
+
case "BinaryExpression":
|
|
53729
|
+
case "LogicalExpression":
|
|
53730
|
+
return SafeEval.evalBinaryExpression(ast, subs);
|
|
53731
|
+
case "Compound":
|
|
53732
|
+
return SafeEval.evalCompound(ast, subs);
|
|
53733
|
+
case "ConditionalExpression":
|
|
53734
|
+
return SafeEval.evalConditionalExpression(ast, subs);
|
|
53735
|
+
case "Identifier":
|
|
53736
|
+
return SafeEval.evalIdentifier(ast, subs);
|
|
53737
|
+
case "Literal":
|
|
53738
|
+
return SafeEval.evalLiteral(ast, subs);
|
|
53739
|
+
case "MemberExpression":
|
|
53740
|
+
return SafeEval.evalMemberExpression(ast, subs);
|
|
53741
|
+
case "UnaryExpression":
|
|
53742
|
+
return SafeEval.evalUnaryExpression(ast, subs);
|
|
53743
|
+
case "ArrayExpression":
|
|
53744
|
+
return SafeEval.evalArrayExpression(ast, subs);
|
|
53745
|
+
case "CallExpression":
|
|
53746
|
+
return SafeEval.evalCallExpression(ast, subs);
|
|
53747
|
+
case "AssignmentExpression":
|
|
53748
|
+
return SafeEval.evalAssignmentExpression(ast, subs);
|
|
53749
|
+
default:
|
|
53750
|
+
throw SyntaxError("Unexpected expression", ast);
|
|
53751
|
+
}
|
|
53752
|
+
},
|
|
53753
|
+
evalBinaryExpression(ast, subs) {
|
|
53754
|
+
const result = {
|
|
53755
|
+
"||": (a, b2) => a || b2(),
|
|
53756
|
+
"&&": (a, b2) => a && b2(),
|
|
53757
|
+
"|": (a, b2) => a | b2(),
|
|
53758
|
+
"^": (a, b2) => a ^ b2(),
|
|
53759
|
+
"&": (a, b2) => a & b2(),
|
|
53760
|
+
// eslint-disable-next-line eqeqeq -- API
|
|
53761
|
+
"==": (a, b2) => a == b2(),
|
|
53762
|
+
// eslint-disable-next-line eqeqeq -- API
|
|
53763
|
+
"!=": (a, b2) => a != b2(),
|
|
53764
|
+
"===": (a, b2) => a === b2(),
|
|
53765
|
+
"!==": (a, b2) => a !== b2(),
|
|
53766
|
+
"<": (a, b2) => a < b2(),
|
|
53767
|
+
">": (a, b2) => a > b2(),
|
|
53768
|
+
"<=": (a, b2) => a <= b2(),
|
|
53769
|
+
">=": (a, b2) => a >= b2(),
|
|
53770
|
+
"<<": (a, b2) => a << b2(),
|
|
53771
|
+
">>": (a, b2) => a >> b2(),
|
|
53772
|
+
">>>": (a, b2) => a >>> b2(),
|
|
53773
|
+
"+": (a, b2) => a + b2(),
|
|
53774
|
+
"-": (a, b2) => a - b2(),
|
|
53775
|
+
"*": (a, b2) => a * b2(),
|
|
53776
|
+
"/": (a, b2) => a / b2(),
|
|
53777
|
+
"%": (a, b2) => a % b2()
|
|
53778
|
+
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
|
|
53779
|
+
return result;
|
|
53780
|
+
},
|
|
53781
|
+
evalCompound(ast, subs) {
|
|
53782
|
+
let last2;
|
|
53783
|
+
for (let i = 0; i < ast.body.length; i++) {
|
|
53784
|
+
if (ast.body[i].type === "Identifier" && ["var", "let", "const"].includes(ast.body[i].name) && ast.body[i + 1] && ast.body[i + 1].type === "AssignmentExpression") {
|
|
53785
|
+
i += 1;
|
|
53786
|
+
}
|
|
53787
|
+
const expr = ast.body[i];
|
|
53788
|
+
last2 = SafeEval.evalAst(expr, subs);
|
|
53789
|
+
}
|
|
53790
|
+
return last2;
|
|
53791
|
+
},
|
|
53792
|
+
evalConditionalExpression(ast, subs) {
|
|
53793
|
+
if (SafeEval.evalAst(ast.test, subs)) {
|
|
53794
|
+
return SafeEval.evalAst(ast.consequent, subs);
|
|
53795
|
+
}
|
|
53796
|
+
return SafeEval.evalAst(ast.alternate, subs);
|
|
53797
|
+
},
|
|
53798
|
+
evalIdentifier(ast, subs) {
|
|
53799
|
+
if (Object.hasOwn(subs, ast.name)) {
|
|
53800
|
+
return subs[ast.name];
|
|
53801
|
+
}
|
|
53802
|
+
throw ReferenceError(`${ast.name} is not defined`);
|
|
53803
|
+
},
|
|
53804
|
+
evalLiteral(ast) {
|
|
53805
|
+
return ast.value;
|
|
53806
|
+
},
|
|
53807
|
+
evalMemberExpression(ast, subs) {
|
|
53808
|
+
const prop = String(
|
|
53809
|
+
// NOTE: `String(value)` throws error when
|
|
53810
|
+
// value has overwritten the toString method to return non-string
|
|
53811
|
+
// i.e. `value = {toString: () => []}`
|
|
53812
|
+
ast.computed ? SafeEval.evalAst(ast.property) : ast.property.name
|
|
53813
|
+
// `object.property` property is Identifier
|
|
53814
|
+
);
|
|
53815
|
+
const obj = SafeEval.evalAst(ast.object, subs);
|
|
53816
|
+
if (obj === void 0 || obj === null) {
|
|
53817
|
+
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
53818
|
+
}
|
|
53819
|
+
if (!Object.hasOwn(obj, prop) && BLOCKED_PROTO_PROPERTIES.has(prop)) {
|
|
53820
|
+
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
53821
|
+
}
|
|
53822
|
+
const result = obj[prop];
|
|
53823
|
+
if (typeof result === "function") {
|
|
53824
|
+
return result.bind(obj);
|
|
53825
|
+
}
|
|
53826
|
+
return result;
|
|
53827
|
+
},
|
|
53828
|
+
evalUnaryExpression(ast, subs) {
|
|
53829
|
+
const result = {
|
|
53830
|
+
"-": (a) => -SafeEval.evalAst(a, subs),
|
|
53831
|
+
"!": (a) => !SafeEval.evalAst(a, subs),
|
|
53832
|
+
"~": (a) => ~SafeEval.evalAst(a, subs),
|
|
53833
|
+
// eslint-disable-next-line no-implicit-coercion -- API
|
|
53834
|
+
"+": (a) => +SafeEval.evalAst(a, subs),
|
|
53835
|
+
typeof: (a) => typeof SafeEval.evalAst(a, subs),
|
|
53836
|
+
// eslint-disable-next-line no-void, sonarjs/void-use -- feature
|
|
53837
|
+
void: (a) => void SafeEval.evalAst(a, subs)
|
|
53838
|
+
}[ast.operator](ast.argument);
|
|
53839
|
+
return result;
|
|
53840
|
+
},
|
|
53841
|
+
evalArrayExpression(ast, subs) {
|
|
53842
|
+
return ast.elements.map((el) => SafeEval.evalAst(el, subs));
|
|
53843
|
+
},
|
|
53844
|
+
evalCallExpression(ast, subs) {
|
|
53845
|
+
const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));
|
|
53846
|
+
const func = SafeEval.evalAst(ast.callee, subs);
|
|
53847
|
+
if (func === Function) {
|
|
53848
|
+
throw new Error("Function constructor is disabled");
|
|
53849
|
+
}
|
|
53850
|
+
return func(...args);
|
|
53851
|
+
},
|
|
53852
|
+
evalAssignmentExpression(ast, subs) {
|
|
53853
|
+
if (ast.left.type !== "Identifier") {
|
|
53854
|
+
throw SyntaxError("Invalid left-hand side in assignment");
|
|
53855
|
+
}
|
|
53856
|
+
const id = ast.left.name;
|
|
53857
|
+
const value = SafeEval.evalAst(ast.right, subs);
|
|
53858
|
+
subs[id] = value;
|
|
53859
|
+
return subs[id];
|
|
53860
|
+
}
|
|
53861
|
+
};
|
|
53862
|
+
class SafeScript {
|
|
53863
|
+
/**
|
|
53864
|
+
* @param {string} expr Expression to evaluate
|
|
53865
|
+
*/
|
|
53866
|
+
constructor(expr) {
|
|
53867
|
+
this.code = expr;
|
|
53868
|
+
this.ast = jsep(this.code);
|
|
53869
|
+
}
|
|
53870
|
+
/**
|
|
53871
|
+
* @param {object} context Object whose items will be added
|
|
53872
|
+
* to evaluation
|
|
53873
|
+
* @returns {EvaluatedResult} Result of evaluated code
|
|
53874
|
+
*/
|
|
53875
|
+
runInNewContext(context) {
|
|
53876
|
+
const keyMap = Object.assign(/* @__PURE__ */ Object.create(null), context);
|
|
53877
|
+
return SafeEval.evalAst(this.ast, keyMap);
|
|
53878
|
+
}
|
|
53879
|
+
}
|
|
53880
|
+
function push(arr, item) {
|
|
53881
|
+
arr = arr.slice();
|
|
53882
|
+
arr.push(item);
|
|
53883
|
+
return arr;
|
|
53884
|
+
}
|
|
53885
|
+
function unshift(item, arr) {
|
|
53886
|
+
arr = arr.slice();
|
|
53887
|
+
arr.unshift(item);
|
|
53888
|
+
return arr;
|
|
53889
|
+
}
|
|
53890
|
+
class NewError extends Error {
|
|
53891
|
+
/**
|
|
53892
|
+
* @param {AnyResult} value The evaluated scalar value
|
|
53893
|
+
*/
|
|
53894
|
+
constructor(value) {
|
|
53895
|
+
super('JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)');
|
|
53896
|
+
this.avoidNew = true;
|
|
53897
|
+
this.value = value;
|
|
53898
|
+
this.name = "NewError";
|
|
53899
|
+
}
|
|
53900
|
+
}
|
|
53901
|
+
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {
|
|
53902
|
+
if (!(this instanceof JSONPath)) {
|
|
53903
|
+
try {
|
|
53904
|
+
return new JSONPath(opts, expr, obj, callback, otherTypeCallback);
|
|
53905
|
+
} catch (e) {
|
|
53906
|
+
if (!e.avoidNew) {
|
|
53907
|
+
throw e;
|
|
53908
|
+
}
|
|
53909
|
+
return e.value;
|
|
53910
|
+
}
|
|
53911
|
+
}
|
|
53912
|
+
if (typeof opts === "string") {
|
|
53913
|
+
otherTypeCallback = callback;
|
|
53914
|
+
callback = obj;
|
|
53915
|
+
obj = expr;
|
|
53916
|
+
expr = opts;
|
|
53917
|
+
opts = null;
|
|
53918
|
+
}
|
|
53919
|
+
const optObj = opts && typeof opts === "object";
|
|
53920
|
+
opts = opts || {};
|
|
53921
|
+
this.json = opts.json || obj;
|
|
53922
|
+
this.path = opts.path || expr;
|
|
53923
|
+
this.resultType = opts.resultType || "value";
|
|
53924
|
+
this.flatten = opts.flatten || false;
|
|
53925
|
+
this.wrap = Object.hasOwn(opts, "wrap") ? opts.wrap : true;
|
|
53926
|
+
this.sandbox = opts.sandbox || {};
|
|
53927
|
+
this.eval = opts.eval === void 0 ? "safe" : opts.eval;
|
|
53928
|
+
this.ignoreEvalErrors = typeof opts.ignoreEvalErrors === "undefined" ? false : opts.ignoreEvalErrors;
|
|
53929
|
+
this.parent = opts.parent || null;
|
|
53930
|
+
this.parentProperty = opts.parentProperty || null;
|
|
53931
|
+
this.callback = opts.callback || callback || null;
|
|
53932
|
+
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function() {
|
|
53933
|
+
throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.");
|
|
53934
|
+
};
|
|
53935
|
+
if (opts.autostart !== false) {
|
|
53936
|
+
const args = {
|
|
53937
|
+
path: optObj ? opts.path : expr
|
|
53938
|
+
};
|
|
53939
|
+
if (!optObj) {
|
|
53940
|
+
args.json = obj;
|
|
53941
|
+
} else if ("json" in opts) {
|
|
53942
|
+
args.json = opts.json;
|
|
53943
|
+
}
|
|
53944
|
+
const ret = this.evaluate(args);
|
|
53945
|
+
if (!ret || typeof ret !== "object") {
|
|
53946
|
+
throw new NewError(ret);
|
|
53947
|
+
}
|
|
53948
|
+
return ret;
|
|
53949
|
+
}
|
|
53950
|
+
}
|
|
53951
|
+
JSONPath.prototype.evaluate = function(expr, json, callback, otherTypeCallback) {
|
|
53952
|
+
let currParent = this.parent, currParentProperty = this.parentProperty;
|
|
53953
|
+
let {
|
|
53954
|
+
flatten: flatten2,
|
|
53955
|
+
wrap
|
|
53956
|
+
} = this;
|
|
53957
|
+
this.currResultType = this.resultType;
|
|
53958
|
+
this.currEval = this.eval;
|
|
53959
|
+
this.currSandbox = this.sandbox;
|
|
53960
|
+
callback = callback || this.callback;
|
|
53961
|
+
this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
|
|
53962
|
+
json = json || this.json;
|
|
53963
|
+
expr = expr || this.path;
|
|
53964
|
+
if (expr && typeof expr === "object" && !Array.isArray(expr)) {
|
|
53965
|
+
if (!expr.path && expr.path !== "") {
|
|
53966
|
+
throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');
|
|
53967
|
+
}
|
|
53968
|
+
if (!Object.hasOwn(expr, "json")) {
|
|
53969
|
+
throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');
|
|
53970
|
+
}
|
|
53971
|
+
({
|
|
53972
|
+
json
|
|
53973
|
+
} = expr);
|
|
53974
|
+
flatten2 = Object.hasOwn(expr, "flatten") ? expr.flatten : flatten2;
|
|
53975
|
+
this.currResultType = Object.hasOwn(expr, "resultType") ? expr.resultType : this.currResultType;
|
|
53976
|
+
this.currSandbox = Object.hasOwn(expr, "sandbox") ? expr.sandbox : this.currSandbox;
|
|
53977
|
+
wrap = Object.hasOwn(expr, "wrap") ? expr.wrap : wrap;
|
|
53978
|
+
this.currEval = Object.hasOwn(expr, "eval") ? expr.eval : this.currEval;
|
|
53979
|
+
callback = Object.hasOwn(expr, "callback") ? expr.callback : callback;
|
|
53980
|
+
this.currOtherTypeCallback = Object.hasOwn(expr, "otherTypeCallback") ? expr.otherTypeCallback : this.currOtherTypeCallback;
|
|
53981
|
+
currParent = Object.hasOwn(expr, "parent") ? expr.parent : currParent;
|
|
53982
|
+
currParentProperty = Object.hasOwn(expr, "parentProperty") ? expr.parentProperty : currParentProperty;
|
|
53983
|
+
expr = expr.path;
|
|
53984
|
+
}
|
|
53985
|
+
currParent = currParent || null;
|
|
53986
|
+
currParentProperty = currParentProperty || null;
|
|
53987
|
+
if (Array.isArray(expr)) {
|
|
53988
|
+
expr = JSONPath.toPathString(expr);
|
|
53989
|
+
}
|
|
53990
|
+
if (!expr && expr !== "" || !json) {
|
|
53991
|
+
return void 0;
|
|
53992
|
+
}
|
|
53993
|
+
const exprList = JSONPath.toPathArray(expr);
|
|
53994
|
+
if (exprList[0] === "$" && exprList.length > 1) {
|
|
53995
|
+
exprList.shift();
|
|
53996
|
+
}
|
|
53997
|
+
this._hasParentSelector = null;
|
|
53998
|
+
const result = this._trace(exprList, json, ["$"], currParent, currParentProperty, callback).filter(function(ea2) {
|
|
53999
|
+
return ea2 && !ea2.isParentSelector;
|
|
54000
|
+
});
|
|
54001
|
+
if (!result.length) {
|
|
54002
|
+
return wrap ? [] : void 0;
|
|
54003
|
+
}
|
|
54004
|
+
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
|
|
54005
|
+
return this._getPreferredOutput(result[0]);
|
|
54006
|
+
}
|
|
54007
|
+
return result.reduce((rslt, ea2) => {
|
|
54008
|
+
const valOrPath = this._getPreferredOutput(ea2);
|
|
54009
|
+
if (flatten2 && Array.isArray(valOrPath)) {
|
|
54010
|
+
rslt = rslt.concat(valOrPath);
|
|
54011
|
+
} else {
|
|
54012
|
+
rslt.push(valOrPath);
|
|
54013
|
+
}
|
|
54014
|
+
return rslt;
|
|
54015
|
+
}, []);
|
|
54016
|
+
};
|
|
54017
|
+
JSONPath.prototype._getPreferredOutput = function(ea2) {
|
|
54018
|
+
const resultType = this.currResultType;
|
|
54019
|
+
switch (resultType) {
|
|
54020
|
+
case "all": {
|
|
54021
|
+
const path2 = Array.isArray(ea2.path) ? ea2.path : JSONPath.toPathArray(ea2.path);
|
|
54022
|
+
ea2.pointer = JSONPath.toPointer(path2);
|
|
54023
|
+
ea2.path = typeof ea2.path === "string" ? ea2.path : JSONPath.toPathString(ea2.path);
|
|
54024
|
+
return ea2;
|
|
54025
|
+
}
|
|
54026
|
+
case "value":
|
|
54027
|
+
case "parent":
|
|
54028
|
+
case "parentProperty":
|
|
54029
|
+
return ea2[resultType];
|
|
54030
|
+
case "path":
|
|
54031
|
+
return JSONPath.toPathString(ea2[resultType]);
|
|
54032
|
+
case "pointer":
|
|
54033
|
+
return JSONPath.toPointer(ea2.path);
|
|
54034
|
+
default:
|
|
54035
|
+
throw new TypeError("Unknown result type");
|
|
54036
|
+
}
|
|
54037
|
+
};
|
|
54038
|
+
JSONPath.prototype._handleCallback = function(fullRetObj, callback, type4) {
|
|
54039
|
+
if (callback) {
|
|
54040
|
+
const preferredOutput = this._getPreferredOutput(fullRetObj);
|
|
54041
|
+
fullRetObj.path = typeof fullRetObj.path === "string" ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path);
|
|
54042
|
+
callback(preferredOutput, type4, fullRetObj);
|
|
54043
|
+
}
|
|
54044
|
+
};
|
|
54045
|
+
JSONPath.prototype._trace = function(expr, val, path2, parent2, parentPropName, callback, hasArrExpr, literalPriority) {
|
|
54046
|
+
let retObj;
|
|
54047
|
+
if (!expr.length) {
|
|
54048
|
+
retObj = {
|
|
54049
|
+
path: path2,
|
|
54050
|
+
value: val,
|
|
54051
|
+
parent: parent2,
|
|
54052
|
+
parentProperty: parentPropName,
|
|
54053
|
+
hasArrExpr
|
|
54054
|
+
};
|
|
54055
|
+
this._handleCallback(retObj, callback, "value");
|
|
54056
|
+
return retObj;
|
|
54057
|
+
}
|
|
54058
|
+
const loc = expr[0], x2 = expr.slice(1);
|
|
54059
|
+
const ret = [];
|
|
54060
|
+
function addRet(elems) {
|
|
54061
|
+
if (Array.isArray(elems)) {
|
|
54062
|
+
elems.forEach((t) => {
|
|
54063
|
+
ret.push(t);
|
|
54064
|
+
});
|
|
54065
|
+
} else {
|
|
54066
|
+
ret.push(elems);
|
|
54067
|
+
}
|
|
54068
|
+
}
|
|
54069
|
+
if ((typeof loc !== "string" || literalPriority) && val && Object.hasOwn(val, loc)) {
|
|
54070
|
+
addRet(this._trace(x2, val[loc], push(path2, loc), val, loc, callback, hasArrExpr));
|
|
54071
|
+
} else if (loc === "*") {
|
|
54072
|
+
this._walk(val, (m) => {
|
|
54073
|
+
addRet(this._trace(x2, val[m], push(path2, m), val, m, callback, true, true));
|
|
54074
|
+
});
|
|
54075
|
+
} else if (loc === "..") {
|
|
54076
|
+
addRet(this._trace(x2, val, path2, parent2, parentPropName, callback, hasArrExpr));
|
|
54077
|
+
this._walk(val, (m) => {
|
|
54078
|
+
if (typeof val[m] === "object") {
|
|
54079
|
+
addRet(this._trace(expr.slice(), val[m], push(path2, m), val, m, callback, true));
|
|
54080
|
+
}
|
|
54081
|
+
});
|
|
54082
|
+
} else if (loc === "^") {
|
|
54083
|
+
this._hasParentSelector = true;
|
|
54084
|
+
return {
|
|
54085
|
+
path: path2.slice(0, -1),
|
|
54086
|
+
expr: x2,
|
|
54087
|
+
isParentSelector: true
|
|
54088
|
+
};
|
|
54089
|
+
} else if (loc === "~") {
|
|
54090
|
+
retObj = {
|
|
54091
|
+
path: push(path2, loc),
|
|
54092
|
+
value: parentPropName,
|
|
54093
|
+
parent: parent2,
|
|
54094
|
+
parentProperty: null
|
|
54095
|
+
};
|
|
54096
|
+
this._handleCallback(retObj, callback, "property");
|
|
54097
|
+
return retObj;
|
|
54098
|
+
} else if (loc === "$") {
|
|
54099
|
+
addRet(this._trace(x2, val, path2, null, null, callback, hasArrExpr));
|
|
54100
|
+
} else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
|
|
54101
|
+
addRet(this._slice(loc, x2, val, path2, parent2, parentPropName, callback));
|
|
54102
|
+
} else if (loc.indexOf("?(") === 0) {
|
|
54103
|
+
if (this.currEval === false) {
|
|
54104
|
+
throw new Error("Eval [?(expr)] prevented in JSONPath expression.");
|
|
54105
|
+
}
|
|
54106
|
+
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, "$1");
|
|
54107
|
+
const nested = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(safeLoc);
|
|
54108
|
+
if (nested) {
|
|
54109
|
+
this._walk(val, (m) => {
|
|
54110
|
+
const npath = [nested[2]];
|
|
54111
|
+
const nvalue = nested[1] ? val[m][nested[1]] : val[m];
|
|
54112
|
+
const filterResults = this._trace(npath, nvalue, path2, parent2, parentPropName, callback, true);
|
|
54113
|
+
if (filterResults.length > 0) {
|
|
54114
|
+
addRet(this._trace(x2, val[m], push(path2, m), val, m, callback, true));
|
|
54115
|
+
}
|
|
54116
|
+
});
|
|
54117
|
+
} else {
|
|
54118
|
+
this._walk(val, (m) => {
|
|
54119
|
+
if (this._eval(safeLoc, val[m], m, path2, parent2, parentPropName)) {
|
|
54120
|
+
addRet(this._trace(x2, val[m], push(path2, m), val, m, callback, true));
|
|
54121
|
+
}
|
|
54122
|
+
});
|
|
54123
|
+
}
|
|
54124
|
+
} else if (loc[0] === "(") {
|
|
54125
|
+
if (this.currEval === false) {
|
|
54126
|
+
throw new Error("Eval [(expr)] prevented in JSONPath expression.");
|
|
54127
|
+
}
|
|
54128
|
+
addRet(this._trace(unshift(this._eval(loc, val, path2.at(-1), path2.slice(0, -1), parent2, parentPropName), x2), val, path2, parent2, parentPropName, callback, hasArrExpr));
|
|
54129
|
+
} else if (loc[0] === "@") {
|
|
54130
|
+
let addType = false;
|
|
54131
|
+
const valueType = loc.slice(1, -2);
|
|
54132
|
+
switch (valueType) {
|
|
54133
|
+
case "scalar":
|
|
54134
|
+
if (!val || !["object", "function"].includes(typeof val)) {
|
|
54135
|
+
addType = true;
|
|
54136
|
+
}
|
|
54137
|
+
break;
|
|
54138
|
+
case "boolean":
|
|
54139
|
+
case "string":
|
|
54140
|
+
case "undefined":
|
|
54141
|
+
case "function":
|
|
54142
|
+
if (typeof val === valueType) {
|
|
54143
|
+
addType = true;
|
|
54144
|
+
}
|
|
54145
|
+
break;
|
|
54146
|
+
case "integer":
|
|
54147
|
+
if (Number.isFinite(val) && !(val % 1)) {
|
|
54148
|
+
addType = true;
|
|
54149
|
+
}
|
|
54150
|
+
break;
|
|
54151
|
+
case "number":
|
|
54152
|
+
if (Number.isFinite(val)) {
|
|
54153
|
+
addType = true;
|
|
54154
|
+
}
|
|
54155
|
+
break;
|
|
54156
|
+
case "nonFinite":
|
|
54157
|
+
if (typeof val === "number" && !Number.isFinite(val)) {
|
|
54158
|
+
addType = true;
|
|
54159
|
+
}
|
|
54160
|
+
break;
|
|
54161
|
+
case "object":
|
|
54162
|
+
if (val && typeof val === valueType) {
|
|
54163
|
+
addType = true;
|
|
54164
|
+
}
|
|
54165
|
+
break;
|
|
54166
|
+
case "array":
|
|
54167
|
+
if (Array.isArray(val)) {
|
|
54168
|
+
addType = true;
|
|
54169
|
+
}
|
|
54170
|
+
break;
|
|
54171
|
+
case "other":
|
|
54172
|
+
addType = this.currOtherTypeCallback(val, path2, parent2, parentPropName);
|
|
54173
|
+
break;
|
|
54174
|
+
case "null":
|
|
54175
|
+
if (val === null) {
|
|
54176
|
+
addType = true;
|
|
54177
|
+
}
|
|
54178
|
+
break;
|
|
54179
|
+
/* c8 ignore next 2 */
|
|
54180
|
+
default:
|
|
54181
|
+
throw new TypeError("Unknown value type " + valueType);
|
|
54182
|
+
}
|
|
54183
|
+
if (addType) {
|
|
54184
|
+
retObj = {
|
|
54185
|
+
path: path2,
|
|
54186
|
+
value: val,
|
|
54187
|
+
parent: parent2,
|
|
54188
|
+
parentProperty: parentPropName
|
|
54189
|
+
};
|
|
54190
|
+
this._handleCallback(retObj, callback, "value");
|
|
54191
|
+
return retObj;
|
|
54192
|
+
}
|
|
54193
|
+
} else if (loc[0] === "`" && val && Object.hasOwn(val, loc.slice(1))) {
|
|
54194
|
+
const locProp = loc.slice(1);
|
|
54195
|
+
addRet(this._trace(x2, val[locProp], push(path2, locProp), val, locProp, callback, hasArrExpr, true));
|
|
54196
|
+
} else if (loc.includes(",")) {
|
|
54197
|
+
const parts = loc.split(",");
|
|
54198
|
+
for (const part of parts) {
|
|
54199
|
+
addRet(this._trace(unshift(part, x2), val, path2, parent2, parentPropName, callback, true));
|
|
54200
|
+
}
|
|
54201
|
+
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
|
|
54202
|
+
addRet(this._trace(x2, val[loc], push(path2, loc), val, loc, callback, hasArrExpr, true));
|
|
54203
|
+
}
|
|
54204
|
+
if (this._hasParentSelector) {
|
|
54205
|
+
for (let t = 0; t < ret.length; t++) {
|
|
54206
|
+
const rett = ret[t];
|
|
54207
|
+
if (rett && rett.isParentSelector) {
|
|
54208
|
+
const tmp = this._trace(rett.expr, val, rett.path, parent2, parentPropName, callback, hasArrExpr);
|
|
54209
|
+
if (Array.isArray(tmp)) {
|
|
54210
|
+
ret[t] = tmp[0];
|
|
54211
|
+
const tl = tmp.length;
|
|
54212
|
+
for (let tt2 = 1; tt2 < tl; tt2++) {
|
|
54213
|
+
t++;
|
|
54214
|
+
ret.splice(t, 0, tmp[tt2]);
|
|
54215
|
+
}
|
|
54216
|
+
} else {
|
|
54217
|
+
ret[t] = tmp;
|
|
54218
|
+
}
|
|
54219
|
+
}
|
|
54220
|
+
}
|
|
54221
|
+
}
|
|
54222
|
+
return ret;
|
|
54223
|
+
};
|
|
54224
|
+
JSONPath.prototype._walk = function(val, f) {
|
|
54225
|
+
if (Array.isArray(val)) {
|
|
54226
|
+
const n = val.length;
|
|
54227
|
+
for (let i = 0; i < n; i++) {
|
|
54228
|
+
f(i);
|
|
54229
|
+
}
|
|
54230
|
+
} else if (val && typeof val === "object") {
|
|
54231
|
+
Object.keys(val).forEach((m) => {
|
|
54232
|
+
f(m);
|
|
54233
|
+
});
|
|
54234
|
+
}
|
|
54235
|
+
};
|
|
54236
|
+
JSONPath.prototype._slice = function(loc, expr, val, path2, parent2, parentPropName, callback) {
|
|
54237
|
+
if (!Array.isArray(val)) {
|
|
54238
|
+
return void 0;
|
|
54239
|
+
}
|
|
54240
|
+
const len = val.length, parts = loc.split(":"), step = parts[2] && Number.parseInt(parts[2]) || 1;
|
|
54241
|
+
let start = parts[0] && Number.parseInt(parts[0]) || 0, end = parts[1] && Number.parseInt(parts[1]) || len;
|
|
54242
|
+
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
|
|
54243
|
+
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
|
|
54244
|
+
const ret = [];
|
|
54245
|
+
for (let i = start; i < end; i += step) {
|
|
54246
|
+
const tmp = this._trace(unshift(i, expr), val, path2, parent2, parentPropName, callback, true);
|
|
54247
|
+
tmp.forEach((t) => {
|
|
54248
|
+
ret.push(t);
|
|
54249
|
+
});
|
|
54250
|
+
}
|
|
54251
|
+
return ret;
|
|
54252
|
+
};
|
|
54253
|
+
JSONPath.prototype._eval = function(code, _v, _vname, path2, parent2, parentPropName) {
|
|
54254
|
+
this.currSandbox._$_parentProperty = parentPropName;
|
|
54255
|
+
this.currSandbox._$_parent = parent2;
|
|
54256
|
+
this.currSandbox._$_property = _vname;
|
|
54257
|
+
this.currSandbox._$_root = this.json;
|
|
54258
|
+
this.currSandbox._$_v = _v;
|
|
54259
|
+
const containsPath = code.includes("@path");
|
|
54260
|
+
if (containsPath) {
|
|
54261
|
+
this.currSandbox._$_path = JSONPath.toPathString(path2.concat([_vname]));
|
|
54262
|
+
}
|
|
54263
|
+
const scriptCacheKey = this.currEval + "Script:" + code;
|
|
54264
|
+
if (!JSONPath.cache[scriptCacheKey]) {
|
|
54265
|
+
let script = code.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
|
|
54266
|
+
if (containsPath) {
|
|
54267
|
+
script = script.replaceAll("@path", "_$_path");
|
|
54268
|
+
}
|
|
54269
|
+
if (this.currEval === "safe" || this.currEval === true || this.currEval === void 0) {
|
|
54270
|
+
JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);
|
|
54271
|
+
} else if (this.currEval === "native") {
|
|
54272
|
+
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
|
|
54273
|
+
} else if (typeof this.currEval === "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
|
|
54274
|
+
const CurrEval = this.currEval;
|
|
54275
|
+
JSONPath.cache[scriptCacheKey] = new CurrEval(script);
|
|
54276
|
+
} else if (typeof this.currEval === "function") {
|
|
54277
|
+
JSONPath.cache[scriptCacheKey] = {
|
|
54278
|
+
runInNewContext: (context) => this.currEval(script, context)
|
|
54279
|
+
};
|
|
54280
|
+
} else {
|
|
54281
|
+
throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
|
|
54282
|
+
}
|
|
54283
|
+
}
|
|
54284
|
+
try {
|
|
54285
|
+
return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);
|
|
54286
|
+
} catch (e) {
|
|
54287
|
+
if (this.ignoreEvalErrors) {
|
|
54288
|
+
return false;
|
|
54289
|
+
}
|
|
54290
|
+
throw new Error("jsonPath: " + e.message + ": " + code);
|
|
54291
|
+
}
|
|
54292
|
+
};
|
|
54293
|
+
JSONPath.cache = {};
|
|
54294
|
+
JSONPath.toPathString = function(pathArr) {
|
|
54295
|
+
const x2 = pathArr, n = x2.length;
|
|
54296
|
+
let p = "$";
|
|
54297
|
+
for (let i = 1; i < n; i++) {
|
|
54298
|
+
if (!/^(~|\^|@.*?\(\))$/u.test(x2[i])) {
|
|
54299
|
+
p += /^[0-9*]+$/u.test(x2[i]) ? "[" + x2[i] + "]" : "['" + x2[i] + "']";
|
|
54300
|
+
}
|
|
54301
|
+
}
|
|
54302
|
+
return p;
|
|
54303
|
+
};
|
|
54304
|
+
JSONPath.toPointer = function(pointer) {
|
|
54305
|
+
const x2 = pointer, n = x2.length;
|
|
54306
|
+
let p = "";
|
|
54307
|
+
for (let i = 1; i < n; i++) {
|
|
54308
|
+
if (!/^(~|\^|@.*?\(\))$/u.test(x2[i])) {
|
|
54309
|
+
p += "/" + x2[i].toString().replaceAll("~", "~0").replaceAll("/", "~1");
|
|
54310
|
+
}
|
|
54311
|
+
}
|
|
54312
|
+
return p;
|
|
54313
|
+
};
|
|
54314
|
+
JSONPath.toPathArray = function(expr) {
|
|
54315
|
+
const {
|
|
54316
|
+
cache
|
|
54317
|
+
} = JSONPath;
|
|
54318
|
+
if (cache[expr]) {
|
|
54319
|
+
return cache[expr].concat();
|
|
54320
|
+
}
|
|
54321
|
+
const subx = [];
|
|
54322
|
+
const normalized = expr.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu, function($0, $1) {
|
|
54323
|
+
return "[#" + (subx.push($1) - 1) + "]";
|
|
54324
|
+
}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function($0, prop) {
|
|
54325
|
+
return "['" + prop.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
|
|
54326
|
+
}).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function($0, ups) {
|
|
54327
|
+
return ";" + ups.split("").join(";") + ";";
|
|
54328
|
+
}).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "");
|
|
54329
|
+
const exprList = normalized.split(";").map(function(exp) {
|
|
54330
|
+
const match = exp.match(/#(\d+)/u);
|
|
54331
|
+
return !match || !match[1] ? exp : subx[match[1]];
|
|
54332
|
+
});
|
|
54333
|
+
cache[expr] = exprList;
|
|
54334
|
+
return cache[expr].concat();
|
|
54335
|
+
};
|
|
54336
|
+
JSONPath.prototype.safeVm = {
|
|
54337
|
+
Script: SafeScript
|
|
54338
|
+
};
|
|
54339
|
+
const moveToAnotherArray = function(source, target, conditionCb) {
|
|
54340
|
+
const il = source.length;
|
|
54341
|
+
for (let i = 0; i < il; i++) {
|
|
54342
|
+
const item = source[i];
|
|
54343
|
+
if (conditionCb(item)) {
|
|
54344
|
+
target.push(source.splice(i--, 1)[0]);
|
|
54345
|
+
}
|
|
54346
|
+
}
|
|
54347
|
+
};
|
|
54348
|
+
class Script {
|
|
54349
|
+
/**
|
|
54350
|
+
* @param {string} expr Expression to evaluate
|
|
54351
|
+
*/
|
|
54352
|
+
constructor(expr) {
|
|
54353
|
+
this.code = expr;
|
|
54354
|
+
}
|
|
54355
|
+
/**
|
|
54356
|
+
* @param {object} context Object whose items will be added
|
|
54357
|
+
* to evaluation
|
|
54358
|
+
* @returns {EvaluatedResult} Result of evaluated code
|
|
54359
|
+
*/
|
|
54360
|
+
runInNewContext(context) {
|
|
54361
|
+
let expr = this.code;
|
|
54362
|
+
const keys2 = Object.keys(context);
|
|
54363
|
+
const funcs = [];
|
|
54364
|
+
moveToAnotherArray(keys2, funcs, (key) => {
|
|
54365
|
+
return typeof context[key] === "function";
|
|
54366
|
+
});
|
|
54367
|
+
const values = keys2.map((vr) => {
|
|
54368
|
+
return context[vr];
|
|
54369
|
+
});
|
|
54370
|
+
const funcString = funcs.reduce((s, func) => {
|
|
54371
|
+
let fString = context[func].toString();
|
|
54372
|
+
if (!/function/u.test(fString)) {
|
|
54373
|
+
fString = "function " + fString;
|
|
54374
|
+
}
|
|
54375
|
+
return "var " + func + "=" + fString + ";" + s;
|
|
54376
|
+
}, "");
|
|
54377
|
+
expr = funcString + expr;
|
|
54378
|
+
if (!/(['"])use strict\1/u.test(expr) && !keys2.includes("arguments")) {
|
|
54379
|
+
expr = "var arguments = undefined;" + expr;
|
|
54380
|
+
}
|
|
54381
|
+
expr = expr.replace(/;\s*$/u, "");
|
|
54382
|
+
const lastStatementEnd = expr.lastIndexOf(";");
|
|
54383
|
+
const code = lastStatementEnd !== -1 ? expr.slice(0, lastStatementEnd + 1) + " return " + expr.slice(lastStatementEnd + 1) : " return " + expr;
|
|
54384
|
+
return new Function(...keys2, code)(...values);
|
|
54385
|
+
}
|
|
54386
|
+
}
|
|
54387
|
+
JSONPath.prototype.vm = {
|
|
54388
|
+
Script
|
|
54389
|
+
};
|
|
52664
54390
|
const parseJsonSchema = (schema2, paramsConfig = /* @__PURE__ */ new Map()) => {
|
|
52665
54391
|
if (!schema2 || typeof schema2 !== "object") return schema2;
|
|
52666
54392
|
switch (schema2.type) {
|
|
@@ -52682,7 +54408,7 @@ const parseJsonSchema = (schema2, paramsConfig = /* @__PURE__ */ new Map()) => {
|
|
|
52682
54408
|
};
|
|
52683
54409
|
function processJsonSchemaSubModel0(mapItem, apiData) {
|
|
52684
54410
|
return mapItem.fields.reduce((acc, { leftFieldKey, rightFieldKey }) => {
|
|
52685
|
-
let value =
|
|
54411
|
+
let value = JSONPath({ path: rightFieldKey, json: apiData })?.[0];
|
|
52686
54412
|
value = (Array.isArray(value) ? value[0] : value) ?? void 0;
|
|
52687
54413
|
acc[leftFieldKey] = typeof value === "object" ? void 0 : value;
|
|
52688
54414
|
return acc;
|
|
@@ -52690,7 +54416,7 @@ function processJsonSchemaSubModel0(mapItem, apiData) {
|
|
|
52690
54416
|
}
|
|
52691
54417
|
function processJsonSchemaSubModel1(mapItem, apiData) {
|
|
52692
54418
|
const fieldValues = mapItem.fields.reduce((acc, { leftFieldKey, rightFieldKey }) => {
|
|
52693
|
-
let value =
|
|
54419
|
+
let value = JSONPath({ path: rightFieldKey, json: apiData });
|
|
52694
54420
|
let arr = Array.isArray(value) ? value.filter((v) => v != null && typeof v !== "object") : value != null && typeof value !== "object" ? [value] : [];
|
|
52695
54421
|
acc[leftFieldKey] = arr;
|
|
52696
54422
|
return acc;
|
|
@@ -98424,6 +100150,7 @@ async function initializeDocumentEngine(props, payload, result) {
|
|
|
98424
100150
|
const { id, requestInfo, fillModeType, paramsConfig } = result;
|
|
98425
100151
|
const mainModelKey = requestInfo.modelKey || payload.modelKey || "";
|
|
98426
100152
|
const materialNo = paramsConfig?.materialNo || requestInfo.materialNo;
|
|
100153
|
+
await payload.ctx.runtime.ensureModelFieldsReady(mainModelKey);
|
|
98427
100154
|
await addSubModelsToFieldScope(mainModelKey, payload.ctx);
|
|
98428
100155
|
const masterSlaveList = payload.ctx.runtime.getMasterSlaveFieldList(mainModelKey);
|
|
98429
100156
|
const cloneRuntimeJson = cloneDeep(JSON.parse(requestInfo.runtimeJson || "{}"));
|
|
@@ -98477,7 +100204,8 @@ async function initializeDocumentEngine(props, payload, result) {
|
|
|
98477
100204
|
});
|
|
98478
100205
|
const rawData = conversionFormState({
|
|
98479
100206
|
masterSlaveList,
|
|
98480
|
-
interfaceData
|
|
100207
|
+
interfaceData,
|
|
100208
|
+
subTableInfoList: docModel.getSubTableInfoList() ?? []
|
|
98481
100209
|
});
|
|
98482
100210
|
const docRuntimeMeta = {
|
|
98483
100211
|
...requestInfo,
|
|
@@ -98616,6 +100344,7 @@ function useDocumentFactory(props, payload) {
|
|
|
98616
100344
|
} = freshExecute;
|
|
98617
100345
|
const mainModelKey = requestInfo.modelKey || payload.modelKey || "";
|
|
98618
100346
|
const materialNo = paramsConfig?.materialNo || props.materialNo;
|
|
100347
|
+
await payload.ctx.runtime.ensureModelFieldsReady(mainModelKey);
|
|
98619
100348
|
const masterSlaveList = payload.ctx.runtime.getMasterSlaveFieldList(mainModelKey);
|
|
98620
100349
|
const instances = doc.model?.getWidgetInstances() ?? [];
|
|
98621
100350
|
const { initDocModelJson } = doc.docRuntimeMeta.handleInfo;
|
|
@@ -98644,7 +100373,7 @@ function useDocumentFactory(props, payload) {
|
|
|
98644
100373
|
const rawData = conversionFormState({
|
|
98645
100374
|
masterSlaveList,
|
|
98646
100375
|
interfaceData,
|
|
98647
|
-
|
|
100376
|
+
subTableInfoList: doc.model?.getSubTableInfoList() ?? []
|
|
98648
100377
|
});
|
|
98649
100378
|
doc.dataManager.setRawData(rawData);
|
|
98650
100379
|
await waitForDataManagerSettle();
|
|
@@ -99116,6 +100845,13 @@ class SuiteRuntime {
|
|
|
99116
100845
|
getModel(modelKey) {
|
|
99117
100846
|
return this.modelService.getModelSync(modelKey);
|
|
99118
100847
|
}
|
|
100848
|
+
/**
|
|
100849
|
+
* 确保主模型字段已拉取并写入缓存(避免 preload 与文档 immediate 加载竞态)。
|
|
100850
|
+
*/
|
|
100851
|
+
async ensureModelFieldsReady(modelKey) {
|
|
100852
|
+
if (!modelKey) return;
|
|
100853
|
+
await this.loadFieldList(modelKey);
|
|
100854
|
+
}
|
|
99119
100855
|
getMasterSlaveFieldList(modelKey) {
|
|
99120
100856
|
return this.fieldService.getFieldList(modelKey)?.filter((i) => i.type === FIELD_TYPE.MASTERSLAVE) || [];
|
|
99121
100857
|
}
|
|
@@ -104118,9 +105854,6 @@ function rowKey(row, fallbackIndex) {
|
|
|
104118
105854
|
}
|
|
104119
105855
|
return `idx:${fallbackIndex}`;
|
|
104120
105856
|
}
|
|
104121
|
-
function normalizeFormData(data) {
|
|
104122
|
-
return getSubmitFormData(data || {});
|
|
104123
|
-
}
|
|
104124
105857
|
function getFieldMeta(metaMap, runtimePath) {
|
|
104125
105858
|
if (!metaMap) return {};
|
|
104126
105859
|
return metaMap.get(runtimePath) || {};
|
|
@@ -104220,8 +105953,8 @@ function buildWidgetFieldMetaMap(instances) {
|
|
|
104220
105953
|
return map;
|
|
104221
105954
|
}
|
|
104222
105955
|
function buildFieldChangeList(params) {
|
|
104223
|
-
const baseline =
|
|
104224
|
-
const current =
|
|
105956
|
+
const baseline = getSubmitFormData(params.baselineData || {}, params.subTableInfoList);
|
|
105957
|
+
const current = getSubmitFormData(params.currentData || {}, params.subTableInfoList);
|
|
104225
105958
|
const changeList = [];
|
|
104226
105959
|
const keys2 = /* @__PURE__ */ new Set([...Object.keys(baseline || {}), ...Object.keys(current || {})]);
|
|
104227
105960
|
for (const fieldKey of keys2) {
|
|
@@ -104320,8 +106053,9 @@ function useDocOperations(docRef) {
|
|
|
104320
106053
|
const baselineSnapshot = doc.dataManager.getRawData();
|
|
104321
106054
|
const instances = doc.getWidgetInstances() ?? [];
|
|
104322
106055
|
const widgetMetaMap = buildWidgetFieldMetaMap(instances);
|
|
106056
|
+
const subTableInfoList = doc.model?.getSubTableInfoList() ?? [];
|
|
104323
106057
|
doc.setMode(DocModeTypeConst.Fill);
|
|
104324
|
-
return { baselineSnapshot, widgetMetaMap };
|
|
106058
|
+
return { baselineSnapshot, widgetMetaMap, subTableInfoList };
|
|
104325
106059
|
}
|
|
104326
106060
|
async function computeBaselineChanges(ctx) {
|
|
104327
106061
|
await Promise.resolve();
|
|
@@ -104333,7 +106067,8 @@ function useDocOperations(docRef) {
|
|
|
104333
106067
|
return buildFieldChangeList({
|
|
104334
106068
|
baselineData: ctx.baselineSnapshot,
|
|
104335
106069
|
currentData,
|
|
104336
|
-
widgetMetaMap: ctx.widgetMetaMap
|
|
106070
|
+
widgetMetaMap: ctx.widgetMetaMap,
|
|
106071
|
+
subTableInfoList: ctx.subTableInfoList
|
|
104337
106072
|
});
|
|
104338
106073
|
}
|
|
104339
106074
|
function setAnnotation(ids, list) {
|
|
@@ -104432,6 +106167,13 @@ function useDocController(factory2, ops) {
|
|
|
104432
106167
|
rawData() {
|
|
104433
106168
|
return doc.dataManager.getRawData();
|
|
104434
106169
|
},
|
|
106170
|
+
getSubmitFormData(formData) {
|
|
106171
|
+
const subTableInfoList = doc.model?.getSubTableInfoList() ?? [];
|
|
106172
|
+
return getSubmitFormData(
|
|
106173
|
+
formData ?? doc.dataManager.getRawData(),
|
|
106174
|
+
subTableInfoList
|
|
106175
|
+
);
|
|
106176
|
+
},
|
|
104435
106177
|
setRawData(data, defaultDataMap) {
|
|
104436
106178
|
doc.dataManager.setRawData(data, defaultDataMap);
|
|
104437
106179
|
},
|
|
@@ -111368,10 +113110,10 @@ const _sfc_main$1X = /* @__PURE__ */ defineComponent({
|
|
|
111368
113110
|
get() {
|
|
111369
113111
|
if (docInst.value.isInEditMode()) {
|
|
111370
113112
|
const value2 = docInst.value?.dataManager?.getDefault(runtimeValuePath.value);
|
|
111371
|
-
return getValue$1(value2, isMultiple.value);
|
|
113113
|
+
return toBoolean(getValue$1(value2, isMultiple.value));
|
|
111372
113114
|
}
|
|
111373
113115
|
const value = docInst.value?.dataManager?.get(runtimeValuePath.value);
|
|
111374
|
-
return getValue$1(value, isMultiple.value);
|
|
113116
|
+
return toBoolean(getValue$1(value, isMultiple.value));
|
|
111375
113117
|
},
|
|
111376
113118
|
set(v) {
|
|
111377
113119
|
const data = setValue(v, runtimeValuePath.value, {
|
|
@@ -122565,8 +124307,8 @@ const edhrSuitePlugin = {
|
|
|
122565
124307
|
key: SUITE_KEY,
|
|
122566
124308
|
install: installEdhrSuite
|
|
122567
124309
|
};
|
|
122568
|
-
function registerSuite(
|
|
122569
|
-
|
|
124310
|
+
function registerSuite(plugin2) {
|
|
124311
|
+
plugin2.install();
|
|
122570
124312
|
}
|
|
122571
124313
|
const _hoisted_1$e = { class: "options-dropdown" };
|
|
122572
124314
|
const _hoisted_2$9 = { class: "options-search" };
|
|
@@ -125086,7 +126828,6 @@ export {
|
|
|
125086
126828
|
GctLayout,
|
|
125087
126829
|
PageSizeEnumConst,
|
|
125088
126830
|
edhrSuitePlugin,
|
|
125089
|
-
getSubmitFormData,
|
|
125090
126831
|
registerSuite,
|
|
125091
126832
|
setupPlatformAdapters,
|
|
125092
126833
|
setupVueRuntime,
|