(P: ParseState, fnTok: Token)
| 3563 | } |
| 3564 | |
| 3565 | function parseFunction(P: ParseState, fnTok: Token): TsNode { |
| 3566 | const fnKw = leaf(P, 'function', fnTok) |
| 3567 | skipBlanks(P.L) |
| 3568 | const nameTok = nextToken(P.L, 'arg') |
| 3569 | const name = mk(P, 'word', nameTok.start, nameTok.end, []) |
| 3570 | const kids: TsNode[] = [fnKw, name] |
| 3571 | skipBlanks(P.L) |
| 3572 | if (peek(P.L) === '(' && peek(P.L, 1) === ')') { |
| 3573 | const o = nextToken(P.L, 'cmd') |
| 3574 | const c = nextToken(P.L, 'cmd') |
| 3575 | kids.push(leaf(P, '(', o)) |
| 3576 | kids.push(leaf(P, ')', c)) |
| 3577 | } |
| 3578 | skipBlanks(P.L) |
| 3579 | skipNewlines(P) |
| 3580 | const body = parseCommand(P) |
| 3581 | if (body) { |
| 3582 | // Hoist redirects from redirected_statement(compound_statement, ...) to |
| 3583 | // function_definition level per tree-sitter grammar |
| 3584 | if ( |
| 3585 | body.type === 'redirected_statement' && |
| 3586 | body.children.length >= 2 && |
| 3587 | body.children[0]!.type === 'compound_statement' |
| 3588 | ) { |
| 3589 | kids.push(...body.children) |
| 3590 | } else { |
| 3591 | kids.push(body) |
| 3592 | } |
| 3593 | } |
| 3594 | const last = kids[kids.length - 1]! |
| 3595 | return mk(P, 'function_definition', fnKw.startIndex, last.endIndex, kids) |
| 3596 | } |
| 3597 | |
| 3598 | function parseDeclaration(P: ParseState, kwTok: Token): TsNode { |
| 3599 | const kw = leaf(P, kwTok.value, kwTok) |
no test coverage detected