@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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
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.28.5](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.28.4...@next-core/brick-utils@2.28.5) (2021-09-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @next-core/brick-utils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.28.4](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.28.3...@next-core/brick-utils@2.28.4) (2021-09-30)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @next-core/brick-utils
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [2.28.3](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.28.2...@next-core/brick-utils@2.28.3) (2021-09-27)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @next-core/brick-utils
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [2.28.2](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.28.1...@next-core/brick-utils@2.28.2) (2021-09-23)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @next-core/brick-utils
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
## [2.28.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.28.0...@next-core/brick-utils@2.28.1) (2021-09-22)
|
|
7
39
|
|
|
8
40
|
**Note:** Version bump only for package @next-core/brick-utils
|
package/dist/index.bundle.js
CHANGED
|
@@ -825,6 +825,7 @@
|
|
|
825
825
|
}
|
|
826
826
|
class DeclarativeEnvironment extends EnvironmentRecord {}
|
|
827
827
|
class FunctionEnvironment extends EnvironmentRecord {}
|
|
828
|
+
var SourceNode = Symbol.for("SourceNode");
|
|
828
829
|
var FormalParameters = Symbol.for("FormalParameters");
|
|
829
830
|
var ECMAScriptCode = Symbol.for("ECMAScriptCode");
|
|
830
831
|
var Environment = Symbol.for("Environment");
|
|
@@ -1290,8 +1291,11 @@
|
|
|
1290
1291
|
|
|
1291
1292
|
function cook(rootAst, codeSource, {
|
|
1292
1293
|
rules,
|
|
1293
|
-
globalVariables = {}
|
|
1294
|
+
globalVariables = {},
|
|
1295
|
+
hooks = {}
|
|
1294
1296
|
} = {}) {
|
|
1297
|
+
var _hooks$beforeEvaluate3;
|
|
1298
|
+
|
|
1295
1299
|
var expressionOnly = rootAst.type !== "FunctionDeclaration";
|
|
1296
1300
|
var rootEnv = new DeclarativeEnvironment(null);
|
|
1297
1301
|
var rootContext = new ExecutionContext();
|
|
@@ -1328,7 +1332,10 @@
|
|
|
1328
1332
|
}
|
|
1329
1333
|
|
|
1330
1334
|
function Evaluate(node, optionalChainRef) {
|
|
1331
|
-
|
|
1335
|
+
var _hooks$beforeEvaluate, _hooks$beforeBranch, _hooks$beforeBranch2;
|
|
1336
|
+
|
|
1337
|
+
(_hooks$beforeEvaluate = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate === void 0 ? void 0 : _hooks$beforeEvaluate.call(hooks, node); // Expressions:
|
|
1338
|
+
|
|
1332
1339
|
switch (node.type) {
|
|
1333
1340
|
case "ArrayExpression":
|
|
1334
1341
|
{
|
|
@@ -1667,7 +1674,7 @@
|
|
|
1667
1674
|
|
|
1668
1675
|
case "IfStatement":
|
|
1669
1676
|
// https://tc39.es/ecma262/#sec-if-statement
|
|
1670
|
-
return GetValue(Evaluate(node.test)) ? UpdateEmpty(Evaluate(node.consequent), undefined) : node.alternate ? UpdateEmpty(Evaluate(node.alternate), undefined) : NormalCompletion(undefined);
|
|
1677
|
+
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);
|
|
1671
1678
|
|
|
1672
1679
|
case "ReturnStatement":
|
|
1673
1680
|
{
|
|
@@ -1725,6 +1732,9 @@
|
|
|
1725
1732
|
_R = Evaluate(node.block);
|
|
1726
1733
|
} catch (error) {
|
|
1727
1734
|
if (node.handler) {
|
|
1735
|
+
var _hooks$beforeEvaluate2;
|
|
1736
|
+
|
|
1737
|
+
(_hooks$beforeEvaluate2 = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate2 === void 0 ? void 0 : _hooks$beforeEvaluate2.call(hooks, node.handler);
|
|
1728
1738
|
_R = CatchClauseEvaluation(node.handler, error);
|
|
1729
1739
|
} else {
|
|
1730
1740
|
throw error;
|
|
@@ -2432,6 +2442,9 @@
|
|
|
2432
2442
|
|
|
2433
2443
|
|
|
2434
2444
|
function CallFunction(closure, args) {
|
|
2445
|
+
var _hooks$beforeCall;
|
|
2446
|
+
|
|
2447
|
+
(_hooks$beforeCall = hooks.beforeCall) === null || _hooks$beforeCall === void 0 ? void 0 : _hooks$beforeCall.call(hooks, closure[SourceNode]);
|
|
2435
2448
|
PrepareForOrdinaryCall(closure);
|
|
2436
2449
|
var result = OrdinaryCallEvaluateBody(closure, args);
|
|
2437
2450
|
executionContextStack.pop();
|
|
@@ -2592,7 +2605,7 @@
|
|
|
2592
2605
|
|
|
2593
2606
|
|
|
2594
2607
|
function InstantiateFunctionObject(func, scope) {
|
|
2595
|
-
return OrdinaryFunctionCreate(func
|
|
2608
|
+
return OrdinaryFunctionCreate(func, scope, true);
|
|
2596
2609
|
} // https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionexpression
|
|
2597
2610
|
|
|
2598
2611
|
|
|
@@ -2603,11 +2616,13 @@
|
|
|
2603
2616
|
var name = functionExpression.id.name;
|
|
2604
2617
|
var funcEnv = new DeclarativeEnvironment(scope);
|
|
2605
2618
|
funcEnv.CreateImmutableBinding(name, false);
|
|
2606
|
-
var closure = OrdinaryFunctionCreate(functionExpression
|
|
2619
|
+
var closure = OrdinaryFunctionCreate(functionExpression, // functionExpression.params,
|
|
2620
|
+
// functionExpression.body,
|
|
2621
|
+
funcEnv, true);
|
|
2607
2622
|
funcEnv.InitializeBinding(name, closure);
|
|
2608
2623
|
return closure;
|
|
2609
2624
|
} else {
|
|
2610
|
-
var _closure = OrdinaryFunctionCreate(functionExpression
|
|
2625
|
+
var _closure = OrdinaryFunctionCreate(functionExpression, scope, true);
|
|
2611
2626
|
|
|
2612
2627
|
return _closure;
|
|
2613
2628
|
}
|
|
@@ -2616,36 +2631,33 @@
|
|
|
2616
2631
|
|
|
2617
2632
|
function InstantiateArrowFunctionExpression(arrowFunction) {
|
|
2618
2633
|
var scope = getRunningContext().LexicalEnvironment;
|
|
2619
|
-
var closure = OrdinaryFunctionCreate(arrowFunction
|
|
2634
|
+
var closure = OrdinaryFunctionCreate(arrowFunction, scope, false);
|
|
2620
2635
|
return closure;
|
|
2621
2636
|
} // https://tc39.es/ecma262/#sec-ordinaryfunctioncreate
|
|
2622
2637
|
|
|
2623
2638
|
|
|
2624
|
-
function OrdinaryFunctionCreate(
|
|
2639
|
+
function OrdinaryFunctionCreate(sourceNode, // parameterList: FunctionDeclaration["params"],
|
|
2640
|
+
// body: BlockStatement | Expression,
|
|
2641
|
+
scope, isConstructor) {
|
|
2625
2642
|
var F = function () {
|
|
2626
2643
|
// eslint-disable-next-line prefer-rest-params
|
|
2627
2644
|
return CallFunction(F, arguments);
|
|
2628
2645
|
};
|
|
2629
2646
|
|
|
2630
2647
|
Object.defineProperties(F, {
|
|
2648
|
+
[SourceNode]: {
|
|
2649
|
+
value: sourceNode
|
|
2650
|
+
},
|
|
2631
2651
|
[FormalParameters]: {
|
|
2632
|
-
|
|
2633
|
-
writable: false,
|
|
2634
|
-
value: parameterList
|
|
2652
|
+
value: sourceNode.params
|
|
2635
2653
|
},
|
|
2636
2654
|
[ECMAScriptCode]: {
|
|
2637
|
-
|
|
2638
|
-
writable: false,
|
|
2639
|
-
value: body.type === "BlockStatement" ? body.body : body
|
|
2655
|
+
value: sourceNode.body.type === "BlockStatement" ? sourceNode.body.body : sourceNode.body
|
|
2640
2656
|
},
|
|
2641
2657
|
[Environment]: {
|
|
2642
|
-
enumerable: false,
|
|
2643
|
-
writable: false,
|
|
2644
2658
|
value: scope
|
|
2645
2659
|
},
|
|
2646
2660
|
[IsConstructor]: {
|
|
2647
|
-
enumerable: false,
|
|
2648
|
-
writable: false,
|
|
2649
2661
|
value: isConstructor
|
|
2650
2662
|
}
|
|
2651
2663
|
});
|
|
@@ -2719,15 +2731,15 @@
|
|
|
2719
2731
|
|
|
2720
2732
|
var result;
|
|
2721
2733
|
|
|
2722
|
-
for (var
|
|
2723
|
-
if (!
|
|
2734
|
+
for (var _node of elements) {
|
|
2735
|
+
if (!_node) {
|
|
2724
2736
|
// Elision element.
|
|
2725
2737
|
iteratorRecord.next();
|
|
2726
2738
|
result = NormalCompletion(Empty);
|
|
2727
|
-
} else if (
|
|
2739
|
+
} else if (_node.type === "RestElement") {
|
|
2728
2740
|
// Rest element.
|
|
2729
|
-
if (
|
|
2730
|
-
var lhs = ResolveBinding(
|
|
2741
|
+
if (_node.argument.type === "Identifier") {
|
|
2742
|
+
var lhs = ResolveBinding(_node.argument.name, environment);
|
|
2731
2743
|
var A = [];
|
|
2732
2744
|
var n = 0; // eslint-disable-next-line no-constant-condition
|
|
2733
2745
|
|
|
@@ -2756,7 +2768,7 @@
|
|
|
2756
2768
|
} = iteratorRecord.next();
|
|
2757
2769
|
|
|
2758
2770
|
if (_done2) {
|
|
2759
|
-
result = BindingInitialization(
|
|
2771
|
+
result = BindingInitialization(_node.argument, _A, environment);
|
|
2760
2772
|
break;
|
|
2761
2773
|
}
|
|
2762
2774
|
|
|
@@ -2766,7 +2778,7 @@
|
|
|
2766
2778
|
}
|
|
2767
2779
|
} else {
|
|
2768
2780
|
// Normal element.
|
|
2769
|
-
var bindingElement =
|
|
2781
|
+
var bindingElement = _node.type === "AssignmentPattern" ? _node.left : _node;
|
|
2770
2782
|
|
|
2771
2783
|
switch (bindingElement.type) {
|
|
2772
2784
|
case "ObjectPattern":
|
|
@@ -2782,8 +2794,8 @@
|
|
|
2782
2794
|
v = _value5;
|
|
2783
2795
|
}
|
|
2784
2796
|
|
|
2785
|
-
if (
|
|
2786
|
-
var defaultValue = Evaluate(
|
|
2797
|
+
if (_node.type === "AssignmentPattern" && v === undefined) {
|
|
2798
|
+
var defaultValue = Evaluate(_node.right);
|
|
2787
2799
|
v = GetValue(defaultValue);
|
|
2788
2800
|
}
|
|
2789
2801
|
|
|
@@ -2808,9 +2820,9 @@
|
|
|
2808
2820
|
_v = _value6;
|
|
2809
2821
|
}
|
|
2810
2822
|
|
|
2811
|
-
if (
|
|
2823
|
+
if (_node.type === "AssignmentPattern" && _v === undefined) {
|
|
2812
2824
|
// IsAnonymousFunctionDefinition(Initializer)
|
|
2813
|
-
var _defaultValue = Evaluate(
|
|
2825
|
+
var _defaultValue = Evaluate(_node.right);
|
|
2814
2826
|
|
|
2815
2827
|
_v = GetValue(_defaultValue);
|
|
2816
2828
|
}
|
|
@@ -2880,6 +2892,7 @@
|
|
|
2880
2892
|
return GetValue(Evaluate(rootAst));
|
|
2881
2893
|
}
|
|
2882
2894
|
|
|
2895
|
+
(_hooks$beforeEvaluate3 = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate3 === void 0 ? void 0 : _hooks$beforeEvaluate3.call(hooks, rootAst);
|
|
2883
2896
|
ThrowIfFunctionIsInvalid(rootAst);
|
|
2884
2897
|
var [fn] = collectBoundNames(rootAst); // Create an immutable binding for the root function.
|
|
2885
2898
|
|
|
@@ -17567,7 +17580,8 @@
|
|
|
17567
17580
|
|
|
17568
17581
|
function precook(rootAst, {
|
|
17569
17582
|
expressionOnly,
|
|
17570
|
-
visitors
|
|
17583
|
+
visitors,
|
|
17584
|
+
hooks = {}
|
|
17571
17585
|
} = {}) {
|
|
17572
17586
|
var attemptToVisitGlobals = new Set();
|
|
17573
17587
|
var analysisContextStack = [];
|
|
@@ -17593,7 +17607,10 @@
|
|
|
17593
17607
|
Evaluate(n);
|
|
17594
17608
|
}
|
|
17595
17609
|
} else if (node) {
|
|
17596
|
-
// `node` maybe `null` in some cases.
|
|
17610
|
+
var _hooks$beforeVisit; // `node` maybe `null` in some cases.
|
|
17611
|
+
|
|
17612
|
+
|
|
17613
|
+
(_hooks$beforeVisit = hooks.beforeVisit) === null || _hooks$beforeVisit === void 0 ? void 0 : _hooks$beforeVisit.call(hooks, node);
|
|
17597
17614
|
visitors && visit(node); // Expressions:
|
|
17598
17615
|
|
|
17599
17616
|
switch (node.type) {
|
|
@@ -18002,6 +18019,7 @@
|
|
|
18002
18019
|
file = parse_1(source, {
|
|
18003
18020
|
plugins: ["estree", typescript && "typescript"].filter(Boolean),
|
|
18004
18021
|
strictMode: true,
|
|
18022
|
+
attachComment: false,
|
|
18005
18023
|
// Allow export/import declarations to make linter handle errors.
|
|
18006
18024
|
sourceType: "unambiguous"
|
|
18007
18025
|
});
|
|
@@ -18116,7 +18134,7 @@
|
|
|
18116
18134
|
},
|
|
18117
18135
|
|
|
18118
18136
|
VariableDeclaration(node) {
|
|
18119
|
-
if (rules !== null && rules !== void 0 && rules.noVar) {
|
|
18137
|
+
if (node.kind === "var" && rules !== null && rules !== void 0 && rules.noVar) {
|
|
18120
18138
|
errors.push({
|
|
18121
18139
|
type: "SyntaxError",
|
|
18122
18140
|
message: "Var declaration is not recommended, use `let` or `const` instead",
|
|
@@ -18161,7 +18179,8 @@
|
|
|
18161
18179
|
return parseExpression_1(source, {
|
|
18162
18180
|
plugins: ["estree", ["pipelineOperator", {
|
|
18163
18181
|
proposal: "minimal"
|
|
18164
|
-
}]]
|
|
18182
|
+
}]],
|
|
18183
|
+
attachComment: false
|
|
18165
18184
|
});
|
|
18166
18185
|
}
|
|
18167
18186
|
function parseAsEstree(source, {
|
|
@@ -18169,7 +18188,8 @@
|
|
|
18169
18188
|
} = {}) {
|
|
18170
18189
|
var file = parse_1(source, {
|
|
18171
18190
|
plugins: ["estree", typescript && "typescript"].filter(Boolean),
|
|
18172
|
-
strictMode: true
|
|
18191
|
+
strictMode: true,
|
|
18192
|
+
attachComment: false
|
|
18173
18193
|
});
|
|
18174
18194
|
var body = file.program.body;
|
|
18175
18195
|
var jsNodes = typescript ? [] : body;
|
|
@@ -18191,7 +18211,7 @@
|
|
|
18191
18211
|
}
|
|
18192
18212
|
|
|
18193
18213
|
if (jsNodes.length > 1 || jsNodes[0].type !== "FunctionDeclaration") {
|
|
18194
|
-
throw new SyntaxError("Expect a single function declaration, but received: ".concat(jsNodes.map(node => "\"".concat(node.type, "\"")).join(", ")));
|
|
18214
|
+
throw new SyntaxError("Expect a single function declaration at top level, but received: ".concat(jsNodes.map(node => "\"".concat(node.type, "\"")).join(", ")));
|
|
18195
18215
|
}
|
|
18196
18216
|
|
|
18197
18217
|
return jsNodes[0];
|