diff --git a/packages/language-core/lib/codegen/script/globalTypes.ts b/packages/language-core/lib/codegen/script/globalTypes.ts index 7148e107b0..923d971aa9 100644 --- a/packages/language-core/lib/codegen/script/globalTypes.ts +++ b/packages/language-core/lib/codegen/script/globalTypes.ts @@ -100,6 +100,7 @@ declare global { : false; function __VLS_normalizeSlot(s: S): S extends () => infer R ? (props: {}) => R : S; + function __VLS_tryAsConstant(t: T): T; /** * emit diff --git a/packages/language-core/lib/codegen/template/element.ts b/packages/language-core/lib/codegen/template/element.ts index a7a55b479f..763d9237e2 100644 --- a/packages/language-core/lib/codegen/template/element.ts +++ b/packages/language-core/lib/codegen/template/element.ts @@ -444,7 +444,9 @@ function* generateComponentSlot( slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, - slotDir.arg.loc + slotDir.arg.loc, + false, + true, ); yield ': __VLS_thisSlot'; } diff --git a/packages/language-core/lib/codegen/template/objectProperty.ts b/packages/language-core/lib/codegen/template/objectProperty.ts index 702908d19b..eadf2a3a97 100644 --- a/packages/language-core/lib/codegen/template/objectProperty.ts +++ b/packages/language-core/lib/codegen/template/objectProperty.ts @@ -14,10 +14,25 @@ export function* generateObjectProperty( offset: number, features: VueCodeInformation, astHolder?: any, - shouldCamelize = false + shouldCamelize = false, + shouldBeConstant = false ): Generator { if (code.startsWith('[') && code.endsWith(']') && astHolder) { - yield* generateInterpolation(options, ctx, code, astHolder, offset, features, '', ''); + if (shouldBeConstant) { + yield* generateInterpolation( + options, + ctx, + code.slice(1, -1), + astHolder, + offset + 1, + features, + '[__VLS_tryAsConstant(', + ')]', + ); + } + else { + yield* generateInterpolation(options, ctx, code, astHolder, offset, features, '', ''); + } } else if (shouldCamelize) { if (variableNameRegex.test(camelize(code))) { diff --git a/test-workspace/tsc/vue3/#4668/child.vue b/test-workspace/tsc/vue3/#4668/child.vue new file mode 100644 index 0000000000..3163f4d0d3 --- /dev/null +++ b/test-workspace/tsc/vue3/#4668/child.vue @@ -0,0 +1,8 @@ + + + diff --git a/test-workspace/tsc/vue3/#4668/main.vue b/test-workspace/tsc/vue3/#4668/main.vue new file mode 100644 index 0000000000..5e701d317a --- /dev/null +++ b/test-workspace/tsc/vue3/#4668/main.vue @@ -0,0 +1,16 @@ + +