@@ -19,6 +19,104 @@ const ELEMENT_ATTRIBUTE_MAPPING = {
19
19
} ,
20
20
}
21
21
22
+ // Reference: https://developer.mozilla.org/en-US/docs/Web/SVG/Element#SVG_elements
23
+ const ELEMENT_TAG_NAME_MAPPING = {
24
+ a : 'a' ,
25
+ altglyph : 'altGlyph' ,
26
+ altglyphdef : 'altGlyphDef' ,
27
+ altglyphitem : 'altGlyphItem' ,
28
+ animate : 'animate' ,
29
+ animatecolor : 'animateColor' ,
30
+ animatemotion : 'animateMotion' ,
31
+ animatetransform : 'animateTransform' ,
32
+ audio : 'audio' ,
33
+ canvas : 'canvas' ,
34
+ circle : 'circle' ,
35
+ clippath : 'clipPath' ,
36
+ 'color-profile' : 'colorProfile' ,
37
+ cursor : 'cursor' ,
38
+ defs : 'defs' ,
39
+ desc : 'desc' ,
40
+ discard : 'discard' ,
41
+ ellipse : 'ellipse' ,
42
+ feblend : 'feBlend' ,
43
+ fecolormatrix : 'feColorMatrix' ,
44
+ fecomponenttransfer : 'feComponentTransfer' ,
45
+ fecomposite : 'feComposite' ,
46
+ feconvolvematrix : 'feConvolveMatrix' ,
47
+ fediffuselighting : 'feDiffuseLighting' ,
48
+ fedisplacementmap : 'feDisplacementMap' ,
49
+ fedistantlight : 'feDistantLight' ,
50
+ fedropshadow : 'feDropShadow' ,
51
+ feflood : 'feFlood' ,
52
+ fefunca : 'feFuncA' ,
53
+ fefuncb : 'feFuncB' ,
54
+ fefuncg : 'feFuncG' ,
55
+ fefuncr : 'feFuncR' ,
56
+ fegaussianblur : 'feGaussianBlur' ,
57
+ feimage : 'feImage' ,
58
+ femerge : 'feMerge' ,
59
+ femergenode : 'feMergeNode' ,
60
+ femorphology : 'feMorphology' ,
61
+ feoffset : 'feOffset' ,
62
+ fepointlight : 'fePointLight' ,
63
+ fespecularlighting : 'feSpecularLighting' ,
64
+ fespotlight : 'feSpotLight' ,
65
+ fetile : 'feTile' ,
66
+ feturbulence : 'feTurbulence' ,
67
+ filter : 'filter' ,
68
+ font : 'font' ,
69
+ 'font-face' : 'fontFace' ,
70
+ 'font-face-format' : 'fontFaceFormat' ,
71
+ 'font-face-name' : 'fontFaceName' ,
72
+ 'font-face-src' : 'fontFaceSrc' ,
73
+ 'font-face-uri' : 'fontFaceUri' ,
74
+ foreignobject : 'foreignObject' ,
75
+ g : 'g' ,
76
+ glyph : 'glyph' ,
77
+ glyphref : 'glyphRef' ,
78
+ hatch : 'hatch' ,
79
+ hatchpath : 'hatchpath' ,
80
+ hkern : 'hkern' ,
81
+ iframe : 'iframe' ,
82
+ image : 'image' ,
83
+ line : 'line' ,
84
+ lineargradient : 'linearGradient' ,
85
+ marker : 'marker' ,
86
+ mask : 'mask' ,
87
+ mesh : 'mesh' ,
88
+ meshgradient : 'meshgradient' ,
89
+ meshpatch : 'meshpatch' ,
90
+ meshrow : 'meshrow' ,
91
+ metadata : 'metadata' ,
92
+ 'missing-glyph' : 'missingGlyph' ,
93
+ mpath : 'mpath' ,
94
+ path : 'path' ,
95
+ pattern : 'pattern' ,
96
+ polygon : 'polygon' ,
97
+ polyline : 'polyline' ,
98
+ radialgradient : 'radialGradient' ,
99
+ rect : 'rect' ,
100
+ script : 'script' ,
101
+ set : 'set' ,
102
+ solidcolor : 'solidcolor' ,
103
+ stop : 'stop' ,
104
+ style : 'style' ,
105
+ svg : 'svg' ,
106
+ switch : 'switch' ,
107
+ symbol : 'symbol' ,
108
+ text : 'text' ,
109
+ textpath : 'textPath' ,
110
+ title : 'title' ,
111
+ tref : 'tref' ,
112
+ tspan : 'tspan' ,
113
+ unknown : 'unknown' ,
114
+ use : 'use' ,
115
+ video : 'video' ,
116
+ view : 'view' ,
117
+ vkern : 'vkern'
118
+ } ;
119
+
22
120
function isNumeric ( input ) {
23
121
return (
24
122
input !== undefined &&
@@ -47,6 +145,11 @@ function getAttributeName(attribute, node) {
47
145
return attribute . name
48
146
}
49
147
148
+ function transformTagName ( tagName ) {
149
+ const lowercaseTagName = tagName . toLowerCase ( ) ;
150
+ return ELEMENT_TAG_NAME_MAPPING [ lowercaseTagName ] || lowercaseTagName ;
151
+ }
152
+
50
153
function getAttributeValue ( attribute ) {
51
154
return attribute . value
52
155
}
@@ -63,7 +166,8 @@ export default {
63
166
HTMLElement : {
64
167
enter ( path ) {
65
168
const jsxElement = new JSXElement ( )
66
- jsxElement . name = path . node . tagName . toLowerCase ( )
169
+
170
+ jsxElement . name = transformTagName ( path . node . tagName )
67
171
jsxElement . attributes = listToArray ( path . node . attributes )
68
172
jsxElement . children = listToArray ( path . node . childNodes )
69
173
path . replace ( jsxElement )
0 commit comments