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.
Assistant
I'll start by exploring the repository structure to understand the codebase and then find the relevant files mentioned in the issue.
Assistant
Let me explore the repository structure first.
Assistant
Let me look at the model.rs file mentioned in the issue.
Assistant
Now let me understand the data structures. Let me find where
define_modelsand the macro info is defined, includingtype_arg/typeArg.Assistant
Now let me look at the issue more carefully. The issue mentions
info.type_argand the pathcrates/vize_atelier_sfc/src/compile_script/.../model.rs. Let me look at how@vue/compiler-sfcgenerates the type for model props. Let me also look at the type resolution code.Assistant
Now let me understand how the
build_model_props_emitsis called and whatmodel_infoscontains. The issue says the tuple is(String, String, Option<String>)but mentionsinfo.type_arg. Let me look at how it's called.Assistant
Now let me look at how the MacroCall for define_model captures
type_args, and check the context.rs to understand how define_models are populated.Assistant
Now let me look at the OXC-based parser to see how
define_modelsMacroCalls are built and whethertype_argsis captured.Assistant
Let me look at the existing test fixtures for defineModel to understand the expected output format.
Assistant
Let me look at the props.rs to understand how
build_user_props_declworks and how type resolution is done for props.Assistant
Now let me understand how
@vue/compiler-sfchandlesdefineModel<T>()type argument. Let me look at the git log for #762 and the Vue compiler-sfc reference. Let me first look at how the type_handling module works.Assistant
Now let me understand how
@vue/compiler-sfchandles the type argument for defineModel. Let me look at how Vue generates the prop type and runtime type. Let me check the Vue compiler-sfc source in the repo (if there's a reference vendored).Assistant
No Vue compiler-sfc available. Let me look at how the issue PR #762 changed things, and check the existing snapshot tests to understand the expected output format. Let me look at the snapshot tests for defineModel in the sfc/ts tests.
Assistant
Now let me look at the snapshot tests source to understand how they're set up.
Assistant
Let me look at the snapshot_tests.rs to understand how snapshots are generated and the ts tests structure.
Assistant
Now let me understand how the runtime type resolution works for props. Let me look at the props.rs in compile_script root.
Assistant
Let me look at the
resolve_prop_js_typeandts_type_to_js_typefunctions.Assistant
Let me understand the test infrastructure - the coverage oracle and generate-expected.
Assistant
Now I understand. The
generate-expected.tsuses@vue/compiler-sfcto generate the expected output. The coverage oracle compares the vize output against@vue/compiler-sfc. Let me check if the npm dependencies are installed, and try generating the expected output for a test case withdefineModel<string>().Let me first create a small test to understand what
@vue/compiler-sfcgenerates fordefineModel<string>().Let me check if node_modules has @vue/compiler-sfc.
Assistant
Let me look at how
model_infosis used throughout the codebase.Assistant
Let me check the git history for PR #762 to understand the mergeModels work.
Assistant
Let me look at the coverage oracle and test runner to understand how fixtures are compared.
Assistant
Let me run the existing tests to see the current state.
Assistant
Let me write a quick test to see what the current vize output is for
defineModel<string>().Assistant
Let me create a temporary test to see the current vize output for defineModel with type args.
Assistant
Let me add a temporary test case to the snapshot_tests or write a standalone. Let me create a small test in the crate.
Assistant
There's no tests directory for the crate. Let me add it as an integration test by creating the tests directory. But the crate's
harness = falseis for a[[test]]. Let me check the Cargo.toml more.Assistant
The tests use
harness = falsefor the[[bench]]. There's no[[test]]with harness=false for unit tests; unit tests are inline (insrc/). Let me just add a test inline in the snapshot_tests.rs temporarily, or better, add it as a regular integration test in tests/ directory with default harness (which requires amain... no, default harness tests are fine with #[test]).Actually, integration tests in
tests/directory run with default test harness (libtest). Let me create the directory and file.Assistant
Let me look for any vendored Vue compiler or cached outputs in the repo.
Assistant
No Vue compiler available. Let me try installing node so I can run the generate-expected.ts.
Assistant
Now let me set up node in PATH and install the Vue compiler dependencies.
Assistant
The package.json doesn't have @vue/compiler-sfc as a direct dependency. The generate-expected.ts imports from "@vue/compiler-sfc". Let me check where the dependency comes from - maybe in tests/tooling.
Assistant
@vue/compiler-sfcis in/vize/tests/package.jsonascatalog:vue-beta. Let me check the pnpm catalog and install the needed packages.Assistant
Now let me write a quick test to see what Vue's compiler-sfc produces for
defineModel<string>()etc.Assistant
Excellent! Now I understand Vue's behavior. Let me test a few more edge cases to be thorough.
Assistant
Let me check the public API in props.rs and test more null/undefined cases.
Assistant
Interesting, there's some inconsistency. Let me re-test null vs undefined cases carefully.
Assistant
Let me look at the
type_includes_top_level_nullandtype_includes_top_level_undefinedfunctions and check their visibility.Assistant
Let me look at how Vue's defineModel spec tests modifiers to understand what fixture to add.
Assistant
Let me test what vize currently produces for the destructured modifiers case and the basic modifiers.
Assistant
Let me test Vue's handling of options combined with get/set to understand the stripping format precisely.
Assistant
Let me check all usages of the model_infos tuple, including component_output.rs.
Assistant
Now let me check the component_output.rs for model_infos usage.
Assistant
Now let me verify the OXC parser captures type_args for defineModel calls.
Assistant
Let me verify Vue's behavior for a few union+null combinations to ensure my logic matches.
Assistant
The Vue TS output includes the type arg in
_useModel<string>(...). Let me check where vize generates the_useModelcall.Assistant
Let me look at how the defineModel statement is stripped from the setup body.
Assistant
Let me look at parser.rs to see how setup lines are extracted and whether defineModel is stripped.
Assistant
Let me check how the vize coverage oracle compiles SFC (what is_ts setting it uses).
Assistant
Let me see the full normalize_code to understand how comparison works.
Assistant
Let me test Vue's behavior with v-model modifiers and check vize's current handling.
Assistant
Let me test what vize produces for
generic="T"and union types to check support.Assistant
Let me check the union and vmodel_trim outputs.
Assistant
Now I understand the full picture. Let me implement the changes. First, add a helper in
compile_script/props.rsto resolve a model type argument to a runtime type.Assistant
Now let me add the helper function after
strip_readonly_prefix:Assistant
Now let me check how
propsmodule is exported (lib re-exports) so I can useresolve_model_runtime_typefrom model.rs.Assistant
Now let me edit model.rs. Let me view the relevant sections.
Assistant
Now let me make the changes. First, update the import:
Assistant
Now let me update the
build_model_props_emitssignature and props building. Let me view the exact lines.Assistant
There's a leftover duplicate
} else { ... }block. Let me remove lines 200-202.Assistant
There's a duplicate line 200/201. Let me fix that and the emits loop destructuring.
Assistant
Now fix the emits loop destructuring
(name, _, _)→(name, _, _, _):Assistant
Now update
collect_model_infosto capture the type_arg and return the 4-tuple:Assistant
The closing
})for the map closure is missing and.collect()is mis-indented. Let me fix:Assistant
Now update body.rs type annotation and setup_emit.rs. Let me update body.rs:
Assistant
Now update setup_emit.rs - the signature and the destructure loop, plus add the type arg to the
_useModelcall.Assistant
There's an extra
}at line 148. Let me remove it:Assistant
Now let me build to check for compilation errors.
Assistant
Build succeeds. Now let me run my temporary tests to see the vize output with the new changes.
Assistant
Let me check whether existing lang=ts fixtures pass the coverage oracle and how imports are handled.
Assistant
Let me check how vize vs Vue imports compare for an existing lang=ts case that passes.
Assistant
Let me find a lang=ts case in the expected and compare its imports with vize output.
Assistant
Let me look at how the preamble emits imports (useModel and defineComponent).
Assistant
So the preamble emits
useModelimport (line 49) anddefineComponentimport (line 76) as SEPARATE lines. But Vue combines them when both present.So I need to combine the
useModelanddefineComponentimports into one line when both are present (i.e., when has_define_model AND is_ts/defineComponent needed).Let me look at the preamble logic more fully around lines 41-80.
Assistant
Let me check Vue's import ordering when mergeModels + defineModel + lang=ts are all present.
Assistant
Vue's order is
useModel, mergeModels, defineComponentcombined on one line. Let me refactor the preamble to combine the component helper import with the useModel import when both are needed.Assistant
The edit went into the wrong file (setup_emit.rs was open, not preamble.rs). Let me revert setup_emit.rs from git and redo.
Assistant
Now setup_emit.rs is reverted to the ORIGINAL (3-tuple). I need to re-apply my setup_emit.rs changes (the 4-tuple signature + _useModel type arg). And do the preamble.rs edit with --file.
Let me first do the preamble.rs edit properly with --file.
Assistant
Now preamble.rs is open. Let me apply the edit to combine the imports:
Assistant
Now let me re-apply the setup_emit.rs changes (4-tuple + _useModel type arg):
Assistant
Build succeeds. Now let me create the fixture file and add new test cases. First, let me append new cases to define-model.toml.
Assistant
Now I need to generate the expected snapshot for define-model.toml using the Vue compiler. Let me run generate-expected.ts with the Vue compiler available.
Assistant
The NODE_PATH approach doesn't work for ESM. Let me create a modified copy in /tmp/vuegen with absolute paths.
Assistant
Let me copy the generate-expected.ts and patch the directory paths to absolute.
Assistant
Now let me run the patched generate-expected for the define-model fixture.
Assistant
Let me write a proper generator in /tmp/vuegen that mimics generate-expected.ts's compileSFC logic exactly.
Assistant
Now let me run the coverage oracle to see if the new fixtures pass.
Assistant
All 12 define-model cases pass. Let me run the full coverage to confirm nothing else broke.
Assistant
All pass. Let me check the coverage.rs minimums and budget logic to ensure adding fixtures doesn't trip a budget check.
Assistant
All pass with no regression. Now let me run the insta snapshot tests to ensure I didn't break existing snapshots.
Assistant
Let me look at the 3 failing tests.
Assistant
Let me look at the existing snapshot for this test and check how is_ts/source_is_ts are set in compile_sfc.
Assistant
So this test uses
compile_sfc(&descriptor, SfcCompileOptions::default()). The default options produce JS output (is_ts=false) - note the output has;semicolons, double quotes, no type annotations, nodefineComponentwrapper. So is_ts=false, source_is_ts=... let me check. The output has no_useModel<Layer>type arg. So source_is_ts must be false here too (or the type arg isn't emitted because source_is_ts=false).Wait, the source is
<script setup lang="ts">. But the output is JS (no type annotations,: anyremoved, etc.). Socompile_sfcwith default options treats it as JS output (is_ts=false). And source_is_ts - let me check. The output has NO type arg. So source_is_ts must be false, OR my condition is false.Assistant
Let me look at the third failing test to understand if it's a real bug.
Assistant
Let me check the .new output for this test to see what changed.
Assistant
Let me check the ImportedSelectField.vue fixture to confirm the type arg.
Assistant
Let me look at how PR #762 handled snapshot updates when it changed output, to follow project convention.
Assistant
PR #762 updated snapshots when output changed, so the project convention is to update snapshots. Let me verify whether vize's props handling of
| undefinedmatches Vue (for consistency decisions).Assistant
So Vue produces
nullfor explicitstring | undefinedin props too, and vize's props produceString(a pre-existing latent gap not exercised by coverage). My model behavior is consistent with vize's props. Let me find all.newsnapshot files and accept the legitimate ones.Assistant
Only 2
.newfiles exist (the third test panicked before writing its.new). Let me accept the 2 pending snapshots.Assistant
Now let me handle the
script_setup__definemodel_basicsnapshot. Let me run the snapshot test with insta accept mode to regenerate it.Assistant
Let me verify the diffs of the 3 updated script_setup snapshots are legitimate (just the combined import).
Assistant
The diffs are just the combined import line — correct, matching Vue's TS output. Now let me run the full crate test suite.
Assistant
All 405 tests pass. Now let me clean up the temporary test file and run the broader test suite.
Assistant
Let me run the coverage oracle once more and the test_runner tests to confirm everything is green.
Assistant
Let me run the coverage module's own unit test that tracks the known-failure budget.
Assistant
Let me check that budget test to see if it asserts exact counts that may need updating.
Assistant
Now let me run clippy on the changed crate to ensure no lint issues (the project uses strict clippy).
Assistant
Let me run clippy with all targets for the changed crate.
Assistant
These warnings are pre-existing (criterion benches, insta macros). Let me confirm none are in my changed files.
Assistant
Let me check that warning at define_model.rs:87 to see if it's pre-existing or caused by my change.
Assistant
That's a pre-existing warning from the
insta::assert_debug_snapshot!macro in define_model.rs (which I didn't touch). All my changed files are clean. Let me review the full git status and diff.Assistant
Let me verify the generated expected snap for one of the new cases matches Vue's output.
Assistant
This is exactly Vue's output, and vize matches it. Let me do a final review of the core source changes.
Assistant
Let me verify how
source_is_tsis determined in the compile path to ensure my gate is correct.Assistant
Let me re-run that specific test to confirm the current output (the
_useModeltype arg presence).Assistant
Let me check the compile.rs path to understand how
is_ts/source_is_tsflow for default options.Assistant
Let me find where
is_tsis determined in the compile_sfc flow.Assistant
Let me re-examine the accepted snapshot and re-run the test to confirm current behavior.
Assistant
Let me re-run that specific test to confirm current behavior matches the snapshot.
Assistant
Let me force-regenerate this snapshot fresh to see the true current output.
Assistant
Let me check how compile_sfc decides inline vs function mode and whether this test path uses inline.
Assistant
The
_useModeltype arg is emitted (source_is_ts=true) but then stripped by the TS→JS transform since this test produces JS output (is_ts=false) — correct behavior. Thetype: Objectruntime field is preserved. Let me run the full lib test suite once more to confirm all green.Assistant
All 405 tests pass. Let me do a final coverage oracle run and confirm there are no stray untracked files.
Assistant
Let me verify the expected snap has all 12 cases (5 original + 7 new).
Assistant
All 12 cases present covering every scenario from the issue. Let me build the entire workspace to ensure no other crate breaks.
Assistant
Entire workspace builds cleanly. Let me run the workspace test suite to confirm no regressions across crates.
Assistant
The
vize_carton --test loadingfailure is an environment issue (pkl server binary missing), unrelated to my changes. Let me confirm it's pre-existing by stashing my changes and running it.Assistant
Confirmed the
vize_carton --test loadingfailure is pre-existing (fails on clean checkout due to missing pkl binary) and unrelated to my changes. Let me verify my regenerated expected snap's first 5 cases match the original byte-for-byte (to ensure my generator matches the official generate-expected.ts).Assistant
The first 5 cases are byte-identical to the original, confirming my generator matches the official
generate-expected.tsoutput. The implementation is complete and verified.Let me do a final review of the complete set of changes and run the coverage oracle one final time.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.