From 4c3c8c4242d789c5219bb4c59669ca4097b7168a 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, 2 Nov 2024 16:33:44 +0800 Subject: [PATCH] feat(language-core): support `@vue-generic` (#4971) --- .../lib/codegen/template/context.ts | 5 ++++ .../lib/codegen/template/element.ts | 26 ++++++++++++++++++- .../lib/codegen/template/elementDirectives.ts | 1 + .../lib/codegen/template/templateChild.ts | 16 +++++++++--- .../lib/plugins/vue-template-inline-ts.ts | 14 +++++++++- .../lib/plugins/vue-directive-comments.ts | 17 +++++++----- .../tsc/passedFixtures/vue2/tsconfig.json | 1 + .../passedFixtures/vue3/v-generic/comp.vue | 5 ++++ .../passedFixtures/vue3/v-generic/main.vue | 17 ++++++++++++ 9 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 test-workspace/tsc/passedFixtures/vue3/v-generic/comp.vue create mode 100644 test-workspace/tsc/passedFixtures/vue3/v-generic/main.vue diff --git a/packages/language-core/lib/codegen/template/context.ts b/packages/language-core/lib/codegen/template/context.ts index c5abab54e1..7334ae85a3 100644 --- a/packages/language-core/lib/codegen/template/context.ts +++ b/packages/language-core/lib/codegen/template/context.ts @@ -63,6 +63,10 @@ export function createTemplateCodegenContext(options: Pick { + if (ctx.lastGenericComment) { + const { content, offset } = ctx.lastGenericComment; + yield* wrapWith( + offset, + offset + content.length, + ctx.codeFeatures.verification, + `<`, + [ + content, + 'template', + offset, + ctx.codeFeatures.all + ], + `>` + ); + } + ctx.lastGenericComment = undefined; +} + function* generateComponentSlot( options: TemplateCodegenOptions, ctx: TemplateCodegenContext, diff --git a/packages/language-core/lib/codegen/template/elementDirectives.ts b/packages/language-core/lib/codegen/template/elementDirectives.ts index 3c67bce054..c8ebf4758a 100644 --- a/packages/language-core/lib/codegen/template/elementDirectives.ts +++ b/packages/language-core/lib/codegen/template/elementDirectives.ts @@ -24,6 +24,7 @@ export function* generateElementDirectives( || prop.name === 'bind' || prop.name === 'scope' || prop.name === 'data' + || prop.name === 'generic' ) { continue; } diff --git a/packages/language-core/lib/codegen/template/templateChild.ts b/packages/language-core/lib/codegen/template/templateChild.ts index c7df01b522..69be101239 100644 --- a/packages/language-core/lib/codegen/template/templateChild.ts +++ b/packages/language-core/lib/codegen/template/templateChild.ts @@ -36,16 +36,26 @@ export function* generateTemplateChild( ): Generator { if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) { const commentText = prevNode.content.trim().split(' ')[0]; - if (commentText.match(/^@vue-skip\b[\s\S]*/)) { + if (/^@vue-skip\b[\s\S]*/.test(commentText)) { yield `// @vue-skip${newLine}`; return; } - else if (commentText.match(/^@vue-ignore\b[\s\S]*/)) { + else if (/^@vue-ignore\b[\s\S]*/.test(commentText)) { yield* ctx.ignoreError(); } - else if (commentText.match(/^@vue-expect-error\b[\s\S]*/)) { + else if (/^@vue-expect-error\b[\s\S]*/.test(commentText)) { yield* ctx.expectError(prevNode); } + else { + const match = prevNode.loc.source.match(/^ + + + + + + +