@next-core/brick-utils 2.31.3 → 2.32.1

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 CHANGED
@@ -3,6 +3,44 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.32.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.32.0...@next-core/brick-utils@2.32.1) (2021-12-28)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * refine visiting storyboard ([5352ba4](https://github.com/easyops-cn/next-core/commit/5352ba460a333094e74a38257488085ebdad649e))
12
+
13
+
14
+
15
+
16
+
17
+ # [2.32.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.31.5...@next-core/brick-utils@2.32.0) (2021-12-28)
18
+
19
+
20
+ ### Features
21
+
22
+ * refine storyboard functions and expressions ([6626c61](https://github.com/easyops-cn/next-core/commit/6626c61bd910864daaa81be946f765630cfb8103))
23
+
24
+
25
+
26
+
27
+
28
+ ## [2.31.5](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.31.4...@next-core/brick-utils@2.31.5) (2021-12-24)
29
+
30
+ **Note:** Version bump only for package @next-core/brick-utils
31
+
32
+
33
+
34
+
35
+
36
+ ## [2.31.4](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.31.3...@next-core/brick-utils@2.31.4) (2021-12-23)
37
+
38
+ **Note:** Version bump only for package @next-core/brick-utils
39
+
40
+
41
+
42
+
43
+
6
44
  ## [2.31.3](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.31.2...@next-core/brick-utils@2.31.3) (2021-12-17)
7
45
 
8
46
  **Note:** Version bump only for package @next-core/brick-utils
@@ -19336,6 +19336,70 @@
19336
19336
  /* noop */
19337
19337
  }
19338
19338
 
19339
+ function visitStoryboardFunctions(functions, beforeVisitGlobal) {
19340
+ if (Array.isArray(functions)) {
19341
+ for (var fn of functions) {
19342
+ try {
19343
+ precookFunction(fn.source, {
19344
+ typescript: fn.typescript,
19345
+ withParent: true,
19346
+ hooks: {
19347
+ beforeVisitGlobal
19348
+ }
19349
+ });
19350
+ } catch (error) {
19351
+ // eslint-disable-next-line no-console
19352
+ console.error("Parse storyboard function \"".concat(fn.name, "\" failed:"), error);
19353
+ }
19354
+ }
19355
+ }
19356
+ }
19357
+ function visitStoryboardExpressions(data, beforeVisitGlobal, // If `options` is a string, it means the *keyword*.
19358
+ options) {
19359
+ var memo = new WeakSet();
19360
+ var {
19361
+ matchExpressionString,
19362
+ visitNonExpressionString,
19363
+ visitObject
19364
+ } = typeof options === "string" ? {
19365
+ matchExpressionString: v => v.includes(options)
19366
+ } : options;
19367
+
19368
+ function visit(value) {
19369
+ if (typeof value === "string") {
19370
+ if (matchExpressionString(value) && isEvaluable(value)) {
19371
+ try {
19372
+ preevaluate(value, {
19373
+ withParent: true,
19374
+ hooks: {
19375
+ beforeVisitGlobal
19376
+ }
19377
+ });
19378
+ } catch (error) {
19379
+ // eslint-disable-next-line no-console
19380
+ console.error("Parse storyboard expression failed:", error);
19381
+ }
19382
+ } else {
19383
+ visitNonExpressionString === null || visitNonExpressionString === void 0 ? void 0 : visitNonExpressionString(value);
19384
+ }
19385
+ } else if (isObject(value)) {
19386
+ // Avoid call stack overflow.
19387
+ if (memo.has(value)) {
19388
+ return;
19389
+ }
19390
+
19391
+ memo.add(value);
19392
+ visitObject === null || visitObject === void 0 ? void 0 : visitObject(value);
19393
+
19394
+ for (var item of Array.isArray(value) ? value : Object.values(value)) {
19395
+ visit(item);
19396
+ }
19397
+ }
19398
+ }
19399
+
19400
+ visit(data);
19401
+ }
19402
+
19339
19403
  var PROCESSORS = "PROCESSORS";
19340
19404
  function scanProcessorsInStoryboard(storyboard) {
19341
19405
  var _storyboard$meta;
@@ -19346,50 +19410,21 @@
19346
19410
  function scanProcessorsInAny(data) {
19347
19411
  var isUniq = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
19348
19412
  var collection = [];
19349
- collectProcessors(data, collection);
19413
+ visitStoryboardExpressions(data, beforeVisitProcessorsFactory(collection), PROCESSORS);
19350
19414
  return isUniq ? lodash.uniq(collection) : collection;
19351
19415
  }
19352
19416
 
19353
- function collectProcessors(data, collection) {
19354
- var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
19355
-
19356
- if (typeof data === "string") {
19357
- if (data.includes(PROCESSORS) && isEvaluable(data)) {
19358
- preevaluate(data, {
19359
- withParent: true,
19360
- hooks: {
19361
- beforeVisitGlobal(node, parent) {
19362
- if (node.name === PROCESSORS) {
19363
- var memberParent = parent[parent.length - 1];
19364
- var outerMemberParent = parent[parent.length - 2];
19365
-
19366
- 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") {
19367
- collection.push("".concat(memberParent.node.property.name, ".").concat(outerMemberParent.node.property.name));
19368
- }
19369
- }
19370
- }
19371
-
19372
- }
19373
- });
19374
- }
19375
- } else if (isObject(data)) {
19376
- // Avoid call stack overflow.
19377
- if (memo.has(data)) {
19378
- return;
19379
- }
19380
-
19381
- memo.add(data);
19417
+ function beforeVisitProcessorsFactory(collection) {
19418
+ return function beforeVisitProcessors(node, parent) {
19419
+ if (node.name === PROCESSORS) {
19420
+ var memberParent = parent[parent.length - 1];
19421
+ var outerMemberParent = parent[parent.length - 2];
19382
19422
 
19383
- if (Array.isArray(data)) {
19384
- for (var item of data) {
19385
- collectProcessors(item, collection, memo);
19386
- }
19387
- } else {
19388
- for (var _item of Object.values(data)) {
19389
- collectProcessors(_item, collection, memo);
19423
+ 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") {
19424
+ collection.push("".concat(memberParent.node.property.name, ".").concat(outerMemberParent.node.property.name));
19390
19425
  }
19391
19426
  }
19392
- }
19427
+ };
19393
19428
  }
19394
19429
 
19395
19430
  function getDllAndDepsOfStoryboard(storyboard, brickPackages, options) {
@@ -20142,58 +20177,37 @@
20142
20177
  function scanPermissionActionsInStoryboard(storyboard) {
20143
20178
  var _storyboard$meta;
20144
20179
 
20145
- return scanPermissionActionsInAny([storyboard.routes, (_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.customTemplates]);
20180
+ var collection = new Set();
20181
+ var beforeVisitPermissions = beforeVisitPermissionsFactory(collection);
20182
+ var {
20183
+ customTemplates,
20184
+ functions
20185
+ } = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
20186
+ visitStoryboardExpressions([storyboard.routes, customTemplates], beforeVisitPermissions, PERMISSIONS);
20187
+ visitStoryboardFunctions(functions, beforeVisitPermissions);
20188
+ return Array.from(collection);
20146
20189
  }
20147
20190
  function scanPermissionActionsInAny(data) {
20148
20191
  var collection = new Set();
20149
- collectPermissionActions(data, collection);
20192
+ visitStoryboardExpressions(data, beforeVisitPermissionsFactory(collection), PERMISSIONS);
20150
20193
  return Array.from(collection);
20151
20194
  }
20152
20195
 
20153
- function collectPermissionActions(data, collection) {
20154
- var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
20155
-
20156
- if (typeof data === "string") {
20157
- if (data.includes(PERMISSIONS) && isEvaluable(data)) {
20158
- preevaluate(data, {
20159
- withParent: true,
20160
- hooks: {
20161
- beforeVisitGlobal(node, parent) {
20162
- if (node.name === PERMISSIONS) {
20163
- var memberParent = parent[parent.length - 1];
20164
- var callParent = parent[parent.length - 2];
20165
-
20166
- 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) {
20167
- for (var arg of callParent.node.arguments) {
20168
- if (arg.type === "Literal" && typeof arg.value === "string") {
20169
- collection.add(arg.value);
20170
- }
20171
- }
20172
- }
20173
- }
20174
- }
20196
+ function beforeVisitPermissionsFactory(collection) {
20197
+ return function beforeVisitPermissions(node, parent) {
20198
+ if (node.name === PERMISSIONS) {
20199
+ var memberParent = parent[parent.length - 1];
20200
+ var callParent = parent[parent.length - 2];
20175
20201
 
20202
+ 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) {
20203
+ for (var arg of callParent.node.arguments) {
20204
+ if (arg.type === "Literal" && typeof arg.value === "string") {
20205
+ collection.add(arg.value);
20206
+ }
20176
20207
  }
20177
- });
20178
- }
20179
- } else if (isObject(data)) {
20180
- // Avoid call stack overflow.
20181
- if (memo.has(data)) {
20182
- return;
20183
- }
20184
-
20185
- memo.add(data);
20186
-
20187
- if (Array.isArray(data)) {
20188
- for (var item of data) {
20189
- collectPermissionActions(item, collection, memo);
20190
- }
20191
- } else {
20192
- for (var _item of Object.values(data)) {
20193
- collectPermissionActions(_item, collection, memo);
20194
20208
  }
20195
20209
  }
20196
- }
20210
+ };
20197
20211
  }
20198
20212
 
20199
20213
  function scanRouteAliasInStoryboard(storyboard) {
@@ -20253,69 +20267,25 @@
20253
20267
  var _storyboard$meta;
20254
20268
 
20255
20269
  var collection = new Map();
20256
- var beforeVisitGlobal = beforeVisitGlobalFactory(collection); // Notice: `menus` may contain evaluations of I18N too.
20270
+ var beforeVisitI18n = beforeVisitI18nFactory(collection); // Notice: `menus` may contain evaluations of I18N too.
20257
20271
 
20258
20272
  var {
20259
20273
  customTemplates,
20260
20274
  menus,
20261
20275
  functions
20262
20276
  } = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
20263
- collectI18N([storyboard.routes, customTemplates, menus], beforeVisitGlobal);
20264
-
20265
- if (Array.isArray(functions)) {
20266
- for (var fn of functions) {
20267
- precookFunction(fn.source, {
20268
- typescript: fn.typescript,
20269
- withParent: true,
20270
- hooks: {
20271
- beforeVisitGlobal
20272
- }
20273
- });
20274
- }
20275
- }
20276
-
20277
+ visitStoryboardExpressions([storyboard.routes, customTemplates, menus], beforeVisitI18n, I18N);
20278
+ visitStoryboardFunctions(functions, beforeVisitI18n);
20277
20279
  return collection;
20278
20280
  }
20279
20281
  function scanI18NInAny(data) {
20280
20282
  var collection = new Map();
20281
- collectI18N(data, beforeVisitGlobalFactory(collection));
20283
+ visitStoryboardExpressions(data, beforeVisitI18nFactory(collection), I18N);
20282
20284
  return collection;
20283
20285
  }
20284
20286
 
20285
- function collectI18N(data, beforeVisitGlobal) {
20286
- var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
20287
-
20288
- if (typeof data === "string") {
20289
- if (data.includes(I18N) && isEvaluable(data)) {
20290
- preevaluate(data, {
20291
- withParent: true,
20292
- hooks: {
20293
- beforeVisitGlobal
20294
- }
20295
- });
20296
- }
20297
- } else if (isObject(data)) {
20298
- // Avoid call stack overflow.
20299
- if (memo.has(data)) {
20300
- return;
20301
- }
20302
-
20303
- memo.add(data);
20304
-
20305
- if (Array.isArray(data)) {
20306
- for (var item of data) {
20307
- collectI18N(item, beforeVisitGlobal, memo);
20308
- }
20309
- } else {
20310
- for (var _item of Object.values(data)) {
20311
- collectI18N(_item, beforeVisitGlobal, memo);
20312
- }
20313
- }
20314
- }
20315
- }
20316
-
20317
- function beforeVisitGlobalFactory(collection) {
20318
- return function beforeVisitGlobal(node, parent) {
20287
+ function beforeVisitI18nFactory(collection) {
20288
+ return function beforeVisitI18n(node, parent) {
20319
20289
  if (node.name === I18N) {
20320
20290
  var callParent = parent[parent.length - 1];
20321
20291
 
@@ -20924,6 +20894,7 @@
20924
20894
  convertUnitValueByPrecision: convertValueByPrecision
20925
20895
  } = pipes.utils;
20926
20896
 
20897
+ var CTX$1 = "CTX";
20927
20898
  function resolveContextConcurrently(_x, _x2) {
20928
20899
  return _resolveContextConcurrently.apply(this, arguments);
20929
20900
  }
@@ -20999,9 +20970,7 @@
20999
20970
  };
21000
20971
 
21001
20972
  if (!_contextConf.property) {
21002
- collectContexts(_contextConf.if, stats);
21003
- collectContexts(_contextConf.value, stats);
21004
- collectContexts(_contextConf.resolve, stats);
20973
+ visitStoryboardExpressions([_contextConf.if, _contextConf.value, _contextConf.resolve], beforeVisitContextFactory(stats), CTX$1);
21005
20974
  }
21006
20975
 
21007
20976
  depsMap.set(_contextConf, stats);
@@ -21009,60 +20978,30 @@
21009
20978
 
21010
20979
  return depsMap;
21011
20980
  }
21012
- var CTX$1 = "CTX";
21013
20981
 
21014
- function collectContexts(data, stats) {
21015
- var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
21016
-
21017
- if (typeof data === "string") {
21018
- if (data.includes(CTX$1) && isEvaluable(data)) {
21019
- preevaluate(data, {
21020
- withParent: true,
21021
- hooks: {
21022
- beforeVisitGlobal(node, parent) {
21023
- if (node.name === CTX$1) {
21024
- var memberParent = parent[parent.length - 1];
21025
-
21026
- if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
21027
- var memberNode = memberParent.node;
21028
- var dep;
21029
-
21030
- if (!memberNode.computed && memberNode.property.type === "Identifier") {
21031
- dep = memberNode.property.name;
21032
- } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
21033
- dep = memberNode.property.value;
21034
- } else {
21035
- stats.includesComputed = true;
21036
- }
20982
+ function beforeVisitContextFactory(stats) {
20983
+ return function beforeVisitContext(node, parent) {
20984
+ if (node.name === CTX$1) {
20985
+ var memberParent = parent[parent.length - 1];
21037
20986
 
21038
- if (dep !== undefined && !stats.dependencies.includes(dep)) {
21039
- stats.dependencies.push(dep);
21040
- }
21041
- }
21042
- }
21043
- }
20987
+ if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
20988
+ var memberNode = memberParent.node;
20989
+ var dep;
21044
20990
 
20991
+ if (!memberNode.computed && memberNode.property.type === "Identifier") {
20992
+ dep = memberNode.property.name;
20993
+ } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
20994
+ dep = memberNode.property.value;
20995
+ } else {
20996
+ stats.includesComputed = true;
21045
20997
  }
21046
- });
21047
- }
21048
- } else if (isObject(data)) {
21049
- // Avoid call stack overflow.
21050
- if (memo.has(data)) {
21051
- return;
21052
- }
21053
20998
 
21054
- memo.add(data);
21055
-
21056
- if (Array.isArray(data)) {
21057
- for (var item of data) {
21058
- collectContexts(item, stats, memo);
21059
- }
21060
- } else {
21061
- for (var _item of Object.values(data)) {
21062
- collectContexts(_item, stats, memo);
20999
+ if (dep !== undefined && !stats.dependencies.includes(dep)) {
21000
+ stats.dependencies.push(dep);
21001
+ }
21063
21002
  }
21064
21003
  }
21065
- }
21004
+ };
21066
21005
  }
21067
21006
 
21068
21007
  function detectCircularContexts(dependencyMap) {
@@ -21466,6 +21405,8 @@
21466
21405
  exports.trackContext = trackContext;
21467
21406
  exports.transform = transform;
21468
21407
  exports.transformAndInject = transformAndInject;
21408
+ exports.visitStoryboardExpressions = visitStoryboardExpressions;
21409
+ exports.visitStoryboardFunctions = visitStoryboardFunctions;
21469
21410
 
21470
21411
  Object.defineProperty(exports, '__esModule', { value: true });
21471
21412