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, then identify existing lowering/DOM compiler APIs and tests so the implementation follows repository conventions rather than duplicating infrastructure.
- Assistant
There is no
dom.rsyet, so this is a new public layer. I’ll read the crate’s AST/lowering contracts and locate the existing Vue DOM code generation crate and its callable entry points. - Assistant
Next I’ll inspect DOM compiler options, transform pipeline, codegen result types, and how preambles are emitted. The key design question is whether lowered
RootNodes can enter the compiler after parsing; the available low-level APIs should answer that. - Assistant
The normal DOM entry point combines parse, transform, and codegen. Since JSX already produces a
RootNode, I’ll determine whether we can invoke the same transform/codegen stages directly and which DOM-specific transforms are actually wired into core. - Assistant
The shared core exposes exactly the needed post-lowering transform and codegen functions. I’ll now inspect generated output shape, JSX IR details (especially attributes/directives/components), and diagnostic structures before implementing the adapter and dependency wiring.
- Assistant
Implementation is straightforward, but diagnostics need safe source ranges and the mode directive must gate VDOM generation. I’ll inspect exact
CompilerErrorfields/accessors and workspace dependency declarations, then adddom.rs, exports, and dependencies. - Assistant
Some guessed file paths differ, so I’ll list and read the actual definitions. I also need to check whether
CompilerErrordistinguishes warnings; if not, transform diagnostics will conservatively be treated as errors to satisfy “invalid input must produce diagnostics” andhas_errors(). - Assistant
I’ll compare function vs module codegen output and inspect option defaults. JSX output should have an import preamble, so module mode is likely required; a quick temporary example using the existing compiler will establish the exact behavior before coding.
- Assistant
I’ll implement the adapter with module-mode codegen (which yields Vue helper imports in
preamble), default VDOM mode, per-root component names, shared Croquis analysis, and transform diagnostic conversion. If lowering has hard errors, codegen will be skipped entirely to avoid returning malformed artifacts. Vapor-directed roots will retain their mode metadata but should not be fed through the VDOM backend; because this API is specifically “to DOM,” I’ll inspect the mode enum docs before deciding whether to emit or diagnose those roots. - Assistant
I’m adding the public types and compile function now. The generated
codewill be a completeexport function render(...)implementation, while helper imports remain inpreamble, matching the existing DOM codegen contract. Transform warnings classified as recoverable will remain warnings; all other compiler diagnostics become errors with original source offsets when available. - Assistant
The first check found only an import-surface mismatch: DOM’s
optionsmodule contains DOM compiler options, while low-level options remain invize_atelier_core. I’ll explicitly depend on core for those option types, while continuing to use DOM’s re-exported transform/codegen infrastructure, then re-check. - Assistant
Croquis metadata and legacy template
BindingMetadataare intentionally distinct. JSX lexical expressions should remain lexical (Babel-plugin shape), not become_ctx.*, so I’ll rely on Croquis during transform, disable template-style identifier prefixing, and omit legacy metadata. I’ll also make per-root error gating local rather than allowing one root’s transform error to suppress all later roots. - Assistant
The crate compiles and all existing JSX tests pass. I’ll now run a temporary smoke program (removed afterward) across the requested feature categories—fragments, components, spreads, class/style, DOM props, directives, slots, model, patch flags, TSX, component naming/modes, and invalid input—to inspect actual emitted code and uncover integration mismatches not covered by lowering tests.
- Assistant
The smoke test exposed a real correctness issue: object-style JSX slots containing nested JSX were preserved as raw
<span>inside generated JavaScript, violating the requirement against malformed render output. I’ll inspect child lowering and the slot IR/codegen expectations to represent common JSX slot forms correctly rather than merely diagnosing valid slot syntax. - Assistant
The smoke output also confirms top-level fragments work, but nested fragments currently become a resolved component named
"Fragment". I’ll normalize lowered fragment wrapper nodes into their parent child arrays only in the DOM adapter, preserving the existing lowering API while ensuring VDOM fragment semantics. I’ll then rerun focused smoke output. Named/object slot syntax is more involved; direct JSX children already compile as stable default slots, but raw nested JSX inside arbitrary JavaScript expressions needs a diagnostic guard to prevent malformed output. - Assistant
I’ll implement compile-only fragment flattening first. This avoids changing tested lowering behavior and ensures nested fragments generate arrays of sibling VNodes instead of
_resolveComponent("Fragment"). - Assistant
Now I’ll add a lowering diagnostic specifically when JSX appears inside an arbitrary JavaScript expression (such as an object slot expression or JSX-valued prop), because the shared template expression IR cannot encode nested JSX there. Direct JSX children remain fully supported and produce Vue slots. This is preferable to silently emitting syntactically invalid JavaScript and gives callers an actionable source range.
- Assistant
OXC’s expression visitor can reliably detect nested JSX without string heuristics. I’ll add a helper that converts non-empty
JSXExpressiontoExpression, reports one precise diagnostic, and use it for child and attribute containers. Explicit JSX-valued attributes will also report directly. - Assistant
To preserve the existing neutral lowering contract, the diagnostic must be DOM-adapter-specific. I’ll add a backend-validation flag to
Lowerer:lower_sourcekeeps current behavior, whilecompile_to_domperforms the same single parse/lower pass with embedded-JSX validation enabled. This avoids both duplicate parsing and regressions in the public lowering API. - Assistant
The validation machinery compiles; the warning correctly indicates the DOM entry point still calls ordinary lowering. I’ll add a private single-pass lowering helper that enables the flag and switch
compile_to_domto it, then rerun tests and smoke checks. - Assistant
The focused smoke checks now show: nested fragments flatten correctly, direct component children compile to stable Vue slots, and unsupported object-embedded JSX returns an error with no render output rather than malformed code. I’ll run formatting, the full affected crate test suite again, and Clippy/checks, then inspect the final diff for API/documentation or accidental-file issues.
- Assistant
All checks are clean. Before final submission I’ll verify the DOM compiler’s own tests still pass under the new dependency integration, inspect the complete new module and lockfile delta, and run a release-style
cargo checkfor the affected package. - Assistant
One final API-consistency check:
source_mapis an exposed option, but the specifiedDomComponentinterface has no map field. I’ll verify whether core embeds a source-map comment or only returns side data; if it only returns side data, I’ll retain the specified interface exactly rather than inventing an undocumented public field. I’ll also check component naming and setup-returned render behavior with a final temporary sample. - Assistant
The final sample exposed that
cache_handlers: truecurrently has no effect when identifier prefixing is disabled. I’ll inspect the handler transform’s cache condition. If caching is unnecessarily tied to_ctxprefixing, I’ll choose the established DOM compiler configuration that actually honors the option while preserving valid lexical JSX expressions. - Assistant
The issue is not prefixing: JSX
onClick={...}is neutrally lowered asv-bind:onClick, so DOM codegen cannot recognize it as an event or cache it. I’ll normalize JSXonXxxdynamic attributes intov-on:xxxdirectives in the DOM adapter before transform. This keeps neutral lowering unchanged and enables proper event patch flags and handler caching. - Assistant
Rust correctly rejected overlapping mutable borrows in the normalization helper. I’ll end the argument mutation before assigning the directive name, then rerun the cache smoke test.
- Assistant
Handler caching now works and removes the unnecessary dynamic-prop patch flag, matching Vue behavior. I’ll perform the definitive verification pass: JSX tests, DOM tests, Clippy with warnings denied, formatting/diff checks, and repository status.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.