Skip to content

Commit

Permalink
feat(language-core): add fallthroughAttributes compiler option
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Aug 27, 2024
1 parent d94bd3c commit ebb8490
Show file tree
Hide file tree
Showing 30 changed files with 36 additions and 28 deletions.
14 changes: 10 additions & 4 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}`);
}
Expand Down
1 change: 1 addition & 0 deletions packages/language-core/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface VueCompilerOptions {
jsxSlots: boolean;
strictTemplates: boolean;
skipTemplateCodegen: boolean;
fallthroughAttributes: boolean;
dataAttributes: string[];
htmlAttributes: string[];
optionsWrapper: [string, string] | [];
Expand Down
1 change: 1 addition & 0 deletions packages/language-core/lib/utils/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions
jsxSlots: vueOptions.jsxSlots ?? false,
strictTemplates: vueOptions.strictTemplates ?? false,
skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false,
fallthroughAttributes: vueOptions.fallthroughAttributes ?? false,
dataAttributes: vueOptions.dataAttributes ?? [],
htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'],
optionsWrapper: vueOptions.optionsWrapper ?? (
Expand Down
6 changes: 6 additions & 0 deletions packages/language-core/schemas/vue-tsconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@
},
"skipTemplateCodegen": {
"type": "boolean",
"default": false,
"markdownDescription": "https://github.com/vuejs/language-tools/issues/577"
},
"fallthroughAttributes": {
"type": "boolean",
"default": false,
"markdownDescription": "Enable to support typed fallthrough attributes. Please note that enabling may significantly slow down type checking."
},
"dataAttributes": {
"type": "array",
"default": [ ],
Expand Down
24 changes: 1 addition & 23 deletions packages/tsc/tests/__snapshots__/dts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -170,30 +170,8 @@ type __VLS_Prettify<T> = {
`;
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<Partial<{
"onUpdate:title"?: (title: string) => 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<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_OmitIndexSignature<Partial<{
"onUpdate:title"?: (title: string) => 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<import("vue").ExtractPropTypes<{}>>, {}, {}>;
export default _default;
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
type __VLS_TypePropsToOption<T> = {
[K in keyof T]-?: {} extends Pick<T, K> ? {
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
} : {
type: import('vue').PropType<T[K]>;
required: true;
};
};
type __VLS_OmitIndexSignature<T> = {
[K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K];
};
"
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../../tsconfig.base.json",
"vueCompilerOptions": {
"fallthroughAttributes": true,
},
"include": [ "**/*" ],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.base.json",
"vueCompilerOptions": {
"fallthroughAttributes": true,
"strictTemplates": true,
},
"include": [ "**/*" ],
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@
"../vue3_strictTemplate/#3140",
"../vue3_strictTemplate/#3718",
"../vue3_strictTemplate/intrinsicProps",
"../vue3_strictTemplate/inheritAttrs",
]
}
2 changes: 2 additions & 0 deletions test-workspace/tsc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down

0 comments on commit ebb8490

Please sign in to comment.