Skip to content

Fix statement and comment handling in the patched Vize event handlers - #159

Merged
JuroOravec merged 2 commits into
mainfrom
third-party/vize-expression-patches
Oct 1, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
third-party/vize-expression-patches

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

(Opus 5.5)

Citry's patched copies of the Vize compiler crates (vize_atelier_core and vize_s1_to_s2, added in #140) can turn some Vue templates into JavaScript that the browser cannot parse, without reporting an error. This PR fixes how the two crates read event handlers and other template expressions, so their output and diagnostics match @vue/compiler-core. The two exceptions, described below, are cases where Vue's own output does not parse.

What goes wrong today

When the text could not be parsed as one expression, the crates tried again and read it as a list of statements. They did this everywhere, not only in event handlers. Vue reads text as statements only for an event handler that contains ;. In every other case it reports an invalid expression.

With Citry's options (prefix_identifiers on), the current crates produce:

Template Current output Vue 3.5.42
@click="a; b()" onClick: _ctx.a; _ctx.b() (does not parse) onClick: $event => {_ctx.a; _ctx.b()}
@click="if (ok) run()" No error; $event => ($event => (if (_ctx.ok) _ctx.run())) Invalid expression error
:title="a; b", {{ a; b }}, v-if="a; b" No error; the statements are written where only an expression is valid Invalid expression error
@click="count++; log() // note" $event => {$event => {_ctx.count++; _ctx.log() // note}} (the comment hides the closing braces) $event => {_ctx.count++; _ctx.log() // note} (no error, but this does not parse either)

What changes

In both crates:

  • Text is read as statements only for an event handler that contains ;. This also applies to the TypeScript fallback. Elsewhere, vize_atelier_core reports statements as invalid expressions. vize_s1_to_s2 refuses them, so vize_atelier_dom falls back to vize_atelier_core and reports the same diagnostic.
  • The checks that decide whether a handler is a plain reference (handler) or a function (() => run()) now require that one expression to be the whole text. a; b() compiles to $event => {_ctx.a; _ctx.b()}, the same output Vue produces. For () => run(); log(), Vue checks only the first statement and writes the text unwrapped, which does not parse. These crates write $event => {() => _ctx.run(); _ctx.log()} instead. With TypeScript on (is_ts), both checks read the text after its type syntax is removed, so @click="foo!" is still passed on as the reference _ctx.foo.
  • Line comments in an event handler are written as block comments. A trailing // note can no longer hide the closing } of $event => {...} or the , before the next prop. A // inside a string is left alone. Vue writes the comment unchanged, so its output for count++; log() // note does not parse.

Each crate's README.citry.md lists the changed files and the new tests.

Why this lands before #137

#137 moves Citry's Vue rendering onto these crates through citry_vue_compiler. It already contains an earlier version of this change (its commit 372558a). This PR adds the fixes and tests that a review of that version found necessary. Merging it here first keeps #137 smaller, and lets this compiler change be reviewed separately from the Vue migration. After this PR merges, #137 should drop its copy of the commit and rebase.

How it was tested

On main these crates are not workspace members, and their manifests (copied from the crates.io archives) do not declare the development dependencies their tests use. As a result, the Rust tests workflow does not build or test them. To test them, I copied both crates into a temporary Cargo workspace. That workspace adds the missing published development dependencies (insta, toml, vize_atelier_dom, vize_atelier_sfc, vize_croquis, vize_s1, vize_s2, vize_davinci) and patches crates.io to the local copies, as #137 does.

  • New regression tests. vize_atelier_core/tests/event_handler_statements.rs (6 tests) and vize_s1_to_s2/tests/citry_event_handler_statements.rs (7 tests) cover each case above. To write them, I ran the crates and @vue/compiler-dom 3.5.42 on the same templates with prefixIdentifiers: true, and then copied the observed handlers into the assertions. When Vue's own output does not parse, the test says so. Each test that expects compiled output also checks that the render code parses as JavaScript.
  • Each test fails without the fix. With the main source restored, 11 of the 13 tests fail. The other two, typescript_handler_reference_stays_a_reference in each crate, pass on main. They guard against a regression that the whole-text check would otherwise introduce for foo!. I also turned off each part of the fix one at a time, and for each part at least one test failed. The parts are: the TypeScript fallback, the whole-text check, the TypeScript reference check, the comment conversion in vize_atelier_core codegen, and the three comment conversions in vize_s1_to_s2 (block bodies, prefixed handlers, and unprefixed handlers).
  • Through the entry point Citry uses. I compiled the cases through vize_atelier_dom::compile_template_with_options with Citry's options. Before the fix, none of @click="if (ok) run()", :title="a; b", and {{ a; b }} reported an error. After it, all three report InvalidExpression, and @click="a; b()" and the trailing-comment handler compile to code that parses.
  • Full suites. With the legacy feature on vize_atelier_core and the typescript feature on vize_s1_to_s2, 1,058 tests pass after this change, compared with 1,045 before it. The 13 new tests account for the difference. The same 6 tests fail before and after this change. Five are upstream tests whose expected output predates the Vendor patched Vize compiler crates #140 patches (quoted modifier keys and keyed children in conditional fragments). The sixth, the_matrix_plane_is_metamorphically_stable, reads fixture files that exist only in the upstream repository. Nine targets cannot build outside the upstream Vize repository, because they need its unpublished test crates (davinci_harness, davinci_test_support) or feature-gated corpora.
  • Formatting and lints. cargo fmt --check passes for both crates. cargo clippy -- -D warnings passes for both libraries and the new test targets.

Refs #138, which tracks sending these fixes upstream and removing the local copies.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits October 1, 2026 16:27
The patched Vize copies retried any text that failed to parse as an
expression as a list of statements, wherever the text appeared. So an
event handler such as `if (ok) run()`, or `a; b` in a bound attribute,
an interpolation, or a `v-if`, compiled without a diagnostic into
JavaScript that the browser cannot parse. `@vue/compiler-core` reads text
as statements only for an event handler that contains `;`, and reports
everything else as an invalid expression.

In `vize_atelier_core` and `vize_s1_to_s2`:

- read text as statements only for an event handler that contains `;`,
  in the TypeScript fallback too. `vize_atelier_core` reports other
  statements as invalid expressions. `vize_s1_to_s2` refuses them, so
  `vize_atelier_dom` falls back to `vize_atelier_core`, which reports the
  diagnostic.
- require the handler reference and function checks to match the whole
  text, so `a; b()` compiles to `$event => {_ctx.a; _ctx.b()}` instead of
  being written unwrapped as if it were the reference `a`. With `is_ts`,
  both checks read the text after its TypeScript syntax is removed, so
  `foo!` is still passed on as the reference `foo`.
- write line comments in an event handler as block comments, so a
  trailing `// note` cannot hide the closing `}` of `$event => {...}` or
  the `,` before the next prop. Vue itself writes the comment unchanged
  here, which produces code that does not parse.

New regression tests in both crates compare the written handlers with
the output of `@vue/compiler-dom` 3.5.42 and, where they expect compiled
output, check that the render code parses. Each `README.citry.md` lists the changed files and
the new tests.

Refs #138

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The statement and comment fixes change what the crates compile, so the
local version label moves on. Also describe the copies without the word
"vendor", per the house style.

Refs #138

Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec added a commit that referenced this pull request Oct 1, 2026
Take the final Vize sources from #159 (statement and comment handling in
event handlers, with its review fixes and regression tests) and label the
crates 0.420.0+citry.2, since what they compile changed. The compiler
identity Citry records moves with the label.

Refs #138

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 9930152 into main Oct 1, 2026
28 of 29 checks passed
@JuroOravec
JuroOravec deleted the third-party/vize-expression-patches branch October 1, 2026 18:06
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.

1 participant