Repository navigation
fix: decode static template references once, as Vue does - #330
Merged
Merged
Conversation
In a component that uses Vue, a written `&#40;` in text or a static attribute value showed `(`, where Vue and the browser show `(`: the vize_atelier_core code generator decoded numeric references a second time in escape_js_string, and the S2 emitter matched it for `(` and `)`. Both lanes now decode each reference once. The S2 emitter also decodes a static `style` before splitting it at `;`, so `"` inside a declaration stays in it, writes a kept comment as written, and decodes and escapes a static `is` on `<component>`, which vize_atelier_core now escapes too. S2 refuses a dynamic slot name that is not JavaScript, such as `#[x&y]`, so the vize_atelier_core code generator reports Vue's invalid-expression error instead of S2 writing an empty name. A legacy name that a letter follows in an attribute value (`title="a¬in"`) stays as written, as in the browser (Vue's compiler writes `a¬in`); a new test locks that on both lanes. The patched Vize crates and the compiler identity move to 0.420.0+citry.6. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
In a component that uses Vue, these read differently from Vue and the
browser:
A written
&#40;showed(:Vue and the browser show
(in both places, because each referencedecodes once. The patched
vize_atelier_corecode generator decodednumeric references a second time in
escape_js_string, on text theparser had already decoded. The S2 emitter matched that for
(and)only (decode_escaped_numeric_parenthesis).On S2, a static
<component is="a&b">wrote"a&b", withoutdecoding or escaping the value. Vue writes
"a&b".On S2, a dynamic slot name that is not JavaScript, such as
#[x&y]orv-slot:[n&m], wrote{ []: ... }, which is notvalid JavaScript either. A dynamic argument is part of the attribute
name, so
&stays as written. Vue reports an invalid expression.On S2, a static
stylewas split at;before it was decoded, sostyle="font-family:"A B",serif"lost everything after thefirst
". Vue decodes first.On
vize_atelier_core, a staticiswas written into the stringliteral without escaping, so
is="a"b"gave invalid JavaScript.On S2, a kept comment decoded its references, where Vue keeps a
comment as written. Citry drops comments, so only the two lanes'
agreement changes.
The fix
vize_atelier_core(codegen/helpers.rs):escape_js_stringescapesthe text it is given without decoding it. Its callers pass text and
attribute values that the parser has already decoded, and names and
comments, which Vue never decodes.
vize_s1_to_s2(emit/entity.rs): every decoder reads each referenceonce; the parenthesis special case is gone.
vize_s1_to_s2(emit/builtin.rs): a staticisgoes throughescape_js_attribute_string.vize_s1_to_s2(emit/create_slots/entry.rs,emit/slots/params.rs):a dynamic slot name whose prefixing fails is refused instead of being
written as an empty string, so Citry compiles the template with
vize_atelier_core, which reportsInvalidExpression, and Citry showsthat to the user.
vize_s1_to_s2(emit/style.rs,emit/children.rs): a staticstyleis decoded before it is split, and a kept comment is written as written.
vize_atelier_core(codegen/element/block.rs,inline.rs): a staticisis escaped for its string literal.0.420.0+citry.6,because the compiled code changes. Both
README.citry.mdfiles list thechange.
A legacy name that a letter or digit follows in an attribute value, such
as
title="a¬in", already stays as written on both lanes, as thebrowser reads it. Vue's compiler writes
a¬inthere. The server HTMLand the browser are the reference, so this keeps the browser's reading,
and a new test locks it.
Tests
crates/citry_vue_compiler/tests/static_reference_entities.rsruns eachcase on S2 alone and on the
vize_atelier_corelane alone. It covers thesingle decode in text and attributes (including
&#x22;),a¬inin an attribute and in text, a static
is(with&and"),a static
stylewith", and a kept comment. It also checks thatS2 refuses both dynamic slot names and that
vize_atelier_corereportsInvalidExpressionfor them. Each case excepta¬infails onmain.Replaying the 1,432 compile requests recorded from the
citryandcitry_uitest suites gives the same result as onmain: no template in themwrites a doubled reference, so their code is unchanged.
The existing
vize_s1_to_s2andvize_atelier_coretest targets have thesame results as before (
emit_if,metamorphicanddynamic_v_model_argumentfail onmaintoo).Changelog: a Fixes line in
CHANGELOG.md.Not fixed here
S2 condenses whitespace in text before it decodes it, where Vue decodes
first, so
<p>a b</p>keeps two line feeds on S2 where Vuewrites one space. Changing that order touches the source positions that
Citry's authored text plan records for each condensed run, so it needs
its own change.
🤖 Generated with Claude Code