@next-core/brick-utils 2.31.5 → 2.32.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/dist/index.esm.js CHANGED
@@ -19331,6 +19331,59 @@ function noop() {
19331
19331
  /* noop */
19332
19332
  }
19333
19333
 
19334
+ function visitStoryboardFunctions(functions, beforeVisitGlobal) {
19335
+ if (Array.isArray(functions)) {
19336
+ for (var fn of functions) {
19337
+ try {
19338
+ precookFunction(fn.source, {
19339
+ typescript: fn.typescript,
19340
+ withParent: true,
19341
+ hooks: {
19342
+ beforeVisitGlobal
19343
+ }
19344
+ });
19345
+ } catch (error) {
19346
+ // eslint-disable-next-line no-console
19347
+ console.error("Parse storyboard function \"".concat(fn.name, "\" failed:"), error);
19348
+ }
19349
+ }
19350
+ }
19351
+ }
19352
+ function visitStoryboardExpressions(data, beforeVisitGlobal, keyword) {
19353
+ var memo = new WeakSet();
19354
+
19355
+ function visit(value) {
19356
+ if (typeof value === "string") {
19357
+ if (value.includes(keyword) && isEvaluable(value)) {
19358
+ try {
19359
+ preevaluate(value, {
19360
+ withParent: true,
19361
+ hooks: {
19362
+ beforeVisitGlobal
19363
+ }
19364
+ });
19365
+ } catch (error) {
19366
+ // eslint-disable-next-line no-console
19367
+ console.error("Parse storyboard expression failed:", error);
19368
+ }
19369
+ }
19370
+ } else if (isObject(value)) {
19371
+ // Avoid call stack overflow.
19372
+ if (memo.has(value)) {
19373
+ return;
19374
+ }
19375
+
19376
+ memo.add(value);
19377
+
19378
+ for (var item of Array.isArray(value) ? value : Object.values(value)) {
19379
+ visit(item);
19380
+ }
19381
+ }
19382
+ }
19383
+
19384
+ visit(data);
19385
+ }
19386
+
19334
19387
  var PROCESSORS = "PROCESSORS";
19335
19388
  function scanProcessorsInStoryboard(storyboard) {
19336
19389
  var _storyboard$meta;
@@ -19341,50 +19394,21 @@ function scanProcessorsInStoryboard(storyboard) {
19341
19394
  function scanProcessorsInAny(data) {
19342
19395
  var isUniq = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
19343
19396
  var collection = [];
19344
- collectProcessors(data, collection);
19397
+ visitStoryboardExpressions(data, beforeVisitProcessorsFactory(collection), PROCESSORS);
19345
19398
  return isUniq ? uniq(collection) : collection;
19346
19399
  }
19347
19400
 
19348
- function collectProcessors(data, collection) {
19349
- var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
19350
-
19351
- if (typeof data === "string") {
19352
- if (data.includes(PROCESSORS) && isEvaluable(data)) {
19353
- preevaluate(data, {
19354
- withParent: true,
19355
- hooks: {
19356
- beforeVisitGlobal(node, parent) {
19357
- if (node.name === PROCESSORS) {
19358
- var memberParent = parent[parent.length - 1];
19359
- var outerMemberParent = parent[parent.length - 2];
19360
-
19361
- if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object" && !memberParent.node.computed && memberParent.node.property.type === "Identifier" && (outerMemberParent === null || outerMemberParent === void 0 ? void 0 : outerMemberParent.node.type) === "MemberExpression" && outerMemberParent.key === "object" && !outerMemberParent.node.computed && outerMemberParent.node.property.type === "Identifier") {
19362
- collection.push("".concat(memberParent.node.property.name, ".").concat(outerMemberParent.node.property.name));
19363
- }
19364
- }
19365
- }
19401
+ function beforeVisitProcessorsFactory(collection) {
19402
+ return function beforeVisitProcessors(node, parent) {
19403
+ if (node.name === PROCESSORS) {
19404
+ var memberParent = parent[parent.length - 1];
19405
+ var outerMemberParent = parent[parent.length - 2];
19366
19406
 
19367
- }
19368
- });
19369
- }
19370
- } else if (isObject(data)) {
19371
- // Avoid call stack overflow.
19372
- if (memo.has(data)) {
19373
- return;
19374
- }
19375
-
19376
- memo.add(data);
19377
-
19378
- if (Array.isArray(data)) {
19379
- for (var item of data) {
19380
- collectProcessors(item, collection, memo);
19381
- }
19382
- } else {
19383
- for (var _item of Object.values(data)) {
19384
- collectProcessors(_item, collection, memo);
19407
+ if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object" && !memberParent.node.computed && memberParent.node.property.type === "Identifier" && (outerMemberParent === null || outerMemberParent === void 0 ? void 0 : outerMemberParent.node.type) === "MemberExpression" && outerMemberParent.key === "object" && !outerMemberParent.node.computed && outerMemberParent.node.property.type === "Identifier") {
19408
+ collection.push("".concat(memberParent.node.property.name, ".").concat(outerMemberParent.node.property.name));
19385
19409
  }
19386
19410
  }
19387
- }
19411
+ };
19388
19412
  }
19389
19413
 
19390
19414
  function getDllAndDepsOfStoryboard(storyboard, brickPackages, options) {
@@ -20137,58 +20161,37 @@ var check = "check";
20137
20161
  function scanPermissionActionsInStoryboard(storyboard) {
20138
20162
  var _storyboard$meta;
20139
20163
 
20140
- return scanPermissionActionsInAny([storyboard.routes, (_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.customTemplates]);
20164
+ var collection = new Set();
20165
+ var beforeVisitPermissions = beforeVisitPermissionsFactory(collection);
20166
+ var {
20167
+ customTemplates,
20168
+ functions
20169
+ } = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
20170
+ visitStoryboardExpressions([storyboard.routes, customTemplates], beforeVisitPermissions, PERMISSIONS);
20171
+ visitStoryboardFunctions(functions, beforeVisitPermissions);
20172
+ return Array.from(collection);
20141
20173
  }
20142
20174
  function scanPermissionActionsInAny(data) {
20143
20175
  var collection = new Set();
20144
- collectPermissionActions(data, collection);
20176
+ visitStoryboardExpressions(data, beforeVisitPermissionsFactory(collection), PERMISSIONS);
20145
20177
  return Array.from(collection);
20146
20178
  }
20147
20179
 
20148
- function collectPermissionActions(data, collection) {
20149
- var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
20150
-
20151
- if (typeof data === "string") {
20152
- if (data.includes(PERMISSIONS) && isEvaluable(data)) {
20153
- preevaluate(data, {
20154
- withParent: true,
20155
- hooks: {
20156
- beforeVisitGlobal(node, parent) {
20157
- if (node.name === PERMISSIONS) {
20158
- var memberParent = parent[parent.length - 1];
20159
- var callParent = parent[parent.length - 2];
20160
-
20161
- if ((callParent === null || callParent === void 0 ? void 0 : callParent.node.type) === "CallExpression" && (callParent === null || callParent === void 0 ? void 0 : callParent.key) === "callee" && (memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object" && !memberParent.node.computed && memberParent.node.property.type === "Identifier" && memberParent.node.property.name === check) {
20162
- for (var arg of callParent.node.arguments) {
20163
- if (arg.type === "Literal" && typeof arg.value === "string") {
20164
- collection.add(arg.value);
20165
- }
20166
- }
20167
- }
20168
- }
20169
- }
20180
+ function beforeVisitPermissionsFactory(collection) {
20181
+ return function beforeVisitPermissions(node, parent) {
20182
+ if (node.name === PERMISSIONS) {
20183
+ var memberParent = parent[parent.length - 1];
20184
+ var callParent = parent[parent.length - 2];
20170
20185
 
20186
+ if ((callParent === null || callParent === void 0 ? void 0 : callParent.node.type) === "CallExpression" && (callParent === null || callParent === void 0 ? void 0 : callParent.key) === "callee" && (memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object" && !memberParent.node.computed && memberParent.node.property.type === "Identifier" && memberParent.node.property.name === check) {
20187
+ for (var arg of callParent.node.arguments) {
20188
+ if (arg.type === "Literal" && typeof arg.value === "string") {
20189
+ collection.add(arg.value);
20190
+ }
20171
20191
  }
20172
- });
20173
- }
20174
- } else if (isObject(data)) {
20175
- // Avoid call stack overflow.
20176
- if (memo.has(data)) {
20177
- return;
20178
- }
20179
-
20180
- memo.add(data);
20181
-
20182
- if (Array.isArray(data)) {
20183
- for (var item of data) {
20184
- collectPermissionActions(item, collection, memo);
20185
- }
20186
- } else {
20187
- for (var _item of Object.values(data)) {
20188
- collectPermissionActions(_item, collection, memo);
20189
20192
  }
20190
20193
  }
20191
- }
20194
+ };
20192
20195
  }
20193
20196
 
20194
20197
  function scanRouteAliasInStoryboard(storyboard) {
@@ -20248,69 +20251,25 @@ function scanI18NInStoryboard(storyboard) {
20248
20251
  var _storyboard$meta;
20249
20252
 
20250
20253
  var collection = new Map();
20251
- var beforeVisitGlobal = beforeVisitGlobalFactory(collection); // Notice: `menus` may contain evaluations of I18N too.
20254
+ var beforeVisitI18n = beforeVisitI18nFactory(collection); // Notice: `menus` may contain evaluations of I18N too.
20252
20255
 
20253
20256
  var {
20254
20257
  customTemplates,
20255
20258
  menus,
20256
20259
  functions
20257
20260
  } = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
20258
- collectI18N([storyboard.routes, customTemplates, menus], beforeVisitGlobal);
20259
-
20260
- if (Array.isArray(functions)) {
20261
- for (var fn of functions) {
20262
- precookFunction(fn.source, {
20263
- typescript: fn.typescript,
20264
- withParent: true,
20265
- hooks: {
20266
- beforeVisitGlobal
20267
- }
20268
- });
20269
- }
20270
- }
20271
-
20261
+ visitStoryboardExpressions([storyboard.routes, customTemplates, menus], beforeVisitI18n, I18N);
20262
+ visitStoryboardFunctions(functions, beforeVisitI18n);
20272
20263
  return collection;
20273
20264
  }
20274
20265
  function scanI18NInAny(data) {
20275
20266
  var collection = new Map();
20276
- collectI18N(data, beforeVisitGlobalFactory(collection));
20267
+ visitStoryboardExpressions(data, beforeVisitI18nFactory(collection), I18N);
20277
20268
  return collection;
20278
20269
  }
20279
20270
 
20280
- function collectI18N(data, beforeVisitGlobal) {
20281
- var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
20282
-
20283
- if (typeof data === "string") {
20284
- if (data.includes(I18N) && isEvaluable(data)) {
20285
- preevaluate(data, {
20286
- withParent: true,
20287
- hooks: {
20288
- beforeVisitGlobal
20289
- }
20290
- });
20291
- }
20292
- } else if (isObject(data)) {
20293
- // Avoid call stack overflow.
20294
- if (memo.has(data)) {
20295
- return;
20296
- }
20297
-
20298
- memo.add(data);
20299
-
20300
- if (Array.isArray(data)) {
20301
- for (var item of data) {
20302
- collectI18N(item, beforeVisitGlobal, memo);
20303
- }
20304
- } else {
20305
- for (var _item of Object.values(data)) {
20306
- collectI18N(_item, beforeVisitGlobal, memo);
20307
- }
20308
- }
20309
- }
20310
- }
20311
-
20312
- function beforeVisitGlobalFactory(collection) {
20313
- return function beforeVisitGlobal(node, parent) {
20271
+ function beforeVisitI18nFactory(collection) {
20272
+ return function beforeVisitI18n(node, parent) {
20314
20273
  if (node.name === I18N) {
20315
20274
  var callParent = parent[parent.length - 1];
20316
20275
 
@@ -20919,6 +20878,7 @@ var {
20919
20878
  convertUnitValueByPrecision: convertValueByPrecision
20920
20879
  } = utils;
20921
20880
 
20881
+ var CTX$1 = "CTX";
20922
20882
  function resolveContextConcurrently(_x, _x2) {
20923
20883
  return _resolveContextConcurrently.apply(this, arguments);
20924
20884
  }
@@ -20994,9 +20954,7 @@ function getDependencyMapOfContext(contextConfs) {
20994
20954
  };
20995
20955
 
20996
20956
  if (!_contextConf.property) {
20997
- collectContexts(_contextConf.if, stats);
20998
- collectContexts(_contextConf.value, stats);
20999
- collectContexts(_contextConf.resolve, stats);
20957
+ visitStoryboardExpressions([_contextConf.if, _contextConf.value, _contextConf.resolve], beforeVisitContextFactory(stats), CTX$1);
21000
20958
  }
21001
20959
 
21002
20960
  depsMap.set(_contextConf, stats);
@@ -21004,60 +20962,30 @@ function getDependencyMapOfContext(contextConfs) {
21004
20962
 
21005
20963
  return depsMap;
21006
20964
  }
21007
- var CTX$1 = "CTX";
21008
20965
 
21009
- function collectContexts(data, stats) {
21010
- var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
21011
-
21012
- if (typeof data === "string") {
21013
- if (data.includes(CTX$1) && isEvaluable(data)) {
21014
- preevaluate(data, {
21015
- withParent: true,
21016
- hooks: {
21017
- beforeVisitGlobal(node, parent) {
21018
- if (node.name === CTX$1) {
21019
- var memberParent = parent[parent.length - 1];
21020
-
21021
- if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
21022
- var memberNode = memberParent.node;
21023
- var dep;
21024
-
21025
- if (!memberNode.computed && memberNode.property.type === "Identifier") {
21026
- dep = memberNode.property.name;
21027
- } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
21028
- dep = memberNode.property.value;
21029
- } else {
21030
- stats.includesComputed = true;
21031
- }
20966
+ function beforeVisitContextFactory(stats) {
20967
+ return function beforeVisitContext(node, parent) {
20968
+ if (node.name === CTX$1) {
20969
+ var memberParent = parent[parent.length - 1];
21032
20970
 
21033
- if (dep !== undefined && !stats.dependencies.includes(dep)) {
21034
- stats.dependencies.push(dep);
21035
- }
21036
- }
21037
- }
21038
- }
20971
+ if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
20972
+ var memberNode = memberParent.node;
20973
+ var dep;
21039
20974
 
20975
+ if (!memberNode.computed && memberNode.property.type === "Identifier") {
20976
+ dep = memberNode.property.name;
20977
+ } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
20978
+ dep = memberNode.property.value;
20979
+ } else {
20980
+ stats.includesComputed = true;
21040
20981
  }
21041
- });
21042
- }
21043
- } else if (isObject(data)) {
21044
- // Avoid call stack overflow.
21045
- if (memo.has(data)) {
21046
- return;
21047
- }
21048
20982
 
21049
- memo.add(data);
21050
-
21051
- if (Array.isArray(data)) {
21052
- for (var item of data) {
21053
- collectContexts(item, stats, memo);
21054
- }
21055
- } else {
21056
- for (var _item of Object.values(data)) {
21057
- collectContexts(_item, stats, memo);
20983
+ if (dep !== undefined && !stats.dependencies.includes(dep)) {
20984
+ stats.dependencies.push(dep);
20985
+ }
21058
20986
  }
21059
20987
  }
21060
- }
20988
+ };
21061
20989
  }
21062
20990
 
21063
20991
  function detectCircularContexts(dependencyMap) {
@@ -21399,5 +21327,5 @@ function trackContext(raw) {
21399
21327
  return false;
21400
21328
  }
21401
21329
 
21402
- 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 };
21330
+ 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 };
21403
21331
  //# sourceMappingURL=index.esm.js.map