feat: Support SVG 2 elements, using @vue/shared to ensure consistent behavior with vue (#745)

This commit is contained in:
崮生 2025-03-03 13:51:20 +08:00 committed by GitHub
parent fb925b8a28
commit a7607de7b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 26 deletions

View File

@ -31,15 +31,13 @@
"@babel/types": "^7.26.9", "@babel/types": "^7.26.9",
"@vue/babel-helper-vue-transform-on": "workspace:*", "@vue/babel-helper-vue-transform-on": "workspace:*",
"@vue/babel-plugin-resolve-type": "workspace:*", "@vue/babel-plugin-resolve-type": "workspace:*",
"html-tags": "^3.3.1", "@vue/shared": "^3.5.13"
"svg-tags": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.26.9", "@babel/core": "^7.26.9",
"@babel/preset-env": "^7.26.9", "@babel/preset-env": "^7.26.9",
"@types/babel__template": "^7.4.4", "@types/babel__template": "^7.4.4",
"@types/babel__traverse": "^7.20.6", "@types/babel__traverse": "^7.20.6",
"@types/svg-tags": "^1.0.2",
"@vue/test-utils": "^2.4.6", "@vue/test-utils": "^2.4.6",
"regenerator-runtime": "^0.14.1", "regenerator-runtime": "^0.14.1",
"vue": "catalog:" "vue": "catalog:"

View File

@ -1,10 +1,8 @@
import * as t from '@babel/types'; import * as t from '@babel/types';
import htmlTags from 'html-tags';
import svgTags from 'svg-tags';
import { type NodePath } from '@babel/traverse'; import { type NodePath } from '@babel/traverse';
import { isHTMLTag, isSVGTag } from '@vue/shared';
import type { State } from './interface'; import type { State } from './interface';
import SlotFlags from './slotFlags'; import SlotFlags from './slotFlags';
export const JSX_HELPER_KEY = 'JSX_HELPER_KEY'; export const JSX_HELPER_KEY = 'JSX_HELPER_KEY';
export const FRAGMENT = 'Fragment'; export const FRAGMENT = 'Fragment';
export const KEEP_ALIVE = 'KeepAlive'; export const KEEP_ALIVE = 'KeepAlive';
@ -60,8 +58,8 @@ export const checkIsComponent = (
return ( return (
!state.opts.isCustomElement?.(tag) && !state.opts.isCustomElement?.(tag) &&
shouldTransformedToSlots(tag) && shouldTransformedToSlots(tag) &&
!htmlTags.includes(tag as htmlTags.htmlTags) && !isHTMLTag(tag) &&
!svgTags.includes(tag) !isSVGTag(tag)
); );
}; };
@ -99,10 +97,7 @@ export const getTag = (
const namePath = path.get('openingElement').get('name'); const namePath = path.get('openingElement').get('name');
if (namePath.isJSXIdentifier()) { if (namePath.isJSXIdentifier()) {
const { name } = namePath.node; const { name } = namePath.node;
if ( if (!isHTMLTag(name) && !isSVGTag(name)) {
!htmlTags.includes(name as htmlTags.htmlTags) &&
!svgTags.includes(name)
) {
return name === FRAGMENT return name === FRAGMENT
? createIdentifier(state, FRAGMENT) ? createIdentifier(state, FRAGMENT)
: path.scope.hasBinding(name) : path.scope.hasBinding(name)

17
pnpm-lock.yaml generated
View File

@ -106,12 +106,9 @@ importers:
'@vue/babel-plugin-resolve-type': '@vue/babel-plugin-resolve-type':
specifier: workspace:* specifier: workspace:*
version: link:../babel-plugin-resolve-type version: link:../babel-plugin-resolve-type
html-tags: '@vue/shared':
specifier: ^3.3.1 specifier: ^3.5.13
version: 3.3.1 version: 3.5.13
svg-tags:
specifier: ^1.0.0
version: 1.0.0
devDependencies: devDependencies:
'@babel/core': '@babel/core':
specifier: ^7.26.9 specifier: ^7.26.9
@ -125,9 +122,6 @@ importers:
'@types/babel__traverse': '@types/babel__traverse':
specifier: ^7.20.6 specifier: ^7.20.6
version: 7.20.6 version: 7.20.6
'@types/svg-tags':
specifier: ^1.0.2
version: 1.0.2
'@vue/test-utils': '@vue/test-utils':
specifier: ^2.4.6 specifier: ^2.4.6
version: 2.4.6 version: 2.4.6
@ -1157,9 +1151,6 @@ packages:
'@types/node@22.13.4': '@types/node@22.13.4':
resolution: {integrity: sha512-ywP2X0DYtX3y08eFVx5fNIw7/uIv8hYUKgXoK8oayJlLnKcRfEYCxWMVE1XagUdVtCJlZT1AU4LXEABW+L1Peg==} resolution: {integrity: sha512-ywP2X0DYtX3y08eFVx5fNIw7/uIv8hYUKgXoK8oayJlLnKcRfEYCxWMVE1XagUdVtCJlZT1AU4LXEABW+L1Peg==}
'@types/svg-tags@1.0.2':
resolution: {integrity: sha512-D8rhCFfpmWzXvzVqdXo40EXNeropfqp4gvwn8fcVfzYIci8M1C1tk/L26Yacn/U9vaPM7FlS73BNoUtfjAjwAw==}
'@typescript-eslint/eslint-plugin@8.24.1': '@typescript-eslint/eslint-plugin@8.24.1':
resolution: {integrity: sha512-ll1StnKtBigWIGqvYDVuDmXJHVH4zLVot1yQ4fJtLpL7qacwkxJc1T0bptqw+miBQ/QfUbhl1TcQ4accW5KUyA==} resolution: {integrity: sha512-ll1StnKtBigWIGqvYDVuDmXJHVH4zLVot1yQ4fJtLpL7qacwkxJc1T0bptqw+miBQ/QfUbhl1TcQ4accW5KUyA==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
@ -3840,8 +3831,6 @@ snapshots:
dependencies: dependencies:
undici-types: 6.20.0 undici-types: 6.20.0
'@types/svg-tags@1.0.2': {}
'@typescript-eslint/eslint-plugin@8.24.1(@typescript-eslint/parser@8.24.1(eslint@9.20.1(jiti@2.4.2))(typescript@5.7.3))(eslint@9.20.1(jiti@2.4.2))(typescript@5.7.3)': '@typescript-eslint/eslint-plugin@8.24.1(@typescript-eslint/parser@8.24.1(eslint@9.20.1(jiti@2.4.2))(typescript@5.7.3))(eslint@9.20.1(jiti@2.4.2))(typescript@5.7.3)':
dependencies: dependencies:
'@eslint-community/regexpp': 4.12.1 '@eslint-community/regexpp': 4.12.1