[Bug] tree-sitter-bash parses `$_` / `${_}` as variable_name instead of special_variable_name
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- Menos de una hora
- Aptitud para principiantes
- 85/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- bash, typescript
- Área
- compilers
Línea de trabajo
Comienza en src/parser.ts en parseDollar() y parseExpansion(), donde 0 recibe un tratamiento especial; aplica el diff de dos líneas para tratar también _ como especial. Añade las líneas del fixture a packages/tree-sitter-bash/test/fixtures/differential/expansions.txt. Ejecuta pnpm --filter @moonshot-ai/tree-sitter-bash test; hecho significa que la suite diferencial pasa con special_variable_name para un _ solitario.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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)
- Lenguaje dominante
- TypeScript
- Estrellas
- 7.9k
- Forks
- 1.3k
- Merge medio
- 1 d 13 h
- PR fusionados (30 d)
- 97
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de MoonshotAI/kimi-code
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
MoonshotAI/kimi-code#4369 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
MoonshotAI/kimi-code#4368 ·
Los mantenedores suelen responder en 1 día
-
[Bug] Cancelling retry backoff leaves a referenced timeout alive until the original delay expiresAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
MoonshotAI/kimi-code#4334 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
MoonshotAI/kimi-code#4315 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
MoonshotAI/kimi-code#4225 ·
Los mantenedores suelen responder en 1 día
Todos los issues de MoonshotAI/kimi-code
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
awesome-dsh-plugin/awesome-dsh-plugin#9184 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
farion1231/cc-switch#8829 ·
Los mantenedores suelen responder en 1 día
-
[core-client] Remove unused hand-maintained transport helpers after the definition-table cutoverAbiertodoc-audit enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100