MCPcopy Index your code
hub / github.com/codeaashu/claude-code / isRedirectLiteralStart

Function isRedirectLiteralStart

src/utils/bash/bashParser.ts:1588–1614  ·  view source on GitHub ↗

* Can the current position start a redirect destination literal? * Returns false at redirect ops, terminators, or file-descriptor-prefixed ops * so file_redirect's repeat1($._literal) stops at the right boundary.

(P: ParseState)

Source from the content-addressed store, hash-verified

1586 * so file_redirect's repeat1($._literal) stops at the right boundary.
1587 */
1588function isRedirectLiteralStart(P: ParseState): boolean {
1589 const c = peek(P.L)
1590 if (c === '' || c === '\n') return false
1591 // Shell terminators and operators
1592 if (c === '|' || c === '&' || c === ';' || c === '(' || c === ')')
1593 return false
1594 // Redirect operators (< > with any suffix; <( >( handled by caller)
1595 if (c === '<' || c === '>') {
1596 // <( >( are process substitutions — those ARE literals
1597 return peek(P.L, 1) === '('
1598 }
1599 // N< N> file descriptor prefix — starts a new redirect, not a literal
1600 if (isDigit(c)) {
1601 let j = P.L.i
1602 while (j < P.L.len && isDigit(P.L.src[j]!)) j++
1603 const after = j < P.L.len ? P.L.src[j]! : ''
1604 if (after === '>' || after === '<') return false
1605 }
1606 // `}` only terminates if we're in a context where it's a closer — but
1607 // file_redirect sees `}` as word char (e.g., `>$HOME}` is valid path char).
1608 // Actually `}` at top level terminates compound_statement — need to stop.
1609 if (c === '}') return false
1610 // Test command closer — when parseSimpleCommand is called from `[` context,
1611 // `]` must terminate so parseCommand can return and `[` handler consume it.
1612 if (P.stopToken === ']' && c === ']') return false
1613 return true
1614}
1615
1616/**
1617 * Parse a redirect operator + destination(s).

Callers 1

tryParseRedirectFunction · 0.85

Calls 2

isDigitFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected