@next-core/brick-utils 2.30.1 → 2.31.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/dist/index.esm.js CHANGED
@@ -2,9 +2,9 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
2
2
  import { uniq, get, cloneDeep, set, isEmpty, escapeRegExp } from 'lodash';
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
5
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
6
  import { processPipes, utils } from '@next-core/pipes';
6
7
  export { pipes } from '@next-core/pipes';
7
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
8
8
  import yaml from 'js-yaml';
9
9
 
10
10
  var cache$1 = new Map();
@@ -18386,7 +18386,72 @@ function getParserClass(pluginsFromOptions) {
18386
18386
 
18387
18387
  var parse_1 = lib.parse = parse$1;
18388
18388
  var parseExpression_1 = lib.parseExpression = parseExpression;
18389
- lib.tokTypes = tokTypes;
18389
+ var tokTypes_1 = lib.tokTypes = tokTypes;
18390
+
18391
+ function parseAsEstreeExpression(source) {
18392
+ return parseExpression_1(source, {
18393
+ plugins: ["estree", ["pipelineOperator", {
18394
+ proposal: "minimal"
18395
+ }]],
18396
+ attachComment: false
18397
+ });
18398
+ }
18399
+ function parseAsEstree(source) {
18400
+ var {
18401
+ typescript
18402
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18403
+ var file = parse_1(source, {
18404
+ plugins: ["estree", typescript && "typescript"].filter(Boolean),
18405
+ strictMode: true,
18406
+ attachComment: false
18407
+ });
18408
+ var body = file.program.body;
18409
+ var jsNodes = typescript ? [] : body;
18410
+
18411
+ if (typescript) {
18412
+ for (var node of body) {
18413
+ if (node.type.startsWith("TS")) {
18414
+ if (/Enum|Import|Export/.test(node.type)) {
18415
+ throw new SyntaxError("Unsupported TypeScript syntax: ".concat(node.type));
18416
+ }
18417
+ } else {
18418
+ jsNodes.push(node);
18419
+ }
18420
+ }
18421
+ }
18422
+
18423
+ if (jsNodes.length === 0) {
18424
+ throw new SyntaxError("Function declaration not found");
18425
+ }
18426
+
18427
+ if (jsNodes.length > 1 || jsNodes[0].type !== "FunctionDeclaration") {
18428
+ throw new SyntaxError("Expect a single function declaration at top level, but received: ".concat(jsNodes.map(node => "\"".concat(node.type, "\"")).join(", ")));
18429
+ }
18430
+
18431
+ return jsNodes[0];
18432
+ }
18433
+ /** For next-core internal or devtools usage only. */
18434
+
18435
+ function parseForAnalysis(source) {
18436
+ var {
18437
+ typescript,
18438
+ tokens
18439
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18440
+
18441
+ try {
18442
+ return parse_1(source, {
18443
+ plugins: ["estree", typescript && "typescript"].filter(Boolean),
18444
+ strictMode: true,
18445
+ attachComment: false,
18446
+ // Allow export/import declarations to make analyser handle errors.
18447
+ sourceType: "unambiguous",
18448
+ tokens
18449
+ });
18450
+ } catch (e) {
18451
+ // Return no errors if parse failed.
18452
+ return null;
18453
+ }
18454
+ }
18390
18455
 
18391
18456
  function hasOwnProperty(object, property) {
18392
18457
  return Object.prototype.hasOwnProperty.call(object, property);
@@ -18432,6 +18497,7 @@ function precook(rootAst) {
18432
18497
  var {
18433
18498
  expressionOnly,
18434
18499
  visitors,
18500
+ withParent,
18435
18501
  hooks = {}
18436
18502
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18437
18503
  var attemptToVisitGlobals = new Set();
@@ -18452,102 +18518,107 @@ function precook(rootAst) {
18452
18518
  }
18453
18519
  }
18454
18520
 
18455
- function Evaluate(node) {
18521
+ function EvaluateChildren(node, keys, parent) {
18522
+ for (var key of keys) {
18523
+ Evaluate(node[key], parent === null || parent === void 0 ? void 0 : parent.concat({
18524
+ node,
18525
+ key
18526
+ }));
18527
+ }
18528
+ }
18529
+
18530
+ function Evaluate(node, parent) {
18456
18531
  if (Array.isArray(node)) {
18457
- for (var n of node) {
18458
- Evaluate(n);
18459
- }
18532
+ node.forEach((n, index) => {
18533
+ Evaluate(n, parent ? parent.slice(0, -1).concat(_objectSpread(_objectSpread({}, parent[parent.length - 1]), {}, {
18534
+ index
18535
+ })) : parent);
18536
+ });
18460
18537
  } else if (node) {
18461
- var _hooks$beforeVisit; // `node` maybe `null` in some cases.
18538
+ var _hooks$beforeVisit, _hooks$beforeVisitUnk; // `node` maybe `null` in some cases.
18462
18539
 
18463
18540
 
18464
- (_hooks$beforeVisit = hooks.beforeVisit) === null || _hooks$beforeVisit === void 0 ? void 0 : _hooks$beforeVisit.call(hooks, node);
18541
+ (_hooks$beforeVisit = hooks.beforeVisit) === null || _hooks$beforeVisit === void 0 ? void 0 : _hooks$beforeVisit.call(hooks, node, parent);
18465
18542
  visitors && visit(node); // Expressions:
18466
18543
 
18467
18544
  switch (node.type) {
18468
18545
  case "Identifier":
18469
18546
  if (!ResolveBinding(node.name)) {
18470
- attemptToVisitGlobals.add(node.name);
18547
+ var _hooks$beforeVisitGlo;
18471
18548
 
18472
- if (visitors && hasOwnProperty(visitors, "__GlobalVariable")) {
18473
- visitors.__GlobalVariable(node);
18474
- }
18549
+ (_hooks$beforeVisitGlo = hooks.beforeVisitGlobal) === null || _hooks$beforeVisitGlo === void 0 ? void 0 : _hooks$beforeVisitGlo.call(hooks, node, parent);
18550
+ attemptToVisitGlobals.add(node.name);
18475
18551
  }
18476
18552
 
18477
18553
  return;
18478
18554
 
18479
18555
  case "ArrayExpression":
18480
18556
  case "ArrayPattern":
18481
- Evaluate(node.elements);
18557
+ EvaluateChildren(node, ["elements"], parent);
18482
18558
  return;
18483
18559
 
18484
18560
  case "ArrowFunctionExpression":
18485
18561
  {
18486
18562
  var env = getRunningContext().LexicalEnvironment;
18487
18563
  var closure = OrdinaryFunctionCreate(node, env);
18488
- CallFunction(closure);
18564
+ CallFunction(closure, parent);
18489
18565
  return;
18490
18566
  }
18491
18567
 
18492
18568
  case "AssignmentPattern":
18493
18569
  case "BinaryExpression":
18494
18570
  case "LogicalExpression":
18495
- Evaluate(node.left);
18496
- Evaluate(node.right);
18571
+ EvaluateChildren(node, ["left", "right"], parent);
18497
18572
  return;
18498
18573
 
18499
18574
  case "CallExpression":
18500
18575
  case "NewExpression":
18501
- Evaluate(node.callee);
18502
- Evaluate(node.arguments);
18576
+ EvaluateChildren(node, ["callee", "arguments"], parent);
18503
18577
  return;
18504
18578
 
18505
18579
  case "ChainExpression":
18506
- Evaluate(node.expression);
18580
+ EvaluateChildren(node, ["expression"], parent);
18507
18581
  return;
18508
18582
 
18509
18583
  case "ConditionalExpression":
18510
- Evaluate(node.test);
18511
- Evaluate(node.consequent);
18512
- Evaluate(node.alternate);
18584
+ EvaluateChildren(node, ["test", "consequent", "alternate"], parent);
18513
18585
  return;
18514
18586
 
18515
18587
  case "MemberExpression":
18516
- Evaluate(node.object);
18588
+ EvaluateChildren(node, ["object"], parent);
18517
18589
 
18518
18590
  if (node.computed) {
18519
- Evaluate(node.property);
18591
+ EvaluateChildren(node, ["property"], parent);
18520
18592
  }
18521
18593
 
18522
18594
  return;
18523
18595
 
18524
18596
  case "ObjectExpression":
18525
18597
  case "ObjectPattern":
18526
- Evaluate(node.properties);
18598
+ EvaluateChildren(node, ["properties"], parent);
18527
18599
  return;
18528
18600
 
18529
18601
  case "Property":
18530
18602
  if (node.computed) {
18531
- Evaluate(node.key);
18603
+ EvaluateChildren(node, ["key"], parent);
18532
18604
  }
18533
18605
 
18534
- Evaluate(node.value);
18606
+ EvaluateChildren(node, ["value"], parent);
18535
18607
  return;
18536
18608
 
18537
18609
  case "RestElement":
18538
18610
  case "SpreadElement":
18539
18611
  case "UnaryExpression":
18540
- Evaluate(node.argument);
18612
+ EvaluateChildren(node, ["argument"], parent);
18541
18613
  return;
18542
18614
 
18543
18615
  case "SequenceExpression":
18544
18616
  case "TemplateLiteral":
18545
- Evaluate(node.expressions);
18617
+ EvaluateChildren(node, ["expressions"], parent);
18546
18618
  return;
18547
18619
 
18548
18620
  case "TaggedTemplateExpression":
18549
- Evaluate(node.tag);
18550
- Evaluate(node.quasi);
18621
+ EvaluateChildren(node, ["tag", "quasi"], parent);
18551
18622
  return;
18552
18623
 
18553
18624
  case "Literal":
@@ -18558,8 +18629,7 @@ function precook(rootAst) {
18558
18629
  // Statements and assignments:
18559
18630
  switch (node.type) {
18560
18631
  case "AssignmentExpression":
18561
- Evaluate(node.right);
18562
- Evaluate(node.left);
18632
+ EvaluateChildren(node, ["right", "left"], parent);
18563
18633
  return;
18564
18634
 
18565
18635
  case "BlockStatement":
@@ -18573,7 +18643,7 @@ function precook(rootAst) {
18573
18643
  var blockEnv = new AnalysisEnvironment(oldEnv);
18574
18644
  BlockDeclarationInstantiation(node.body, blockEnv);
18575
18645
  runningContext.LexicalEnvironment = blockEnv;
18576
- Evaluate(node.body);
18646
+ EvaluateChildren(node, ["body"], parent);
18577
18647
  runningContext.LexicalEnvironment = oldEnv;
18578
18648
  return;
18579
18649
  }
@@ -18591,20 +18661,18 @@ function precook(rootAst) {
18591
18661
  var catchEnv = new AnalysisEnvironment(_oldEnv);
18592
18662
  BoundNamesInstantiation(node.param, catchEnv);
18593
18663
  _runningContext.LexicalEnvironment = catchEnv;
18594
- Evaluate(node.param);
18595
- Evaluate(node.body);
18664
+ EvaluateChildren(node, ["param", "body"], parent);
18596
18665
  _runningContext.LexicalEnvironment = _oldEnv;
18597
18666
  return;
18598
18667
  }
18599
18668
 
18600
18669
  case "DoWhileStatement":
18601
- Evaluate(node.body);
18602
- Evaluate(node.test);
18670
+ EvaluateChildren(node, ["body", "test"], parent);
18603
18671
  return;
18604
18672
 
18605
18673
  case "ExpressionStatement":
18606
18674
  case "TSAsExpression":
18607
- Evaluate(node.expression);
18675
+ EvaluateChildren(node, ["expression"], parent);
18608
18676
  return;
18609
18677
 
18610
18678
  case "ForInStatement":
@@ -18623,7 +18691,7 @@ function precook(rootAst) {
18623
18691
  _runningContext2.LexicalEnvironment = newEnv;
18624
18692
  }
18625
18693
 
18626
- Evaluate(node.right);
18694
+ EvaluateChildren(node, ["right"], parent);
18627
18695
  _runningContext2.LexicalEnvironment = _oldEnv2; // ForIn/OfBodyEvaluation
18628
18696
 
18629
18697
  if (lexicalBinding) {
@@ -18632,8 +18700,7 @@ function precook(rootAst) {
18632
18700
  _runningContext2.LexicalEnvironment = iterationEnv;
18633
18701
  }
18634
18702
 
18635
- Evaluate(node.left);
18636
- Evaluate(node.body);
18703
+ EvaluateChildren(node, ["left", "body"], parent);
18637
18704
  _runningContext2.LexicalEnvironment = _oldEnv2;
18638
18705
  return;
18639
18706
  }
@@ -18654,10 +18721,7 @@ function precook(rootAst) {
18654
18721
  _runningContext3.LexicalEnvironment = loopEnv;
18655
18722
  }
18656
18723
 
18657
- Evaluate(node.init);
18658
- Evaluate(node.test);
18659
- Evaluate(node.body);
18660
- Evaluate(node.update);
18724
+ EvaluateChildren(node, ["init", "test", "body", "update"], parent);
18661
18725
  _runningContext3.LexicalEnvironment = _oldEnv3;
18662
18726
  return;
18663
18727
  }
@@ -18670,7 +18734,7 @@ function precook(rootAst) {
18670
18734
 
18671
18735
  _env.CreateBinding(fn);
18672
18736
 
18673
- CallFunction(fo);
18737
+ CallFunction(fo, parent);
18674
18738
  return;
18675
18739
  }
18676
18740
 
@@ -18678,30 +18742,27 @@ function precook(rootAst) {
18678
18742
  {
18679
18743
  var _closure = InstantiateOrdinaryFunctionExpression(node);
18680
18744
 
18681
- CallFunction(_closure);
18745
+ CallFunction(_closure, parent);
18682
18746
  return;
18683
18747
  }
18684
18748
 
18685
18749
  case "IfStatement":
18686
- Evaluate(node.test);
18687
- Evaluate(node.consequent);
18688
- Evaluate(node.alternate);
18750
+ EvaluateChildren(node, ["test", "consequent", "alternate"], parent);
18689
18751
  return;
18690
18752
 
18691
18753
  case "ReturnStatement":
18692
18754
  case "ThrowStatement":
18693
18755
  case "UpdateExpression":
18694
- Evaluate(node.argument);
18756
+ EvaluateChildren(node, ["argument"], parent);
18695
18757
  return;
18696
18758
 
18697
18759
  case "SwitchCase":
18698
- Evaluate(node.test);
18699
- Evaluate(node.consequent);
18760
+ EvaluateChildren(node, ["test", "consequent"], parent);
18700
18761
  return;
18701
18762
 
18702
18763
  case "SwitchStatement":
18703
18764
  {
18704
- Evaluate(node.discriminant);
18765
+ EvaluateChildren(node, ["discriminant"], parent);
18705
18766
 
18706
18767
  var _runningContext4 = getRunningContext();
18707
18768
 
@@ -18711,36 +18772,32 @@ function precook(rootAst) {
18711
18772
 
18712
18773
  BlockDeclarationInstantiation(node.cases, _blockEnv);
18713
18774
  _runningContext4.LexicalEnvironment = _blockEnv;
18714
- Evaluate(node.cases);
18775
+ EvaluateChildren(node, ["cases"], parent);
18715
18776
  _runningContext4.LexicalEnvironment = _oldEnv4;
18716
18777
  return;
18717
18778
  }
18718
18779
 
18719
18780
  case "TryStatement":
18720
- Evaluate(node.block);
18721
- Evaluate(node.handler);
18722
- Evaluate(node.finalizer);
18781
+ EvaluateChildren(node, ["block", "handler", "finalizer"], parent);
18723
18782
  return;
18724
18783
 
18725
18784
  case "VariableDeclaration":
18726
- Evaluate(node.declarations);
18785
+ EvaluateChildren(node, ["declarations"], parent);
18727
18786
  return;
18728
18787
 
18729
18788
  case "VariableDeclarator":
18730
- Evaluate(node.id);
18731
- Evaluate(node.init);
18789
+ EvaluateChildren(node, ["id", "init"], parent);
18732
18790
  return;
18733
18791
 
18734
18792
  case "WhileStatement":
18735
- Evaluate(node.test);
18736
- Evaluate(node.body);
18793
+ EvaluateChildren(node, ["test", "body"], parent);
18737
18794
  return;
18738
18795
  }
18739
18796
  }
18740
18797
 
18741
- if (visitors && hasOwnProperty(visitors, "__UnknownNode")) {
18742
- visitors.__UnknownNode(node);
18743
- } else {
18798
+ var silent = (_hooks$beforeVisitUnk = hooks.beforeVisitUnknown) === null || _hooks$beforeVisitUnk === void 0 ? void 0 : _hooks$beforeVisitUnk.call(hooks, node, parent);
18799
+
18800
+ if (!silent) {
18744
18801
  // eslint-disable-next-line no-console
18745
18802
  console.warn("Unsupported node type `".concat(node.type, "`"));
18746
18803
  }
@@ -18770,10 +18827,16 @@ function precook(rootAst) {
18770
18827
  BoundNamesInstantiation(declarations, env);
18771
18828
  }
18772
18829
 
18773
- function CallFunction(closure) {
18830
+ function CallFunction(closure, parent) {
18774
18831
  PrepareOrdinaryCall(closure);
18775
- FunctionDeclarationInstantiation(closure);
18776
- Evaluate(closure.ECMAScriptCode);
18832
+ FunctionDeclarationInstantiation(closure, parent);
18833
+ Evaluate(closure.ECMAScriptCode, parent === null || parent === void 0 ? void 0 : parent.concat({
18834
+ node: closure.Function,
18835
+ key: "body"
18836
+ }).concat(closure.Function.body.type === "BlockStatement" ? {
18837
+ node: closure.Function.body,
18838
+ key: "body"
18839
+ } : []));
18777
18840
  analysisContextStack.pop();
18778
18841
  }
18779
18842
 
@@ -18785,7 +18848,7 @@ function precook(rootAst) {
18785
18848
  analysisContextStack.push(calleeContext);
18786
18849
  }
18787
18850
 
18788
- function FunctionDeclarationInstantiation(func) {
18851
+ function FunctionDeclarationInstantiation(func, parent) {
18789
18852
  var calleeContext = getRunningContext();
18790
18853
  var code = func.ECMAScriptCode;
18791
18854
  var formals = func.FormalParameters;
@@ -18797,7 +18860,10 @@ function precook(rootAst) {
18797
18860
  var varNames = collectBoundNames(varDeclarations);
18798
18861
  var env = calleeContext.LexicalEnvironment;
18799
18862
  BoundNamesInstantiation(formals, env);
18800
- Evaluate(formals);
18863
+ Evaluate(formals, parent === null || parent === void 0 ? void 0 : parent.concat({
18864
+ node: func.Function,
18865
+ key: "params"
18866
+ }));
18801
18867
  var varEnv;
18802
18868
 
18803
18869
  if (!hasParameterExpressions) {
@@ -18842,19 +18908,16 @@ function precook(rootAst) {
18842
18908
  return OrdinaryFunctionCreate(functionExpression, funcEnv);
18843
18909
  }
18844
18910
 
18845
- function OrdinaryFunctionCreate(_ref, scope) {
18846
- var {
18847
- params,
18848
- body
18849
- } = _ref;
18911
+ function OrdinaryFunctionCreate(func, scope) {
18850
18912
  return {
18851
- FormalParameters: params,
18852
- ECMAScriptCode: body.type === "BlockStatement" ? body.body : body,
18913
+ Function: func,
18914
+ FormalParameters: func.params,
18915
+ ECMAScriptCode: func.body.type === "BlockStatement" ? func.body.body : func.body,
18853
18916
  Environment: scope
18854
18917
  };
18855
18918
  }
18856
18919
 
18857
- Evaluate(rootAst);
18920
+ Evaluate(rootAst, withParent ? [] : undefined);
18858
18921
  return attemptToVisitGlobals;
18859
18922
  }
18860
18923
 
@@ -18866,17 +18929,11 @@ function lint(source) {
18866
18929
  rules
18867
18930
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18868
18931
  var errors = [];
18869
- var file;
18932
+ var file = typeof source === "string" ? parseForAnalysis(source, {
18933
+ typescript
18934
+ }) : source;
18870
18935
 
18871
- try {
18872
- file = parse_1(source, {
18873
- plugins: ["estree", typescript && "typescript"].filter(Boolean),
18874
- strictMode: true,
18875
- attachComment: false,
18876
- // Allow export/import declarations to make linter handle errors.
18877
- sourceType: "unambiguous"
18878
- });
18879
- } catch (e) {
18936
+ if (!file) {
18880
18937
  // Return no errors if parse failed.
18881
18938
  return errors;
18882
18939
  }
@@ -18932,93 +18989,100 @@ function lint(source) {
18932
18989
  }
18933
18990
  });
18934
18991
  } else {
18935
- var FunctionVisitor = node => {
18936
- if (node.async || node.generator) {
18937
- errors.push({
18938
- type: "SyntaxError",
18939
- message: "".concat(node.async ? "Async" : "Generator", " function is not allowed"),
18940
- loc: node.loc
18941
- });
18942
- }
18943
- };
18944
-
18945
18992
  precook(func, {
18946
- visitors: {
18947
- ArrowFunctionExpression: FunctionVisitor,
18948
- FunctionDeclaration: FunctionVisitor,
18949
- FunctionExpression: FunctionVisitor,
18950
-
18951
- Literal(node) {
18952
- if (node.regex) {
18953
- if (node.value === null) {
18954
- errors.push({
18955
- type: "SyntaxError",
18956
- message: "Invalid regular expression",
18957
- loc: node.loc
18958
- });
18959
- } else if (node.regex.flags.includes("u")) {
18960
- errors.push({
18961
- type: "SyntaxError",
18962
- message: "Unsupported unicode flag in regular expression",
18963
- loc: node.loc
18964
- });
18965
- }
18966
- }
18967
- },
18968
-
18969
- ObjectExpression(node) {
18970
- for (var prop of node.properties) {
18971
- if (prop.type === "Property") {
18972
- if (prop.kind !== "init") {
18993
+ hooks: {
18994
+ beforeVisit(node) {
18995
+ switch (node.type) {
18996
+ case "ArrowFunctionExpression":
18997
+ case "FunctionDeclaration":
18998
+ case "FunctionExpression":
18999
+ if (node.async || node.generator) {
18973
19000
  errors.push({
18974
19001
  type: "SyntaxError",
18975
- message: "Unsupported object getter/setter property",
18976
- loc: prop.loc
19002
+ message: "".concat(node.async ? "Async" : "Generator", " function is not allowed"),
19003
+ loc: node.loc
18977
19004
  });
18978
- } else if (!prop.computed && prop.key.type === "Identifier" && prop.key.name === "__proto__") {
19005
+ }
19006
+
19007
+ break;
19008
+
19009
+ case "Literal":
19010
+ if (node.regex) {
19011
+ if (node.value === null) {
19012
+ errors.push({
19013
+ type: "SyntaxError",
19014
+ message: "Invalid regular expression",
19015
+ loc: node.loc
19016
+ });
19017
+ } else if (node.regex.flags.includes("u")) {
19018
+ errors.push({
19019
+ type: "SyntaxError",
19020
+ message: "Unsupported unicode flag in regular expression",
19021
+ loc: node.loc
19022
+ });
19023
+ }
19024
+ }
19025
+
19026
+ break;
19027
+
19028
+ case "ObjectExpression":
19029
+ for (var prop of node.properties) {
19030
+ if (prop.type === "Property") {
19031
+ if (prop.kind !== "init") {
19032
+ errors.push({
19033
+ type: "SyntaxError",
19034
+ message: "Unsupported object getter/setter property",
19035
+ loc: prop.loc
19036
+ });
19037
+ } else if (!prop.computed && prop.key.type === "Identifier" && prop.key.name === "__proto__") {
19038
+ errors.push({
19039
+ type: "TypeError",
19040
+ message: "Setting '__proto__' property is not allowed",
19041
+ loc: prop.key.loc
19042
+ });
19043
+ }
19044
+ }
19045
+ }
19046
+
19047
+ break;
19048
+
19049
+ case "VariableDeclaration":
19050
+ if (node.kind === "var" && rules !== null && rules !== void 0 && rules.noVar) {
18979
19051
  errors.push({
18980
- type: "TypeError",
18981
- message: "Setting '__proto__' property is not allowed",
18982
- loc: prop.key.loc
19052
+ type: "SyntaxError",
19053
+ message: "Var declaration is not recommended, use `let` or `const` instead",
19054
+ loc: {
19055
+ start: node.loc.start,
19056
+ end: {
19057
+ line: node.loc.end.line,
19058
+ // Only decorate the "var".
19059
+ column: node.loc.start.column + 3
19060
+ }
19061
+ }
18983
19062
  });
18984
19063
  }
18985
- }
19064
+
19065
+ break;
18986
19066
  }
18987
19067
  },
18988
19068
 
18989
- VariableDeclaration(node) {
18990
- if (node.kind === "var" && rules !== null && rules !== void 0 && rules.noVar) {
19069
+ beforeVisitGlobal(node) {
19070
+ if (node.name === "arguments") {
18991
19071
  errors.push({
18992
19072
  type: "SyntaxError",
18993
- message: "Var declaration is not recommended, use `let` or `const` instead",
18994
- loc: {
18995
- start: node.loc.start,
18996
- end: {
18997
- line: node.loc.end.line,
18998
- // Only decorate the "var".
18999
- column: node.loc.start.column + 3
19000
- }
19001
- }
19073
+ message: "Use the rest parameters instead of 'arguments'",
19074
+ loc: node.loc
19002
19075
  });
19003
19076
  }
19004
19077
  },
19005
19078
 
19006
- __UnknownNode(node) {
19079
+ beforeVisitUnknown(node) {
19007
19080
  errors.push({
19008
19081
  type: "SyntaxError",
19009
19082
  message: "Unsupported syntax: `".concat(node.type, "`"),
19010
19083
  loc: node.loc
19011
19084
  });
19012
- },
19013
-
19014
- __GlobalVariable(node) {
19015
- if (node.name === "arguments") {
19016
- errors.push({
19017
- type: "SyntaxError",
19018
- message: "Use the rest parameters instead of 'arguments'",
19019
- loc: node.loc
19020
- });
19021
- }
19085
+ return true;
19022
19086
  }
19023
19087
 
19024
19088
  }
@@ -19028,49 +19092,6 @@ function lint(source) {
19028
19092
  return errors;
19029
19093
  }
19030
19094
 
19031
- function parseAsEstreeExpression(source) {
19032
- return parseExpression_1(source, {
19033
- plugins: ["estree", ["pipelineOperator", {
19034
- proposal: "minimal"
19035
- }]],
19036
- attachComment: false
19037
- });
19038
- }
19039
- function parseAsEstree(source) {
19040
- var {
19041
- typescript
19042
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
19043
- var file = parse_1(source, {
19044
- plugins: ["estree", typescript && "typescript"].filter(Boolean),
19045
- strictMode: true,
19046
- attachComment: false
19047
- });
19048
- var body = file.program.body;
19049
- var jsNodes = typescript ? [] : body;
19050
-
19051
- if (typescript) {
19052
- for (var node of body) {
19053
- if (node.type.startsWith("TS")) {
19054
- if (/Enum|Import|Export/.test(node.type)) {
19055
- throw new SyntaxError("Unsupported TypeScript syntax: ".concat(node.type));
19056
- }
19057
- } else {
19058
- jsNodes.push(node);
19059
- }
19060
- }
19061
- }
19062
-
19063
- if (jsNodes.length === 0) {
19064
- throw new SyntaxError("Function declaration not found");
19065
- }
19066
-
19067
- if (jsNodes.length > 1 || jsNodes[0].type !== "FunctionDeclaration") {
19068
- throw new SyntaxError("Expect a single function declaration at top level, but received: ".concat(jsNodes.map(node => "\"".concat(node.type, "\"")).join(", ")));
19069
- }
19070
-
19071
- return jsNodes[0];
19072
- }
19073
-
19074
19095
  var _excluded = ["typescript"];
19075
19096
  function precookFunction(source) {
19076
19097
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
@@ -19156,12 +19177,16 @@ function collectProcessors(data, collection) {
19156
19177
  if (typeof data === "string") {
19157
19178
  if (data.includes(PROCESSORS) && isEvaluable(data)) {
19158
19179
  preevaluate(data, {
19159
- visitors: {
19160
- MemberExpression(node) {
19161
- var accessNamespace = node.object;
19162
-
19163
- if (!node.computed && node.property.type === "Identifier" && accessNamespace.type === "MemberExpression" && !accessNamespace.computed && accessNamespace.object.type === "Identifier" && accessNamespace.object.name === PROCESSORS && accessNamespace.property.type === "Identifier") {
19164
- collection.push("".concat(accessNamespace.property.name, ".").concat(node.property.name));
19180
+ withParent: true,
19181
+ hooks: {
19182
+ beforeVisitGlobal(node, parent) {
19183
+ if (node.name === PROCESSORS) {
19184
+ var memberParent = parent[parent.length - 1];
19185
+ var outerMemberParent = parent[parent.length - 2];
19186
+
19187
+ 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") {
19188
+ collection.push("".concat(memberParent.node.property.name, ".").concat(outerMemberParent.node.property.name));
19189
+ }
19165
19190
  }
19166
19191
  }
19167
19192
 
@@ -19952,12 +19977,18 @@ function collectPermissionActions(data, collection) {
19952
19977
  if (typeof data === "string") {
19953
19978
  if (data.includes(PERMISSIONS) && isEvaluable(data)) {
19954
19979
  preevaluate(data, {
19955
- visitors: {
19956
- CallExpression(node) {
19957
- if (node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === PERMISSIONS && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === check) {
19958
- for (var arg of node.arguments) {
19959
- if (arg.type === "Literal" && typeof arg.value === "string") {
19960
- collection.add(arg.value);
19980
+ withParent: true,
19981
+ hooks: {
19982
+ beforeVisitGlobal(node, parent) {
19983
+ if (node.name === PERMISSIONS) {
19984
+ var memberParent = parent[parent.length - 1];
19985
+ var callParent = parent[parent.length - 2];
19986
+
19987
+ 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) {
19988
+ for (var arg of callParent.node.arguments) {
19989
+ if (arg.type === "Literal" && typeof arg.value === "string") {
19990
+ collection.add(arg.value);
19991
+ }
19961
19992
  }
19962
19993
  }
19963
19994
  }
@@ -20040,39 +20071,47 @@ function collectRouteAliasInRouteConfs(routes, collection) {
20040
20071
 
20041
20072
  var I18N = "I18N";
20042
20073
  function scanI18NInStoryboard(storyboard) {
20043
- // Notice: `menus` may contain evaluations of I18N too.
20044
- return scanI18NInAny([storyboard.routes, storyboard.meta && [storyboard.meta.customTemplates, storyboard.meta.menus]]);
20074
+ var _storyboard$meta;
20075
+
20076
+ var collection = new Map();
20077
+ var beforeVisitGlobal = beforeVisitGlobalFactory(collection); // Notice: `menus` may contain evaluations of I18N too.
20078
+
20079
+ var {
20080
+ customTemplates,
20081
+ menus,
20082
+ functions
20083
+ } = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
20084
+ collectI18N([storyboard.routes, customTemplates, menus], beforeVisitGlobal);
20085
+
20086
+ if (Array.isArray(functions)) {
20087
+ for (var fn of functions) {
20088
+ precookFunction(fn.source, {
20089
+ typescript: fn.typescript,
20090
+ withParent: true,
20091
+ hooks: {
20092
+ beforeVisitGlobal
20093
+ }
20094
+ });
20095
+ }
20096
+ }
20097
+
20098
+ return collection;
20045
20099
  }
20046
20100
  function scanI18NInAny(data) {
20047
20101
  var collection = new Map();
20048
- collectI18N(data, collection);
20102
+ collectI18N(data, beforeVisitGlobalFactory(collection));
20049
20103
  return collection;
20050
20104
  }
20051
20105
 
20052
- function collectI18N(data, collection) {
20106
+ function collectI18N(data, beforeVisitGlobal) {
20053
20107
  var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
20054
20108
 
20055
20109
  if (typeof data === "string") {
20056
20110
  if (data.includes(I18N) && isEvaluable(data)) {
20057
20111
  preevaluate(data, {
20058
- visitors: {
20059
- CallExpression(node) {
20060
- var [keyNode, defaultNode] = node.arguments;
20061
-
20062
- if (node.callee.type === "Identifier" && node.callee.name === I18N && keyNode && keyNode.type === "Literal" && typeof keyNode.value === "string") {
20063
- var valueSet = collection.get(keyNode.value);
20064
-
20065
- if (!valueSet) {
20066
- valueSet = new Set();
20067
- collection.set(keyNode.value, valueSet);
20068
- }
20069
-
20070
- if (defaultNode && defaultNode.type === "Literal" && typeof defaultNode.value === "string") {
20071
- valueSet.add(defaultNode.value);
20072
- }
20073
- }
20074
- }
20075
-
20112
+ withParent: true,
20113
+ hooks: {
20114
+ beforeVisitGlobal
20076
20115
  }
20077
20116
  });
20078
20117
  }
@@ -20086,16 +20125,41 @@ function collectI18N(data, collection) {
20086
20125
 
20087
20126
  if (Array.isArray(data)) {
20088
20127
  for (var item of data) {
20089
- collectI18N(item, collection, memo);
20128
+ collectI18N(item, beforeVisitGlobal, memo);
20090
20129
  }
20091
20130
  } else {
20092
20131
  for (var _item of Object.values(data)) {
20093
- collectI18N(_item, collection, memo);
20132
+ collectI18N(_item, beforeVisitGlobal, memo);
20094
20133
  }
20095
20134
  }
20096
20135
  }
20097
20136
  }
20098
20137
 
20138
+ function beforeVisitGlobalFactory(collection) {
20139
+ return function beforeVisitGlobal(node, parent) {
20140
+ if (node.name === I18N) {
20141
+ var callParent = parent[parent.length - 1];
20142
+
20143
+ if ((callParent === null || callParent === void 0 ? void 0 : callParent.node.type) === "CallExpression" && callParent.key === "callee") {
20144
+ var [keyNode, defaultNode] = callParent.node.arguments;
20145
+
20146
+ if (keyNode && keyNode.type === "Literal" && typeof keyNode.value === "string") {
20147
+ var valueSet = collection.get(keyNode.value);
20148
+
20149
+ if (!valueSet) {
20150
+ valueSet = new Set();
20151
+ collection.set(keyNode.value, valueSet);
20152
+ }
20153
+
20154
+ if (defaultNode && defaultNode.type === "Literal" && typeof defaultNode.value === "string") {
20155
+ valueSet.add(defaultNode.value);
20156
+ }
20157
+ }
20158
+ }
20159
+ }
20160
+ };
20161
+ }
20162
+
20099
20163
  var LexicalStatus;
20100
20164
 
20101
20165
  (function (LexicalStatus) {
@@ -20766,23 +20830,35 @@ function getDependencyMapOfContext(contextConfs) {
20766
20830
 
20767
20831
  return depsMap;
20768
20832
  }
20769
- var CTX = "CTX";
20833
+ var CTX$1 = "CTX";
20770
20834
 
20771
20835
  function collectContexts(data, stats) {
20772
20836
  var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
20773
20837
 
20774
20838
  if (typeof data === "string") {
20775
- if (data.includes(CTX) && isEvaluable(data)) {
20839
+ if (data.includes(CTX$1) && isEvaluable(data)) {
20776
20840
  preevaluate(data, {
20777
- visitors: {
20778
- MemberExpression(node) {
20779
- if (node.object.type === "Identifier" && node.object.name === CTX) {
20780
- if (!node.computed && node.property.type === "Identifier") {
20781
- if (!stats.dependencies.includes(node.property.name)) {
20782
- stats.dependencies.push(node.property.name);
20841
+ withParent: true,
20842
+ hooks: {
20843
+ beforeVisitGlobal(node, parent) {
20844
+ if (node.name === CTX$1) {
20845
+ var memberParent = parent[parent.length - 1];
20846
+
20847
+ if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
20848
+ var memberNode = memberParent.node;
20849
+ var dep;
20850
+
20851
+ if (!memberNode.computed && memberNode.property.type === "Identifier") {
20852
+ dep = memberNode.property.name;
20853
+ } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
20854
+ dep = memberNode.property.value;
20855
+ } else {
20856
+ stats.includesComputed = true;
20857
+ }
20858
+
20859
+ if (dep !== undefined && !stats.dependencies.includes(dep)) {
20860
+ stats.dependencies.push(dep);
20783
20861
  }
20784
- } else {
20785
- stats.includesComputed = true;
20786
20862
  }
20787
20863
  }
20788
20864
  }
@@ -21080,6 +21156,7 @@ function deepFreeze(object) {
21080
21156
  }
21081
21157
 
21082
21158
  var TRACK_CONTEXT = "track context";
21159
+ var CTX = "CTX";
21083
21160
  /**
21084
21161
  * Get tracking CTX for an evaluable expression in `track context` mode.
21085
21162
  *
@@ -21113,13 +21190,20 @@ function trackContext(raw) {
21113
21190
  var {
21114
21191
  expression
21115
21192
  } = preevaluate(raw, {
21116
- visitors: {
21117
- MemberExpression(node) {
21118
- if (node.object.type === "Identifier" && node.object.name === "CTX") {
21119
- if (!node.computed && node.property.type === "Identifier") {
21120
- contexts.add(node.property.name);
21121
- } else if (node.computed && node.property.type === "Literal" && typeof node.property.value === "string") {
21122
- contexts.add(node.property.value);
21193
+ withParent: true,
21194
+ hooks: {
21195
+ beforeVisitGlobal(node, parent) {
21196
+ if (node.name === CTX) {
21197
+ var memberParent = parent[parent.length - 1];
21198
+
21199
+ if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
21200
+ var memberNode = memberParent.node;
21201
+
21202
+ if (!memberNode.computed && memberNode.property.type === "Identifier") {
21203
+ contexts.add(memberNode.property.name);
21204
+ } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
21205
+ contexts.add(memberNode.property.value);
21206
+ }
21123
21207
  }
21124
21208
  }
21125
21209
  }
@@ -21141,5 +21225,5 @@ function trackContext(raw) {
21141
21225
  return false;
21142
21226
  }
21143
21227
 
21144
- 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, precookFunction, preevaluate, prefetchScript, resolveContextConcurrently, restoreDynamicTemplates, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, toPath, trackContext, transform, transformAndInject };
21228
+ 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 };
21145
21229
  //# sourceMappingURL=index.esm.js.map