(
this: Parser,
node: Undone<N.Function>,
allowExpression?: boolean | null,
isMethod: boolean = false,
)
| 2609 | |
| 2610 | // Parse function body and check parameters. |
| 2611 | parseFunctionBody( |
| 2612 | this: Parser, |
| 2613 | node: Undone<N.Function>, |
| 2614 | allowExpression?: boolean | null, |
| 2615 | isMethod: boolean = false, |
| 2616 | ): void { |
| 2617 | const isExpression = allowExpression && !this.match(tt.braceL); |
| 2618 | this.expressionScope.enter(sharedExpressionScope); |
| 2619 | |
| 2620 | if (isExpression) { |
| 2621 | // https://tc39.es/ecma262/#prod-ExpressionBody |
| 2622 | (node as Undone<N.ArrowFunctionExpression>).body = |
| 2623 | this.parseMaybeAssign(); |
| 2624 | this.checkParams(node, false, allowExpression, false); |
| 2625 | } else { |
| 2626 | const oldStrict = this.state.strict; |
| 2627 | // Start a new scope with regard to labels |
| 2628 | // flag (restore them to their old value afterwards). |
| 2629 | const oldLabels = this.state.labels; |
| 2630 | this.state.labels = []; |
| 2631 | |
| 2632 | // FunctionBody[Yield, Await]: |
| 2633 | // StatementList[?Yield, ?Await, +Return] opt |
| 2634 | this.prodParam.enter( |
| 2635 | this.prodParam.currentFlags() | ParamKind.PARAM_RETURN, |
| 2636 | ); |
| 2637 | node.body = this.parseBlock( |
| 2638 | true, |
| 2639 | false, |
| 2640 | // Strict mode function checks after we parse the statements in the function body. |
| 2641 | (hasStrictModeDirective: boolean) => { |
| 2642 | const nonSimple = !this.isSimpleParamList(node.params); |
| 2643 | |
| 2644 | if (hasStrictModeDirective && nonSimple) { |
| 2645 | // This logic is here to align the error location with the ESTree plugin. |
| 2646 | this.raise( |
| 2647 | Errors.IllegalLanguageModeDirective, |
| 2648 | // @ts-expect-error kind may not index node |
| 2649 | (node.kind === "method" || node.kind === "constructor") && |
| 2650 | // @ts-expect-error key may not index node |
| 2651 | !!node.key |
| 2652 | ? this.optionFlags & OptionFlags.Locations |
| 2653 | ? // @ts-expect-error node.key has been guarded |
| 2654 | node.key.loc.end |
| 2655 | : // @ts-expect-error node.key has been guarded |
| 2656 | node.key |
| 2657 | : node, |
| 2658 | ); |
| 2659 | } |
| 2660 | |
| 2661 | const strictModeChanged = !oldStrict && this.state.strict; |
| 2662 | |
| 2663 | // Add the params to varDeclaredNames to ensure that an error is thrown |
| 2664 | // if a let/const declaration in the function clashes with one of the params. |
| 2665 | this.checkParams( |
| 2666 | node, |
| 2667 | !this.state.strict && !allowExpression && !isMethod && !nonSimple, |
| 2668 | allowExpression, |
nothing calls this directly
no test coverage detected