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.
- Assistant
I’ll first inspect the compile-script model implementation, neighboring type-resolution code, and relevant fixture/test infrastructure. Then I’ll reproduce the unresolved output with the narrowest existing test or CLI before modifying the implementation.
- Assistant
The issue’s abbreviated path does not match the repository layout, so I’ll locate the actual file and then inspect the same implementation and references there.
- Assistant
ripgrepis unavailable, but the target issrc/compile_script/inline/compiler/model.rs. I’ll inspect it alongsidedefine_propsand the script context/type resolver to identify the established API for resolving a TypeScript type into runtime constructors. - Assistant
The builder currently receives only
(model name, binding, options), so the type argument is discarded before generation. I’ll trace construction ofmodel_infos, inspect runtime prop type inference (PropTypeInfo), and examine existing expected Vue outputs to implement the exact constructor/skipCheckand option-merging behavior. - Assistant
I found existing model fixtures but they omit the requested typed cases. Before editing, I’ll inspect
collect_model_infos, setup-call rewriting, type-to-runtime mapping, and the generated expected format. I’ll also run the current fixture suite (or its focused command) to establish the exact mismatch. - Assistant
The expected behavior is likely Vue’s
genModelProps: infer runtime constructors fromT, merge inferred{ type: ... }with runtime options, preserve explicittype, and addskipCheckfor unresolved union members. I’ll query the installed compiler oracle through the repository’s generator and inspect expected files and test-runner commands rather than guessing formatting. - Assistant
Because the agent constraints prohibit modifying or adding tests, I will not commit fixture changes despite the issue’s upstream work list; I can still use a temporary fixture/script and remove it. I’ll now inspect the oracle generator and current expected model snapshot, then invoke
@vue/compiler-sfcdirectly on representative typed models to capture exact output. - Assistant
The current runtime type helper is private and returns only constructors, while model generation needs it for a standalone type argument. I’ll first run the focused coverage oracle to reproduce failures, then use the installed test package environment (or install its locked dependencies if absent) to obtain Vue output for string, alias/options, named, multiple, modifiers, and unknown unions.
- Assistant
Baseline coverage is 100%, confirming the reported gap is absent from current fixtures rather than a regression in existing cases. I’ll install only
@vue/compiler-sfcin/tmp(leaving the repository untouched) and compile a matrix of representative typeddefineModelcalls to establish exact oracle semantics. - Assistant
Node/npm are unavailable in this environment, so I’ll derive semantics from the compiler version already represented by expected snapshots and, where useful, inspect any cached pnpm package sources. The main implementation can reuse the existing prop type resolver by exposing a small standalone inference function, avoiding duplicated type logic.
- Assistant
I’ll implement a dedicated
resolve_runtime_typeutility beside the existing prop inference so it can preserve nullable unions and resolve aliases/interfaces from the script context. Then I’ll thread each model’stype_argsthrough collection intobuild_model_props_emits, generating Vue-style{ type: X }or{ type: X, ...options }. This keeps untyped output unchanged and handles named/multiple/modifier models uniformly. - Assistant
One important edge case is modifiers:
defineModel<Value, Modifier>()stores all type parameters as a comma-separated string, but only the first is the model value type. I’ll verify extraction and add a nesting-aware first-type-parameter splitter so commas inside generics/tuples are not mistaken for the modifier separator. - Assistant
The code compiles. Next I’ll create a temporary Rust example (not a test and removed afterward) that calls the public SFC compiler on the requested matrix. This verifies parsing, alias resolution, generated runtime props, named/multiple models, and modifier type-parameter splitting end to end.
- Assistant
I located the public compile API. I’ll run the temporary example and inspect only the generated
props/emitssections, then remove it immediately. - Assistant
End-to-end output now resolves direct types, local aliases, nested generic value types, modifier type parameters, and nullable unions correctly. The TS transform reformats spread options, which is expected downstream behavior.
I’ll now review the diff for accidental broad changes, run the crate’s full tests and clippy-level compile checks, then rerun the full coverage oracle to ensure all existing fixtures remain at 100%.
- Assistant
Two existing Rust snapshots fail only because they encode the old unresolved behavior (
{ required: true }/{ default: undefined }); their diffs show the intended fix (type: Object/type: String). Per the constraint not to modify existing tests, I’ll leave those snapshots unchanged. I’ll verify all oracle fixtures remain passing and inspect generated.snap.newartifacts so they are not accidentally submitted. - Assistant
Coverage remains 100% and no temporary artifacts remain. I’ll do one final quality pass: verify the generated
useModelbindings for modifiers, restrict the new helper to crate visibility, and run clippy plus targeted non-snapshot tests. - Assistant
The modifier verification uncovered an adjacent required case: destructured
defineModel<T, Modifiers>()currently emits a fallback binding named after the prop (const bar = ...) and leavesvalue/modifiersundefined. Since modifiers are explicitly in scope, I’ll fix macro binding extraction for array patterns rather than only type splitting. I’ll inspect the OXC variable-declaration parser and binding metadata support, then minimally preserve the source binding pattern foruseModel. - Assistant
The parser already registers individual array-pattern bindings later, but macro calls only retain simple identifier declarations. I’ll preserve the declaration pattern’s exact source slice as the macro binding for
defineModelonly; other macros retain current identifier-only semantics. This yieldsconst [value, modifiers] = _useModel(...)without changing props/emits behavior. - Assistant
The parser change compiles. I’ll rerun the temporary end-to-end modifier case to confirm both the runtime prop type and destructured binding, then clean it and run final clippy/coverage checks.
- Assistant
Final verification is clean: modifier destructuring now emits
const [value, modifiers] = _useModel(...), clippy passes with warnings denied, and the coverage oracle remains 673/673. I’ll perform a final diff/status review and ensure no temporary or snapshot-update artifacts exist before submission. - Assistant
Checklist before submission:
- Reproduced the reported error: the existing typed-model snapshots and a temporary end-to-end compiler example showed that
defineModel<string>()and alias/interface variants emitted no resolved runtimetype. - Confirmed the fix resolves it: temporary compilation now emits
String, alias-derived constructor arrays,Object, nullable unions, named/multiple model types, and correctly separates modifier type parameters. It also now preserves[value, modifiers]bindings. - Considered edge cases: handled local aliases/interfaces, nested generic commas, second modifier type arguments, nullable types, options merging via Vue-style spread, named/default models, multiple models, and tuple destructuring.
- Ran affected tests: and clippy with pass; the coverage oracle remains . The full crate test run has 403 passing and two expected snapshot failures whose diffs specifically encode the newly corrected typed output; those snapshots were not changed because the environment explicitly prohibits modifying tests. No or temporary files remain.
- Reproduced the reported error: the existing typed-model snapshots and a temporary end-to-end compiler example showed that
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.