From b2707f07108fe0a7a46878d5d6733ce5c6098047 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Mon, 26 Aug 2024 15:19:25 +0800 Subject: [PATCH] fix(language-core): fallthrough attributes should be optional --- .../language-core/lib/codegen/script/template.ts | 2 +- packages/tsc/tests/__snapshots__/dts.spec.ts.snap | 14 +++++++------- .../vue3_strictTemplate/inheritAttrs/main.vue | 2 +- .../inheritAttrs_requiredProps/basic.vue | 7 +++++++ .../inheritAttrs_requiredProps/child.vue | 5 +++++ .../inheritAttrs_requiredProps/main.vue | 7 +++++++ 6 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/basic.vue create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/child.vue create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/main.vue diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 50113a84fb..582b9a1345 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -158,7 +158,7 @@ function* generateTemplateContext( yield `return {${newLine}`; yield `slots: ${options.scriptSetupRanges?.slots.name ?? '__VLS_slots'},${newLine}`; yield `refs: __VLS_refs as __VLS_PickRefsExpose,${newLine}`; - yield `attrs: __VLS_inheritedAttrs,${newLine}`; + yield `attrs: {} as Partial,${newLine}`; yield `}${endOfLine}`; } diff --git a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap index fa28f7d399..4a8769e32e 100644 --- a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap +++ b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap @@ -170,17 +170,17 @@ type __VLS_Prettify = { `; exports[`vue-tsc-dts > Input: generic/main.vue, Output: generic/main.vue.d.ts 1`] = ` -"declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<__VLS_OmitIndexSignature<{ +"declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<__VLS_OmitIndexSignature any; onBar?: (data: number) => any; title?: string; foo: number; -} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly any; onBar?: (data: number) => any; title?: string; foo: number; -} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps>>>>, {}, {}>; +} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps>>>>>, {}, {}>; export default _default; type __VLS_NonUndefinedable = T extends undefined ? never : T; type __VLS_TypePropsToOption = { @@ -671,7 +671,7 @@ exports[`vue-tsc-dts > Input: template-slots/component.vue, Output: template-slo }): any; }; refs: __VLS_PickRefsExpose<{}>; - attrs: {}; + attrs: Partial<{}>; }; type __VLS_Slots = ReturnType['slots']; declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly>, {}, {}>; @@ -714,7 +714,7 @@ declare const __VLS_template: () => { 'no-bind': () => VNode[]; }; refs: __VLS_PickRefsExpose<{}>; - attrs: {}; + attrs: Partial<{}>; }; type __VLS_Slots = ReturnType['slots']; declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly>, {}, {}>; @@ -740,7 +740,7 @@ exports[`vue-tsc-dts > Input: template-slots/component-destructuring.vue, Output }) => any[]; }; refs: __VLS_PickRefsExpose<{}>; - attrs: {}; + attrs: Partial<{}>; }; type __VLS_Slots = ReturnType['slots']; declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly>, {}, {}>; @@ -770,7 +770,7 @@ exports[`vue-tsc-dts > Input: template-slots/component-no-script.vue, Output: te }): any; }; refs: __VLS_PickRefsExpose<{}>; - attrs: {}; + attrs: Partial<{}>; }; type __VLS_Slots = ReturnType['slots']; declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly>, {}, {}>; diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/main.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/main.vue index b9a545507a..976b5e849c 100644 --- a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/main.vue +++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/main.vue @@ -1,4 +1,4 @@ - + + diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/child.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/child.vue new file mode 100644 index 0000000000..74e63d8179 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/child.vue @@ -0,0 +1,5 @@ + diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/main.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/main.vue new file mode 100644 index 0000000000..e177ec22aa --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/main.vue @@ -0,0 +1,7 @@ + + +