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 identify the existing shared lowering and DOM compiler APIs, then implement the public entry point consistently with repository conventions and run focused tests.
- Assistant
The crate currently has parsing, root discovery, and shared JSX lowering but no
dom.rs. I’ll inspect those data structures plus the existing VDOM compiler/codegen crates so the new API can bridge them rather than duplicate transformation logic. - Assistant
Next I’ll map
vize_atelier_dom’s compiler inputs/outputs and inspect its test expectations. This should reveal whether JSX IR needs normalization or whether it can be passed directly to transform and codegen. - Assistant
I need a lower-level compile function because the JSX root is already parsed. I’ll inspect DOM compile internals and core transform/codegen APIs, including error and source-map representations, before choosing the smallest public integration point.
- Assistant
The DOM pipeline uses core transforms directly; platform behavior is encoded in the shared transform/codegen and options. Since JSX already owns a
RootNode, the clean integration is to invoke core transform and codegen from the JSX crate while passing Croquis binding metadata. I’ll verify exact option defaults, codegen shape, compiler diagnostics fields, and JSX lowering conventions (especially JSX directives/spreads/model) before implementing. - Assistant
The lowering covers the requested constructs by representing dynamic JSX attributes as
v-bind, spreads as argument-lessv-bind, and Vue-prefixed names as directives. I’ll now inspect the exact core defaults and run a temporary proof-of-concept against a lowered JSX root to see generated output and identify any JSX-specific gaps (notably component tag classification and event/model syntax). - Assistant
The previous combined command didn’t expose option/error definitions due to path assumptions, so I’ll locate them precisely. I’ll also check workspace dependency declarations to add the correct internal crates without introducing cycles.
- Assistant
I’ll inspect transform/codegen options and
CompilerErrorlocation semantics, then implementdom.rswith:- defaults all false,
- early suppression of codegen on parse/lowering errors,
- per-root transform and codegen in source order,
- error conversion to
JsxDiagnostic, - VDOM default/mode metadata and public re-exports.
- Assistant
I’ll implement the API now. I’m choosing ES-module codegen so
preamblecontains Vue helper imports as specified, while leaving identifier prefixing off to preserve JSX lexical expressions. Transform and codegen receive TS mode, component name, binding metadata, and all three options. A root with transform errors will retain its metadata entry but have empty code/preamble, preventing malformed output while preserving the “one entry per root” contract. - Assistant
Compilation exposed that Croquis analysis metadata and core compiler metadata are intentionally distinct types. I’ll locate the repository’s existing conversion helper and reuse it; if none exists, I’ll rely on the
Croquisanalysis reference (already passed to transform) and omit the legacy metadata option rather than create a lossy conversion. - Assistant
There is an established conversion in the SFC compiler. I’ll mirror that small conversion locally (including binding types, aliases, and script-setup flag), then rerun compilation and tests.
- Assistant
The crate builds and all existing tests pass. I’ll now run a temporary executable (removed afterward) against representative JSX/TSX: dynamic class/style and spreads, components/slots, fragments, model/directives, multiple roots/modes, and malformed input. This will validate actual emitted VDOM shape rather than only type-checking the bridge.
- Assistant
The probe confirms core VDOM behavior for merging, patch flags, models, fragments, and directives. It also reveals a dangerous edge case: JSX nested inside a JavaScript expression child (for example, a render-function slot arrow) remains raw JSX in generated JavaScript. Until shared IR can structurally represent such nested expression JSX, this must produce a diagnostic rather than malformed output. I’ll add a pre-transform validation walk over expression nodes to detect residual JSX syntax, while ensuring ordinary comparison operators don’t false-positive. I’ll inspect AST traversal ergonomics and expression node fields first.
- Assistant
I’ll inspect the node definitions and then implement narrowly-scoped validation based on interpolation/directive expression source, using OXC parsing would be ideal but expensive and requires distinguishing JSX tokens. A structural scanner can reliably detect
<Identifier,</, or<>outside strings, but OXC’s parser already knows this syntax; I’ll see whether expression source spans can be reparsed as JSX and visited. - Assistant
A better and fully reliable place is the lowering pass, where OXC still has the expression AST. I’ll inspect child lowering and use an OXC visitor to detect JSX descendants inside expression containers. This avoids heuristic scanning and reports the exact expression range.
- Assistant
OXC’s
JSXExpressionis a generated superset enum, so I’ll inspect its conversion/accessor methods. If it dereferences to normalExpression, a tiny visitor can identify nested JSX nodes exactly. - Assistant
The visitor API directly supports
visit_jsx_expression. I’ll add a small detector inchild.rsthat reports nested JSX in expression children. This makes the previously malformed arrow-slot case an explicit lowering error; ordinary element slots remain fully supported by core slot generation. - Assistant
I’ll cover all residual-JSX paths, not only children: expression containers, spread children, spread attributes, and JSX element/fragment attribute values. Unsupported nested JSX will be diagnosed at its exact span and module codegen will be suppressed.
- Assistant
The residual-JSX validation compiles. I’ll rerun the probe with a standard element slot (which the shared DOM pipeline supports), model/directives, options, and invalid nested JSX to verify valid slot output remains intact and invalid expressions no longer produce code. Then I’ll run the crate test suite and inspect the final diff for API/documentation consistency.
- Assistant
The focused test run caught an important compatibility constraint: shared lowering intentionally preserves render-function/object slot expressions for non-VDOM consumers, so adding diagnostics there changes its contract. I’ll revert those lowering changes and move validation exclusively into
compile_to_dom, by reusing OXC’s visitor over the original module and detecting JSX nested specifically within JSX expression containers. This preserves backend-neutral lowering while ensuring the VDOM API never emits residual JSX. - Assistant
The VDOM-only validation now preserves all lowering tests and suppresses malformed render-function slot output. I’ll complete its coverage for spread expressions and direct JSX-valued attributes, then run formatting, tests, and Clippy.
- Assistant
All focused tests and strict Clippy pass, with no whitespace errors. Before submission I’ll do a final API review and inspect source-map codegen behavior plus the complete diff (including the untracked new file), ensuring no temporary artifacts remain and no accidental lockfile changes beyond the new dependency.
- Assistant
The final review shows the source-map flag is accepted and forwarded to core codegen, while the requested public component shape intentionally does not expose a map field. The only cleanup needed is correcting module documentation that claimed parsing occurs once (VDOM safety validation performs a second lightweight parse). I’ll fix that wording, run Rustdoc/check once more, then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.