@next-core/brick-utils 2.52.2 → 2.52.4

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.
@@ -1149,6 +1149,8 @@
1149
1149
  // Currently unicode flag is not fully supported across major browsers.
1150
1150
  throw new SyntaxError("Unsupported unicode flag in regular expression: ".concat(node.raw));
1151
1151
  }
1152
+ // Always create a new RegExp, because the AST will be reused.
1153
+ return NormalCompletion(new RegExp(node.regex.pattern, node.regex.flags));
1152
1154
  }
1153
1155
  return NormalCompletion(node.value);
1154
1156
  }
@@ -2130,8 +2132,8 @@
2130
2132
  }
2131
2133
 
2132
2134
  // https://tc39.es/ecma262/#sec-runtime-semantics-instantiatefunctionobject
2133
- function InstantiateFunctionObject(func, scope) {
2134
- return OrdinaryFunctionCreate(func, scope, true);
2135
+ function InstantiateFunctionObject(func, scope, isRoot) {
2136
+ return OrdinaryFunctionCreate(func, scope, true, isRoot);
2135
2137
  }
2136
2138
 
2137
2139
  // https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionexpression
@@ -2158,10 +2160,19 @@
2158
2160
  }
2159
2161
 
2160
2162
  // https://tc39.es/ecma262/#sec-ordinaryfunctioncreate
2161
- function OrdinaryFunctionCreate(sourceNode, scope, isConstructor) {
2163
+ function OrdinaryFunctionCreate(sourceNode, scope, isConstructor, isRoot) {
2162
2164
  var F = function () {
2165
+ var perf = isRoot && hooks.perfCall;
2166
+ var start;
2167
+ if (perf) {
2168
+ start = performance.now();
2169
+ }
2163
2170
  // eslint-disable-next-line prefer-rest-params
2164
- return CallFunction(F, arguments);
2171
+ var result = CallFunction(F, arguments);
2172
+ if (perf) {
2173
+ perf(performance.now() - start);
2174
+ }
2175
+ return result;
2165
2176
  };
2166
2177
  Object.defineProperties(F, {
2167
2178
  [SourceNode]: {
@@ -2377,7 +2388,7 @@
2377
2388
  var [fn] = collectBoundNames(rootAst);
2378
2389
  // Create an immutable binding for the root function.
2379
2390
  rootEnv.CreateImmutableBinding(fn, true);
2380
- var fo = InstantiateFunctionObject(rootAst, rootEnv);
2391
+ var fo = InstantiateFunctionObject(rootAst, rootEnv, true);
2381
2392
  rootEnv.InitializeBinding(fn, fo);
2382
2393
  return fo;
2383
2394
  }
@@ -2836,13 +2847,13 @@
2836
2847
  PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
2837
2848
  PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
2838
2849
  };
2839
- var _excluded$1 = ["toMessage"],
2850
+ var _excluded$1$1 = ["toMessage"],
2840
2851
  _excluded2$1 = ["message"];
2841
2852
  function toParseErrorConstructor(_ref) {
2842
2853
  var {
2843
2854
  toMessage
2844
2855
  } = _ref,
2845
- properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
2856
+ properties = _objectWithoutPropertiesLoose(_ref, _excluded$1$1);
2846
2857
  return function constructor(_ref39) {
2847
2858
  var {
2848
2859
  loc,
@@ -17464,32 +17475,56 @@
17464
17475
  return errors;
17465
17476
  }
17466
17477
 
17467
- var _excluded = ["typescript"];
17478
+ var _excluded$1 = ["typescript", "cacheKey"];
17479
+ var ASTCache$1 = new WeakMap();
17468
17480
  function precookFunction(source) {
17469
17481
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
17470
17482
  {
17471
- typescript
17483
+ typescript,
17484
+ cacheKey
17472
17485
  } = _ref,
17473
- restOptions = _objectWithoutProperties__default["default"](_ref, _excluded);
17474
- var func = parseAsEstree(source, {
17475
- typescript
17476
- });
17486
+ restOptions = _objectWithoutProperties__default["default"](_ref, _excluded$1);
17487
+ var func = cacheKey ? ASTCache$1.get(cacheKey) : undefined;
17488
+ if (!func) {
17489
+ func = parseAsEstree(source, {
17490
+ typescript
17491
+ });
17492
+ if (cacheKey) {
17493
+ ASTCache$1.set(cacheKey, func);
17494
+ }
17495
+ }
17477
17496
  var attemptToVisitGlobals = precook(func, restOptions);
17478
17497
  return {
17479
17498
  function: func,
17480
17499
  attemptToVisitGlobals
17481
17500
  };
17482
17501
  }
17502
+ function clearFunctionASTCache() {
17503
+ ASTCache$1 = new WeakMap();
17504
+ }
17483
17505
 
17506
+ var _excluded = ["cache"];
17507
+ var ASTCache = new Map();
17484
17508
  // `raw` should always be asserted by `isEvaluable`.
17485
- function preevaluate(raw, options) {
17509
+ function preevaluate(raw) {
17510
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
17511
+ {
17512
+ cache
17513
+ } = _ref,
17514
+ restOptions = _objectWithoutProperties__default["default"](_ref, _excluded);
17486
17515
  var fixes = [];
17487
17516
  var source = raw.replace(/^\s*<%[~=!]?\s|\s%>\s*$/g, m => {
17488
17517
  fixes.push(m);
17489
17518
  return "";
17490
17519
  });
17491
- var expression = parseAsEstreeExpression(source);
17492
- var attemptToVisitGlobals = precook(expression, _objectSpread__default["default"](_objectSpread__default["default"]({}, options), {}, {
17520
+ var expression = cache ? ASTCache.get(source) : undefined;
17521
+ if (!expression) {
17522
+ expression = parseAsEstreeExpression(source);
17523
+ if (cache) {
17524
+ ASTCache.set(source, expression);
17525
+ }
17526
+ }
17527
+ var attemptToVisitGlobals = precook(expression, _objectSpread__default["default"](_objectSpread__default["default"]({}, restOptions), {}, {
17493
17528
  expressionOnly: true
17494
17529
  }));
17495
17530
  return {
@@ -17512,6 +17547,9 @@
17512
17547
  function isTrackAll(raw) {
17513
17548
  return /^\s*<%=\s/.test(raw) && /\s%>\s*$/.test(raw);
17514
17549
  }
17550
+ function clearExpressionASTCache() {
17551
+ ASTCache.clear();
17552
+ }
17515
17553
 
17516
17554
  // istanbul ignore file
17517
17555
 
@@ -17538,11 +17576,15 @@
17538
17576
  return value != null && (type == "object" || type == "function");
17539
17577
  }
17540
17578
 
17541
- function visitStoryboardFunctions(functions, beforeVisitGlobal) {
17579
+ function visitStoryboardFunctions(functions, beforeVisitGlobal, options) {
17542
17580
  if (Array.isArray(functions)) {
17543
17581
  for (var fn of functions) {
17582
+ if (options !== null && options !== void 0 && options.matchSource && !options.matchSource(fn.source)) {
17583
+ continue;
17584
+ }
17544
17585
  try {
17545
17586
  precookFunction(fn.source, {
17587
+ cacheKey: fn,
17546
17588
  typescript: fn.typescript,
17547
17589
  withParent: true,
17548
17590
  hooks: {
@@ -17573,6 +17615,7 @@
17573
17615
  if (matchExpressionString(value) && customIsEvaluable(value)) {
17574
17616
  try {
17575
17617
  preevaluate(value, {
17618
+ cache: true,
17576
17619
  withParent: true,
17577
17620
  hooks: {
17578
17621
  beforeVisitGlobal
@@ -18934,7 +18977,9 @@
18934
18977
  functions
18935
18978
  } = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
18936
18979
  visitStoryboardExpressions([storyboard.routes, customTemplates], beforeVisitPermissions, PERMISSIONS);
18937
- visitStoryboardFunctions(functions, beforeVisitPermissions);
18980
+ visitStoryboardFunctions(functions, beforeVisitPermissions, {
18981
+ matchSource: source => source.includes(PERMISSIONS)
18982
+ });
18938
18983
  return Array.from(collection);
18939
18984
  }
18940
18985
  function scanPermissionActionsInAny(data) {
@@ -19023,30 +19068,36 @@
19023
19068
  }
19024
19069
 
19025
19070
  var APP = "APP";
19026
- var GET_MENUS = "getMenu";
19071
+ var GET_MENU = "getMenu";
19027
19072
  function scanAppGetMenuInStoryboard(storyboard) {
19028
19073
  var _storyboard$meta;
19029
19074
  var collection = new Set();
19030
- var beforeVisitPermissions = beforeVisitAppFactory(collection);
19075
+ var beforeVisitApp = beforeVisitAppFactory(collection);
19031
19076
  var {
19032
- customTemplates,
19033
- functions
19077
+ customTemplates
19034
19078
  } = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
19035
- visitStoryboardExpressions([storyboard.routes, customTemplates], beforeVisitPermissions, APP);
19036
- visitStoryboardFunctions(functions, beforeVisitPermissions);
19079
+ visitStoryboardExpressions([storyboard.routes, customTemplates], beforeVisitApp, {
19080
+ matchExpressionString: matchAppGetMenu
19081
+ });
19082
+ // `APP` is not available in storyboard functions
19037
19083
  return Array.from(collection);
19038
19084
  }
19039
19085
  function scanAppGetMenuInAny(data) {
19040
19086
  var collection = new Set();
19041
- visitStoryboardExpressions(data, beforeVisitAppFactory(collection), APP);
19087
+ visitStoryboardExpressions(data, beforeVisitAppFactory(collection), {
19088
+ matchExpressionString: matchAppGetMenu
19089
+ });
19042
19090
  return Array.from(collection);
19043
19091
  }
19092
+ function matchAppGetMenu(source) {
19093
+ return source.includes(APP) && source.includes(GET_MENU);
19094
+ }
19044
19095
  function beforeVisitAppFactory(collection) {
19045
19096
  return function beforeVisitAPP(node, parent) {
19046
19097
  if (node.name === APP) {
19047
19098
  var memberParent = parent[parent.length - 1];
19048
19099
  var callParent = parent[parent.length - 2];
19049
- 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 === GET_MENUS) {
19100
+ 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 === GET_MENU) {
19050
19101
  if (callParent.node.arguments.length === 1) {
19051
19102
  var menuId = callParent.node.arguments[0];
19052
19103
  if (menuId.type === "Literal" && typeof menuId.value === "string") {
@@ -19554,6 +19605,8 @@
19554
19605
  convertUnitValueByPrecision: convertValueByPrecision
19555
19606
  } = pipes.utils;
19556
19607
 
19608
+ var TRACK_NAMES = ["CTX", "STATE", "FORM_STATE"];
19609
+
19557
19610
  /**
19558
19611
  * Get tracking CTX for an evaluable expression in `track context` mode.
19559
19612
  *
@@ -19608,6 +19661,7 @@
19608
19661
  var {
19609
19662
  expression
19610
19663
  } = preevaluate(raw, {
19664
+ cache: true,
19611
19665
  withParent: true,
19612
19666
  hooks: {
19613
19667
  beforeVisitGlobal: beforeVisitContextFactory(usage, variableName)
@@ -19627,15 +19681,17 @@
19627
19681
  return false;
19628
19682
  }
19629
19683
  function trackAll(raw) {
19630
- if (raw) {
19684
+ // Do not pre-evaluate a string if it doesn't include track names.
19685
+ if (TRACK_NAMES.some(name => raw.includes(name))) {
19631
19686
  var usage = {
19632
19687
  usedContexts: [],
19633
19688
  includesComputed: false
19634
19689
  };
19635
19690
  preevaluate(raw, {
19691
+ cache: true,
19636
19692
  withParent: true,
19637
19693
  hooks: {
19638
- beforeVisitGlobal: beforeVisitContextFactory(usage, ["CTX", "STATE", "FORM_STATE"], true)
19694
+ beforeVisitGlobal: beforeVisitContextFactory(usage, TRACK_NAMES, true)
19639
19695
  }
19640
19696
  });
19641
19697
  if (usage.usedContexts.length > 0) {
@@ -20208,11 +20264,10 @@
20208
20264
  var beforeVisitInstalledApps = beforeVisitInstalledAppsFactory(collection);
20209
20265
  var {
20210
20266
  customTemplates,
20211
- functions,
20212
20267
  menus
20213
20268
  } = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
20214
20269
  visitStoryboardExpressions([storyboard.routes, customTemplates, menus], beforeVisitInstalledApps, INSTALLED_APPS);
20215
- visitStoryboardFunctions(functions, beforeVisitInstalledApps);
20270
+ // `INSTALLED_APPS` is not available in storyboard functions
20216
20271
  return Array.from(collection);
20217
20272
  }
20218
20273
  function beforeVisitInstalledAppsFactory(collection) {
@@ -20431,7 +20486,9 @@
20431
20486
  expression,
20432
20487
  attemptToVisitGlobals,
20433
20488
  source
20434
- } = preevaluate(ifContainer.if);
20489
+ } = preevaluate(ifContainer.if, {
20490
+ cache: true
20491
+ });
20435
20492
  var {
20436
20493
  constantFeatureFlags,
20437
20494
  featureFlags
@@ -20730,6 +20787,8 @@
20730
20787
  exports.PrecookVisitor = PrecookVisitor;
20731
20788
  exports.asyncProcessBrick = asyncProcessBrick;
20732
20789
  exports.asyncProcessStoryboard = asyncProcessStoryboard;
20790
+ exports.clearExpressionASTCache = clearExpressionASTCache;
20791
+ exports.clearFunctionASTCache = clearFunctionASTCache;
20733
20792
  exports.collectBricksByCustomTemplates = collectBricksByCustomTemplates;
20734
20793
  exports.collectContextUsage = collectContextUsage;
20735
20794
  exports.computeConstantCondition = computeConstantCondition;