From 05a8bef08d948e5648be2a946a60de3b55be5b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E9=9B=BE=E4=B8=89=E8=AF=AD?= <32354856+baiwusanyu-c@users.noreply.github.com> Date: Tue, 18 Apr 2023 21:08:34 +0800 Subject: [PATCH] fix: Ignore jsx and tsx parsing(close:#47 ) --- package.json | 3 +- packages/core/index.ts | 7 +- play/src/comp.vue | 12 +- play/vite.config.ts | 3 +- pnpm-lock.yaml | 427 ++++++++++++++++++++++++++++++++++++++++- utils/constant.ts | 1 + 6 files changed, 443 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index f7220e1..521bcbe 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,8 @@ "@unplugin-vue-cssvars/entry": "workspace:*", "@unplugin-vue-cssvars/play": "workspace:*", "@unplugin-vue-cssvars/utils": "workspace:*", - "@vitejs/plugin-vue": "^4.0.0", + "@vitejs/plugin-vue": "^4.1.0", + "@vitejs/plugin-vue-jsx": "^3.0.1", "@vitest/coverage-c8": "^0.30.1", "@vitest/ui": "^0.30.1", "@vue/compiler-sfc": "^3.2.47", diff --git a/packages/core/index.ts b/packages/core/index.ts index de13635..7f73715 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -1,5 +1,5 @@ import { createUnplugin } from 'unplugin' -import { NAME, SUPPORT_FILE_REG } from '@unplugin-vue-cssvars/utils' +import { JSX_TSX_REG, NAME, SUPPORT_FILE_REG } from '@unplugin-vue-cssvars/utils' import { createFilter } from '@rollup/pluginutils' import { parse } from '@vue/compiler-sfc' import chalk from 'chalk' @@ -47,6 +47,11 @@ const unplugin = createUnplugin( // ⭐TODO: 只支持 .vue ? jsx, tsx, js, ts ? if (id.endsWith('.vue')) { const { descriptor } = parse(code) + const lang = descriptor?.script?.lang ?? 'js' + // ⭐TODO: 只支持 .vue ? jsx, tsx, js, ts ? + if (JSX_TSX_REG.test(`.${lang}`)) + return code + isScriptSetup = !!descriptor.scriptSetup const { vbindVariableListByPath, diff --git a/play/src/comp.vue b/play/src/comp.vue index 77137b9..85174ca 100644 --- a/play/src/comp.vue +++ b/play/src/comp.vue @@ -1,5 +1,5 @@ -