From 8cf123f9e2dc962b899d71767ef426b839499cf7 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: Sat, 21 Dec 2024 07:49:25 +0800 Subject: [PATCH] feat(language-core): type support of `$attrs` (#5076) --- .../lib/codegen/template/context.ts | 5 ++- .../lib/codegen/template/elementProps.ts | 45 +++++++++++-------- .../lib/codegen/template/index.ts | 17 ++++++- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/packages/language-core/lib/codegen/template/context.ts b/packages/language-core/lib/codegen/template/context.ts index bf219f05b7..0a9d629d14 100644 --- a/packages/language-core/lib/codegen/template/context.ts +++ b/packages/language-core/lib/codegen/template/context.ts @@ -125,6 +125,8 @@ export function createTemplateCodegenContext(options: Pick(); const templateRefs = new Map(); return { @@ -140,7 +142,8 @@ export function createTemplateCodegenContext(options: Pick { } yield endOfLine; yield `var $attrs!: Partial & Record${endOfLine}`; + + if (ctx.bindingAttrLocs.length) { + yield `[`; + for (const loc of ctx.bindingAttrLocs) { + yield [ + loc.source, + 'template', + loc.start.offset, + ctx.codeFeatures.all + ]; + yield `,`; + } + yield `]${endOfLine}`; + } } function* generateRefs(ctx: TemplateCodegenContext): Generator {