@next-core/brick-utils 2.45.15 → 2.45.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.bundle.js +233 -127
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +232 -128
- package/dist/index.esm.js.map +1 -1
- package/dist/types/resolveContextConcurrently.d.ts +10 -6
- package/dist/types/track.d.ts +5 -0
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -19456,42 +19456,244 @@ var {
|
|
|
19456
19456
|
convertUnitValueByPrecision: convertValueByPrecision
|
|
19457
19457
|
} = utils;
|
|
19458
19458
|
|
|
19459
|
-
|
|
19459
|
+
/**
|
|
19460
|
+
* Get tracking CTX for an evaluable expression in `track context` mode.
|
|
19461
|
+
*
|
|
19462
|
+
* A `track context` mode is an evaluable expression which is a sequence expression
|
|
19463
|
+
* starting with the exact literal string expression of "track context".
|
|
19464
|
+
*
|
|
19465
|
+
* @param raw - A raw string, which must be checked by `isEvaluable` first.
|
|
19466
|
+
*
|
|
19467
|
+
* @returns
|
|
19468
|
+
*
|
|
19469
|
+
* Returns used CTXs if `track context` mode is enabled, or returns false if not enabled or
|
|
19470
|
+
* no CTX found.
|
|
19471
|
+
*
|
|
19472
|
+
* @example
|
|
19473
|
+
*
|
|
19474
|
+
* ```js
|
|
19475
|
+
* trackContext('<% "track context", [CTX.hello, CTX.world] %>');
|
|
19476
|
+
* // => ["hello", "world"]
|
|
19477
|
+
*
|
|
19478
|
+
* trackContext('<% [CTX.hello, CTX.world] %>');
|
|
19479
|
+
* // => false
|
|
19480
|
+
*
|
|
19481
|
+
* trackContext('<% "track context", DATA.any %>');
|
|
19482
|
+
* // => false
|
|
19483
|
+
* ```
|
|
19484
|
+
*/
|
|
19485
|
+
function trackContext(raw) {
|
|
19486
|
+
return track(raw, "track context", "CTX");
|
|
19487
|
+
}
|
|
19488
|
+
function trackState(raw) {
|
|
19489
|
+
return track(raw, "track state", "STATE");
|
|
19490
|
+
}
|
|
19491
|
+
function trackFormState(raw) {
|
|
19492
|
+
return track(raw, "track formstate", "FORM_STATE");
|
|
19493
|
+
}
|
|
19494
|
+
function trackUsedContext(data) {
|
|
19495
|
+
return collectContextUsage(data, "CTX").usedContexts;
|
|
19496
|
+
}
|
|
19497
|
+
function trackUsedState(data) {
|
|
19498
|
+
return collectContextUsage(data, "STATE").usedContexts;
|
|
19499
|
+
}
|
|
19500
|
+
function track(raw, trackText, variableName) {
|
|
19501
|
+
if (raw.includes(trackText)) {
|
|
19502
|
+
// const contexts = new Set<string>();
|
|
19503
|
+
var usage = {
|
|
19504
|
+
usedContexts: [],
|
|
19505
|
+
includesComputed: false
|
|
19506
|
+
};
|
|
19507
|
+
var {
|
|
19508
|
+
expression
|
|
19509
|
+
} = preevaluate(raw, {
|
|
19510
|
+
withParent: true,
|
|
19511
|
+
hooks: {
|
|
19512
|
+
beforeVisitGlobal: beforeVisitContextFactory(usage, variableName)
|
|
19513
|
+
}
|
|
19514
|
+
});
|
|
19515
|
+
// const contexts = usage
|
|
19516
|
+
var trackCtxExp;
|
|
19517
|
+
if (expression.type === "SequenceExpression" && (trackCtxExp = expression.expressions[0]) && trackCtxExp.type === "Literal" && trackCtxExp.value === trackText) {
|
|
19518
|
+
if (usage.usedContexts.length > 0) {
|
|
19519
|
+
return usage.usedContexts;
|
|
19520
|
+
} else {
|
|
19521
|
+
// eslint-disable-next-line no-console
|
|
19522
|
+
console.warn("You are using \"".concat(trackText, "\" but no `").concat(variableName, "` usage found in your expression: ").concat(JSON.stringify(raw)));
|
|
19523
|
+
}
|
|
19524
|
+
}
|
|
19525
|
+
}
|
|
19526
|
+
return false;
|
|
19527
|
+
}
|
|
19528
|
+
function beforeVisitContextFactory(usage, variableName) {
|
|
19529
|
+
return function beforeVisitContext(node, parent) {
|
|
19530
|
+
if (node.name === variableName) {
|
|
19531
|
+
var memberParent = parent[parent.length - 1];
|
|
19532
|
+
if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
|
|
19533
|
+
var memberNode = memberParent.node;
|
|
19534
|
+
var used;
|
|
19535
|
+
if (!memberNode.computed && memberNode.property.type === "Identifier") {
|
|
19536
|
+
used = memberNode.property.name;
|
|
19537
|
+
} else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
|
|
19538
|
+
used = memberNode.property.value;
|
|
19539
|
+
} else {
|
|
19540
|
+
usage.includesComputed = true;
|
|
19541
|
+
}
|
|
19542
|
+
if (used !== undefined && !usage.usedContexts.includes(used)) {
|
|
19543
|
+
usage.usedContexts.push(used);
|
|
19544
|
+
}
|
|
19545
|
+
}
|
|
19546
|
+
}
|
|
19547
|
+
};
|
|
19548
|
+
}
|
|
19549
|
+
function collectContextUsage(data, variableName) {
|
|
19550
|
+
var usage = {
|
|
19551
|
+
usedContexts: [],
|
|
19552
|
+
includesComputed: false
|
|
19553
|
+
};
|
|
19554
|
+
visitStoryboardExpressions(data, beforeVisitContextFactory(usage, variableName), variableName);
|
|
19555
|
+
return usage;
|
|
19556
|
+
}
|
|
19557
|
+
|
|
19558
|
+
function deferResolveContextConcurrently(contextConfs, resolveContext) {
|
|
19559
|
+
var keyword = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "CTX";
|
|
19560
|
+
var dependencyMap = getDependencyMapOfContext(contextConfs, keyword);
|
|
19561
|
+
// There maybe multiple context confs for a specific name, since there are conditional contexts.
|
|
19562
|
+
// This is a map of how many pending context confs for each context name.
|
|
19563
|
+
var pendingDeps = new Map();
|
|
19564
|
+
for (var contextName of Array.from(dependencyMap.keys()).map(contextConf => contextConf.name)) {
|
|
19565
|
+
var _pendingDeps$get;
|
|
19566
|
+
pendingDeps.set(contextName, ((_pendingDeps$get = pendingDeps.get(contextName)) !== null && _pendingDeps$get !== void 0 ? _pendingDeps$get : 0) + 1);
|
|
19567
|
+
}
|
|
19568
|
+
var includesComputed = Array.from(dependencyMap.values()).some(stats => stats.includesComputed);
|
|
19569
|
+
var processed = new WeakSet();
|
|
19570
|
+
var deferredContexts = new Map();
|
|
19571
|
+
var pendingContexts = new Map([...new Set(contextConfs.map(contextConf => contextConf.name))].map(contextName => [contextName, new Promise((resolve, reject) => {
|
|
19572
|
+
deferredContexts.set(contextName, {
|
|
19573
|
+
resolve,
|
|
19574
|
+
reject
|
|
19575
|
+
});
|
|
19576
|
+
})]));
|
|
19577
|
+
var wrapResolve = /*#__PURE__*/function () {
|
|
19578
|
+
var _ref = _asyncToGenerator(function* (contextConf) {
|
|
19579
|
+
var _pendingDeps$get2;
|
|
19580
|
+
processed.add(contextConf);
|
|
19581
|
+
var resolved = yield resolveContext(contextConf);
|
|
19582
|
+
dependencyMap.delete(contextConf);
|
|
19583
|
+
var left = (_pendingDeps$get2 = pendingDeps.get(contextConf.name)) !== null && _pendingDeps$get2 !== void 0 ? _pendingDeps$get2 : 0;
|
|
19584
|
+
if (resolved) {
|
|
19585
|
+
deferredContexts.get(contextConf.name).resolve();
|
|
19586
|
+
pendingDeps.delete(contextConf.name);
|
|
19587
|
+
if (left === 0) {
|
|
19588
|
+
throw new Error("Duplicated context defined: ".concat(contextConf.name));
|
|
19589
|
+
}
|
|
19590
|
+
} else {
|
|
19591
|
+
// Assert: left >= 1
|
|
19592
|
+
if (left === 1) {
|
|
19593
|
+
deferredContexts.get(contextConf.name).resolve();
|
|
19594
|
+
pendingDeps.delete(contextConf.name);
|
|
19595
|
+
} else {
|
|
19596
|
+
pendingDeps.set(contextConf.name, left - 1);
|
|
19597
|
+
}
|
|
19598
|
+
}
|
|
19599
|
+
yield scheduleNext();
|
|
19600
|
+
});
|
|
19601
|
+
return function wrapResolve(_x) {
|
|
19602
|
+
return _ref.apply(this, arguments);
|
|
19603
|
+
};
|
|
19604
|
+
}();
|
|
19605
|
+
var scheduleAsSerial = includesComputed;
|
|
19606
|
+
function scheduleNext() {
|
|
19607
|
+
return _scheduleNext.apply(this, arguments);
|
|
19608
|
+
}
|
|
19609
|
+
function _scheduleNext() {
|
|
19610
|
+
_scheduleNext = _asyncToGenerator(function* () {
|
|
19611
|
+
var readyContexts = Array.from(dependencyMap.entries()).filter(predicateNextResolveFactory(pendingDeps, scheduleAsSerial)).map(entry => entry[0]).filter(contextConf => !processed.has(contextConf));
|
|
19612
|
+
yield Promise.all(readyContexts.map(wrapResolve));
|
|
19613
|
+
});
|
|
19614
|
+
return _scheduleNext.apply(this, arguments);
|
|
19615
|
+
}
|
|
19616
|
+
var pendingResult = scheduleNext().then( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
19617
|
+
// If there are still contexts left, it implies one of these situations:
|
|
19618
|
+
// - Circular contexts.
|
|
19619
|
+
// Such as: a depends on b, while b depends on a.
|
|
19620
|
+
// - Related contexts are all ignored.
|
|
19621
|
+
// Such as: a depends on b,
|
|
19622
|
+
// while both them are ignore by a falsy result of `if`.
|
|
19623
|
+
if (dependencyMap.size > 0) {
|
|
19624
|
+
// This will throw if circular contexts detected.
|
|
19625
|
+
detectCircularContexts(dependencyMap, keyword);
|
|
19626
|
+
scheduleAsSerial = true;
|
|
19627
|
+
yield scheduleNext();
|
|
19628
|
+
}
|
|
19629
|
+
// There maybe ignored contexts which are still not fulfilled.
|
|
19630
|
+
// We treat them as RESOLVED.
|
|
19631
|
+
for (var deferred of deferredContexts.values()) {
|
|
19632
|
+
deferred.resolve();
|
|
19633
|
+
}
|
|
19634
|
+
})).catch(error => {
|
|
19635
|
+
// There maybe contexts left not fulfilled, when an error occurred.
|
|
19636
|
+
// We treat them as REJECTED.
|
|
19637
|
+
for (var deferred of deferredContexts.values()) {
|
|
19638
|
+
deferred.reject(error);
|
|
19639
|
+
}
|
|
19640
|
+
throw error;
|
|
19641
|
+
});
|
|
19642
|
+
return {
|
|
19643
|
+
pendingResult,
|
|
19644
|
+
pendingContexts
|
|
19645
|
+
};
|
|
19646
|
+
}
|
|
19647
|
+
function resolveContextConcurrently(_x2, _x3) {
|
|
19460
19648
|
return _resolveContextConcurrently.apply(this, arguments);
|
|
19461
19649
|
}
|
|
19462
19650
|
function _resolveContextConcurrently() {
|
|
19463
19651
|
_resolveContextConcurrently = _asyncToGenerator(function* (contextConfs, resolveContext) {
|
|
19464
19652
|
var keyword = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "CTX";
|
|
19465
19653
|
var dependencyMap = getDependencyMapOfContext(contextConfs, keyword);
|
|
19466
|
-
var pendingDeps = new
|
|
19654
|
+
var pendingDeps = new Map();
|
|
19655
|
+
for (var contextName of Array.from(dependencyMap.keys()).map(contextConf => contextConf.name)) {
|
|
19656
|
+
var _pendingDeps$get5;
|
|
19657
|
+
pendingDeps.set(contextName, ((_pendingDeps$get5 = pendingDeps.get(contextName)) !== null && _pendingDeps$get5 !== void 0 ? _pendingDeps$get5 : 0) + 1);
|
|
19658
|
+
}
|
|
19467
19659
|
var includesComputed = Array.from(dependencyMap.values()).some(stats => stats.includesComputed);
|
|
19468
19660
|
var processed = new WeakSet();
|
|
19469
19661
|
var wrapResolve = /*#__PURE__*/function () {
|
|
19470
|
-
var
|
|
19662
|
+
var _ref3 = _asyncToGenerator(function* (contextConf) {
|
|
19663
|
+
var _pendingDeps$get6;
|
|
19471
19664
|
processed.add(contextConf);
|
|
19472
19665
|
var resolved = yield resolveContext(contextConf);
|
|
19473
19666
|
dependencyMap.delete(contextConf);
|
|
19667
|
+
var left = (_pendingDeps$get6 = pendingDeps.get(contextConf.name)) !== null && _pendingDeps$get6 !== void 0 ? _pendingDeps$get6 : 0;
|
|
19474
19668
|
if (resolved) {
|
|
19475
|
-
|
|
19669
|
+
pendingDeps.delete(contextConf.name);
|
|
19670
|
+
if (left === 0) {
|
|
19476
19671
|
throw new Error("Duplicated context defined: ".concat(contextConf.name));
|
|
19477
19672
|
}
|
|
19673
|
+
} else {
|
|
19674
|
+
// Assert: left >= 1
|
|
19675
|
+
if (left === 1) {
|
|
19676
|
+
pendingDeps.delete(contextConf.name);
|
|
19677
|
+
} else {
|
|
19678
|
+
pendingDeps.set(contextConf.name, left - 1);
|
|
19679
|
+
}
|
|
19478
19680
|
}
|
|
19479
19681
|
yield scheduleNext();
|
|
19480
19682
|
});
|
|
19481
|
-
return function wrapResolve(
|
|
19482
|
-
return
|
|
19683
|
+
return function wrapResolve(_x4) {
|
|
19684
|
+
return _ref3.apply(this, arguments);
|
|
19483
19685
|
};
|
|
19484
19686
|
}();
|
|
19485
19687
|
var scheduleAsSerial = includesComputed;
|
|
19486
19688
|
function scheduleNext() {
|
|
19487
|
-
return
|
|
19689
|
+
return _scheduleNext2.apply(this, arguments);
|
|
19488
19690
|
}
|
|
19489
|
-
function
|
|
19490
|
-
|
|
19691
|
+
function _scheduleNext2() {
|
|
19692
|
+
_scheduleNext2 = _asyncToGenerator(function* () {
|
|
19491
19693
|
var readyContexts = Array.from(dependencyMap.entries()).filter(predicateNextResolveFactory(pendingDeps, scheduleAsSerial)).map(entry => entry[0]).filter(contextConf => !processed.has(contextConf));
|
|
19492
19694
|
yield Promise.all(readyContexts.map(wrapResolve));
|
|
19493
19695
|
});
|
|
19494
|
-
return
|
|
19696
|
+
return _scheduleNext2.apply(this, arguments);
|
|
19495
19697
|
}
|
|
19496
19698
|
yield scheduleNext();
|
|
19497
19699
|
|
|
@@ -19513,19 +19715,33 @@ function _resolveContextConcurrently() {
|
|
|
19513
19715
|
function syncResolveContextConcurrently(contextConfs, resolveContext) {
|
|
19514
19716
|
var keyword = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "CTX";
|
|
19515
19717
|
var dependencyMap = getDependencyMapOfContext(contextConfs, keyword);
|
|
19516
|
-
var pendingDeps = new
|
|
19718
|
+
var pendingDeps = new Map();
|
|
19719
|
+
for (var contextName of Array.from(dependencyMap.keys()).map(contextConf => contextConf.name)) {
|
|
19720
|
+
var _pendingDeps$get3;
|
|
19721
|
+
pendingDeps.set(contextName, ((_pendingDeps$get3 = pendingDeps.get(contextName)) !== null && _pendingDeps$get3 !== void 0 ? _pendingDeps$get3 : 0) + 1);
|
|
19722
|
+
}
|
|
19517
19723
|
var includesComputed = Array.from(dependencyMap.values()).some(stats => stats.includesComputed);
|
|
19518
19724
|
var scheduleAsSerial = includesComputed;
|
|
19519
19725
|
function scheduleNext() {
|
|
19520
19726
|
var dep = Array.from(dependencyMap.entries()).find(predicateNextResolveFactory(pendingDeps, scheduleAsSerial));
|
|
19521
19727
|
if (dep) {
|
|
19728
|
+
var _pendingDeps$get4;
|
|
19522
19729
|
var [_contextConf] = dep;
|
|
19523
19730
|
var resolved = resolveContext(_contextConf);
|
|
19524
19731
|
dependencyMap.delete(_contextConf);
|
|
19732
|
+
var left = (_pendingDeps$get4 = pendingDeps.get(_contextConf.name)) !== null && _pendingDeps$get4 !== void 0 ? _pendingDeps$get4 : 0;
|
|
19525
19733
|
if (resolved) {
|
|
19526
|
-
|
|
19734
|
+
pendingDeps.delete(_contextConf.name);
|
|
19735
|
+
if (left === 0) {
|
|
19527
19736
|
throw new Error("Duplicated context defined: ".concat(_contextConf.name));
|
|
19528
19737
|
}
|
|
19738
|
+
} else {
|
|
19739
|
+
// Assert: left >= 1
|
|
19740
|
+
if (left === 1) {
|
|
19741
|
+
pendingDeps.delete(_contextConf.name);
|
|
19742
|
+
} else {
|
|
19743
|
+
pendingDeps.set(_contextConf.name, left - 1);
|
|
19744
|
+
}
|
|
19529
19745
|
}
|
|
19530
19746
|
scheduleNext();
|
|
19531
19747
|
}
|
|
@@ -19551,51 +19767,24 @@ function predicateNextResolveFactory(pendingDeps, scheduleAsSerial) {
|
|
|
19551
19767
|
// So make them process sequentially, keep the same behavior as before.
|
|
19552
19768
|
scheduleAsSerial ? index === 0 :
|
|
19553
19769
|
// A context is ready when it has no pending dependencies.
|
|
19554
|
-
!entry[1].
|
|
19770
|
+
!entry[1].usedContexts.some(dep => pendingDeps.has(dep));
|
|
19555
19771
|
}
|
|
19556
19772
|
function getDependencyMapOfContext(contextConfs) {
|
|
19557
19773
|
var keyword = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "CTX";
|
|
19558
19774
|
var depsMap = new Map();
|
|
19559
19775
|
for (var _contextConf2 of contextConfs) {
|
|
19560
|
-
var stats =
|
|
19561
|
-
dependencies: [],
|
|
19562
|
-
includesComputed: false
|
|
19563
|
-
};
|
|
19564
|
-
if (!_contextConf2.property) {
|
|
19565
|
-
visitStoryboardExpressions([_contextConf2.if, _contextConf2.value, _contextConf2.resolve], beforeVisitContextFactory$1(stats, keyword), keyword);
|
|
19566
|
-
}
|
|
19776
|
+
var stats = collectContextUsage(_contextConf2.property ? null : [_contextConf2.if, _contextConf2.value, _contextConf2.resolve], keyword);
|
|
19567
19777
|
depsMap.set(_contextConf2, stats);
|
|
19568
19778
|
}
|
|
19569
19779
|
return depsMap;
|
|
19570
19780
|
}
|
|
19571
|
-
function beforeVisitContextFactory$1(stats, keyword) {
|
|
19572
|
-
return function beforeVisitContext(node, parent) {
|
|
19573
|
-
if (node.name === keyword) {
|
|
19574
|
-
var memberParent = parent[parent.length - 1];
|
|
19575
|
-
if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
|
|
19576
|
-
var memberNode = memberParent.node;
|
|
19577
|
-
var dep;
|
|
19578
|
-
if (!memberNode.computed && memberNode.property.type === "Identifier") {
|
|
19579
|
-
dep = memberNode.property.name;
|
|
19580
|
-
} else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
|
|
19581
|
-
dep = memberNode.property.value;
|
|
19582
|
-
} else {
|
|
19583
|
-
stats.includesComputed = true;
|
|
19584
|
-
}
|
|
19585
|
-
if (dep !== undefined && !stats.dependencies.includes(dep)) {
|
|
19586
|
-
stats.dependencies.push(dep);
|
|
19587
|
-
}
|
|
19588
|
-
}
|
|
19589
|
-
}
|
|
19590
|
-
};
|
|
19591
|
-
}
|
|
19592
19781
|
function detectCircularContexts(dependencyMap, keyword) {
|
|
19593
19782
|
var duplicatedMap = new Map(dependencyMap);
|
|
19594
19783
|
var pendingDeps = new Set(Array.from(duplicatedMap.keys()).map(contextConf => contextConf.name));
|
|
19595
19784
|
var next = () => {
|
|
19596
19785
|
var processedAtLeastOne = false;
|
|
19597
19786
|
for (var [_contextConf3, stats] of duplicatedMap.entries()) {
|
|
19598
|
-
if (!stats.
|
|
19787
|
+
if (!stats.usedContexts.some(dep => pendingDeps.has(dep))) {
|
|
19599
19788
|
duplicatedMap.delete(_contextConf3);
|
|
19600
19789
|
pendingDeps.delete(_contextConf3.name);
|
|
19601
19790
|
processedAtLeastOne = true;
|
|
@@ -19838,91 +20027,6 @@ function deepFreeze(object) {
|
|
|
19838
20027
|
return Object.freeze(object);
|
|
19839
20028
|
}
|
|
19840
20029
|
|
|
19841
|
-
/**
|
|
19842
|
-
* Get tracking CTX for an evaluable expression in `track context` mode.
|
|
19843
|
-
*
|
|
19844
|
-
* A `track context` mode is an evaluable expression which is a sequence expression
|
|
19845
|
-
* starting with the exact literal string expression of "track context".
|
|
19846
|
-
*
|
|
19847
|
-
* @param raw - A raw string, which must be checked by `isEvaluable` first.
|
|
19848
|
-
*
|
|
19849
|
-
* @returns
|
|
19850
|
-
*
|
|
19851
|
-
* Returns used CTXs if `track context` mode is enabled, or returns false if not enabled or
|
|
19852
|
-
* no CTX found.
|
|
19853
|
-
*
|
|
19854
|
-
* @example
|
|
19855
|
-
*
|
|
19856
|
-
* ```js
|
|
19857
|
-
* trackContext('<% "track context", [CTX.hello, CTX.world] %>');
|
|
19858
|
-
* // => ["hello", "world"]
|
|
19859
|
-
*
|
|
19860
|
-
* trackContext('<% [CTX.hello, CTX.world] %>');
|
|
19861
|
-
* // => false
|
|
19862
|
-
*
|
|
19863
|
-
* trackContext('<% "track context", DATA.any %>');
|
|
19864
|
-
* // => false
|
|
19865
|
-
* ```
|
|
19866
|
-
*/
|
|
19867
|
-
function trackContext(raw) {
|
|
19868
|
-
return track(raw, "track context", "CTX");
|
|
19869
|
-
}
|
|
19870
|
-
function trackState(raw) {
|
|
19871
|
-
return track(raw, "track state", "STATE");
|
|
19872
|
-
}
|
|
19873
|
-
function trackFormState(raw) {
|
|
19874
|
-
return track(raw, "track formstate", "FORM_STATE");
|
|
19875
|
-
}
|
|
19876
|
-
function trackUsedContext(data) {
|
|
19877
|
-
return trackUsed(data, "CTX");
|
|
19878
|
-
}
|
|
19879
|
-
function trackUsedState(data) {
|
|
19880
|
-
return trackUsed(data, "STATE");
|
|
19881
|
-
}
|
|
19882
|
-
function track(raw, trackText, variableName) {
|
|
19883
|
-
if (raw.includes(trackText)) {
|
|
19884
|
-
var contexts = new Set();
|
|
19885
|
-
var {
|
|
19886
|
-
expression
|
|
19887
|
-
} = preevaluate(raw, {
|
|
19888
|
-
withParent: true,
|
|
19889
|
-
hooks: {
|
|
19890
|
-
beforeVisitGlobal: beforeVisitContextFactory(contexts, variableName)
|
|
19891
|
-
}
|
|
19892
|
-
});
|
|
19893
|
-
var trackCtxExp;
|
|
19894
|
-
if (expression.type === "SequenceExpression" && (trackCtxExp = expression.expressions[0]) && trackCtxExp.type === "Literal" && trackCtxExp.value === trackText) {
|
|
19895
|
-
if (contexts.size > 0) {
|
|
19896
|
-
return Array.from(contexts);
|
|
19897
|
-
} else {
|
|
19898
|
-
// eslint-disable-next-line no-console
|
|
19899
|
-
console.warn("You are using \"".concat(trackText, "\" but no `").concat(variableName, "` usage found in your expression: ").concat(JSON.stringify(raw)));
|
|
19900
|
-
}
|
|
19901
|
-
}
|
|
19902
|
-
}
|
|
19903
|
-
return false;
|
|
19904
|
-
}
|
|
19905
|
-
function trackUsed(data, variableName) {
|
|
19906
|
-
var contexts = new Set();
|
|
19907
|
-
visitStoryboardExpressions(data, beforeVisitContextFactory(contexts, variableName), variableName);
|
|
19908
|
-
return Array.from(contexts);
|
|
19909
|
-
}
|
|
19910
|
-
function beforeVisitContextFactory(contexts, variableName) {
|
|
19911
|
-
return function beforeVisitContext(node, parent) {
|
|
19912
|
-
if (node.name === variableName) {
|
|
19913
|
-
var memberParent = parent[parent.length - 1];
|
|
19914
|
-
if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
|
|
19915
|
-
var memberNode = memberParent.node;
|
|
19916
|
-
if (!memberNode.computed && memberNode.property.type === "Identifier") {
|
|
19917
|
-
contexts.add(memberNode.property.name);
|
|
19918
|
-
} else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
|
|
19919
|
-
contexts.add(memberNode.property.value);
|
|
19920
|
-
}
|
|
19921
|
-
}
|
|
19922
|
-
}
|
|
19923
|
-
};
|
|
19924
|
-
}
|
|
19925
|
-
|
|
19926
20030
|
// The debounce function receives our function as a parameter
|
|
19927
20031
|
function debounceByAnimationFrame(fn) {
|
|
19928
20032
|
// This holds the requestAnimationFrame reference, so we can cancel it if we wish
|
|
@@ -20227,5 +20331,5 @@ function isConstantLogical(node, expect, options) {
|
|
|
20227
20331
|
return node.type === "LogicalExpression" ? node.operator === (expect ? "||" : "&&") && [node.left, node.right].some(item => isConstantLogical(item, expect, options)) : node.type === "UnaryExpression" ? node.operator === "!" && isConstantLogical(node.argument, !expect, options) : node.type === "Literal" ? !!node.value === expect : node.type === "Identifier" ? node.name === "undefined" ? !expect : false : constantFeatureFlags && node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "FLAGS" && (node.computed ? node.property.type === "Literal" && typeof node.property.value === "string" && !!featureFlags[node.property.value] === expect : node.property.type === "Identifier" && !!featureFlags[node.property.name] === expect);
|
|
20228
20332
|
}
|
|
20229
20333
|
|
|
20230
|
-
export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, collectBricksByCustomTemplates, computeConstantCondition, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, debounceByAnimationFrame, deepFreeze, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject$1 as isObject, isRouteNode, isSnippetNode, lint, loadScript, makeThrottledAggregation, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseBrick, parseForAnalysis, parseRoutes, parseStoryboard, parseTemplate, parseTemplates, precook, precookFunction, preevaluate, prefetchScript, removeDeadConditions, removeDeadConditionsInTpl, resolveContextConcurrently, restoreDynamicTemplates, scanAppGetMenuInAny, scanAppGetMenuInStoryboard, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanInstalledAppsInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanStoryboardAst, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackContext, trackFormState, trackState, trackUsedContext, trackUsedState, transform, transformAndInject, traverse, traverseStoryboard, visitStoryboardExpressions, visitStoryboardFunctions };
|
|
20334
|
+
export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, collectBricksByCustomTemplates, collectContextUsage, computeConstantCondition, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, debounceByAnimationFrame, deepFreeze, deferResolveContextConcurrently, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject$1 as isObject, isRouteNode, isSnippetNode, lint, loadScript, makeThrottledAggregation, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseBrick, parseForAnalysis, parseRoutes, parseStoryboard, parseTemplate, parseTemplates, precook, precookFunction, preevaluate, prefetchScript, removeDeadConditions, removeDeadConditionsInTpl, resolveContextConcurrently, restoreDynamicTemplates, scanAppGetMenuInAny, scanAppGetMenuInStoryboard, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanInstalledAppsInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanStoryboardAst, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackContext, trackFormState, trackState, trackUsedContext, trackUsedState, transform, transformAndInject, traverse, traverseStoryboard, visitStoryboardExpressions, visitStoryboardFunctions };
|
|
20231
20335
|
//# sourceMappingURL=index.esm.js.map
|