ISSUE DESCRIPTION SFC: complete defineModel type-argument resolution in compileScript…
- User
ISSUE DESCRIPTION
SFC: complete defineModel type-argument resolution in compileScript Follow-up to #762 (which merged
defineModelviamergeModels). Remaining: resolve the type argument ofdefineModel<T>()/defineModel<T>(options)into the generated runtime + type output so the model prop's resolved type matches@vue/compiler-sfc.Work
In
crates/vize_atelier_sfc/src/compile_script/.../model.rs(build_model_props_emits), compute the resolved type frominfo.type_argusing the script context instead of leaving it unresolved. Add fixtures undertests/fixtures/sfc/coveringdefineModel<string>(),defineModel<T>(options), nameddefineModel('foo'), multiple models, modifiers; regenerate expected viagenerate-expected.ts sfc/<file>and verify with the coverage oracle.ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /vize, current file: none) bash-$
- Assistant
I’ll inspect the compile-script model implementation, nearby type-resolution code, and existing SFC fixture/test conventions before making a focused change.
- Assistant
The issue’s abbreviated path does not match the repository layout, so I’ll locate the crate and implementation first.
- Assistant
ripgrepis unavailable, but the implementation is underinline/compiler/model.rs. I’ll read it alongside props/type handling to identify the established resolver API and output expectations. - Assistant
The current model tuple carries only name, binding, and runtime options, which confirms the type argument is dropped before generation. I’ll inspect collection and macro structures, then compare compiler-sfc output using the repository’s fixture tooling or installed Node dependencies.
- Assistant
Next I’ll verify how
MacroCall.type_argsis parsed, inspect both inline and function-mode model generation, and read the existing define-model fixture. This will clarify whether the requested fix is confined to inline compilation and exactly how Vue merges inferredtypewith explicit options. - Assistant
The fixture already exercises untyped models only. I’ll query
@vue/compiler-sfcdirectly for the requested typed cases, and inspect the type-to-runtime mapper (extract_prop_types_from_type/resolve_prop_js_type) so the Rust implementation can reuse established semantics rather than duplicate them. - Assistant
I’ll generate authoritative Vue outputs for primitive, alias, named, options, unions, unknown/object, and modifier tuple cases. Those edge cases determine when Vue emits
{ type: ... }, spreads options, and addsskipCheck. - Assistant
Node is not installed, so I’ll rely on the checked-in Vue-derived logic and repository oracle workflow later. I’ll inspect the complete runtime type inference mapper and search git history/current snapshots for typed
defineModeloutputs. - Assistant
The existing mapper has all needed TypeScript constructor inference but its core function is private and
resolve_prop_js_typeonly returns a value for unresolved references. I’ll inspect mapper behavior/tests and Vue’s upstream source if it is present in Cargo caches or git objects; then expose a narrow shared helper if appropriate. - Assistant
A checked-in expected snapshot already contains Vue’s typed-model output. I’ll inspect that case and related expected files; it should establish the exact formatting and option merge behavior for the core requested scenarios.
- Assistant
To avoid guessing subtle Vue behavior, I’ll try fetching the exact upstream
defineModel.tssource corresponding to the lockfile’s Vue version. If network access is unavailable, I’ll implement the documented core path only. - Assistant
The upstream source confirms exact generation: infer the model’s type in context, emit
type, combine it with options using TS spread (orObject.assignfor JS), and preserve special unknown/Boolean/Function behavior. I’ll now inspect all tuple consumers and compilation flags, then introduce aModelInfocarryingtype_argand a shared contextual runtime-type resolver. - Assistant
I’ll implement the upstream algorithm’s development-mode form. The shared helper will resolve aliases/interfaces through
ScriptCompileContext, then map the resolved type to constructors. Model options will be combined exactly as Vue does, while all consumers switch from anonymous tuples to a typedModelInfo. - Assistant
Before editing, I’ll confirm whether OXC extraction stores all generic parameters or only the first. This matters for modifier generics: runtime inference must use only model value type, while preserving modifier behavior.
- Assistant
I’ll make the focused source changes now: expose the existing mapper within the crate, add contextual model type inference, merge inferred options per Vue, and update tuple consumers.
- Assistant
Compilation succeeds. I’ll now run the existing typed
defineModel<Layer>(..., options)regression test to reproduce the changed output. A snapshot mismatch is expected because the old snapshot encoded the unresolved model type; its diff will also reveal whether the TS/JS merge branch matches this compiler’s mode flags. - Assistant
The existing regression now resolves
LayertoObject, confirming the bug is fixed, and the compiler correctly selectsObject.assignbecause its default output mode strips TypeScript. I’ll remove Insta’s temporary artifact and use a temporary example (deleted afterward) to verify all requested scenarios, especially aliasTand modifier generic splitting. - Assistant
Primitive and named/multiple/modifier cases resolve correctly, but the crucial alias
Tstill does not: contextual resolution returned an unresolved form. I’ll inspect the resolver and context’s alias representation, then fix this rather than masking it. - Assistant
resolve_type_argsintentionally resolves object-shaped props only, so primitive aliases remain unchanged. For model values we need general alias-chain resolution. I’ll add a model-specific loop using the context’s alias/interface maps, retaining object resolution for interfaces and preventing cycles. - Assistant
Alias resolution now produces
Numberand merges options correctly. The modifier-generic probe exposed a pre-existing invalid binding rewrite for array destructuring ([model, modifiers]becamemodelValue). Since the requested coverage explicitly includes modifiers, I’ll inspect macro binding extraction and makedefineModelpreserve destructuring without broad parser changes. - Assistant
The parser currently records only identifier declarators. I’ll record the source slice for array-pattern macro bindings; model emission can then reproduce
const [model, modifiers] = _useModel(...), while other macros remain unaffected because array patterns are only meaningful here. - Assistant
Modifier destructuring now generates the correct tuple binding. I’ll inspect output-mode configuration and test the TS-preserving branch as well, then run the crate’s non-snapshot unit tests and targeted model tests.
- Assistant
One parity issue is visible from upstream: an unresolved/generic type must emit
{ type: null }, not{}. I’ll correct that and update the stale collection comment. Then I’ll test TS-preserving output usingSfcCompileOptions.is_ts. - Assistant
The option is nested under
script; the failed temporary example remains, so I’ll correct and rerun it, then clean it up. - Assistant
Cleanup already ran despite compilation failure. I’ll recreate the corrected temporary example and verify the TS spread branch.
- Assistant
The TS-preserving branch now matches Vue’s
{ type: null, ...options }form for a genericT. I’ll run formatting/checks and targeted tests for macro extraction, untyped model compilation, and type resolution. The existing typed snapshot will remain intentionally stale because changing test snapshots is prohibited; its earlier diff already verified the new resolved output. - Assistant
I found an edge case in splitting model versus modifier type arguments: a function type’s
=>could incorrectly decrement generic nesting. I’ll harden the splitter (matching the repository’s other type splitters) and allow generic alias base-name lookup before final verification. - Assistant
Core checks pass. Since Node is unavailable, I cannot regenerate the requested fixture oracle locally, and repository policy forbids adding/modifying tests anyway. I’ll inspect the final diff for accidental changes and run Clippy on the affected crate before submission.
- Assistant
Clippy found the repository’s no-
format!performance convention. I’ll replace those allocations with capacity-sizedvize_carton::Stringassembly, then rerun Clippy. - Assistant
Clippy now passes with warnings denied. I’ll do one final targeted run of the typed regression (expecting only its old snapshot mismatch), capture that it resolves to
Object, clean the temporary snapshot, and review repository status for stray files.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-lunaCompare side by side →