[Bug] tree-sitter-bash parses `$_` / `${_}` as variable_name instead of special_variable_name
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 85/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- bash, typescript
- Ambito
- compilers
Direzione di ricerca
Inizia in src/parser.ts presso parseDollar() e parseExpansion(), dove 0 viene gestito come caso speciale; applica la diff di due righe per trattare anche _ come speciale. Aggiungi le righe del fixture a packages/tree-sitter-bash/test/fixtures/differential/expansions.txt. Esegui pnpm --filter @moonshot-ai/tree-sitter-bash test; fatto significa che la suite differenziale passa con special_variable_name per un _ isolato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What issue are you seeing?
packages/tree-sitter-bash parses the special parameter $_ as a variable_name, while the reference grammar ([email protected], the parser this package is differentially compared against) parses a lone _ as a special_variable_name. So ourDump(source) !== referenceDump(source) for input the package claims byte-identical tree parity on.
echo $_:
ours:
program [0,7] "echo $_"
command [0,7] "echo $_"
command_name [0,4] "echo"
word [0,4] "echo"
simple_expansion [5,7] "$_"
($) [5,6] "$"
variable_name [6,7] "_"
reference:
program [0,7] "echo $_"
command [0,7] "echo $_"
command_name [0,4] "echo"
word [0,4] "echo"
simple_expansion [5,7] "$_"
($) [5,6] "$"
special_variable_name [6,7] "_"
Same divergence for echo ${_}, echo ${_#x}, "${_}", ${_:-d}, ${_=x}: the _ child is variable_name here, special_variable_name in the reference.
Not affected (both sides agree): $?, $#, $-, $!, $@, $*, $$, $0, $1; and $_a, ${_a}, $__, which are variable_name on both sides (the \w+ rule wins once another word character follows).
What steps can reproduce the bug?
- Append a fixture to
packages/tree-sitter-bash/test/fixtures/differential/expansions.txt:
@match: echo $_ and ${_} are special parameters, $_a and ${_a} are not
echo $_ ${_} ${_#x} $_a ${_a}
===
pnpm --filter @moonshot-ai/tree-sitter-bash test
The differential suite fails on that fixture with the diff above (echo $_a and echo ${_a} still match).
What is the expected behavior?
A lone _ after $, and a lone _ as an expansion body, should produce special_variable_name "_" — matching _special_variable_name in the reference grammar:
_special_variable_name: $ => alias(choice('*', '@', '?', '!', '#', '-', '$', '0', '_'), $.special_variable_name),
_simple_variable_name: $ => alias(/\w+/, $.variable_name),
Additional information
Root cause: src/grammar.ts already lists _ in SPECIAL_VARIABLES (['@', '*', '#', '?', '-', '$', '!', '0', '_']), but SPECIAL_VARIABLE_CHARS filters word characters out of it (they are normally matched by the \w+ rule), so the only place a lone word-character special parameter is recognized explicitly is:
src/parser.ts,parseDollar()—if (j === i + 2 && next === '0')src/parser.ts,parseExpansion()—const special = nameEnd === j + 1 && this.source[j] === '0';
Both special-case 0 but not _. Proposed fix (two lines, plus comment wording):
- if (j === i + 2 && next === '0') {
+ if (j === i + 2 && (next === '0' || next === '_')) {
...
- const special = nameEnd === j + 1 && this.source[j] === '0';
+ const special = nameEnd === j + 1 && (this.source[j] === '0' || this.source[j] === '_');
With that fix and the fixtures above: pnpm --filter @moonshot-ai/tree-sitter-bash test passes (6 files, 868 tests, 677 of them differential), typecheck is clean, oxlint --type-aware reports nothing.
Scope/impact: no user-visible behavior changes — nothing in packages/agent-core-v2 branches on special_variable_name vs variable_name (the permission policies key on command / command_name / string_content, bashTargets.ts on program / list / pipeline / redirected_statement). This is a fidelity bug against the package's stated contract of matching the reference tree byte for byte. @moonshot-ai/tree-sitter-bash is private, so no changeset is added.
Reproduced on main @ 7ccac2b on Windows 11 x64 with Node 24.21.0 / pnpm 10.33.0.
I'd like to submit the PR for this one — please /approve if that is welcome.
Contribution
- I am willing to submit a PR for this bug fix myself (please wait for maintainer approval in this issue first)
- Lingua principale
- TypeScript
- Stelle
- 8k
- Fork
- 1.3k
- Merge medio
- 1g 2h
- PR unite (30g)
- 115
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MoonshotAI/kimi-code
-
VS Code extension: clickable file links in chat drop the :line suffix, never jump to the lineAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
MoonshotAI/kimi-code#4398 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] vis reports legacy tool-triggered swarm sessions as activeForse già presa @louisss1016 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
MoonshotAI/kimi-code#4395 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
MoonshotAI/kimi-code#4392 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
MoonshotAI/kimi-code#4381 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
MoonshotAI/kimi-code#4369 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di MoonshotAI/kimi-code
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
outline/outline#14348 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Agent import retains quotes in .env API keys followed by inline commentsForse già presa @yxr-2025 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
elie222/rakazo#2322 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
awslabs/visual-asset-management-system#804 ·
I maintainer di solito rispondono entro 1 giorno
-
用户目录有单引号时,热加载时YAML解析崩溃Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
dsh-market/dsh-market#1027 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno