(
this: Parser,
node: Undone<T>,
flags: ParseFunctionFlag = ParseFunctionFlag.Expression,
)
| 1501 | // ParseFunctionFlag.Declaration flag). |
| 1502 | |
| 1503 | parseFunction<T extends N.NormalFunction>( |
| 1504 | this: Parser, |
| 1505 | node: Undone<T>, |
| 1506 | flags: ParseFunctionFlag = ParseFunctionFlag.Expression, |
| 1507 | ): T { |
| 1508 | const isDeclaration = !!(flags & ParseFunctionFlag.Declaration); |
| 1509 | const requireId = isDeclaration && !(flags & ParseFunctionFlag.NullableId); |
| 1510 | const isAsync = !!(flags & ParseFunctionFlag.Async); |
| 1511 | |
| 1512 | this.initFunction(node, isAsync); |
| 1513 | |
| 1514 | if (this.match(tt.star)) { |
| 1515 | if (flags & ParseFunctionFlag.SingleStatement) { |
| 1516 | this.raise( |
| 1517 | Errors.GeneratorInSingleStatementContext, |
| 1518 | this.state.startLoc, |
| 1519 | ); |
| 1520 | } |
| 1521 | this.next(); // eat * |
| 1522 | node.generator = true; |
| 1523 | } |
| 1524 | |
| 1525 | if (isDeclaration) { |
| 1526 | node.id = this.parseFunctionId(requireId); |
| 1527 | } |
| 1528 | |
| 1529 | this.scope.enter(ScopeFlag.FUNCTION); |
| 1530 | this.prodParam.enter(functionFlags(isAsync, node.generator)); |
| 1531 | |
| 1532 | if (!isDeclaration && tokenIsIdentifier(this.state.type)) { |
| 1533 | // The name of a function expression is not part of an enclosing async |
| 1534 | // arrow head, so `await` must not be recorded as an error there: |
| 1535 | // `async (x = function await() {}) => {}` is valid. |
| 1536 | this.expressionScope.enter(sharedExpressionScope); |
| 1537 | node.id = this.parseFunctionId(); |
| 1538 | this.expressionScope.exit(); |
| 1539 | } |
| 1540 | |
| 1541 | this.parseFunctionParams(node, /* isConstructor */ false); |
| 1542 | |
| 1543 | this.parseFunctionBodyAndFinish( |
| 1544 | node, |
| 1545 | isDeclaration ? "FunctionDeclaration" : "FunctionExpression", |
| 1546 | ); |
| 1547 | |
| 1548 | this.prodParam.exit(); |
| 1549 | this.scope.exit(); |
| 1550 | |
| 1551 | if (isDeclaration && !(flags & ParseFunctionFlag.HangingDeclaration)) { |
| 1552 | // We need to register this _after_ parsing the function body |
| 1553 | // because of TypeScript body-less function declarations, |
| 1554 | // which shouldn't be added to the scope. |
| 1555 | this.registerFunctionStatementId(node as T); |
| 1556 | } |
| 1557 | |
| 1558 | return node as T; |
| 1559 | } |
| 1560 |
nothing calls this directly
no test coverage detected