Editing a field of a record in a TypeScript data file (e.g. export const themen = [{ id, titel, text }, …]) and saving throws ReferenceError: WIDTH is not defined.
electron/jsCollections.js references WIDTH in literal() (lines 287 and 295) but never declares it:
if (pad.length + oneLine.length + 1 <= WIDTH && !oneLine.includes('\n')) return oneLine;
// …
if (!val.includes('\n') && inner.length + key.length + 2 + val.length + 1 > WIDTH) {
Any collection whose rows are objects is affected; only arrays of plain strings or numbers never reach that branch.
Fix: declare the constant next to ID_KEY. The comment above the usage already says it should match Prettier's default printWidth:
// Prettier's default printWidth; used by literal() to decide when a record
// stays on one line.
const WIDTH = 80;
With that in place, replaceCollection() writes the record back correctly, long strings dropping to their own line as intended:
{
id: "software",
titel: "Software, Automatisierung und Auswertung",
text:
"Warenwirtschaft, Rechnungswesen, komplexe Automatisierungen sowie Berichte, Gutachten, Kataloge und barrierefreie PDFs.",
},
Reproduces on main at e5e63d8 and in the shipped 0.1.23 build. There are currently no tests for jsCollections.js, which is why it went unnoticed.
Editing a field of a record in a TypeScript data file (e.g.
export const themen = [{ id, titel, text }, …]) and saving throwsReferenceError: WIDTH is not defined.electron/jsCollections.jsreferencesWIDTHinliteral()(lines 287 and 295) but never declares it:Any collection whose rows are objects is affected; only arrays of plain strings or numbers never reach that branch.
Fix: declare the constant next to
ID_KEY. The comment above the usage already says it should match Prettier's defaultprintWidth:With that in place,
replaceCollection()writes the record back correctly, long strings dropping to their own line as intended:Reproduces on
mainat e5e63d8 and in the shipped 0.1.23 build. There are currently no tests forjsCollections.js, which is why it went unnoticed.