ISSUE DESCRIPTION Compile JSX and TSX components to Vue VDOM output Provide the public…
- User
ISSUE DESCRIPTION
Compile JSX and TSX components to Vue VDOM output
Provide the public JSX/TSX-to-VDOM compilation API described in the Interface. It must support render and setup-returned render functions, fragments, components, attributes and spreads, class/style merging, DOM properties, directives, slots, patch flags, dynamic props, and Vue model forms. Invalid input must produce diagnostics rather than malformed render output.
Interface
Type: Function Name: compile_to_dom Path: crates/vize_atelier_jsx/src/dom.rs Input: bump: &Bump, source: &str, lang: JsxLang, options: DomCompileOptions Output: DomOutput Description: Compiles a JSX/TSX module into Vue VDOM render functions using the shared lowering layer and Vize DOM compiler infrastructure. This is the primary entry point for transforming JSX/TSX source into VDOM-compatible render code.
Type: Class Name: DomCompileOptions Path: crates/vize_atelier_jsx/src/dom.rs Public API: DomCompileOptions { hoist_static: bool, cache_handlers: bool, source_map: bool } — all fields default to false. Description: Options controlling JSX/TSX to VDOM compilation with defaults that produce
@vue/babel-plugin-jsx-shaped output (no static hoisting, no handler caching, no source map). Pass an instance tocompile_to_domto customize the compilation behavior.Type: Constant Name: DomComponent.code Path: crates/vize_atelier_jsx/src/dom.rs Value/Type: pub code: String Description: The generated render function code for a single compiled component. This field on
DomComponentcontains the complete VDOM render implementation produced by the codegen pass.Type: Constant Name: DomComponent.component_name Path: crates/vize_atelier_jsx/src/dom.rs Value/Type: pub component_name: Option Description: The resolved enclosing component-function name, if it could be determined from the source. This field on
DomComponentisNonefor anonymous renders.Type: Constant Name: DomComponent.mode Path: crates/vize_atelier_jsx/src/dom.rs Value/Type: pub mode: JsxOutputMode Description: The resolved output mode for the component, defaulting to
JsxOutputMode::Vdomunless overridden by a directive such as"use vue:vapor". This field onDomComponentallows consumers to route the component to the appropriate backend.Type: Constant Name: DomComponent.preamble Path: crates/vize_atelier_jsx/src/dom.rs Value/Type: pub preamble: String Description: The import/preamble section containing runtime helper imports (e.g.,
toDisplayStringfromvue) needed by the generated render code. This field onDomComponentshould be emitted once per module or component as a header.Type: Constant Name: DomOutput.components Path: crates/vize_atelier_jsx/src/dom.rs Value/Type: pub components: Vec Description: The compiled components in source order, one entry per outermost JSX render root. This field on holds the complete list of generated render artifacts returned by .
- Assistant
I’ll first inspect the workspace structure and the JSX crate to understand the existing parser/lowering/codegen infrastructure and identify whether
dom.rsis missing or incomplete. Then I’ll trace analogous compilation APIs, implement the public types and pipeline with minimal duplication, and run focused plus workspace tests. - Assistant
The JSX crate currently has no DOM module, but it already exposes parsed/lowered JSX roots and diagnostics. I’ll now inspect its public IR and tests, then locate the existing Vue DOM compiler/code generator APIs elsewhere in the workspace so the new entry point can adapt the shared IR rather than inventing incompatible output.
- Assistant
The reusable backend appears to be
vize_atelier_dom, likely wrapping core transforms and codegen. I’ll inspect its compile options/results and transformation requirements, along with the JSX lowering details for attributes, expressions, and component tags, to determine what metadata and options need to be passed through. - Assistant
JSX lowering already maps spreads and dynamic attributes into the same directive IR consumed by DOM transforms. The key implementation task is therefore to invoke transforms/codegen directly on each lowered
RootNode(avoiding reparsing as template text), preserve Croquis binding metadata, and split generated preamble from render code. I’ll inspect the exact transform and codegen APIs and output section support next. - Assistant
The core code generator can emit ES-module-shaped output and separate preambles. Since the requested defaults are Babel-plugin-shaped, module mode plus identifier prefixing is likely appropriate, while static hoisting must explicitly default off. I’ll inspect the remaining compile wiring, diagnostics representation/conversion, and current JSX snapshots to establish expected naming and expression behavior before implementing.
- Assistant
One complication is that
lower_sourceowns a non-cloneable whole-module Croquis analysis while each root must be transformed independently. Fortunately transform accepts a borrowed analysis, so the new API can destructure the lowering output and reuse&analysisfor every root. I’ll inspect exported option definitions and compiler error locations, then add an internal DOM entry point for already-lowered roots if needed; that keeps DOM-specific setup centralized and avoids reaching into private namespace logic. - Assistant
The core layout uses re-exported option/error modules from another crate rather than local files. I’ll resolve those definitions with broader searches and inspect
RootNodetransform state, because each root must be transformed exactly once and diagnostics need accurate source offsets. - Assistant
I found the necessary error location fields and public transforms. Rather than expanding
vize_atelier_dom’s API, the JSX crate can depend on both DOM and core and reproduce only the short “transform an existing root + generate” phase. I’ll confirm defaults and transform diagnostics semantics, then implementdom.rs, export it, and add dependencies. - Assistant
I’m going to implement conservative failure behavior: parse/lowering errors produce diagnostics and no components; transform errors produce diagnostics and an empty artifact rather than potentially malformed JavaScript. Successful roots compile in source order, default to VDOM mode, and use module codegen so helper imports are returned in
preamble. Options will map one-to-one to transform/codegen, including TS parsing and source maps. - Assistant
I’ll now create the public module and exports. The implementation will use cloned binding metadata in both transform and codegen, but a single arena-owned Croquis analysis shared across roots. Compiler errors are converted to
JsxDiagnosticwith source spans, and no code is emitted for a root whose transform reports an error. - Assistant
The first build exposed the workspace’s two binding metadata representations: Croquis metadata is used by analysis, while transforms/codegen expect Relief metadata. Existing DOM callers evidently convert this at a higher layer. I’ll locate that established conversion and use it rather than dropping semantic bindings, since imported components and setup refs depend on it.
- Assistant
There is no shared conversion helper, but both maps use the same
BindingType; conversion is straightforward and mirrors SFC assembly. I’ll add a private conversion function preserving bindings, props aliases, and script-setup status, then rebuild and run a temporary smoke example to inspect actual generated code for elements, fragments, components, spreads, directives, and invalid expressions. - Assistant
The crate now builds. I’ll use a temporary example (removed immediately afterward) to inspect output across representative features and verify that malformed expressions become diagnostics with no emitted code. This should reveal JSX-specific normalization gaps that shared template transforms cannot infer on their own.
- Assistant
Smoke output confirms shared handling for spreads, style arrays, slots, patch flags, dynamic props, and basic
v-model, and correctly gates invalid syntax. It also reveals JSX-specific concerns:classNameis currently emitted literally instead of Vue’sclass, and Vue JSX array model forms need decomposition before the template transform. I’ll inspect directive modifier representation and expression AST helpers, then add a pre-transform normalization pass over the lowered IR (including nested nodes) for aliases and model forms. - Assistant
A full model-form implementation can be done without reparsing: the lowered directive retains the original array expression text and source location. I’ll add a small delimiter-aware tuple parser (respecting nested brackets and quoted strings), normalize
[value, modifiers]and[value, argument, modifiers]into the existing directive fields, and recursively normalizeclassName/htmlFor. Malformed tuples remain intact so the standard expression validator reports them. - Assistant
The normalization logic hit an expected borrow issue because tuple slices referenced the expression while replacing its content. I’ll make the tiny tuple parser return owned compact strings; this is cold-path JSX directive handling and avoids unsafe or lifetime complexity. Then I’ll rerun the smoke cases including component arguments/modifiers.
- Assistant
One final ownership adjustment is needed because
vize_carton::Stringis a compact string rather thanstd::String. I’ll copy fromas_str(), verify the temporary example was cleaned up, and rerun. - Assistant
The alias normalization works and now yields Vue’s
CLASSpatch flag. Model tuple normalization mutates the expression, but transform still rejects it, indicating the expression processor likely reparses from source locations or the core model transform validates before/against another field. I’ll inspect thev-modeltransform flow to identify which representation it consumes and adjust locations/content accordingly rather than guessing. - Assistant
The expression node caches its parsed JS AST. Updating only textual content leaves the original array AST attached, so assignment validation still sees the tuple. I’ll clear the cache and ref-transform marker when replacing model content, matching the core’s own expression rewrite behavior, then rerun focused and full crate tests.
- Assistant
The cached AST reset was not sufficient. The diagnostic comes from the analysis-aware expression rewrite using scope data tied to the original source range; the whole directive range confirms generated model handler nodes inherit
dir.loc, causing the rewrite layer to parse the source slice instead of the generated handler text. Basicv-modelhappened to work despite this. I’ll locate the exact assignment validator in the rewrite module and determine whether model tuple normalization must also narrow directive/expression locations to the first tuple item. - Assistant
Rather than continue inferring, I’ll temporarily instrument the normalizer to print the model expression and parser result during the smoke run, then remove the instrumentation. This will establish whether tuple recognition runs and whether a later pass restores the array.
- Assistant
Tuple recognition and mutation do run. Therefore the failure occurs because generated model assignment uses the directive’s whole source location and the expression rewriter’s OXC parse diagnostic is mapped there, but message semantics still imply the generated expression contains the array. I’ll inspect element transform ordering around directive expression processing and model expansion to see whether expansion receives the original directive clone before normalization or whether a second representation is involved.
- Assistant
The culprit is explicit: model expansion intentionally uses
s.loc.sourceas the raw assignment target, nots.content. Tuple normalization must update that source snapshot too. I’ll setexp.loc.sourceto the first item while preserving byte offsets for diagnostics, then verify both model forms and run clippy/checks. - Assistant
The model smoke now produces correct native directive modifiers and component argument/modifier props, and clippy passes. Before final verification, I’ll address handler caching: JSX
onClick={...}lowers generically as a dynamic bind, but core caching applies tov-on. The DOM normalizer should recognize JSX event prop names and convert them toondirectives with normalized event arguments; this also gives standard event patch-flag behavior. Then I’ll re-export the API at crate root and test cached handlers. - Assistant
The event conversion has a localized mutable-borrow conflict between the argument and directive name. I’ll compute and assign the argument inside a nested scope, return a boolean, and mutate the directive name after that borrow ends. Then I’ll rerun the cache smoke and final test suite.
- Assistant
Focused functionality and all JSX tests now pass, including handler caching. I’ll perform a final diff review for accidental files, API/documentation consistency, default values, and formatting. I’ll also run the DOM compiler tests because the new crate dependency exercises its shared core pipeline, though no DOM source was modified.
- Assistant
The final review shows only intended files plus the lockfile dependency edge; all 96 DOM tests pass. I’ll inspect the complete new module once more, especially the tuple parser and diagnostics gating, then run
cargo fmt --checkand submit if clean.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.