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.Interface
No new interfaces are introduced.
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
Now let's look at how defineProps handles type_args resolution - the inline compiler props.rs, type_handling.rs, and type_resolution.rs.
Assistant
Good, there's
ts_type_to_js_typefor single TS type -> JS runtime type string (e.g. "String", "Number", etc). Let's look at that function fully andresolve_prop_js_type.Assistant
Good, we have real @vue/compiler-sfc available via node_modules. Let's check if node_modules is installed and can generate expected output for a test defineModel() fixture.
Assistant
We have network access apparently. Let's try installing nodejs now.
Assistant
Node and npm installed successfully. Now let's check tests/package.json for dependencies and try installing.
Assistant
We have network access to npm registry. Let's write a small script to test defineModel type resolution behaviors.
Assistant
Now let's write a test script to see how Vue compiles
defineModel<T>()variations.Assistant
Good, so
inlinepath is the actual production path used bycompile.rs(the main SFC compile entry). Thefunction_modeis likely a legacy/dead-code path. Let's check.Assistant
Now let's check setup_emit.rs usage precisely.
Assistant
Let's download and install Node 24 to a local directory and use it instead of the apt-installed Node 18.
Assistant
Persisted. Now let's set up minimal node_modules for the generate-expected.ts script (need
@iarna/tomland@vue/compiler-sfc, and optionally@vue/compiler-vaporfor completeness but not needed for sfc mode).Assistant
It works. Let's verify the regenerated snap matches existing (should be unchanged since we haven't modified fixtures/source yet).
Assistant
No diff, confirming our generation pipeline matches exactly what's checked in. Now let's write the new fixtures for defineModel type-argument cases, then generate expected output, then implement the Rust fix.
Assistant
Good. Now let's check current output of the repository binary for such fixtures (before implementing fix), to understand baseline, then design implementation and iterate.
Assistant
Let's build the coverage binary to see current test results (sanity) before modifying anything, and inspect how
compile_sfcis invoked.Assistant
Good, builds fine. Let's run the coverage binary to see baseline pass counts (especially define-model).
Assistant
Everything passes currently 100%. Now let's add new fixture cases to define-model.toml for type argument scenarios.
Assistant
Now let's regenerate expected output for this fixture using the real compiler-sfc to see target output before implementing the fix.
Assistant
Let's write a small Rust test harness script to quickly experiment with different inputs and see current output.
Assistant
Let's insert the new helper function right after
resolve_prop_js_type(after line 533).Assistant
Now let's rewrite model.rs with the new struct and logic.
Assistant
Now let's replace the
strip_runtime_accessorsblock area to addextract_runtime_accessors, and rewritebuild_model_props_emitsandcollect_model_infos.Assistant
Good, the marker matches. Now let's do the actual replacement with the full new implementation.
Assistant
Now let's fix the remaining tuple usages in the same file (emits section iterating
model_infos) andcollect_model_infos.Assistant
Now let's update
collect_model_infosat the bottom of the file.Assistant
Now let's update
body.rsandsetup_emit.rsto useModelInfoand to emit type args + call options for_useModel.Assistant
Now let's update setup_emit.rs.
Assistant
Now let's build the crate to check for compile errors.
Assistant
Compiles cleanly. Now let's run the coverage test to see our new fixtures' pass rate.
Assistant
Now let's build and run coverage to verify.
Assistant
Now let's run coverage.
Assistant
All 679 tests pass, including all 11 define-model cases (up from 5). Now let's check the "unresolved generic type argument" case more closely to make sure it matches expected exactly.
Assistant
Matches expected exactly (
{ type: null },_useModel<T>). Now let's run the full existing test suite (cargo test) to check nothing else broke.Assistant
Confirmed correct — matches real Vue exactly. Let's check the second failing test similarly.
Assistant
Good, this handles it fine. Now let's rewrite the
resolve_model_runtime_typefunction in props.rs.Assistant
Now update model.rs to handle the tuple
(String, bool)and addskipCheckfield.Assistant
Now let's build and check.
Assistant
Still 100%. Now let's rerun the full test suite for the crate.
Assistant
Now
{ type: null, ...{ default: undefined } }correctly matches the real Vue behavior for the union-with-undefined case. Let's verify against real compiler for this specific fixture snippet to be sure, then accept these snapshots.Assistant
Good, another instance of the same expected import-merge fix. Let's accept and keep iterating until clean.
Assistant
All 405 tests pass now. Let's double check the diff of all updated snapshot files to review sanity, then run the entire workspace test suite for safety (other crates might use vize_atelier_sfc).
Assistant
Let's clean up the temp additions (repro bin and node_modules symlink) since they were just for local testing.
Assistant
Clean now. Let's rebuild and rerun the full test suite plus coverage to confirm everything is intact after removing the temp bin.
Assistant
Now let's run the full workspace test suite to be thorough (checking other crates that might be affected by this change, e.g., vize_vitrine, snapshot tests elsewhere).
Assistant
Good, these are unrelated pre-existing environment issues (missing
pklbinary). Let's continue the workspace test run, skipping this failing test binary, to check the rest of the workspace.Assistant
Confirmed pre-existing failure unrelated to our changes (missing
pklbinary in this environment). Now let's clean up any leftover.snap.newfiles from that stash test run.Assistant
Clean. Now let's double check the final diff of the source code changes for quality/review.
Assistant
This all looks solid. Let's view the diffs for the other changed files for a final review.
Assistant
Good. Now the preamble.rs and props.rs diffs.
Assistant
Now let's look at props.rs diff.
Assistant
Now let's rebuild fully and run the whole test suite one more time to make sure everything is stable after cleanup.
Assistant
All tests pass across the whole workspace (excluding the pre-existing, unrelated
vize_cartonpkl-binary failure). Let's do a final review of the fixture file and clean up temporary environments.Assistant
Clean — only intended file changes remain (target/ is the build output directory, ignored). Let's do a final review of the fixture toml and the full generated expected diff for readability.
Assistant
This looks complete and well-tested. Let's do one final full coverage + test run to be safe before finishing.
Assistant
Excellent, everything's passing. Now let's go through the checklist.
Assistant
Everything looks good. Let me go through the checklist explicitly:
Assistant
Checklist Review
-
If an error was reported in the issue description, I have successfully reproduced it. The issue wasn't a runtime error report but a feature gap:
defineModel<T>()'s type argument was left unresolved in the generated runtime/type output. I reproduced this by building areprotest binary againstvize_atelier_sfcand confirmed that, before my fix,defineModel<string>()produced"modelValue": {}(notype:field) and_useModel(__props, "modelValue")(no<string>type echo), instead of matching@vue/compiler-sfc's"modelValue": { type: String }/_useModel<string>(...). -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. After implementing
resolve_model_runtime_type/model_member_runtime_typeinprops.rsand wiring it throughcollect_model_infos/build_model_props_emits/emit_setup_bodyin the inline compiler, I verified byte-for-byte parity against a real@vue/compiler-sfc@3.6.0-beta.10(the exact catalog version pinned in this repo) for every case: baredefineModel<string>(),defineModel<T>(options), nameddefineModel<string>('foo'), multiple typed models, get/set modifiers (including the previously-missing thirduseModel()argument and the necessary combined-Vue-import fix that TS + defineModel exposed), an unresolved generic type parameter (type: null), and even the trickystring | undefinedunion-forces-null /boolean | undefined→skipCheck: trueedge cases (verified against two pre-existing repo fixtures that exercise them). -
I have thought about edge cases and made sure my fix handles them as well. Handled: no type arg (unchanged behavior), type arg with/without options object, named vs. default
modelValue, multiple models, get/set accessor extraction for theuseModel()call (mirroring Vue's non-get/set-only-object stripping), unresolved generic params →null, interface/type-alias references →Object, union types →[A, B],undefined-tainted unions → forcednull(orskipCheck: truewhen combined withBoolean/Function), and thedefineComponent+useModelimport-merging bug that TS-mode defineModel exposed (fixed generally for all script-level Vue helper imports, not just this one combination). -
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Ran
cargo test --workspaceand thevize_test_runnercoverage oracle (679/679, 100%) repeatedly, updating only the insta snapshots whose expected content changed because the new output is more correct (verified each against real@vue/compiler-sfc). The only remaining failures are invize_carton'spkl-loader tests, which fail identically on a clean checkout (missingpklbinary in this sandbox) and are unrelated to this change.
-
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →