From 85f810317688c2bf2ec846c77ebbecd464636201 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Mon, 30 Dec 2024 19:09:19 +0800 Subject: [PATCH] fix: ignore duplicate attribute error of `class` --- packages/language-plugin-pug/index.ts | 11 ++++++++++- test-workspace/tsc/passedFixtures/pug/#5099.vue | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test-workspace/tsc/passedFixtures/pug/#5099.vue diff --git a/packages/language-plugin-pug/index.ts b/packages/language-plugin-pug/index.ts index e445237429..4abb1b1765 100644 --- a/packages/language-plugin-pug/index.ts +++ b/packages/language-plugin-pug/index.ts @@ -1,7 +1,9 @@ import { SourceMap } from '@volar/source-map'; -import type { VueLanguagePlugin } from '@vue/language-core'; +import type { CompilerDOM, VueLanguagePlugin } from '@vue/language-core'; import * as pug from 'volar-service-pug/lib/languageService'; +const classRegex = /^class\s*=/; + const plugin: VueLanguagePlugin = ({ modules }) => { return { @@ -71,6 +73,13 @@ const plugin: VueLanguagePlugin = ({ modules }) => { options?.onWarn?.(createProxyObject(warning)); }, onError(error) { + // #5099 + if ( + error.code === 2 satisfies CompilerDOM.ErrorCodes.DUPLICATE_ATTRIBUTE + && classRegex.test(pugFile.htmlCode.slice(error.loc?.start.offset)) + ) { + return; + } options?.onError?.(createProxyObject(error)); }, }); diff --git a/test-workspace/tsc/passedFixtures/pug/#5099.vue b/test-workspace/tsc/passedFixtures/pug/#5099.vue new file mode 100644 index 0000000000..c6ae8233ca --- /dev/null +++ b/test-workspace/tsc/passedFixtures/pug/#5099.vue @@ -0,0 +1,6 @@ +