@next-core/brick-utils 2.33.1 → 2.34.0
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/CHANGELOG.md +12 -0
- package/dist/index.bundle.js +69 -19
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +68 -20
- package/dist/index.esm.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/resolveContextConcurrently.d.ts +1 -0
- package/dist/types/{trackContext.d.ts → track.d.ts} +1 -0
- package/dist/types/{trackContext.spec.d.ts → track.spec.d.ts} +0 -0
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -21429,7 +21429,7 @@ var {
|
|
|
21429
21429
|
convertUnitValueByPrecision: convertValueByPrecision
|
|
21430
21430
|
} = utils;
|
|
21431
21431
|
|
|
21432
|
-
var CTX
|
|
21432
|
+
var CTX = "CTX";
|
|
21433
21433
|
function resolveContextConcurrently(_x, _x2) {
|
|
21434
21434
|
return _resolveContextConcurrently.apply(this, arguments);
|
|
21435
21435
|
}
|
|
@@ -21469,10 +21469,7 @@ function _resolveContextConcurrently() {
|
|
|
21469
21469
|
|
|
21470
21470
|
function _scheduleNext() {
|
|
21471
21471
|
_scheduleNext = _asyncToGenerator(function* () {
|
|
21472
|
-
var readyContexts = Array.from(dependencyMap.entries()).filter((
|
|
21473
|
-
// So make them process sequentially, keep the same behavior as before.
|
|
21474
|
-
scheduleAsSerial ? index === 0 : // A context is ready when it has no pending dependencies.
|
|
21475
|
-
!entry[1].dependencies.some(dep => pendingDeps.has(dep))).map(entry => entry[0]).filter(contextConf => !processed.has(contextConf));
|
|
21472
|
+
var readyContexts = Array.from(dependencyMap.entries()).filter(predicateNextResolveFactory(pendingDeps, scheduleAsSerial)).map(entry => entry[0]).filter(contextConf => !processed.has(contextConf));
|
|
21476
21473
|
yield Promise.all(readyContexts.map(wrapResolve));
|
|
21477
21474
|
});
|
|
21478
21475
|
return _scheduleNext.apply(this, arguments);
|
|
@@ -21495,20 +21492,66 @@ function _resolveContextConcurrently() {
|
|
|
21495
21492
|
return _resolveContextConcurrently.apply(this, arguments);
|
|
21496
21493
|
}
|
|
21497
21494
|
|
|
21495
|
+
function syncResolveContextConcurrently(contextConfs, resolveContext) {
|
|
21496
|
+
var dependencyMap = getDependencyMapOfContext(contextConfs);
|
|
21497
|
+
var pendingDeps = new Set(Array.from(dependencyMap.keys()).map(contextConf => contextConf.name));
|
|
21498
|
+
var includesComputed = Array.from(dependencyMap.values()).some(stats => stats.includesComputed);
|
|
21499
|
+
var scheduleAsSerial = includesComputed;
|
|
21500
|
+
|
|
21501
|
+
function scheduleNext() {
|
|
21502
|
+
var dep = Array.from(dependencyMap.entries()).find(predicateNextResolveFactory(pendingDeps, scheduleAsSerial));
|
|
21503
|
+
|
|
21504
|
+
if (dep) {
|
|
21505
|
+
var [_contextConf] = dep;
|
|
21506
|
+
var resolved = resolveContext(_contextConf);
|
|
21507
|
+
dependencyMap.delete(_contextConf);
|
|
21508
|
+
|
|
21509
|
+
if (resolved) {
|
|
21510
|
+
if (!pendingDeps.delete(_contextConf.name)) {
|
|
21511
|
+
throw new Error("Duplicated context defined: ".concat(_contextConf.name));
|
|
21512
|
+
}
|
|
21513
|
+
}
|
|
21514
|
+
|
|
21515
|
+
scheduleNext();
|
|
21516
|
+
}
|
|
21517
|
+
}
|
|
21518
|
+
|
|
21519
|
+
scheduleNext(); // If there are still contexts left, it implies one of these situations:
|
|
21520
|
+
// - Circular contexts.
|
|
21521
|
+
// Such as: a depends on b, while b depends on a.
|
|
21522
|
+
// - Related contexts are all ignored.
|
|
21523
|
+
// Such as: a depends on b,
|
|
21524
|
+
// while both them are ignore by a falsy result of `if`.
|
|
21525
|
+
|
|
21526
|
+
if (dependencyMap.size > 0) {
|
|
21527
|
+
// This will throw if circular contexts detected.
|
|
21528
|
+
detectCircularContexts(dependencyMap);
|
|
21529
|
+
scheduleAsSerial = true;
|
|
21530
|
+
scheduleNext();
|
|
21531
|
+
}
|
|
21532
|
+
}
|
|
21533
|
+
|
|
21534
|
+
function predicateNextResolveFactory(pendingDeps, scheduleAsSerial) {
|
|
21535
|
+
return (entry, index) => // When contexts contain computed CTX accesses, it implies a dynamic dependency map.
|
|
21536
|
+
// So make them process sequentially, keep the same behavior as before.
|
|
21537
|
+
scheduleAsSerial ? index === 0 : // A context is ready when it has no pending dependencies.
|
|
21538
|
+
!entry[1].dependencies.some(dep => pendingDeps.has(dep));
|
|
21539
|
+
}
|
|
21540
|
+
|
|
21498
21541
|
function getDependencyMapOfContext(contextConfs) {
|
|
21499
21542
|
var depsMap = new Map();
|
|
21500
21543
|
|
|
21501
|
-
for (var
|
|
21544
|
+
for (var _contextConf2 of contextConfs) {
|
|
21502
21545
|
var stats = {
|
|
21503
21546
|
dependencies: [],
|
|
21504
21547
|
includesComputed: false
|
|
21505
21548
|
};
|
|
21506
21549
|
|
|
21507
|
-
if (!
|
|
21508
|
-
visitStoryboardExpressions([
|
|
21550
|
+
if (!_contextConf2.property) {
|
|
21551
|
+
visitStoryboardExpressions([_contextConf2.if, _contextConf2.value, _contextConf2.resolve], beforeVisitContextFactory(stats), CTX);
|
|
21509
21552
|
}
|
|
21510
21553
|
|
|
21511
|
-
depsMap.set(
|
|
21554
|
+
depsMap.set(_contextConf2, stats);
|
|
21512
21555
|
}
|
|
21513
21556
|
|
|
21514
21557
|
return depsMap;
|
|
@@ -21516,7 +21559,7 @@ function getDependencyMapOfContext(contextConfs) {
|
|
|
21516
21559
|
|
|
21517
21560
|
function beforeVisitContextFactory(stats) {
|
|
21518
21561
|
return function beforeVisitContext(node, parent) {
|
|
21519
|
-
if (node.name === CTX
|
|
21562
|
+
if (node.name === CTX) {
|
|
21520
21563
|
var memberParent = parent[parent.length - 1];
|
|
21521
21564
|
|
|
21522
21565
|
if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
|
|
@@ -21546,10 +21589,10 @@ function detectCircularContexts(dependencyMap) {
|
|
|
21546
21589
|
var next = () => {
|
|
21547
21590
|
var processedAtLeastOne = false;
|
|
21548
21591
|
|
|
21549
|
-
for (var [
|
|
21592
|
+
for (var [_contextConf3, stats] of duplicatedMap.entries()) {
|
|
21550
21593
|
if (!stats.dependencies.some(dep => pendingDeps.has(dep))) {
|
|
21551
|
-
duplicatedMap.delete(
|
|
21552
|
-
pendingDeps.delete(
|
|
21594
|
+
duplicatedMap.delete(_contextConf3);
|
|
21595
|
+
pendingDeps.delete(_contextConf3.name);
|
|
21553
21596
|
processedAtLeastOne = true;
|
|
21554
21597
|
}
|
|
21555
21598
|
}
|
|
@@ -21808,8 +21851,6 @@ function deepFreeze(object) {
|
|
|
21808
21851
|
return Object.freeze(object);
|
|
21809
21852
|
}
|
|
21810
21853
|
|
|
21811
|
-
var TRACK_CONTEXT = "track context";
|
|
21812
|
-
var CTX = "CTX";
|
|
21813
21854
|
/**
|
|
21814
21855
|
* Get tracking CTX for an evaluable expression in `track context` mode.
|
|
21815
21856
|
*
|
|
@@ -21838,7 +21879,14 @@ var CTX = "CTX";
|
|
|
21838
21879
|
*/
|
|
21839
21880
|
|
|
21840
21881
|
function trackContext(raw) {
|
|
21841
|
-
|
|
21882
|
+
return track(raw, "track context", "CTX");
|
|
21883
|
+
}
|
|
21884
|
+
function trackState(raw) {
|
|
21885
|
+
return track(raw, "track state", "STATE");
|
|
21886
|
+
}
|
|
21887
|
+
|
|
21888
|
+
function track(raw, trackText, variableName) {
|
|
21889
|
+
if (raw.includes(trackText)) {
|
|
21842
21890
|
var contexts = new Set();
|
|
21843
21891
|
var {
|
|
21844
21892
|
expression
|
|
@@ -21846,7 +21894,7 @@ function trackContext(raw) {
|
|
|
21846
21894
|
withParent: true,
|
|
21847
21895
|
hooks: {
|
|
21848
21896
|
beforeVisitGlobal(node, parent) {
|
|
21849
|
-
if (node.name ===
|
|
21897
|
+
if (node.name === variableName) {
|
|
21850
21898
|
var memberParent = parent[parent.length - 1];
|
|
21851
21899
|
|
|
21852
21900
|
if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
|
|
@@ -21865,12 +21913,12 @@ function trackContext(raw) {
|
|
|
21865
21913
|
});
|
|
21866
21914
|
var trackCtxExp;
|
|
21867
21915
|
|
|
21868
|
-
if (expression.type === "SequenceExpression" && (trackCtxExp = expression.expressions[0]) && trackCtxExp.type === "Literal" && trackCtxExp.value ===
|
|
21916
|
+
if (expression.type === "SequenceExpression" && (trackCtxExp = expression.expressions[0]) && trackCtxExp.type === "Literal" && trackCtxExp.value === trackText) {
|
|
21869
21917
|
if (contexts.size > 0) {
|
|
21870
21918
|
return Array.from(contexts);
|
|
21871
21919
|
} else {
|
|
21872
21920
|
// eslint-disable-next-line no-console
|
|
21873
|
-
console.warn("You are using \"".concat(
|
|
21921
|
+
console.warn("You are using \"".concat(trackText, "\" but no `").concat(variableName, "` usage found in your expression: ").concat(JSON.stringify(raw)));
|
|
21874
21922
|
}
|
|
21875
21923
|
}
|
|
21876
21924
|
}
|
|
@@ -21878,5 +21926,5 @@ function trackContext(raw) {
|
|
|
21878
21926
|
return false;
|
|
21879
21927
|
}
|
|
21880
21928
|
|
|
21881
|
-
export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, deepFreeze, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject, isRouteNode, isSnippetNode, lint, loadScript, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseForAnalysis, precook, precookFunction, preevaluate, prefetchScript, resolveContextConcurrently, restoreDynamicTemplates, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, toPath, tokTypes_1 as tokTypes, trackContext, transform, transformAndInject, visitStoryboardExpressions, visitStoryboardFunctions };
|
|
21929
|
+
export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, deepFreeze, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject, isRouteNode, isSnippetNode, lint, loadScript, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseForAnalysis, precook, precookFunction, preevaluate, prefetchScript, resolveContextConcurrently, restoreDynamicTemplates, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackContext, trackState, transform, transformAndInject, visitStoryboardExpressions, visitStoryboardFunctions };
|
|
21882
21930
|
//# sourceMappingURL=index.esm.js.map
|