MCPcopy Index your code
hub / github.com/liuup/claude-code-analysis / parseUnset

Function parseUnset

src/utils/bash/bashParser.ts:3650–3686  ·  view source on GitHub ↗
(P: ParseState, kwTok: Token)

Source from the content-addressed store, hash-verified

3648}
3649
3650function parseUnset(P: ParseState, kwTok: Token): TsNode {
3651 const kw = leaf(P, 'unset', kwTok)
3652 const kids: TsNode[] = [kw]
3653 while (true) {
3654 skipBlanks(P.L)
3655 const c = peek(P.L)
3656 if (
3657 c === '' ||
3658 c === '\n' ||
3659 c === ';' ||
3660 c === '&' ||
3661 c === '|' ||
3662 c === ')' ||
3663 c === '<' ||
3664 c === '>'
3665 ) {
3666 break
3667 }
3668 // SECURITY: use parseWord (not raw nextToken) so quoted strings like
3669 // `unset 'a[$(id)]'` emit a raw_string child that ast.ts can reject.
3670 // Previously `break` silently dropped non-WORD args — hiding the
3671 // arithmetic-subscript code-exec vector from the security walker.
3672 const arg = parseWord(P, 'arg')
3673 if (!arg) break
3674 if (arg.type === 'word') {
3675 if (arg.text.startsWith('-')) {
3676 kids.push(arg)
3677 } else {
3678 kids.push(mk(P, 'variable_name', arg.startIndex, arg.endIndex, []))
3679 }
3680 } else {
3681 kids.push(arg)
3682 }
3683 }
3684 const last = kids[kids.length - 1]!
3685 return mk(P, 'unset_command', kw.startIndex, last.endIndex, kids)
3686}
3687
3688function consumeKeyword(P: ParseState, name: string, kids: TsNode[]): void {
3689 skipNewlines(P)

Callers 1

parseCommandFunction · 0.85

Calls 5

leafFunction · 0.85
skipBlanksFunction · 0.85
parseWordFunction · 0.85
mkFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected