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
3 changed files with 8 additions and 26 deletions

View File

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

View File

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