@next-core/brick-utils 2.28.1 → 2.28.5
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 +32 -0
- package/dist/index.bundle.js +55 -35
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +55 -35
- package/dist/index.esm.js.map +1 -1
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -820,6 +820,7 @@ class EnvironmentRecord {
|
|
|
820
820
|
}
|
|
821
821
|
class DeclarativeEnvironment extends EnvironmentRecord {}
|
|
822
822
|
class FunctionEnvironment extends EnvironmentRecord {}
|
|
823
|
+
var SourceNode = Symbol.for("SourceNode");
|
|
823
824
|
var FormalParameters = Symbol.for("FormalParameters");
|
|
824
825
|
var ECMAScriptCode = Symbol.for("ECMAScriptCode");
|
|
825
826
|
var Environment = Symbol.for("Environment");
|
|
@@ -1285,8 +1286,11 @@ function isAllowedConstructor(constructor) {
|
|
|
1285
1286
|
|
|
1286
1287
|
function cook(rootAst, codeSource, {
|
|
1287
1288
|
rules,
|
|
1288
|
-
globalVariables = {}
|
|
1289
|
+
globalVariables = {},
|
|
1290
|
+
hooks = {}
|
|
1289
1291
|
} = {}) {
|
|
1292
|
+
var _hooks$beforeEvaluate3;
|
|
1293
|
+
|
|
1290
1294
|
var expressionOnly = rootAst.type !== "FunctionDeclaration";
|
|
1291
1295
|
var rootEnv = new DeclarativeEnvironment(null);
|
|
1292
1296
|
var rootContext = new ExecutionContext();
|
|
@@ -1323,7 +1327,10 @@ function cook(rootAst, codeSource, {
|
|
|
1323
1327
|
}
|
|
1324
1328
|
|
|
1325
1329
|
function Evaluate(node, optionalChainRef) {
|
|
1326
|
-
|
|
1330
|
+
var _hooks$beforeEvaluate, _hooks$beforeBranch, _hooks$beforeBranch2;
|
|
1331
|
+
|
|
1332
|
+
(_hooks$beforeEvaluate = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate === void 0 ? void 0 : _hooks$beforeEvaluate.call(hooks, node); // Expressions:
|
|
1333
|
+
|
|
1327
1334
|
switch (node.type) {
|
|
1328
1335
|
case "ArrayExpression":
|
|
1329
1336
|
{
|
|
@@ -1662,7 +1669,7 @@ function cook(rootAst, codeSource, {
|
|
|
1662
1669
|
|
|
1663
1670
|
case "IfStatement":
|
|
1664
1671
|
// https://tc39.es/ecma262/#sec-if-statement
|
|
1665
|
-
return GetValue(Evaluate(node.test)) ? UpdateEmpty(Evaluate(node.consequent), undefined) : node.alternate ? UpdateEmpty(Evaluate(node.alternate), undefined) : NormalCompletion(undefined);
|
|
1672
|
+
return GetValue(Evaluate(node.test)) ? ((_hooks$beforeBranch = hooks.beforeBranch) !== null && _hooks$beforeBranch !== void 0 && _hooks$beforeBranch.call(hooks, node, "if"), UpdateEmpty(Evaluate(node.consequent), undefined)) : ((_hooks$beforeBranch2 = hooks.beforeBranch) !== null && _hooks$beforeBranch2 !== void 0 && _hooks$beforeBranch2.call(hooks, node, "else"), node.alternate) ? UpdateEmpty(Evaluate(node.alternate), undefined) : NormalCompletion(undefined);
|
|
1666
1673
|
|
|
1667
1674
|
case "ReturnStatement":
|
|
1668
1675
|
{
|
|
@@ -1720,6 +1727,9 @@ function cook(rootAst, codeSource, {
|
|
|
1720
1727
|
_R = Evaluate(node.block);
|
|
1721
1728
|
} catch (error) {
|
|
1722
1729
|
if (node.handler) {
|
|
1730
|
+
var _hooks$beforeEvaluate2;
|
|
1731
|
+
|
|
1732
|
+
(_hooks$beforeEvaluate2 = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate2 === void 0 ? void 0 : _hooks$beforeEvaluate2.call(hooks, node.handler);
|
|
1723
1733
|
_R = CatchClauseEvaluation(node.handler, error);
|
|
1724
1734
|
} else {
|
|
1725
1735
|
throw error;
|
|
@@ -2427,6 +2437,9 @@ function cook(rootAst, codeSource, {
|
|
|
2427
2437
|
|
|
2428
2438
|
|
|
2429
2439
|
function CallFunction(closure, args) {
|
|
2440
|
+
var _hooks$beforeCall;
|
|
2441
|
+
|
|
2442
|
+
(_hooks$beforeCall = hooks.beforeCall) === null || _hooks$beforeCall === void 0 ? void 0 : _hooks$beforeCall.call(hooks, closure[SourceNode]);
|
|
2430
2443
|
PrepareForOrdinaryCall(closure);
|
|
2431
2444
|
var result = OrdinaryCallEvaluateBody(closure, args);
|
|
2432
2445
|
executionContextStack.pop();
|
|
@@ -2587,7 +2600,7 @@ function cook(rootAst, codeSource, {
|
|
|
2587
2600
|
|
|
2588
2601
|
|
|
2589
2602
|
function InstantiateFunctionObject(func, scope) {
|
|
2590
|
-
return OrdinaryFunctionCreate(func
|
|
2603
|
+
return OrdinaryFunctionCreate(func, scope, true);
|
|
2591
2604
|
} // https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionexpression
|
|
2592
2605
|
|
|
2593
2606
|
|
|
@@ -2598,11 +2611,13 @@ function cook(rootAst, codeSource, {
|
|
|
2598
2611
|
var name = functionExpression.id.name;
|
|
2599
2612
|
var funcEnv = new DeclarativeEnvironment(scope);
|
|
2600
2613
|
funcEnv.CreateImmutableBinding(name, false);
|
|
2601
|
-
var closure = OrdinaryFunctionCreate(functionExpression
|
|
2614
|
+
var closure = OrdinaryFunctionCreate(functionExpression, // functionExpression.params,
|
|
2615
|
+
// functionExpression.body,
|
|
2616
|
+
funcEnv, true);
|
|
2602
2617
|
funcEnv.InitializeBinding(name, closure);
|
|
2603
2618
|
return closure;
|
|
2604
2619
|
} else {
|
|
2605
|
-
var _closure = OrdinaryFunctionCreate(functionExpression
|
|
2620
|
+
var _closure = OrdinaryFunctionCreate(functionExpression, scope, true);
|
|
2606
2621
|
|
|
2607
2622
|
return _closure;
|
|
2608
2623
|
}
|
|
@@ -2611,36 +2626,33 @@ function cook(rootAst, codeSource, {
|
|
|
2611
2626
|
|
|
2612
2627
|
function InstantiateArrowFunctionExpression(arrowFunction) {
|
|
2613
2628
|
var scope = getRunningContext().LexicalEnvironment;
|
|
2614
|
-
var closure = OrdinaryFunctionCreate(arrowFunction
|
|
2629
|
+
var closure = OrdinaryFunctionCreate(arrowFunction, scope, false);
|
|
2615
2630
|
return closure;
|
|
2616
2631
|
} // https://tc39.es/ecma262/#sec-ordinaryfunctioncreate
|
|
2617
2632
|
|
|
2618
2633
|
|
|
2619
|
-
function OrdinaryFunctionCreate(
|
|
2634
|
+
function OrdinaryFunctionCreate(sourceNode, // parameterList: FunctionDeclaration["params"],
|
|
2635
|
+
// body: BlockStatement | Expression,
|
|
2636
|
+
scope, isConstructor) {
|
|
2620
2637
|
var F = function () {
|
|
2621
2638
|
// eslint-disable-next-line prefer-rest-params
|
|
2622
2639
|
return CallFunction(F, arguments);
|
|
2623
2640
|
};
|
|
2624
2641
|
|
|
2625
2642
|
Object.defineProperties(F, {
|
|
2643
|
+
[SourceNode]: {
|
|
2644
|
+
value: sourceNode
|
|
2645
|
+
},
|
|
2626
2646
|
[FormalParameters]: {
|
|
2627
|
-
|
|
2628
|
-
writable: false,
|
|
2629
|
-
value: parameterList
|
|
2647
|
+
value: sourceNode.params
|
|
2630
2648
|
},
|
|
2631
2649
|
[ECMAScriptCode]: {
|
|
2632
|
-
|
|
2633
|
-
writable: false,
|
|
2634
|
-
value: body.type === "BlockStatement" ? body.body : body
|
|
2650
|
+
value: sourceNode.body.type === "BlockStatement" ? sourceNode.body.body : sourceNode.body
|
|
2635
2651
|
},
|
|
2636
2652
|
[Environment]: {
|
|
2637
|
-
enumerable: false,
|
|
2638
|
-
writable: false,
|
|
2639
2653
|
value: scope
|
|
2640
2654
|
},
|
|
2641
2655
|
[IsConstructor]: {
|
|
2642
|
-
enumerable: false,
|
|
2643
|
-
writable: false,
|
|
2644
2656
|
value: isConstructor
|
|
2645
2657
|
}
|
|
2646
2658
|
});
|
|
@@ -2714,15 +2726,15 @@ function cook(rootAst, codeSource, {
|
|
|
2714
2726
|
|
|
2715
2727
|
var result;
|
|
2716
2728
|
|
|
2717
|
-
for (var
|
|
2718
|
-
if (!
|
|
2729
|
+
for (var _node of elements) {
|
|
2730
|
+
if (!_node) {
|
|
2719
2731
|
// Elision element.
|
|
2720
2732
|
iteratorRecord.next();
|
|
2721
2733
|
result = NormalCompletion(Empty);
|
|
2722
|
-
} else if (
|
|
2734
|
+
} else if (_node.type === "RestElement") {
|
|
2723
2735
|
// Rest element.
|
|
2724
|
-
if (
|
|
2725
|
-
var lhs = ResolveBinding(
|
|
2736
|
+
if (_node.argument.type === "Identifier") {
|
|
2737
|
+
var lhs = ResolveBinding(_node.argument.name, environment);
|
|
2726
2738
|
var A = [];
|
|
2727
2739
|
var n = 0; // eslint-disable-next-line no-constant-condition
|
|
2728
2740
|
|
|
@@ -2751,7 +2763,7 @@ function cook(rootAst, codeSource, {
|
|
|
2751
2763
|
} = iteratorRecord.next();
|
|
2752
2764
|
|
|
2753
2765
|
if (_done2) {
|
|
2754
|
-
result = BindingInitialization(
|
|
2766
|
+
result = BindingInitialization(_node.argument, _A, environment);
|
|
2755
2767
|
break;
|
|
2756
2768
|
}
|
|
2757
2769
|
|
|
@@ -2761,7 +2773,7 @@ function cook(rootAst, codeSource, {
|
|
|
2761
2773
|
}
|
|
2762
2774
|
} else {
|
|
2763
2775
|
// Normal element.
|
|
2764
|
-
var bindingElement =
|
|
2776
|
+
var bindingElement = _node.type === "AssignmentPattern" ? _node.left : _node;
|
|
2765
2777
|
|
|
2766
2778
|
switch (bindingElement.type) {
|
|
2767
2779
|
case "ObjectPattern":
|
|
@@ -2777,8 +2789,8 @@ function cook(rootAst, codeSource, {
|
|
|
2777
2789
|
v = _value5;
|
|
2778
2790
|
}
|
|
2779
2791
|
|
|
2780
|
-
if (
|
|
2781
|
-
var defaultValue = Evaluate(
|
|
2792
|
+
if (_node.type === "AssignmentPattern" && v === undefined) {
|
|
2793
|
+
var defaultValue = Evaluate(_node.right);
|
|
2782
2794
|
v = GetValue(defaultValue);
|
|
2783
2795
|
}
|
|
2784
2796
|
|
|
@@ -2803,9 +2815,9 @@ function cook(rootAst, codeSource, {
|
|
|
2803
2815
|
_v = _value6;
|
|
2804
2816
|
}
|
|
2805
2817
|
|
|
2806
|
-
if (
|
|
2818
|
+
if (_node.type === "AssignmentPattern" && _v === undefined) {
|
|
2807
2819
|
// IsAnonymousFunctionDefinition(Initializer)
|
|
2808
|
-
var _defaultValue = Evaluate(
|
|
2820
|
+
var _defaultValue = Evaluate(_node.right);
|
|
2809
2821
|
|
|
2810
2822
|
_v = GetValue(_defaultValue);
|
|
2811
2823
|
}
|
|
@@ -2875,6 +2887,7 @@ function cook(rootAst, codeSource, {
|
|
|
2875
2887
|
return GetValue(Evaluate(rootAst));
|
|
2876
2888
|
}
|
|
2877
2889
|
|
|
2890
|
+
(_hooks$beforeEvaluate3 = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate3 === void 0 ? void 0 : _hooks$beforeEvaluate3.call(hooks, rootAst);
|
|
2878
2891
|
ThrowIfFunctionIsInvalid(rootAst);
|
|
2879
2892
|
var [fn] = collectBoundNames(rootAst); // Create an immutable binding for the root function.
|
|
2880
2893
|
|
|
@@ -17562,7 +17575,8 @@ class AnalysisEnvironment {
|
|
|
17562
17575
|
|
|
17563
17576
|
function precook(rootAst, {
|
|
17564
17577
|
expressionOnly,
|
|
17565
|
-
visitors
|
|
17578
|
+
visitors,
|
|
17579
|
+
hooks = {}
|
|
17566
17580
|
} = {}) {
|
|
17567
17581
|
var attemptToVisitGlobals = new Set();
|
|
17568
17582
|
var analysisContextStack = [];
|
|
@@ -17588,7 +17602,10 @@ function precook(rootAst, {
|
|
|
17588
17602
|
Evaluate(n);
|
|
17589
17603
|
}
|
|
17590
17604
|
} else if (node) {
|
|
17591
|
-
// `node` maybe `null` in some cases.
|
|
17605
|
+
var _hooks$beforeVisit; // `node` maybe `null` in some cases.
|
|
17606
|
+
|
|
17607
|
+
|
|
17608
|
+
(_hooks$beforeVisit = hooks.beforeVisit) === null || _hooks$beforeVisit === void 0 ? void 0 : _hooks$beforeVisit.call(hooks, node);
|
|
17592
17609
|
visitors && visit(node); // Expressions:
|
|
17593
17610
|
|
|
17594
17611
|
switch (node.type) {
|
|
@@ -17997,6 +18014,7 @@ function lint(source, {
|
|
|
17997
18014
|
file = parse_1(source, {
|
|
17998
18015
|
plugins: ["estree", typescript && "typescript"].filter(Boolean),
|
|
17999
18016
|
strictMode: true,
|
|
18017
|
+
attachComment: false,
|
|
18000
18018
|
// Allow export/import declarations to make linter handle errors.
|
|
18001
18019
|
sourceType: "unambiguous"
|
|
18002
18020
|
});
|
|
@@ -18111,7 +18129,7 @@ function lint(source, {
|
|
|
18111
18129
|
},
|
|
18112
18130
|
|
|
18113
18131
|
VariableDeclaration(node) {
|
|
18114
|
-
if (rules !== null && rules !== void 0 && rules.noVar) {
|
|
18132
|
+
if (node.kind === "var" && rules !== null && rules !== void 0 && rules.noVar) {
|
|
18115
18133
|
errors.push({
|
|
18116
18134
|
type: "SyntaxError",
|
|
18117
18135
|
message: "Var declaration is not recommended, use `let` or `const` instead",
|
|
@@ -18156,7 +18174,8 @@ function parseAsEstreeExpression(source) {
|
|
|
18156
18174
|
return parseExpression_1(source, {
|
|
18157
18175
|
plugins: ["estree", ["pipelineOperator", {
|
|
18158
18176
|
proposal: "minimal"
|
|
18159
|
-
}]]
|
|
18177
|
+
}]],
|
|
18178
|
+
attachComment: false
|
|
18160
18179
|
});
|
|
18161
18180
|
}
|
|
18162
18181
|
function parseAsEstree(source, {
|
|
@@ -18164,7 +18183,8 @@ function parseAsEstree(source, {
|
|
|
18164
18183
|
} = {}) {
|
|
18165
18184
|
var file = parse_1(source, {
|
|
18166
18185
|
plugins: ["estree", typescript && "typescript"].filter(Boolean),
|
|
18167
|
-
strictMode: true
|
|
18186
|
+
strictMode: true,
|
|
18187
|
+
attachComment: false
|
|
18168
18188
|
});
|
|
18169
18189
|
var body = file.program.body;
|
|
18170
18190
|
var jsNodes = typescript ? [] : body;
|
|
@@ -18186,7 +18206,7 @@ function parseAsEstree(source, {
|
|
|
18186
18206
|
}
|
|
18187
18207
|
|
|
18188
18208
|
if (jsNodes.length > 1 || jsNodes[0].type !== "FunctionDeclaration") {
|
|
18189
|
-
throw new SyntaxError("Expect a single function declaration, but received: ".concat(jsNodes.map(node => "\"".concat(node.type, "\"")).join(", ")));
|
|
18209
|
+
throw new SyntaxError("Expect a single function declaration at top level, but received: ".concat(jsNodes.map(node => "\"".concat(node.type, "\"")).join(", ")));
|
|
18190
18210
|
}
|
|
18191
18211
|
|
|
18192
18212
|
return jsNodes[0];
|