Skip to content

templates: an authored default is escaped into the JavaScript seed it is written into (#7207) - #7255

Open
delchev wants to merge 1 commit into
masterfrom
issue-7207-js-default-literal
Open

templates: an authored default is escaped into the JavaScript seed it is written into (#7207)#7255
delchev wants to merge 1 commit into
masterfrom
issue-7207-js-default-literal

Conversation

@delchev

@delchev delchev commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

#defaultMeta in detail-register.js.template interpolated a string default into the JavaScript string literal the item dialog seeds a new line from, so an authored defaultValue: "Owner's copy" rendered def: 'Owner's copy' and made the whole generated register a syntax error - the page failed to load entirely, rather than one field mis-seeding. A backslash and a newline did the same.

The seed is now resolved in Java (JsLiterals.defaultValueExpression, called from ModelParameterProcessor as dataDefaultValueJsLiteral), where the backslash, the apostrophe and the control characters that would end the literal are escaped - the JavaScript twin of the Java literal #7154 moved to the same place. Grepping the Harmonia templates confirms this macro is the only place a default is seeded into a JS literal.

The macro's three shapes are unchanged (a checkbox seeds a real boolean, a numeric column a real number, everything else a string - including a DROPDOWN's FK, which stays stringified), so every model that generated before generates byte-identically. Two authoring shapes that used to emit broken JavaScript now seed what the column holds and the repository applies: an SQL-quoted string default ('DRAFT', which rendered def: ''DRAFT''), and a boolean written TRUE or 1, which seeded false next to a DB DEFAULT of true. A numeric default that is not a number falls back to a string rather than a bare identifier the register would choke on.

AuthoredDefaults holds the two readings of the authored text (the SQL quotes, the boolean shapes) that both literal writers share.

Verified: JsLiteralsTest + ModelParameterProcessorTest (125 tests in ide-template, green) and IntentEngineIT#an_authored_default_is_escaped_into_the_item_dialog_seed, which generates the Harmonia UI for a composition child whose defaults carry an apostrophe and a backslash and asserts the emitted seeds - run alongside the two neighbouring default/harmonia ITs, 3/3 green.

Fixes #7207

🤖 Generated with Claude Code

… is written into (#7207)

`#defaultMeta` interpolated a string default into the JavaScript string literal
the item dialog seeds a new line from, so an authored
`defaultValue: "Owner's copy"` rendered `def: 'Owner's copy'` and made the whole
generated register a syntax error - the page failed to load entirely rather than
one field mis-seeding. A backslash and a newline did the same.

The seed is now resolved in Java (`JsLiterals.defaultValueExpression`, called
from `ModelParameterProcessor` as `dataDefaultValueJsLiteral`), where the
backslash, the apostrophe and the control characters that would end the literal
are escaped - the JavaScript twin of the Java literal #7154 moved to the same
place. It is the only place a Harmonia template seeds a default into a JS
literal.

The macro's three shapes are unchanged (a checkbox seeds a real boolean, a
numeric column a real number, everything else a string - including a DROPDOWN's
FK, which stays stringified), so every model that generated before generates
byte-identically. Two authoring shapes that used to emit broken JavaScript now
seed what the column holds and the repository applies: an SQL-quoted string
default (`'DRAFT'`, which rendered `def: ''DRAFT''`), and a boolean written
`TRUE` or `1`, which seeded false next to a DB DEFAULT of true. A numeric
default that is not a number falls back to a string rather than a bare
identifier the register would choke on.

The key is present only on a property that has a default to seed, so the shapes
live in one place instead of being restated in the template's `#if`, and the
macro reads the key's presence. `AuthoredDefaults` holds the two readings of the
authored text both literal writers share.

Fixes #7207

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@delchev
delchev force-pushed the issue-7207-js-default-literal branch from a777ecf to f90938e Compare September 9, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

templates: a string defaultValue containing an apostrophe breaks the generated Harmonia page

1 participant