diff --git a/packages/component-meta/tests/index.spec.ts b/packages/component-meta/tests/index.spec.ts index 65659039a4..cc9aff8640 100644 --- a/packages/component-meta/tests/index.spec.ts +++ b/packages/component-meta/tests/index.spec.ts @@ -31,10 +31,17 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ const bar = meta.props.find(prop => prop.name === 'bar'); const onUpdateBar = meta.events.find(event => event.name === 'update:bar') + const qux = meta.props.find(prop => prop.name === 'qux'); + const quxModifiers = meta.props.find(prop => prop.name === 'quxModifiers'); + const onUpdateQux = meta.events.find(event => event.name === 'update:qux') + expect(foo).toBeDefined(); expect(bar).toBeDefined(); + expect(qux).toBeDefined(); + expect(quxModifiers).toBeDefined(); expect(onUpdateFoo).toBeDefined(); expect(onUpdateBar).toBeDefined(); + expect(onUpdateQux).toBeDefined(); }) test('reference-type-props', () => { diff --git a/packages/language-core/lib/generators/script.ts b/packages/language-core/lib/generators/script.ts index 420df25917..a5b235a39c 100644 --- a/packages/language-core/lib/generators/script.ts +++ b/packages/language-core/lib/generators/script.ts @@ -626,6 +626,7 @@ export function* generate( const start = getGeneratedLength(); definePropMirrors.set(propName, start); yield _(propName); + } else { yield _(propName); @@ -646,6 +647,22 @@ export function* generate( else { yield _(`import('${vueCompilerOptions.lib}').PropType<${type}>,\n`); } + + if (defineProp.modifierType) { + let propModifierName = 'modelModifiers'; + + if (defineProp.name) { + propModifierName = `${scriptSetup.content.substring(defineProp.name.start + 1, defineProp.name.end - 1)}Modifiers`; + } + + const modifierType = scriptSetup.content.substring(defineProp.modifierType.start, defineProp.modifierType.end); + + const start = getGeneratedLength(); + definePropMirrors.set(propModifierName, start); + yield _(propModifierName); + yield _(`: `); + yield _(`import('${vueCompilerOptions.lib}').PropType>,\n`); + } } yield _(`};\n`); } diff --git a/packages/language-core/lib/parsers/scriptSetupRanges.ts b/packages/language-core/lib/parsers/scriptSetupRanges.ts index a03e8e477e..e332edccc3 100644 --- a/packages/language-core/lib/parsers/scriptSetupRanges.ts +++ b/packages/language-core/lib/parsers/scriptSetupRanges.ts @@ -40,6 +40,7 @@ export function parseScriptSetupRanges( name: TextRange | undefined; nameIsString: boolean; type: TextRange | undefined; + modifierType?: TextRange | undefined; defaultValue: TextRange | undefined; required: boolean; isModel?: boolean; @@ -132,6 +133,7 @@ export function parseScriptSetupRanges( name, nameIsString: true, type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined, + modifierType: node.typeArguments && node.typeArguments?.length >= 2 ? _getStartEnd(node.typeArguments[1]) : undefined, defaultValue: undefined, required, isModel: true, diff --git a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap index e105479cd8..8e9c19bd90 100644 --- a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap +++ b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap @@ -317,15 +317,21 @@ exports[`vue-tsc-dts > Input: reference-type-model/component.vue, Output: refere "declare const _default: import("vue").DefineComponent<{ foo: import("vue").PropType; bar: import("vue").PropType; + qux: import("vue").PropType; + quxModifiers: import("vue").PropType>; }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, { "update:foo": (foo: number) => void; "update:bar": (bar: string[]) => void; + "update:qux": (qux: string) => void; }, string, import("vue").PublicProps, Readonly; bar: import("vue").PropType; + qux: import("vue").PropType; + quxModifiers: import("vue").PropType>; }>> & { "onUpdate:foo"?: (foo: number) => any; "onUpdate:bar"?: (bar: string[]) => any; + "onUpdate:qux"?: (qux: string) => any; }, {}, {}>; export default _default; " diff --git a/test-workspace/component-meta/reference-type-model/component.vue b/test-workspace/component-meta/reference-type-model/component.vue index a1d95a2b50..a295842737 100644 --- a/test-workspace/component-meta/reference-type-model/component.vue +++ b/test-workspace/component-meta/reference-type-model/component.vue @@ -1,4 +1,5 @@