From ebb84900b890ddd6b793a8fe78c19d87dc2d7f38 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Tue, 27 Aug 2024 19:13:00 +0800 Subject: [PATCH] feat(language-core): add fallthroughAttributes compiler option --- .../lib/codegen/template/element.ts | 14 +++++++---- packages/language-core/lib/types.ts | 1 + packages/language-core/lib/utils/ts.ts | 1 + .../schemas/vue-tsconfig.schema.json | 6 +++++ .../tsc/tests/__snapshots__/dts.spec.ts.snap | 24 +------------------ .../fallthroughAttributes/tsconfig.json | 7 ++++++ .../unknownTag}/basic.vue | 0 .../unknownTag}/main.vue | 0 .../#4699/HelloWorld.vue | 0 .../#4699/main.vue | 0 .../base}/basic.vue | 0 .../base}/child.vue | 0 .../define-options-inherit-attrs-false.vue | 0 .../base}/inherit-attrs-false-v-bind.vue | 0 .../base}/inherit-attrs-false.vue | 0 .../base}/main.vue | 0 .../duplicateNameEvent}/basic.vue | 0 .../duplicateNameEvent}/child.vue | 0 .../duplicateNameEvent}/main.vue | 0 .../duplicateNameProp}/basic.vue | 0 .../duplicateNameProp}/child.vue | 0 .../duplicateNameProp}/main.vue | 0 .../requiredProp}/basic.vue | 0 .../requiredProp}/child.vue | 0 .../requiredProp}/main.vue | 0 .../tsconfig.json | 8 +++++++ .../unknownTag}/basic.vue | 0 .../unknownTag}/main.vue | 0 .../vue2_strictTemplate/tsconfig.json | 1 - test-workspace/tsc/tsconfig.json | 2 ++ 30 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 test-workspace/tsc/passedFixtures/fallthroughAttributes/tsconfig.json rename test-workspace/tsc/passedFixtures/{vue3/inheritAttrs_unknownTag => fallthroughAttributes/unknownTag}/basic.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3/inheritAttrs_unknownTag => fallthroughAttributes/unknownTag}/main.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate => fallthroughAttributes_strictTemplate}/#4699/HelloWorld.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate => fallthroughAttributes_strictTemplate}/#4699/main.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs => fallthroughAttributes_strictTemplate/base}/basic.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs => fallthroughAttributes_strictTemplate/base}/child.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs => fallthroughAttributes_strictTemplate/base}/define-options-inherit-attrs-false.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs => fallthroughAttributes_strictTemplate/base}/inherit-attrs-false-v-bind.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs => fallthroughAttributes_strictTemplate/base}/inherit-attrs-false.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs => fallthroughAttributes_strictTemplate/base}/main.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_duplicateNameEvent => fallthroughAttributes_strictTemplate/duplicateNameEvent}/basic.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_duplicateNameEvent => fallthroughAttributes_strictTemplate/duplicateNameEvent}/child.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_duplicateNameEvent => fallthroughAttributes_strictTemplate/duplicateNameEvent}/main.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_duplicateNameProp => fallthroughAttributes_strictTemplate/duplicateNameProp}/basic.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_duplicateNameProp => fallthroughAttributes_strictTemplate/duplicateNameProp}/child.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_duplicateNameProp => fallthroughAttributes_strictTemplate/duplicateNameProp}/main.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_requiredProp => fallthroughAttributes_strictTemplate/requiredProp}/basic.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_requiredProp => fallthroughAttributes_strictTemplate/requiredProp}/child.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_requiredProp => fallthroughAttributes_strictTemplate/requiredProp}/main.vue (100%) create mode 100644 test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/tsconfig.json rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_unknownTag => fallthroughAttributes_strictTemplate/unknownTag}/basic.vue (100%) rename test-workspace/tsc/passedFixtures/{vue3_strictTemplate/inheritAttrs_unknownTag => fallthroughAttributes_strictTemplate/unknownTag}/main.vue (100%) diff --git a/packages/language-core/lib/codegen/template/element.ts b/packages/language-core/lib/codegen/template/element.ts index be157ff333..42026ad78b 100644 --- a/packages/language-core/lib/codegen/template/element.ts +++ b/packages/language-core/lib/codegen/template/element.ts @@ -288,8 +288,11 @@ export function* generateComponent( } if ( - node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs') - || node === ctx.singleRootNode + options.vueCompilerOptions.fallthroughAttributes + && ( + node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs') + || node === ctx.singleRootNode + ) ) { const varAttrs = ctx.getInternalVariable(); ctx.inheritedAttrVars.add(varAttrs); @@ -386,8 +389,11 @@ export function* generateElement( } if ( - node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs') - || node === ctx.singleRootNode + options.vueCompilerOptions.fallthroughAttributes + && ( + node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs') + || node === ctx.singleRootNode + ) ) { ctx.inheritedAttrVars.add(`__VLS_intrinsicElements.${node.tag}`); } diff --git a/packages/language-core/lib/types.ts b/packages/language-core/lib/types.ts index 17158d277e..11860c48de 100644 --- a/packages/language-core/lib/types.ts +++ b/packages/language-core/lib/types.ts @@ -30,6 +30,7 @@ export interface VueCompilerOptions { jsxSlots: boolean; strictTemplates: boolean; skipTemplateCodegen: boolean; + fallthroughAttributes: boolean; dataAttributes: string[]; htmlAttributes: string[]; optionsWrapper: [string, string] | []; diff --git a/packages/language-core/lib/utils/ts.ts b/packages/language-core/lib/utils/ts.ts index 18d21ad14c..b17874e8ff 100644 --- a/packages/language-core/lib/utils/ts.ts +++ b/packages/language-core/lib/utils/ts.ts @@ -216,6 +216,7 @@ export function resolveVueCompilerOptions(vueOptions: Partial = { `; 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 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 any; - onBar?: (data: number) => any; - title?: string; - foo: number; -} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps>>>>>, {}, {}>; +"declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly>, {}, {}>; export default _default; -type __VLS_NonUndefinedable = T extends undefined ? never : T; -type __VLS_TypePropsToOption = { - [K in keyof T]-?: {} extends Pick ? { - type: import('vue').PropType<__VLS_NonUndefinedable>; - } : { - type: import('vue').PropType; - required: true; - }; -}; -type __VLS_OmitIndexSignature = { - [K in keyof T as {} extends Record ? never : K]: T[K]; -}; " `; diff --git a/test-workspace/tsc/passedFixtures/fallthroughAttributes/tsconfig.json b/test-workspace/tsc/passedFixtures/fallthroughAttributes/tsconfig.json new file mode 100644 index 0000000000..d5a2c81e67 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/fallthroughAttributes/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../tsconfig.base.json", + "vueCompilerOptions": { + "fallthroughAttributes": true, + }, + "include": [ "**/*" ], +} diff --git a/test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/basic.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes/unknownTag/basic.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/basic.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes/unknownTag/basic.vue diff --git a/test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/main.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes/unknownTag/main.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/main.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes/unknownTag/main.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/#4699/HelloWorld.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/#4699/HelloWorld.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/#4699/HelloWorld.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/#4699/HelloWorld.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/#4699/main.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/#4699/main.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/#4699/main.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/#4699/main.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/basic.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/basic.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/basic.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/basic.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/child.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/child.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/child.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/child.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/define-options-inherit-attrs-false.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/define-options-inherit-attrs-false.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/define-options-inherit-attrs-false.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/define-options-inherit-attrs-false.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/inherit-attrs-false-v-bind.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/inherit-attrs-false-v-bind.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/inherit-attrs-false-v-bind.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/inherit-attrs-false-v-bind.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/inherit-attrs-false.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/inherit-attrs-false.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/inherit-attrs-false.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/inherit-attrs-false.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/main.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/main.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs/main.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/base/main.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/basic.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameEvent/basic.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/basic.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameEvent/basic.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/child.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameEvent/child.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/child.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameEvent/child.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/main.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameEvent/main.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/main.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameEvent/main.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/basic.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameProp/basic.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/basic.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameProp/basic.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/child.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameProp/child.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/child.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameProp/child.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/main.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameProp/main.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/main.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/duplicateNameProp/main.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/basic.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/requiredProp/basic.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/basic.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/requiredProp/basic.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/child.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/requiredProp/child.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/child.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/requiredProp/child.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/main.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/requiredProp/main.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/main.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/requiredProp/main.vue diff --git a/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/tsconfig.json b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/tsconfig.json new file mode 100644 index 0000000000..e93dd518af --- /dev/null +++ b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../../tsconfig.base.json", + "vueCompilerOptions": { + "fallthroughAttributes": true, + "strictTemplates": true, + }, + "include": [ "**/*" ], +} diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/basic.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/unknownTag/basic.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/basic.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/unknownTag/basic.vue diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/main.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/unknownTag/main.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/main.vue rename to test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/unknownTag/main.vue diff --git a/test-workspace/tsc/passedFixtures/vue2_strictTemplate/tsconfig.json b/test-workspace/tsc/passedFixtures/vue2_strictTemplate/tsconfig.json index 2011fc02db..141c51abdd 100644 --- a/test-workspace/tsc/passedFixtures/vue2_strictTemplate/tsconfig.json +++ b/test-workspace/tsc/passedFixtures/vue2_strictTemplate/tsconfig.json @@ -12,6 +12,5 @@ "../vue3_strictTemplate/#3140", "../vue3_strictTemplate/#3718", "../vue3_strictTemplate/intrinsicProps", - "../vue3_strictTemplate/inheritAttrs", ] } diff --git a/test-workspace/tsc/tsconfig.json b/test-workspace/tsc/tsconfig.json index 714f41f63f..ecc8bdbcc3 100644 --- a/test-workspace/tsc/tsconfig.json +++ b/test-workspace/tsc/tsconfig.json @@ -14,6 +14,8 @@ { "path": "./passedFixtures/#3819" }, { "path": "./passedFixtures/#4503" }, { "path": "./passedFixtures/core#9923" }, + { "path": "./passedFixtures/fallthroughAttributes" }, + { "path": "./passedFixtures/fallthroughAttributes_strictTemplate" }, { "path": "./passedFixtures/noPropertyAccessFromIndexSignature" }, // { "path": "./passedFixtures/petite-vue" }, { "path": "./passedFixtures/pug" },