MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseTestBinary

Function parseTestBinary

source code/utils/bash/bashParser.ts:3823–3935  ·  view source on GitHub ↗
(P: ParseState, closer: string)

Source from the content-addressed store, hash-verified

3821}
3822
3823function parseTestBinary(P: ParseState, closer: string): TsNode | null {
3824 skipBlanks(P.L)
3825 // `!` in test context binds tighter than =~/==.
3826 // `[[ ! "x" =~ y ]]` → (binary_expression (unary_expression (string)) (regex))
3827 // `[[ ! -f x ]]` → (unary_expression ! (unary_expression (test_operator) (word)))
3828 const left = parseTestNegatablePrimary(P, closer)
3829 if (!left) return null
3830 skipBlanks(P.L)
3831 // Binary comparison: == != =~ -eq -lt etc.
3832 const c = peek(P.L)
3833 const c1 = peek(P.L, 1)
3834 let op: TsNode | null = null
3835 const os = P.L.b
3836 if (c === '=' && c1 === '=') {
3837 advance(P.L)
3838 advance(P.L)
3839 op = mk(P, '==', os, P.L.b, [])
3840 } else if (c === '!' && c1 === '=') {
3841 advance(P.L)
3842 advance(P.L)
3843 op = mk(P, '!=', os, P.L.b, [])
3844 } else if (c === '=' && c1 === '~') {
3845 advance(P.L)
3846 advance(P.L)
3847 op = mk(P, '=~', os, P.L.b, [])
3848 } else if (c === '=' && c1 !== '=') {
3849 advance(P.L)
3850 op = mk(P, '=', os, P.L.b, [])
3851 } else if (c === '<' && c1 !== '<') {
3852 advance(P.L)
3853 op = mk(P, '<', os, P.L.b, [])
3854 } else if (c === '>' && c1 !== '>') {
3855 advance(P.L)
3856 op = mk(P, '>', os, P.L.b, [])
3857 } else if (c === '-' && isIdentStart(c1)) {
3858 advance(P.L)
3859 while (isIdentChar(peek(P.L))) advance(P.L)
3860 op = mk(P, 'test_operator', os, P.L.b, [])
3861 }
3862 if (!op) return left
3863 skipBlanks(P.L)
3864 // In [[ ]], RHS of ==/!=/=/=~ gets special pattern parsing: paren counting
3865 // so @(a|b|c) doesn't break on |, and segments become extglob_pattern/regex.
3866 if (closer === ']]') {
3867 const opText = op.type
3868 if (opText === '=~') {
3869 skipBlanks(P.L)
3870 // If the ENTIRE RHS is a quoted string, emit string/raw_string not
3871 // regex: `[[ "$x" =~ "$y" ]]` → (binary_expression (string) (string)).
3872 // If there's content after the quote (`' boop '(.*)$`), the whole RHS
3873 // stays a single (regex). Peek past the quote to check.
3874 const rc = peek(P.L)
3875 let rhs: TsNode | null = null
3876 if (rc === '"' || rc === "'") {
3877 const save = saveLex(P.L)
3878 const quoted =
3879 rc === '"'
3880 ? parseDoubleQuoted(P)

Callers 1

parseTestUnaryFunction · 0.85

Calls 15

skipBlanksFunction · 0.85
advanceFunction · 0.85
mkFunction · 0.85
isIdentStartFunction · 0.85
isIdentCharFunction · 0.85
saveLexFunction · 0.85
parseDoubleQuotedFunction · 0.85
leafFunction · 0.85
nextTokenFunction · 0.85
restoreLexFunction · 0.85
parseTestRegexRhsFunction · 0.85

Tested by

no test coverage detected