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 and the relevant
defineModel/compile_scriptcode to see how type arguments are handled today. - Assistant
Let me look at the model.rs file and existing define-model fixtures more carefully.
- Assistant
Let me read the rest of model.rs to understand build_model_props_emits and how type_arg is currently handled.
- Assistant
I'll inspect how
defineModelstores type args and how props type resolution works fordefineProps. - Assistant
rg is not found, let me use grep instead.
- Assistant
I'll inspect props type-resolution and any existing notes about how Vue's
genModelPropshandles model types. - Assistant
I'll check Vue's
genModelPropsand how model types are inferred at runtime. - Assistant
Let me look at git log / issues related to this, and also check props.rs for resolve_prop_js_type and how type-only defineProps generates runtime types. Also check if there's documentation or a PR for...
- Assistant
I'll inspect the #762 commit and any remaining TODOs around model type arguments.
- Assistant
I'll look in the repo and tools for Vue's
genModelPropsimplementation or any reference to defineModel type resolution. - Assistant
There's
@vue/compiler-sfcavailable — I'll inspect itsgenModelPropsand defineModel handling. - Assistant
I'll check how fixtures are generated and whether Vue docs or tests describe defineModel type-arg output.
- Assistant
I'll inspect the expected-generation tooling and how type args for models should be resolved.
- Assistant
I'll install test dependencies and inspect Vue's genModelProps to see the expected type-arg output.
- Assistant
pnpm not found - let me try npm or corepack
- Assistant
I'll search the repo for references to model type resolution and how TS output is shaped.
- Assistant
There's an imported_types fixture that uses defineModel — I'll inspect that next.
- Assistant
I'll get node available so we can run Vue's generator and capture the oracle output.
- Assistant
There's /.nvm in PATH. Let me look there.
- Assistant
I'll inspect how TypeScript mode and PropType emission work around the model builder.
- Assistant
Interesting -
needs_prop_type = falseis hardcoded in body.rs. Let me look at function_mode which might be for TypeScript checking path. - Assistant
I'll install Node so we can run the Vue oracle generator.
- Assistant
I'll download a portable Node binary instead.
- Assistant
Node is ready. Next I'll install test deps and probe Vue's defineModel type-arg output.
- Assistant
pnpm install timed out. Let me try npm install just
@vue/compiler-sfcin a temp folder. - Assistant
I'll compile several defineModel variants through
@vue/compiler-sfcto capture the expected shape. - Assistant
I'll check a few more Vue behaviors and how our compiler currently emits
useModel. - Assistant
Next I'll inspect
setup_emitfor how model bindings and options are generated. - Assistant
I'll extract Vue's
genModelPropsimplementation for reference. - Assistant
I'll also check how Vue emits
useModelwith type parameters and option stripping. - Assistant
I'll inspect how setup scripts rewrite defineModel into useModel and whether type params survive.
- Assistant
I'll finish reading
resolve_prop_js_typeand compare our current JS-mode emit of model options with Vue's. - Assistant
I'll check whether defineModel lines are stripped or rewritten in place, since quote style must match.
- Assistant
I'll check how the oracle compares outputs — it may normalize quotes.
- Assistant
I'll check how binding names are extracted for destructured models.
- Assistant
Checking which helper functions are public so we can reuse them for model type resolution.
- Assistant
I'll check whether isProd / production mode is available in the compiler options.
- Assistant
Wait, the path was wrong because cwd is /tmp/vue-check.
- Assistant
I'll implement the type-arg resolution changes in
model.rsand update related call sites. - Assistant
I'll expose the type-resolution helpers and rewrite model handling to use them.
- Assistant
I'll add a dedicated runtime-type inference helper, then wire it into model prop generation.
- Assistant
Now add infer_model_runtime_type after resolve_prop_js_type. Also make split_type_at_top_level and ts_type_to_js_type pub(crate).
- Assistant
Now I'll make ts_type_to_js_type pub(crate) and add infer_model_runtime_type after resolve_prop_js_type.
- Assistant
Now add the infer function after resolve_prop_js_type.
- Assistant
I'll insert the infer_model_runtime_type function after resolve_prop_js_type.
- Assistant
I may have duplicated the strip_readonly_prefix doc comment. Let me check.
- Assistant
There's a duplicate doc comment. Let me fix that.
- Assistant
Now rewrite model.rs with ModelInfo struct and type resolution.
- Assistant
Updating callers and setup_emit next.
- Assistant
The import for ModelInfo in setup_emit may have failed. Let me check.
- Assistant
Need to add ModelInfo import to setup_emit.rs
- Assistant
Need to goto line 11 first.
- Assistant
I'll fix option handling when parse fails, then try building.
- Assistant
Let me go to collect_model_infos section
- Assistant
I'll clean up option handling and verbose comments in collect_model_infos.
- Assistant
There's leftover duplicate code at the end. Need to remove lines 455-461.
- Assistant
Missing closing brace for the function!
- Assistant
I'll build the crate to catch compile errors.
- Assistant
Need to fix to_compact_string on str - use String::from or .to_compact_string() via &str that implements? Looking at how others do it - probably
.into()orString::from. - Assistant
Also type_arg uses to_compact_string on trim which returns &str - that should work if ToCompactString is for &str. Let me rebuild.
- Assistant
I'll check that regression fixture and how
is_tsis decided. - Assistant
Default compile emits JS even for
lang="ts", so model prop codegen should key offsource_is_ts. Checking and fixing that. - Assistant
I'll use
source_is_tsfor model prop format and check TS stripping behavior. - Assistant
Some of the model.rs edits failed. Let me read and fix model.rs properly. Also body.rs might not have been updated.
- Assistant
I'll use a Python or sed script to do the replacements more reliably.
- Assistant
Also need의 build_user_props_decl to still系 get is_ts. Agood.
For o setup_emit, we use source_is_ts for type args - good. But
is_tsmight be unused now - we have let _ = is_ts.Rebuild and check.
Also special case for empty residual when only get/set: after strip, if residual is empty object like
{\n}and type is present - Vue with residual.For
defineModel<Layer>('layer', { required: true })- residual is{ required: true }- full. Good.Commaشبابin Object.assign path no_longer forsource_is_ts.
- Assistant
I'll inspect how coverage normalization treats object formatting differences.
- Assistant
I'll check how ithe SFC fixture runner sets is_ts.
- Assistant
I'll add fixture directory cases and generate expected outputs with Vue.
- Assistant
I'll verify the typed cases in the expected snap.
- Assistant
I'll run the define-model coverage fixture next.
- Assistant
I'll inspect preamble imports and the $emit fixture mismatch.
- Assistant
I'll merge the useModel and defineComponent imports to match Vue, and restore the corrupted $emit expected case.
- Assistant
Looking at the original $emit expected case from git to restore it.
- Assistant
.git might not be accessible from this path? Earlier git worked from /vize.
- Assistant
I'll restore original and append typed cases.
- Assistant
I'll alsoارتباط raise the min SFC pass fate if needed after verifying.
- Assistant
All 680 tests pass. I'll raise the coverage budgets and clean up the unused helper.
- Assistant
is_ts is still used for build_user_props_decl. Revert that rename.
- Assistant
Coverage is 100%. I'll double-check the budget thresholds and tidy any leftover issues.
- Assistant
Removing temporary snapshot
.newfiles so they aren't submitted.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.