From 66920c8928dd3c477b7287ccd6ec2ed6710d5756 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B1=B1=E5=90=B9=E8=89=B2=E5=BE=A1=E5=AE=88?=
<85992002+KazariEX@users.noreply.github.com>
Date: Mon, 26 Aug 2024 08:05:27 +0800
Subject: [PATCH 01/10] fix(language-core): correct inlay hints for v-bind with
modifier (#4721)
---
.../lib/codegen/template/elementProps.ts | 6 ++++--
.../language-server/tests/inlayHints.spec.ts | 16 ++++++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/packages/language-core/lib/codegen/template/elementProps.ts b/packages/language-core/lib/codegen/template/elementProps.ts
index 150b5ef5b6..780e9d9618 100644
--- a/packages/language-core/lib/codegen/template/elementProps.ts
+++ b/packages/language-core/lib/codegen/template/elementProps.ts
@@ -143,6 +143,7 @@ export function* generateElementProps(
...genereatePropExp(
options,
ctx,
+ prop,
prop.exp,
ctx.codeFeatures.all,
prop.arg?.loc.start.offset === prop.exp?.loc.start.offset,
@@ -266,6 +267,7 @@ export function* generateElementProps(
function* genereatePropExp(
options: TemplateCodegenOptions,
ctx: TemplateCodegenContext,
+ prop: CompilerDOM.DirectiveNode,
exp: CompilerDOM.SimpleExpressionNode | undefined,
features: VueCodeInformation,
isShorthand: boolean,
@@ -299,11 +301,11 @@ function* genereatePropExp(
if (enableCodeFeatures) {
ctx.inlayHints.push({
blockName: 'template',
- offset: exp.loc.end.offset,
+ offset: prop.loc.end.offset,
setting: 'vue.inlayHints.vBindShorthand',
label: `="${propVariableName}"`,
tooltip: [
- `This is a shorthand for \`${exp.loc.source}="${propVariableName}"\`.`,
+ `This is a shorthand for \`${prop.loc.source}="${propVariableName}"\`.`,
'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
'[More info](https://github.com/vuejs/core/pull/9451)',
].join('\n\n'),
diff --git a/packages/language-server/tests/inlayHints.spec.ts b/packages/language-server/tests/inlayHints.spec.ts
index f3ac6a899a..3db8a55abe 100644
--- a/packages/language-server/tests/inlayHints.spec.ts
+++ b/packages/language-server/tests/inlayHints.spec.ts
@@ -174,6 +174,22 @@ describe('Definitions', async () => {
`);
});
+ it('#4720', async () => {
+ expect(
+ await requestInlayHintsResult('fixture.vue', 'vue', `
+
+
+
+ `)
+ ).toMatchInlineSnapshot(`
+ "
+
+
+
+ "
+ `);
+ });
+
const openedDocuments: TextDocument[] = [];
afterEach(async () => {
From 0e2db193fbd0dc1458455e9eaef9286642115c54 Mon Sep 17 00:00:00 2001
From: Johnson Chu
Date: Mon, 26 Aug 2024 08:58:08 +0800
Subject: [PATCH 02/10] fix(language-core): tsNode.text is missing in tsc
---
packages/language-core/lib/codegen/template/element.ts | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/packages/language-core/lib/codegen/template/element.ts b/packages/language-core/lib/codegen/template/element.ts
index 255bb6139b..7cc1b213f2 100644
--- a/packages/language-core/lib/codegen/template/element.ts
+++ b/packages/language-core/lib/codegen/template/element.ts
@@ -15,6 +15,7 @@ import { generateInterpolation } from './interpolation';
import { generatePropertyAccess } from './propertyAccess';
import { generateTemplateChild } from './templateChild';
import { generateObjectProperty } from './objectProperty';
+import { getNodeText } from '../../parsers/scriptSetupRanges';
const colonReg = /:/g;
@@ -726,10 +727,11 @@ function* generateReferencesForScopedCssClasses(
}
function walkIdentifier(node: ts.Identifier) {
+ const text = getNodeText(ts, node, ast);
ctx.scopedClasses.push({
source: 'template',
- className: node.text,
- offset: node.end - node.text.length + startOffset
+ className: text,
+ offset: node.end - text.length + startOffset
});
}
}
From 29b13cf42b35e7d3eab6cb23c0ce1d83805dba1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B1=B1=E5=90=B9=E8=89=B2=E5=BE=A1=E5=AE=88?=
<85992002+KazariEX@users.noreply.github.com>
Date: Mon, 26 Aug 2024 13:13:02 +0800
Subject: [PATCH 03/10] test: add scoped classes renaming case (#4727)
---
.../lib/codegen/template/element.ts | 3 +
.../language-server/tests/renaming.spec.ts | 87 +++++++++++++++++++
2 files changed, 90 insertions(+)
diff --git a/packages/language-core/lib/codegen/template/element.ts b/packages/language-core/lib/codegen/template/element.ts
index 7cc1b213f2..be157ff333 100644
--- a/packages/language-core/lib/codegen/template/element.ts
+++ b/packages/language-core/lib/codegen/template/element.ts
@@ -713,6 +713,9 @@ function* generateReferencesForScopedCssClasses(
if (ts.isIdentifier(name)) {
walkIdentifier(name);
}
+ else if (ts.isStringLiteral(name)) {
+ literals.push(name);
+ }
else if (ts.isComputedPropertyName(name)) {
const { expression } = name;
if (ts.isStringLiteralLike(expression)) {
diff --git a/packages/language-server/tests/renaming.spec.ts b/packages/language-server/tests/renaming.spec.ts
index eeb0e85dac..eec6001974 100644
--- a/packages/language-server/tests/renaming.spec.ts
+++ b/packages/language-server/tests/renaming.spec.ts
@@ -790,6 +790,93 @@ describe('Renaming', async () => {
`);
});
+ it('Scoped Classes', async () => {
+ expect(
+ await requestRename('fixture.vue', 'vue', `
+
+
+
+
+
+
+ `, 'bar')
+ ).toMatchInlineSnapshot(`
+ {
+ "changes": {
+ "file://\${testWorkspacePath}/fixture.vue": [
+ {
+ "newText": "bar",
+ "range": {
+ "end": {
+ "character": 23,
+ "line": 4,
+ },
+ "start": {
+ "character": 20,
+ "line": 4,
+ },
+ },
+ },
+ {
+ "newText": "bar",
+ "range": {
+ "end": {
+ "character": 32,
+ "line": 3,
+ },
+ "start": {
+ "character": 29,
+ "line": 3,
+ },
+ },
+ },
+ {
+ "newText": "bar",
+ "range": {
+ "end": {
+ "character": 23,
+ "line": 3,
+ },
+ "start": {
+ "character": 20,
+ "line": 3,
+ },
+ },
+ },
+ {
+ "newText": "bar",
+ "range": {
+ "end": {
+ "character": 22,
+ "line": 2,
+ },
+ "start": {
+ "character": 19,
+ "line": 2,
+ },
+ },
+ },
+ {
+ "newText": "bar",
+ "range": {
+ "end": {
+ "character": 8,
+ "line": 7,
+ },
+ "start": {
+ "character": 5,
+ "line": 7,
+ },
+ },
+ },
+ ],
+ },
+ }
+ `);
+ });
+
const openedDocuments: TextDocument[] = [];
afterEach(async () => {
From b2707f07108fe0a7a46878d5d6733ce5c6098047 Mon Sep 17 00:00:00 2001
From: Johnson Chu
Date: Mon, 26 Aug 2024 15:19:25 +0800
Subject: [PATCH 04/10] 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 @@
+
+
+
+
+
From 30706912af7d340423cd37cac8666bcc10e33297 Mon Sep 17 00:00:00 2001
From: Johnson Chu
Date: Mon, 26 Aug 2024 18:39:37 +0800
Subject: [PATCH 05/10] fix(language-core): don't fallthrough attributes if
defineEmits exists
---
.../lib/codegen/script/component.ts | 102 ++++++++++++------
.../lib/codegen/script/scriptSetup.ts | 51 ++++-----
.../inheritAttrs_duplicateNameEvent/basic.vue | 12 +++
.../inheritAttrs_duplicateNameEvent/child.vue | 5 +
.../inheritAttrs_duplicateNameEvent/main.vue | 8 ++
.../inheritAttrs_duplicateNameProp/basic.vue | 11 ++
.../child.vue | 0
.../inheritAttrs_duplicateNameProp/main.vue | 9 ++
.../basic.vue | 0
.../inheritAttrs_requiredProp/child.vue | 5 +
.../main.vue | 0
11 files changed, 146 insertions(+), 57 deletions(-)
create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/basic.vue
create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/child.vue
create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/main.vue
create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/basic.vue
rename test-workspace/tsc/passedFixtures/vue3_strictTemplate/{inheritAttrs_requiredProps => inheritAttrs_duplicateNameProp}/child.vue (100%)
create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/main.vue
rename test-workspace/tsc/passedFixtures/vue3_strictTemplate/{inheritAttrs_requiredProps => inheritAttrs_requiredProp}/basic.vue (100%)
create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/child.vue
rename test-workspace/tsc/passedFixtures/vue3_strictTemplate/{inheritAttrs_requiredProps => inheritAttrs_requiredProp}/main.vue (100%)
diff --git a/packages/language-core/lib/codegen/script/component.ts b/packages/language-core/lib/codegen/script/component.ts
index 4d5bbe4215..f1618c3f59 100644
--- a/packages/language-core/lib/codegen/script/component.ts
+++ b/packages/language-core/lib/codegen/script/component.ts
@@ -71,34 +71,34 @@ export function* generateScriptSetupOptions(
scriptSetupRanges: ScriptSetupRanges,
inheritAttrs: boolean
): Generator {
- yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, inheritAttrs);
- yield* generateEmitsOption(options, scriptSetup, scriptSetupRanges);
-}
-
-export function* generatePropsOption(
- options: ScriptCodegenOptions,
- ctx: ScriptCodegenContext,
- scriptSetup: NonNullable,
- scriptSetupRanges: ScriptSetupRanges,
- inheritAttrs: boolean
-) {
+ const emitOptionCodes = [...generateEmitsOption(options, scriptSetup, scriptSetupRanges)];
+ for (const code of emitOptionCodes) {
+ yield code;
+ }
if (options.vueCompilerOptions.target >= 3.5) {
const types = [];
- if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
- types.push(`ReturnType['attrs']`);
+ if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !emitOptionCodes.length) {
+ types.push(`{} as ReturnType['attrs']`);
}
if (ctx.generatedPropsType) {
types.push(`{} as __VLS_PublicProps`);
}
- if (types.length) {
- yield `__typeProps: ${types.join(' & ')},${newLine}`;
+ if (types.length === 1) {
+ yield `__typeProps: ${types[0]},${newLine}`;
+ }
+ else if (types.length >= 2) {
+ yield `__typeProps: {${newLine}`;
+ for (const type of types) {
+ yield `...${type},${newLine}`;
+ }
+ yield `},${newLine}`;
}
}
if (options.vueCompilerOptions.target < 3.5 || !ctx.generatedPropsType || scriptSetupRanges.props.withDefaults) {
const codegens: (() => Generator)[] = [];
- if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
+ if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !emitOptionCodes.length) {
codegens.push(function* () {
yield `{} as ${ctx.helperTypes.TypePropsToOption.name}<__VLS_PickNotAny<${ctx.helperTypes.OmitIndexSignature.name}['attrs']>, {}>>`;
});
@@ -148,25 +148,63 @@ export function* generateEmitsOption(
scriptSetup: NonNullable,
scriptSetupRanges: ScriptSetupRanges
): Generator {
- if (!scriptSetupRanges.emits.define && !scriptSetupRanges.defineProp.some(p => p.isModel)) {
- return;
+ const codes: {
+ optionExp?: Code[],
+ typeOptionType?: Code[],
+ }[] = [];
+ if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
+ codes.push({
+ optionExp: [`{} as __VLS_NormalizeEmits<__VLS_ModelEmitsType>`],
+ typeOptionType: [`__VLS_ModelEmitsType`],
+ });
}
-
- if (options.vueCompilerOptions.target < 3.5 || scriptSetupRanges.emits.define?.arg || scriptSetupRanges.emits.define?.hasUnionTypeArg) {
- yield `emits: ({} as __VLS_NormalizeEmits<__VLS_ModelEmitsType`;
- if (scriptSetupRanges?.emits.define) {
- yield ` & typeof `;
- yield scriptSetupRanges.emits.name ?? '__VLS_emit';
+ if (scriptSetupRanges.emits.define) {
+ const { typeArg, hasUnionTypeArg } = scriptSetupRanges.emits.define;
+ codes.push({
+ optionExp: [`{} as __VLS_NormalizeEmits`],
+ typeOptionType: typeArg && !hasUnionTypeArg ? [scriptSetup.content.slice(typeArg.start, typeArg.end)] : undefined,
+ });
+ }
+ if (options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionType)) {
+ if (codes.length === 1) {
+ yield `__typeEmits: {} as `;
+ for (const code of codes[0].typeOptionType!) {
+ yield code;
+ }
+ yield `,${newLine}`;
+ }
+ else if (codes.length >= 2) {
+ yield `__typeEmits: {} as `;
+ for (const code of codes[0].typeOptionType!) {
+ yield code;
+ }
+ for (let i = 1; i < codes.length; i++) {
+ yield ` & `;
+ for (const code of codes[i].typeOptionType!) {
+ yield code;
+ }
+ }
+ yield `,${newLine}`;
}
- yield `>),${newLine}`;
}
- else {
- yield `__typeEmits: {} as __VLS_ModelEmitsType`;
- const typeArg = scriptSetupRanges.emits.define?.typeArg;
- if (typeArg) {
- yield ` & `;
- yield scriptSetup.content.slice(typeArg.start, typeArg.end);
+ else if (codes.every(code => code.optionExp)) {
+ if (codes.length === 1) {
+ yield `emits: `;
+ for (const code of codes[0].optionExp!) {
+ yield code;
+ }
+ yield `,${newLine}`;
+ }
+ else if (codes.length >= 2) {
+ yield `emits: {${newLine}`;
+ for (const code of codes) {
+ yield `...`;
+ for (const c of code.optionExp!) {
+ yield c;
+ }
+ yield `,${newLine}`;
+ }
+ yield `},${newLine}`;
}
- yield `,${newLine}`;
}
}
diff --git a/packages/language-core/lib/codegen/script/scriptSetup.ts b/packages/language-core/lib/codegen/script/scriptSetup.ts
index 869a9b60ed..05bab1100f 100644
--- a/packages/language-core/lib/codegen/script/scriptSetup.ts
+++ b/packages/language-core/lib/codegen/script/scriptSetup.ts
@@ -303,14 +303,16 @@ function* generateComponentProps(
scriptSetupRanges: ScriptSetupRanges,
definePropMirrors: Map
): Generator {
- yield `const __VLS_fnComponent = `
- + `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${newLine}`;
+ yield `const __VLS_fnComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${newLine}`;
+
if (scriptSetupRanges.props.define?.arg) {
- yield ` props: `;
+ yield `props: `;
yield generateSfcBlockSection(scriptSetup, scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end, codeFeatures.navigation);
yield `,${newLine}`;
}
+
yield* generateEmitsOption(options, scriptSetup, scriptSetupRanges);
+
yield `})${endOfLine}`;
yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
@@ -418,32 +420,31 @@ function* generateModelEmits(
scriptSetup: NonNullable,
scriptSetupRanges: ScriptSetupRanges
): Generator {
- yield `type __VLS_ModelEmitsType = `;
- if (scriptSetupRanges.defineProp.filter(p => p.isModel).length) {
- if (options.vueCompilerOptions.target < 3.5) {
- yield `typeof __VLS_modelEmitsType${endOfLine}`;
- yield `const __VLS_modelEmitsType = (await import('${options.vueCompilerOptions.lib}')).defineEmits<`;
- }
- yield `{${newLine}`;
- for (const defineProp of scriptSetupRanges.defineProp) {
- if (!defineProp.isModel) {
- continue;
+ const defineModels = scriptSetupRanges.defineProp.filter(p => p.isModel);
+ if (defineModels.length) {
+ const generateDefineModels = function* () {
+ for (const defineModel of defineModels) {
+ const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
+ yield `'update:${propName}': [${propName}:`;
+ yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
+ yield `]${endOfLine}`;
}
-
- const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
-
- yield `'update:${propName}': [${propName}:`;
- yield* generateDefinePropType(scriptSetup, propName, localName, defineProp);
- yield `]${endOfLine}`;
+ };
+ if (options.vueCompilerOptions.target >= 3.5) {
+ yield `type __VLS_ModelEmitsType = {${newLine}`;
+ yield* generateDefineModels();
+ yield `}${endOfLine}`;
}
- yield `}`;
- if (options.vueCompilerOptions.target < 3.5) {
- yield `>()`;
+ else {
+ yield `const __VLS_modelEmitsType = (await import('${options.vueCompilerOptions.lib}')).defineEmits<{${newLine}`;
+ yield* generateDefineModels();
+ yield `}>()${endOfLine}`;
+ yield `type __VLS_ModelEmitsType = typeof __VLS_modelEmitsType${endOfLine}`;
}
- } else {
- yield `{}`;
}
- yield endOfLine;
+ else {
+ yield `type __VLS_ModelEmitsType = {}${endOfLine}`;
+ }
}
function* generateStyleModules(
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/basic.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/basic.vue
new file mode 100644
index 0000000000..e7574c27d2
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/basic.vue
@@ -0,0 +1,12 @@
+
+
+
+ exactType(v, {} as string)" />
+
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/child.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/child.vue
new file mode 100644
index 0000000000..57e78c68eb
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/child.vue
@@ -0,0 +1,5 @@
+
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/main.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/main.vue
new file mode 100644
index 0000000000..247181ad3c
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameEvent/main.vue
@@ -0,0 +1,8 @@
+
+
+
+ exactType(v, {} as number)" />
+
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/basic.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/basic.vue
new file mode 100644
index 0000000000..f24d7f587a
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/basic.vue
@@ -0,0 +1,11 @@
+
+
+
+
+
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/child.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/child.vue
similarity index 100%
rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/child.vue
rename to test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/child.vue
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/main.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/main.vue
new file mode 100644
index 0000000000..23c4cd71d8
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_duplicateNameProp/main.vue
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/basic.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/basic.vue
similarity index 100%
rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/basic.vue
rename to test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/basic.vue
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/child.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/child.vue
new file mode 100644
index 0000000000..74e63d8179
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/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_requiredProp/main.vue
similarity index 100%
rename from test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProps/main.vue
rename to test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_requiredProp/main.vue
From 5a9bb123daa1481d196fc812de77ef1bfa1baad5 Mon Sep 17 00:00:00 2001
From: Johnson Chu
Date: Tue, 27 Aug 2024 00:26:03 +0800
Subject: [PATCH 06/10] refactor(language-core): rewrite generatePropsOption
---
.../lib/codegen/script/component.ts | 201 ++++++++----------
.../lib/codegen/script/internalComponent.ts | 17 +-
.../lib/codegen/script/scriptSetup.ts | 12 +-
.../tsc/tests/__snapshots__/dts.spec.ts.snap | 2 +-
4 files changed, 106 insertions(+), 126 deletions(-)
diff --git a/packages/language-core/lib/codegen/script/component.ts b/packages/language-core/lib/codegen/script/component.ts
index f1618c3f59..ca7cf0b44d 100644
--- a/packages/language-core/lib/codegen/script/component.ts
+++ b/packages/language-core/lib/codegen/script/component.ts
@@ -1,4 +1,3 @@
-import type { ScriptRanges } from '../../parsers/scriptRanges';
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
import type { Code, Sfc } from '../../types';
import { endOfLine, generateSfcBlockSection, newLine } from '../common';
@@ -31,10 +30,15 @@ export function* generateComponent(
yield `}${endOfLine}`;
yield `},${newLine}`;
if (!ctx.bypassDefineComponent) {
- yield* generateScriptSetupOptions(options, ctx, scriptSetup, scriptSetupRanges, true);
+ const emitOptionCodes = [...generateEmitsOption(options, scriptSetup, scriptSetupRanges)];
+ for (const code of emitOptionCodes) {
+ yield code;
+ }
+ yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length, true);
}
- if (options.sfc.script && options.scriptRanges) {
- yield* generateScriptOptions(options.sfc.script, options.scriptRanges);
+ if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
+ const { args } = options.scriptRanges.exportDefault;
+ yield generateSfcBlockSection(options.sfc.script, args.start + 1, args.end - 1, codeFeatures.all);
}
if (options.vueCompilerOptions.target >= 3.5 && scriptSetupRanges.templateRefs.length) {
yield `__typeRefs: {} as __VLS_Refs,${newLine}`;
@@ -55,134 +59,42 @@ export function* generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRan
}
}
-export function* generateScriptOptions(
- script: NonNullable,
- scriptRanges: ScriptRanges
-): Generator {
- if (scriptRanges.exportDefault?.args) {
- yield generateSfcBlockSection(script, scriptRanges.exportDefault.args.start + 1, scriptRanges.exportDefault.args.end - 1, codeFeatures.all);
- }
-}
-
-export function* generateScriptSetupOptions(
- options: ScriptCodegenOptions,
- ctx: ScriptCodegenContext,
- scriptSetup: NonNullable,
- scriptSetupRanges: ScriptSetupRanges,
- inheritAttrs: boolean
-): Generator {
- const emitOptionCodes = [...generateEmitsOption(options, scriptSetup, scriptSetupRanges)];
- for (const code of emitOptionCodes) {
- yield code;
- }
-
- if (options.vueCompilerOptions.target >= 3.5) {
- const types = [];
- if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !emitOptionCodes.length) {
- types.push(`{} as ReturnType['attrs']`);
- }
- if (ctx.generatedPropsType) {
- types.push(`{} as __VLS_PublicProps`);
- }
- if (types.length === 1) {
- yield `__typeProps: ${types[0]},${newLine}`;
- }
- else if (types.length >= 2) {
- yield `__typeProps: {${newLine}`;
- for (const type of types) {
- yield `...${type},${newLine}`;
- }
- yield `},${newLine}`;
- }
- }
- if (options.vueCompilerOptions.target < 3.5 || !ctx.generatedPropsType || scriptSetupRanges.props.withDefaults) {
- const codegens: (() => Generator)[] = [];
-
- if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !emitOptionCodes.length) {
- codegens.push(function* () {
- yield `{} as ${ctx.helperTypes.TypePropsToOption.name}<__VLS_PickNotAny<${ctx.helperTypes.OmitIndexSignature.name}['attrs']>, {}>>`;
- });
- }
-
- if (ctx.generatedPropsType) {
- codegens.push(function* () {
- yield `{} as `;
- if (scriptSetupRanges.props.withDefaults?.arg) {
- yield `${ctx.helperTypes.WithDefaults.name}<`;
- }
- yield `${ctx.helperTypes.TypePropsToOption.name}<`;
- yield `__VLS_PublicProps>`;
- if (scriptSetupRanges.props.withDefaults?.arg) {
- yield `, typeof __VLS_withDefaultsArg>`;
- }
- });
- }
- if (scriptSetupRanges.props.define?.arg) {
- const { arg } = scriptSetupRanges.props.define;
- codegens.push(function* () {
- yield generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.navigation);
- });
- }
-
- if (codegens.length === 1) {
- yield `props: `;
- for (const generate of codegens) {
- yield* generate();
- }
- yield `,${newLine}`;
- }
- else if (codegens.length >= 2) {
- yield `props: {${newLine}`;
- for (const generate of codegens) {
- yield `...`;
- yield* generate();
- yield `,${newLine}`;
- }
- yield `},${newLine}`;
- }
- }
-}
-
export function* generateEmitsOption(
options: ScriptCodegenOptions,
scriptSetup: NonNullable,
scriptSetupRanges: ScriptSetupRanges
): Generator {
const codes: {
- optionExp?: Code[],
- typeOptionType?: Code[],
+ optionExp?: Code,
+ typeOptionType?: Code,
}[] = [];
if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
codes.push({
- optionExp: [`{} as __VLS_NormalizeEmits<__VLS_ModelEmitsType>`],
- typeOptionType: [`__VLS_ModelEmitsType`],
+ optionExp: `{} as __VLS_NormalizeEmits<__VLS_ModelEmitsType>`,
+ typeOptionType: `__VLS_ModelEmitsType`,
});
}
if (scriptSetupRanges.emits.define) {
const { typeArg, hasUnionTypeArg } = scriptSetupRanges.emits.define;
codes.push({
- optionExp: [`{} as __VLS_NormalizeEmits`],
- typeOptionType: typeArg && !hasUnionTypeArg ? [scriptSetup.content.slice(typeArg.start, typeArg.end)] : undefined,
+ optionExp: `{} as __VLS_NormalizeEmits`,
+ typeOptionType: typeArg && !hasUnionTypeArg
+ ? scriptSetup.content.slice(typeArg.start, typeArg.end)
+ : undefined,
});
}
if (options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionType)) {
if (codes.length === 1) {
yield `__typeEmits: {} as `;
- for (const code of codes[0].typeOptionType!) {
- yield code;
- }
+ yield codes[0].typeOptionType!;
yield `,${newLine}`;
}
else if (codes.length >= 2) {
yield `__typeEmits: {} as `;
- for (const code of codes[0].typeOptionType!) {
- yield code;
- }
+ yield codes[0].typeOptionType!;
for (let i = 1; i < codes.length; i++) {
yield ` & `;
- for (const code of codes[i].typeOptionType!) {
- yield code;
- }
+ yield codes[i].typeOptionType!;
}
yield `,${newLine}`;
}
@@ -190,18 +102,81 @@ export function* generateEmitsOption(
else if (codes.every(code => code.optionExp)) {
if (codes.length === 1) {
yield `emits: `;
- for (const code of codes[0].optionExp!) {
- yield code;
- }
+ yield codes[0].optionExp!;
yield `,${newLine}`;
}
else if (codes.length >= 2) {
yield `emits: {${newLine}`;
for (const code of codes) {
yield `...`;
- for (const c of code.optionExp!) {
- yield c;
- }
+ yield code.optionExp!;
+ yield `,${newLine}`;
+ }
+ yield `},${newLine}`;
+ }
+ }
+}
+
+export function* generatePropsOption(
+ options: ScriptCodegenOptions,
+ ctx: ScriptCodegenContext,
+ scriptSetup: NonNullable,
+ scriptSetupRanges: ScriptSetupRanges,
+ hasEmitsOption: boolean,
+ inheritAttrs: boolean
+): Generator {
+ const optionExpCodes: Code[] = [];
+ const typeOptionExpCodes: Code[] = [];
+
+ if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !hasEmitsOption) {
+ optionExpCodes.push(`{} as ${ctx.helperTypes.TypePropsToOption.name}<__VLS_PickNotAny<${ctx.helperTypes.OmitIndexSignature.name}['attrs']>, {}>>`);
+ typeOptionExpCodes.push(`{} as ReturnType['attrs']`);
+ }
+ if (ctx.generatedPropsType) {
+ optionExpCodes.push([
+ `{} as `,
+ scriptSetupRanges.props.withDefaults?.arg ? `${ctx.helperTypes.WithDefaults.name}<` : '',
+ `${ctx.helperTypes.TypePropsToOption.name}<__VLS_PublicProps>`,
+ scriptSetupRanges.props.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
+ ].join(''));
+ typeOptionExpCodes.push(`{} as __VLS_PublicProps`);
+ }
+
+ if (scriptSetupRanges.props.define?.arg) {
+ const { arg } = scriptSetupRanges.props.define;
+ optionExpCodes.push(generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.navigation));
+ }
+
+ const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionExpCodes.length;
+ const useOption = (!useTypeOption || scriptSetupRanges.props.withDefaults) && optionExpCodes.length;
+
+ if (useTypeOption) {
+ if (typeOptionExpCodes.length === 1) {
+ yield `__typeProps: `;
+ yield typeOptionExpCodes[0];
+ yield `,${newLine}`;
+ }
+ else if (typeOptionExpCodes.length >= 2) {
+ yield `__typeProps: {${newLine}`;
+ for (const code of typeOptionExpCodes) {
+ yield `...`;
+ yield code;
+ yield `,${newLine}`;
+ }
+ yield `},${newLine}`;
+ }
+ }
+ if (useOption) {
+ if (optionExpCodes.length === 1) {
+ yield `props: `;
+ yield optionExpCodes[0];
+ yield `,${newLine}`;
+ }
+ else if (optionExpCodes.length >= 2) {
+ yield `props: {${newLine}`;
+ for (const code of optionExpCodes) {
+ yield `...`;
+ yield code;
yield `,${newLine}`;
}
yield `},${newLine}`;
diff --git a/packages/language-core/lib/codegen/script/internalComponent.ts b/packages/language-core/lib/codegen/script/internalComponent.ts
index af8859709c..4cf91246f7 100644
--- a/packages/language-core/lib/codegen/script/internalComponent.ts
+++ b/packages/language-core/lib/codegen/script/internalComponent.ts
@@ -1,9 +1,9 @@
import type { Code } from '../../types';
-import { endOfLine, newLine } from '../common';
+import { endOfLine, generateSfcBlockSection, newLine } from '../common';
import type { TemplateCodegenContext } from '../template/context';
-import { generateComponentSetupReturns, generateScriptOptions, generateScriptSetupOptions } from './component';
+import { generateComponentSetupReturns, generateEmitsOption, generatePropsOption } from './component';
import type { ScriptCodegenContext } from './context';
-import type { ScriptCodegenOptions } from './index';
+import { codeFeatures, type ScriptCodegenOptions } from './index';
import { getTemplateUsageVars } from './template';
export function* generateInternalComponent(
@@ -52,10 +52,15 @@ export function* generateInternalComponent(
yield `__typeRefs: {} as __VLS_Refs,${newLine}`;
}
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
- yield* generateScriptSetupOptions(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, false);
+ const emitOptionCodes = [...generateEmitsOption(options, options.sfc.scriptSetup, options.scriptSetupRanges)];
+ for (const code of emitOptionCodes) {
+ yield code;
+ }
+ yield* generatePropsOption(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, !!emitOptionCodes.length, false);
}
- if (options.sfc.script && options.scriptRanges) {
- yield* generateScriptOptions(options.sfc.script, options.scriptRanges);
+ if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
+ const { args } = options.scriptRanges.exportDefault;
+ yield generateSfcBlockSection(options.sfc.script, args.start + 1, args.end - 1, codeFeatures.all);
}
yield `})${endOfLine}`; // defineComponent {
}
diff --git a/packages/language-core/lib/codegen/script/scriptSetup.ts b/packages/language-core/lib/codegen/script/scriptSetup.ts
index 05bab1100f..6c6c014597 100644
--- a/packages/language-core/lib/codegen/script/scriptSetup.ts
+++ b/packages/language-core/lib/codegen/script/scriptSetup.ts
@@ -57,10 +57,13 @@ export function* generateScriptSetup(
+ ` __VLS_setup = (async () => {${newLine}`;
yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined, definePropMirrors);
- const emitTypes = ['__VLS_ModelEmitsType'];
+ const emitTypes: string[] = [];
if (scriptSetupRanges.emits.define) {
- emitTypes.unshift(`typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}`);
+ emitTypes.push(`typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}`);
+ }
+ if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
+ emitTypes.push(`__VLS_ModelEmitsType`);
}
yield ` return {} as {${newLine}`
@@ -68,7 +71,7 @@ export function* generateScriptSetup(
+ ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${newLine}`
+ ` attrs: any,${newLine}`
+ ` slots: __VLS_Slots,${newLine}`
- + ` emit: ${emitTypes.join(' & ')},${newLine}`
+ + ` emit: ${emitTypes.length ? emitTypes.join(' & ') : `{}`},${newLine}`
+ ` }${endOfLine}`;
yield ` })(),${newLine}`; // __VLS_setup = (async () => {
yield `) => ({} as import('${options.vueCompilerOptions.lib}').VNode & { __ctx?: Awaited }))`;
@@ -442,9 +445,6 @@ function* generateModelEmits(
yield `type __VLS_ModelEmitsType = typeof __VLS_modelEmitsType${endOfLine}`;
}
}
- else {
- yield `type __VLS_ModelEmitsType = {}${endOfLine}`;
- }
}
function* generateStyleModules(
diff --git a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap
index 4a8769e32e..6a19645cc1 100644
--- a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap
+++ b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap
@@ -78,7 +78,7 @@ exports[`vue-tsc-dts > Input: events/component-generic.vue, Output: events/compo
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
attrs: any;
slots: {};
- emit: ((evt: "foo", value: string) => void) & {};
+ emit: (evt: "foo", value: string) => void;
}>) => import("vue").VNode & {
From 21205fb9d7c14650c67c2a581cf18f9e7b24bfc4 Mon Sep 17 00:00:00 2001
From: Johnson Chu
Date: Tue, 27 Aug 2024 18:02:51 +0800
Subject: [PATCH 07/10] fix(language-core): fallthrough attributes break
component type when root tag type is unknown (#4729)
---
.../lib/codegen/script/component.ts | 18 +++++++++++++-----
.../vue3/inheritAttrs_unknownTag/basic.vue | 7 +++++++
.../vue3/inheritAttrs_unknownTag/main.vue | 7 +++++++
.../inheritAttrs_unknownTag/basic.vue | 7 +++++++
.../inheritAttrs_unknownTag/main.vue | 7 +++++++
5 files changed, 41 insertions(+), 5 deletions(-)
create mode 100644 test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/basic.vue
create mode 100644 test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/main.vue
create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/basic.vue
create mode 100644 test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/main.vue
diff --git a/packages/language-core/lib/codegen/script/component.ts b/packages/language-core/lib/codegen/script/component.ts
index ca7cf0b44d..9029d2f1d1 100644
--- a/packages/language-core/lib/codegen/script/component.ts
+++ b/packages/language-core/lib/codegen/script/component.ts
@@ -128,10 +128,6 @@ export function* generatePropsOption(
const optionExpCodes: Code[] = [];
const typeOptionExpCodes: Code[] = [];
- if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !hasEmitsOption) {
- optionExpCodes.push(`{} as ${ctx.helperTypes.TypePropsToOption.name}<__VLS_PickNotAny<${ctx.helperTypes.OmitIndexSignature.name}['attrs']>, {}>>`);
- typeOptionExpCodes.push(`{} as ReturnType['attrs']`);
- }
if (ctx.generatedPropsType) {
optionExpCodes.push([
`{} as `,
@@ -141,11 +137,23 @@ export function* generatePropsOption(
].join(''));
typeOptionExpCodes.push(`{} as __VLS_PublicProps`);
}
-
if (scriptSetupRanges.props.define?.arg) {
const { arg } = scriptSetupRanges.props.define;
optionExpCodes.push(generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.navigation));
}
+ if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !hasEmitsOption) {
+ const attrsType = `ReturnType['attrs']`;
+ const propsType = `__VLS_PickNotAny<${ctx.helperTypes.OmitIndexSignature.name}<${attrsType}>, {}>`;
+ const optionType = `${ctx.helperTypes.TypePropsToOption.name}<${propsType}>`;
+ if (optionExpCodes.length) {
+ optionExpCodes.unshift(`{} as ${optionType}`);
+ }
+ else {
+ // workaround for https://github.com/vuejs/core/pull/7419
+ optionExpCodes.unshift(`{} as keyof ${propsType} extends never ? never: ${optionType}`);
+ }
+ typeOptionExpCodes.unshift(`{} as ${attrsType}`);
+ }
const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionExpCodes.length;
const useOption = (!useTypeOption || scriptSetupRanges.props.withDefaults) && optionExpCodes.length;
diff --git a/test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/basic.vue b/test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/basic.vue
new file mode 100644
index 0000000000..88fa3d63aa
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/basic.vue
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/main.vue b/test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/main.vue
new file mode 100644
index 0000000000..e177ec22aa
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3/inheritAttrs_unknownTag/main.vue
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/basic.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/basic.vue
new file mode 100644
index 0000000000..88fa3d63aa
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/basic.vue
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/main.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/main.vue
new file mode 100644
index 0000000000..e177ec22aa
--- /dev/null
+++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/inheritAttrs_unknownTag/main.vue
@@ -0,0 +1,7 @@
+
+
+
+
+
From d94bd3c9d707fc26ebca5f7da79546b005f17f14 Mon Sep 17 00:00:00 2001
From: Johnson Chu
Date: Tue, 27 Aug 2024 18:52:59 +0800
Subject: [PATCH 08/10] fix(language-core): improve fallthrough attributes and
defineEmit compatibility
---
packages/language-core/lib/codegen/script/component.ts | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/packages/language-core/lib/codegen/script/component.ts b/packages/language-core/lib/codegen/script/component.ts
index 9029d2f1d1..fa49ad1791 100644
--- a/packages/language-core/lib/codegen/script/component.ts
+++ b/packages/language-core/lib/codegen/script/component.ts
@@ -141,8 +141,11 @@ export function* generatePropsOption(
const { arg } = scriptSetupRanges.props.define;
optionExpCodes.push(generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.navigation));
}
- if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !hasEmitsOption) {
- const attrsType = `ReturnType['attrs']`;
+ if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
+ let attrsType = `ReturnType['attrs']`;
+ if (hasEmitsOption) {
+ attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
+ }
const propsType = `__VLS_PickNotAny<${ctx.helperTypes.OmitIndexSignature.name}<${attrsType}>, {}>`;
const optionType = `${ctx.helperTypes.TypePropsToOption.name}<${propsType}>`;
if (optionExpCodes.length) {
From ebb84900b890ddd6b793a8fe78c19d87dc2d7f38 Mon Sep 17 00:00:00 2001
From: Johnson Chu
Date: Tue, 27 Aug 2024 19:13:00 +0800
Subject: [PATCH 09/10] 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" },
From 180af0bed813b1e90ddab437f86ce5919373a713 Mon Sep 17 00:00:00 2001
From: Johnson Chu
Date: Tue, 27 Aug 2024 23:29:28 +0800
Subject: [PATCH 10/10] fix(language-core): fix __VLS_template returns when
skipTemplateCodegen enabled
---
packages/language-core/lib/codegen/script/template.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts
index 582b9a1345..3a895a603c 100644
--- a/packages/language-core/lib/codegen/script/template.ts
+++ b/packages/language-core/lib/codegen/script/template.ts
@@ -39,7 +39,7 @@ export function* generateTemplate(
const templateUsageVars = [...getTemplateUsageVars(options, ctx)];
yield `// @ts-ignore${newLine}`;
yield `[${templateUsageVars.join(', ')}]${newLine}`;
- yield `return [{}, {}] as const${endOfLine}`;
+ yield `return { slots: {}, refs: {}, attrs: {} }${endOfLine}`;
yield `}${newLine}`;
}
}