@next-core/brick-utils 2.31.4 → 2.32.2

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,70 @@ 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, // If `options` is a string, it means the *keyword*.
19353
+ options) {
19354
+ var memo = new WeakSet();
19355
+ var {
19356
+ matchExpressionString,
19357
+ visitNonExpressionString,
19358
+ visitObject
19359
+ } = typeof options === "string" ? {
19360
+ matchExpressionString: v => v.includes(options)
19361
+ } : options;
19362
+
19363
+ function visit(value) {
19364
+ if (typeof value === "string") {
19365
+ if (matchExpressionString(value) && isEvaluable(value)) {
19366
+ try {
19367
+ preevaluate(value, {
19368
+ withParent: true,
19369
+ hooks: {
19370
+ beforeVisitGlobal
19371
+ }
19372
+ });
19373
+ } catch (error) {
19374
+ // eslint-disable-next-line no-console
19375
+ console.error("Parse storyboard expression failed:", error);
19376
+ }
19377
+ } else {
19378
+ visitNonExpressionString === null || visitNonExpressionString === void 0 ? void 0 : visitNonExpressionString(value);
19379
+ }
19380
+ } else if (isObject(value)) {
19381
+ // Avoid call stack overflow.
19382
+ if (memo.has(value)) {
19383
+ return;
19384
+ }
19385
+
19386
+ memo.add(value);
19387
+ visitObject === null || visitObject === void 0 ? void 0 : visitObject(value);
19388
+
19389
+ for (var item of Array.isArray(value) ? value : Object.values(value)) {
19390
+ visit(item);
19391
+ }
19392
+ }
19393
+ }
19394
+
19395
+ visit(data);
19396
+ }
19397
+
19334
19398
  var PROCESSORS = "PROCESSORS";
19335
19399
  function scanProcessorsInStoryboard(storyboard) {
19336
19400
  var _storyboard$meta;
@@ -19341,50 +19405,21 @@ function scanProcessorsInStoryboard(storyboard) {
19341
19405
  function scanProcessorsInAny(data) {
19342
19406
  var isUniq = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
19343
19407
  var collection = [];
19344
- collectProcessors(data, collection);
19408
+ visitStoryboardExpressions(data, beforeVisitProcessorsFactory(collection), PROCESSORS);
19345
19409
  return isUniq ? uniq(collection) : collection;
19346
19410
  }
19347
19411
 
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
- }
19366
-
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);
19412
+ function beforeVisitProcessorsFactory(collection) {
19413
+ return function beforeVisitProcessors(node, parent) {
19414
+ if (node.name === PROCESSORS) {
19415
+ var memberParent = parent[parent.length - 1];
19416
+ var outerMemberParent = parent[parent.length - 2];
19377
19417
 
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);
19418
+ 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") {
19419
+ collection.push("".concat(memberParent.node.property.name, ".").concat(outerMemberParent.node.property.name));
19385
19420
  }
19386
19421
  }
19387
- }
19422
+ };
19388
19423
  }
19389
19424
 
19390
19425
  function getDllAndDepsOfStoryboard(storyboard, brickPackages, options) {
@@ -20137,58 +20172,37 @@ var check = "check";
20137
20172
  function scanPermissionActionsInStoryboard(storyboard) {
20138
20173
  var _storyboard$meta;
20139
20174
 
20140
- return scanPermissionActionsInAny([storyboard.routes, (_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.customTemplates]);
20175
+ var collection = new Set();
20176
+ var beforeVisitPermissions = beforeVisitPermissionsFactory(collection);
20177
+ var {
20178
+ customTemplates,
20179
+ functions
20180
+ } = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
20181
+ visitStoryboardExpressions([storyboard.routes, customTemplates], beforeVisitPermissions, PERMISSIONS);
20182
+ visitStoryboardFunctions(functions, beforeVisitPermissions);
20183
+ return Array.from(collection);
20141
20184
  }
20142
20185
  function scanPermissionActionsInAny(data) {
20143
20186
  var collection = new Set();
20144
- collectPermissionActions(data, collection);
20187
+ visitStoryboardExpressions(data, beforeVisitPermissionsFactory(collection), PERMISSIONS);
20145
20188
  return Array.from(collection);
20146
20189
  }
20147
20190
 
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
- }
20191
+ function beforeVisitPermissionsFactory(collection) {
20192
+ return function beforeVisitPermissions(node, parent) {
20193
+ if (node.name === PERMISSIONS) {
20194
+ var memberParent = parent[parent.length - 1];
20195
+ var callParent = parent[parent.length - 2];
20170
20196
 
20197
+ 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) {
20198
+ for (var arg of callParent.node.arguments) {
20199
+ if (arg.type === "Literal" && typeof arg.value === "string") {
20200
+ collection.add(arg.value);
20201
+ }
20171
20202
  }
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
20203
  }
20190
20204
  }
20191
- }
20205
+ };
20192
20206
  }
20193
20207
 
20194
20208
  function scanRouteAliasInStoryboard(storyboard) {
@@ -20248,69 +20262,25 @@ function scanI18NInStoryboard(storyboard) {
20248
20262
  var _storyboard$meta;
20249
20263
 
20250
20264
  var collection = new Map();
20251
- var beforeVisitGlobal = beforeVisitGlobalFactory(collection); // Notice: `menus` may contain evaluations of I18N too.
20265
+ var beforeVisitI18n = beforeVisitI18nFactory(collection); // Notice: `menus` may contain evaluations of I18N too.
20252
20266
 
20253
20267
  var {
20254
20268
  customTemplates,
20255
20269
  menus,
20256
20270
  functions
20257
20271
  } = (_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
-
20272
+ visitStoryboardExpressions([storyboard.routes, customTemplates, menus], beforeVisitI18n, I18N);
20273
+ visitStoryboardFunctions(functions, beforeVisitI18n);
20272
20274
  return collection;
20273
20275
  }
20274
20276
  function scanI18NInAny(data) {
20275
20277
  var collection = new Map();
20276
- collectI18N(data, beforeVisitGlobalFactory(collection));
20278
+ visitStoryboardExpressions(data, beforeVisitI18nFactory(collection), I18N);
20277
20279
  return collection;
20278
20280
  }
20279
20281
 
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) {
20282
+ function beforeVisitI18nFactory(collection) {
20283
+ return function beforeVisitI18n(node, parent) {
20314
20284
  if (node.name === I18N) {
20315
20285
  var callParent = parent[parent.length - 1];
20316
20286
 
@@ -20919,6 +20889,7 @@ var {
20919
20889
  convertUnitValueByPrecision: convertValueByPrecision
20920
20890
  } = utils;
20921
20891
 
20892
+ var CTX$1 = "CTX";
20922
20893
  function resolveContextConcurrently(_x, _x2) {
20923
20894
  return _resolveContextConcurrently.apply(this, arguments);
20924
20895
  }
@@ -20994,9 +20965,7 @@ function getDependencyMapOfContext(contextConfs) {
20994
20965
  };
20995
20966
 
20996
20967
  if (!_contextConf.property) {
20997
- collectContexts(_contextConf.if, stats);
20998
- collectContexts(_contextConf.value, stats);
20999
- collectContexts(_contextConf.resolve, stats);
20968
+ visitStoryboardExpressions([_contextConf.if, _contextConf.value, _contextConf.resolve], beforeVisitContextFactory(stats), CTX$1);
21000
20969
  }
21001
20970
 
21002
20971
  depsMap.set(_contextConf, stats);
@@ -21004,60 +20973,30 @@ function getDependencyMapOfContext(contextConfs) {
21004
20973
 
21005
20974
  return depsMap;
21006
20975
  }
21007
- var CTX$1 = "CTX";
21008
20976
 
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
- }
20977
+ function beforeVisitContextFactory(stats) {
20978
+ return function beforeVisitContext(node, parent) {
20979
+ if (node.name === CTX$1) {
20980
+ var memberParent = parent[parent.length - 1];
21032
20981
 
21033
- if (dep !== undefined && !stats.dependencies.includes(dep)) {
21034
- stats.dependencies.push(dep);
21035
- }
21036
- }
21037
- }
21038
- }
20982
+ if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
20983
+ var memberNode = memberParent.node;
20984
+ var dep;
21039
20985
 
20986
+ if (!memberNode.computed && memberNode.property.type === "Identifier") {
20987
+ dep = memberNode.property.name;
20988
+ } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
20989
+ dep = memberNode.property.value;
20990
+ } else {
20991
+ stats.includesComputed = true;
21040
20992
  }
21041
- });
21042
- }
21043
- } else if (isObject(data)) {
21044
- // Avoid call stack overflow.
21045
- if (memo.has(data)) {
21046
- return;
21047
- }
21048
20993
 
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);
20994
+ if (dep !== undefined && !stats.dependencies.includes(dep)) {
20995
+ stats.dependencies.push(dep);
20996
+ }
21058
20997
  }
21059
20998
  }
21060
- }
20999
+ };
21061
21000
  }
21062
21001
 
21063
21002
  function detectCircularContexts(dependencyMap) {
@@ -21399,5 +21338,5 @@ function trackContext(raw) {
21399
21338
  return false;
21400
21339
  }
21401
21340
 
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 };
21341
+ 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
21342
  //# sourceMappingURL=index.esm.js.map