@next-core/cook 2.4.4 → 2.4.6

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/esm/cook.js CHANGED
@@ -12,7 +12,7 @@ export function __dev_only_getGlobalExecutionContextStack() {
12
12
 
13
13
  /** For next-core internal usage only. */
14
14
  export function cook(rootAst, codeSource) {
15
- var _hooks$beforeEvaluate3;
15
+ var _hooks$beforeEvaluate4;
16
16
  let {
17
17
  rules,
18
18
  debug,
@@ -1137,6 +1137,8 @@ export function cook(rootAst, codeSource) {
1137
1137
 
1138
1138
  // https://tc39.es/ecma262/#sec-runtime-semantics-namedevaluation
1139
1139
  function NamedEvaluation(node, name) {
1140
+ var _hooks$beforeEvaluate3;
1141
+ (_hooks$beforeEvaluate3 = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate3 === void 0 || _hooks$beforeEvaluate3.call(hooks, node);
1140
1142
  // No ParenthesizedExpression in ESTree.
1141
1143
  switch (node.type) {
1142
1144
  case "FunctionExpression":
@@ -1359,6 +1361,11 @@ export function cook(rootAst, codeSource) {
1359
1361
  value: lexicalThis ? Mode.LEXICAL : Mode.STRICT
1360
1362
  }
1361
1363
  });
1364
+ const len = ExpectedArgumentCount(sourceNode.params);
1365
+ Object.defineProperty(F, "length", {
1366
+ configurable: true,
1367
+ value: len
1368
+ });
1362
1369
  if (debug || externalSourceForDebug) {
1363
1370
  Object.defineProperty(F, DebuggerCall, {
1364
1371
  value: function () {
@@ -1369,6 +1376,19 @@ export function cook(rootAst, codeSource) {
1369
1376
  }
1370
1377
  return F;
1371
1378
  }
1379
+ function ExpectedArgumentCount(params) {
1380
+ let count = 0;
1381
+ for (const param of params) {
1382
+ switch (param.type) {
1383
+ case "AssignmentPattern":
1384
+ case "RestElement":
1385
+ return count;
1386
+ default:
1387
+ count++;
1388
+ }
1389
+ }
1390
+ return count;
1391
+ }
1372
1392
 
1373
1393
  // Patterns initialization.
1374
1394
  // https://tc39.es/ecma262/#sec-runtime-semantics-bindinginitialization
@@ -1565,7 +1585,7 @@ export function cook(rootAst, codeSource) {
1565
1585
  if (expressionOnly) {
1566
1586
  return GetValue(unwind(Evaluate(rootAst)));
1567
1587
  }
1568
- (_hooks$beforeEvaluate3 = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate3 === void 0 || _hooks$beforeEvaluate3.call(hooks, rootAst);
1588
+ (_hooks$beforeEvaluate4 = hooks.beforeEvaluate) === null || _hooks$beforeEvaluate4 === void 0 || _hooks$beforeEvaluate4.call(hooks, rootAst);
1569
1589
  ThrowIfFunctionIsInvalid(rootAst);
1570
1590
  const [fn] = collectBoundNames(rootAst);
1571
1591
  // Create an immutable binding for the root function.