From 63c4f50230432d657c4658790a8a4a06fbafa44c Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 2 Nov 2024 16:21:45 +0800 Subject: [PATCH] refactor: use comment syntax --- .../vscode/syntaxes/vue.tmLanguage.json | 6 +++--- .../lib/codegen/template/context.ts | 5 +++++ .../lib/codegen/template/element.ts | 21 ++++++++----------- .../lib/codegen/template/templateChild.ts | 16 +++++++++++--- .../lib/plugins/vue-template-inline-ts.ts | 14 ++++++++++++- .../lib/plugins/vue-directive-comments.ts | 17 ++++++++------- .../passedFixtures/vue3/v-generic/main.vue | 19 ++++++++++------- 7 files changed, 64 insertions(+), 34 deletions(-) diff --git a/extensions/vscode/syntaxes/vue.tmLanguage.json b/extensions/vscode/syntaxes/vue.tmLanguage.json index cb700da6e7..71109bc144 100644 --- a/extensions/vscode/syntaxes/vue.tmLanguage.json +++ b/extensions/vscode/syntaxes/vue.tmLanguage.json @@ -977,10 +977,10 @@ "include": "#vue-directives-style-attr" }, { - "include": "#vue-directives-generic-attr" + "include": "#vue-directives-original" }, { - "include": "#vue-directives-original" + "include": "#vue-directives-generic-attr" } ] }, @@ -1199,7 +1199,7 @@ ] }, "vue-directives-generic-attr": { - "begin": "\\b((?:v-)?generic)\\s*(=)", + "begin": "\\b(generic)\\s*(=)", "captures": { "1": { "name": "entity.other.attribute-name.html.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 { - for (const prop of props) { - if (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE || prop.name !== 'generic' || !prop.exp) { - continue; - } + if (ctx.lastGenericComment) { + const { content, offset } = ctx.lastGenericComment; yield* wrapWith( - prop.exp.loc.start.offset, - prop.exp.loc.end.offset, + offset, + offset + content.length, ctx.codeFeatures.verification, `<`, [ - prop.exp.loc.source, + content, 'template', - prop.exp.loc.start.offset, + offset, ctx.codeFeatures.all ], `>` ); - break; } + ctx.lastGenericComment = undefined; } function* generateComponentSlot( 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(/^ - - \ No newline at end of file + + + + + + + +