Skip to content

Commit a354a99

Browse files
committed
refactor: use custom element check instead static html elements set
1 parent 04e12ea commit a354a99

3 files changed

Lines changed: 5 additions & 118 deletions

File tree

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
UNSAFE_NAME,
55
NAMESPACE_REPLACE_REGEX,
66
HTML_LOWER_CASE,
7-
HTML_ELEMENTS,
87
HTML_ENUMERATED,
98
SVG_CAMEL_CASE,
109
createComponent,
@@ -301,6 +300,8 @@ function _renderToString(
301300

302301
let type = vnode.type,
303302
props = vnode.props;
303+
304+
const isCustomElement = type.includes("-");
304305

305306
// Invoke rendering on Components
306307
if (typeof type == 'function') {
@@ -667,7 +668,7 @@ function _renderToString(
667668
? 'panose-1'
668669
: name.replace(/([A-Z])/g, '-$1').toLowerCase();
669670
}
670-
} else if (HTML_ELEMENTS.has(type) && HTML_LOWER_CASE.has(name)) {
671+
} else if (!isCustomElement && HTML_LOWER_CASE.has(name)) {
671672
name = name.toLowerCase();
672673
}
673674
}

src/lib/util.js

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,120 +2,6 @@ import { DIRTY, BITS } from './constants';
22

33
export const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
44

5-
export const HTML_ELEMENTS = new Set([
6-
'a',
7-
'abbr',
8-
'address',
9-
'area',
10-
'article',
11-
'aside',
12-
'audio',
13-
'b',
14-
'base',
15-
'bdi',
16-
'bdo',
17-
'blockquote',
18-
'body',
19-
'br',
20-
'button',
21-
'canvas',
22-
'caption',
23-
'cite',
24-
'code',
25-
'col',
26-
'colgroup',
27-
'data',
28-
'datalist',
29-
'dd',
30-
'del',
31-
'details',
32-
'dfn',
33-
'dialog',
34-
'div',
35-
'dl',
36-
'dt',
37-
'em',
38-
'embed',
39-
'fieldset',
40-
'figcaption',
41-
'figure',
42-
'footer',
43-
'form',
44-
'h1',
45-
'h2',
46-
'h3',
47-
'h4',
48-
'h5',
49-
'h6',
50-
'head',
51-
'header',
52-
'hgroup',
53-
'hr',
54-
'html',
55-
'i',
56-
'iframe',
57-
'img',
58-
'input',
59-
'ins',
60-
'kbd',
61-
'label',
62-
'legend',
63-
'li',
64-
'link',
65-
'main',
66-
'map',
67-
'mark',
68-
'menu',
69-
'meta',
70-
'meter',
71-
'nav',
72-
'noscript',
73-
'object',
74-
'ol',
75-
'optgroup',
76-
'option',
77-
'output',
78-
'p',
79-
'picture',
80-
'pre',
81-
'progress',
82-
'q',
83-
'rp',
84-
'rt',
85-
'ruby',
86-
's',
87-
'samp',
88-
'script',
89-
'search',
90-
'section',
91-
'select',
92-
'slot',
93-
'small',
94-
'source',
95-
'span',
96-
'strong',
97-
'style',
98-
'sub',
99-
'summary',
100-
'sup',
101-
'table',
102-
'tbody',
103-
'td',
104-
'template',
105-
'textarea',
106-
'tfoot',
107-
'th',
108-
'thead',
109-
'time',
110-
'title',
111-
'tr',
112-
'track',
113-
'u',
114-
'ul',
115-
'var',
116-
'video',
117-
'wbr'
118-
]);
1195
// oxlint-disable-next-line no-control-regex
1206
export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
1217
export const NAMESPACE_REPLACE_REGEX = /^(xlink|xmlns|xml)([A-Z])/;

src/pretty.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
SVG_CAMEL_CASE,
1212
HTML_ENUMERATED,
1313
HTML_LOWER_CASE,
14-
HTML_ELEMENTS,
1514
getContext,
1615
setDirty,
1716
isDirty,
@@ -129,6 +128,7 @@ function _renderToStringPretty(
129128
let nodeName = vnode.type,
130129
props = vnode.props,
131130
isComponent = false;
131+
const isCustomElement = nodeName.includes("-");
132132

133133
// components
134134
if (typeof nodeName === 'function') {
@@ -300,7 +300,7 @@ function _renderToStringPretty(
300300
? 'panose-1'
301301
: name.replace(/([A-Z])/g, '-$1').toLowerCase();
302302
}
303-
} else if (HTML_ELEMENTS.has(nodeName) && HTML_LOWER_CASE.has(name)) {
303+
} else if (!isCustomElement && HTML_LOWER_CASE.has(name)) {
304304
name = name.toLowerCase();
305305
}
306306

0 commit comments

Comments
 (0)