modify(): trailing inline comment is re-attached to the newly inserted property
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- tooling
Direzione di ricerca
Inizia con la riproduzione fornita di modify() e applyEdits(), quindi segui il modo in cui modify() sceglie il punto di inserimento dopo l’ultimo valore di proprietà e gestisce i commenti inline finali. Il lavoro è completato quando il commento rimane associato a port, la nuova proprietà debug lo segue e i casi con scope continuano a comportarsi come descritto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
When a new property is appended with modify(), a same-line (inline) trailing comment on the object's last property is re-attached to the newly inserted property. The comment then documents a different key, so the edit changes the meaning of the file, not just its formatting.
Environment
jsonc-parser: 3.3.1 Also reproduces on 4.0.0-next.2 see the first comment with updated attachment- node: v22
- Reproducible on any OS (pure string manipulation, no I/O involved).
Steps to reproduce
import { modify, applyEdits } from 'jsonc-parser';
const input = `{
"host": "localhost",
"port": 8080 // default port
}`;
const edits = modify(input, ['debug'], true, {
formattingOptions: { tabSize: 2, insertSpaces: true }
});
console.log(applyEdits(input, edits));
(The behavior is identical whether the package is loaded via import or require.)
Actual behavior
{
"host": "localhost",
"port": 8080,
"debug": true // default port
}
The // default port comment clearly belongs to port, but it is now attached to debug: true, where it makes no sense.
Expected behavior
{
"host": "localhost",
"port": 8080, // default port
"debug": true
}
The comment should stay with port, and the new property should be inserted after it.
Scope
Triggers when: the last property of an object has an inline (same-line) trailing comment and a new property is appended.
Does NOT trigger when:
- the comment is on its own line, or
- the inline comment is on a non-last property.
So only the inline comment of the last property is affected.
Likely cause
The insertion point appears to be computed immediately after the last property's value token. The original trailing comma and the inline comment that follow it are left in place, so the inserted text lands before them — which visually re-associates the comment with the newly inserted property.
Related issues
- #76 — Option to keep spaces before inline comments: same area (inline comments handled by
modify), but that report is about lost spacing/alignment, whereas this is about the comment being moved onto the wrong key (a semantic change). - #51 — modify ... capture too much content: also about
modifyaffecting content beyond the targeted node.
This seems distinct enough from #76 to warrant its own issue, but I'm happy to consolidate if you prefer.
- Lingua principale
- TypeScript
- Stelle
- 759
- Fork
- 66
- Merge medio
- 5g 10h
- PR unite (30g)
- 7
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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 microsoft/node-jsonc-parser
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
microsoft/node-jsonc-parser#105 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
microsoft/node-jsonc-parser#103 · 2 commenti · 8 reazioni ·
-
Provide usage examples Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 48/100
microsoft/node-jsonc-parser#97 · 2 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
microsoft/node-jsonc-parser#95 · 1 reazione ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 35/100
Tutte le issue di microsoft/node-jsonc-parser
Issue simili
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
-
code-quality refactoring
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
langchain-ai/deepagents#6450 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
vercel/react-tweet#225 ·