Skip to content

Commit ebb8490

Browse files
committed
feat(language-core): add fallthroughAttributes compiler option
1 parent d94bd3c commit ebb8490

File tree

30 files changed

+36
-28
lines changed

30 files changed

+36
-28
lines changed

packages/language-core/lib/codegen/template/element.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ export function* generateComponent(
288288
}
289289

290290
if (
291-
node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs')
292-
|| node === ctx.singleRootNode
291+
options.vueCompilerOptions.fallthroughAttributes
292+
&& (
293+
node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs')
294+
|| node === ctx.singleRootNode
295+
)
293296
) {
294297
const varAttrs = ctx.getInternalVariable();
295298
ctx.inheritedAttrVars.add(varAttrs);
@@ -386,8 +389,11 @@ export function* generateElement(
386389
}
387390

388391
if (
389-
node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs')
390-
|| node === ctx.singleRootNode
392+
options.vueCompilerOptions.fallthroughAttributes
393+
&& (
394+
node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs')
395+
|| node === ctx.singleRootNode
396+
)
391397
) {
392398
ctx.inheritedAttrVars.add(`__VLS_intrinsicElements.${node.tag}`);
393399
}

packages/language-core/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface VueCompilerOptions {
3030
jsxSlots: boolean;
3131
strictTemplates: boolean;
3232
skipTemplateCodegen: boolean;
33+
fallthroughAttributes: boolean;
3334
dataAttributes: string[];
3435
htmlAttributes: string[];
3536
optionsWrapper: [string, string] | [];

packages/language-core/lib/utils/ts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ export function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions
216216
jsxSlots: vueOptions.jsxSlots ?? false,
217217
strictTemplates: vueOptions.strictTemplates ?? false,
218218
skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false,
219+
fallthroughAttributes: vueOptions.fallthroughAttributes ?? false,
219220
dataAttributes: vueOptions.dataAttributes ?? [],
220221
htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'],
221222
optionsWrapper: vueOptions.optionsWrapper ?? (

packages/language-core/schemas/vue-tsconfig.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@
4747
},
4848
"skipTemplateCodegen": {
4949
"type": "boolean",
50+
"default": false,
5051
"markdownDescription": "https://github.com/vuejs/language-tools/issues/577"
5152
},
53+
"fallthroughAttributes": {
54+
"type": "boolean",
55+
"default": false,
56+
"markdownDescription": "Enable to support typed fallthrough attributes. Please note that enabling may significantly slow down type checking."
57+
},
5258
"dataAttributes": {
5359
"type": "array",
5460
"default": [ ],

packages/tsc/tests/__snapshots__/dts.spec.ts.snap

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -170,30 +170,8 @@ type __VLS_Prettify<T> = {
170170
`;
171171
172172
exports[`vue-tsc-dts > Input: generic/main.vue, Output: generic/main.vue.d.ts 1`] = `
173-
"declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<__VLS_OmitIndexSignature<Partial<{
174-
"onUpdate:title"?: (title: string) => any;
175-
onBar?: (data: number) => any;
176-
title?: string;
177-
foo: number;
178-
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps>>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_OmitIndexSignature<Partial<{
179-
"onUpdate:title"?: (title: string) => any;
180-
onBar?: (data: number) => any;
181-
title?: string;
182-
foo: number;
183-
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps>>>>>, {}, {}>;
173+
"declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
184174
export default _default;
185-
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
186-
type __VLS_TypePropsToOption<T> = {
187-
[K in keyof T]-?: {} extends Pick<T, K> ? {
188-
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
189-
} : {
190-
type: import('vue').PropType<T[K]>;
191-
required: true;
192-
};
193-
};
194-
type __VLS_OmitIndexSignature<T> = {
195-
[K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K];
196-
};
197175
"
198176
`;
199177
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../../tsconfig.base.json",
3+
"vueCompilerOptions": {
4+
"fallthroughAttributes": true,
5+
},
6+
"include": [ "**/*" ],
7+
}

0 commit comments

Comments
 (0)