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