@@ -13,14 +13,12 @@ function invertObject(obj, override) {
13
13
throw new TypeError ( 'First argument must be an object' ) ;
14
14
}
15
15
16
- var key ;
17
- var value ;
18
16
var isOverridePresent = typeof override === 'function' ;
19
17
var overrides = { } ;
20
18
var result = { } ;
21
19
22
- for ( key in obj ) {
23
- value = obj [ key ] ;
20
+ for ( var key in obj ) {
21
+ var value = obj [ key ] ;
24
22
25
23
if ( isOverridePresent ) {
26
24
overrides = override ( key , value ) ;
@@ -47,31 +45,34 @@ function invertObject(obj, override) {
47
45
* @param {object } props - The props being passed to the element.
48
46
* @returns - Whether tag is custom component.
49
47
*/
48
+
49
+ var RESERVED_SVG_MATHML_ELEMENTS = new Set ( [
50
+ 'annotation-xml' ,
51
+ 'color-profile' ,
52
+ 'font-face' ,
53
+ 'font-face-src' ,
54
+ 'font-face-uri' ,
55
+ 'font-face-format' ,
56
+ 'font-face-name' ,
57
+ 'missing-glyph'
58
+ ] ) ;
59
+
50
60
function isCustomComponent ( tagName , props ) {
51
61
if ( tagName . indexOf ( '-' ) === - 1 ) {
52
62
return props && typeof props . is === 'string' ;
53
63
}
54
-
55
- switch ( tagName ) {
56
- // These are reserved SVG and MathML elements.
57
- // We don't mind this whitelist too much because we expect it to never grow.
58
- // The alternative is to track the namespace in a few places which is convoluted.
59
- // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
60
- case 'annotation-xml' :
61
- case 'color-profile' :
62
- case 'font-face' :
63
- case 'font-face-src' :
64
- case 'font-face-uri' :
65
- case 'font-face-format' :
66
- case 'font-face-name' :
67
- case 'missing-glyph' :
68
- return false ;
69
- default :
70
- return true ;
64
+ // These are reserved SVG and MathML elements.
65
+ // We don't mind this whitelist too much because we expect it to never grow.
66
+ // The alternative is to track the namespace in a few places which is convoluted.
67
+ // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
68
+ if ( RESERVED_SVG_MATHML_ELEMENTS . has ( tagName ) ) {
69
+ return false ;
71
70
}
71
+ return true ;
72
72
}
73
73
74
- var styleToJSOptions = { reactCompat : true } ;
74
+ // styleToJSOptions
75
+ var STYLE_TO_JS_OPTIONS = { reactCompat : true } ;
75
76
76
77
/**
77
78
* Sets style prop.
@@ -84,7 +85,7 @@ function setStyleProp(style, props) {
84
85
return ;
85
86
}
86
87
try {
87
- props . style = styleToJS ( style , styleToJSOptions ) ;
88
+ props . style = styleToJS ( style , STYLE_TO_JS_OPTIONS ) ;
88
89
} catch ( err ) {
89
90
props . style = { } ;
90
91
}
@@ -98,7 +99,7 @@ var PRESERVE_CUSTOM_ATTRIBUTES = React.version.split('.')[0] >= 16;
98
99
99
100
// Taken from
100
101
// https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/react-dom/src/client/validateDOMNesting.js#L213
101
- var elementsWithNoTextChildren = new Set ( [
102
+ var ELEMENTS_WITH_NO_TEXT_CHILDREN = new Set ( [
102
103
'tr' ,
103
104
'tbody' ,
104
105
'thead' ,
@@ -117,7 +118,7 @@ var elementsWithNoTextChildren = new Set([
117
118
* @returns - Whether node can contain text nodes.
118
119
*/
119
120
function canTextBeChildOfNode ( node ) {
120
- return ! elementsWithNoTextChildren . has ( node . name ) ;
121
+ return ! ELEMENTS_WITH_NO_TEXT_CHILDREN . has ( node . name ) ;
121
122
}
122
123
123
124
function returnFirstArg ( arg ) {
@@ -126,10 +127,10 @@ function returnFirstArg(arg) {
126
127
127
128
module . exports = {
128
129
PRESERVE_CUSTOM_ATTRIBUTES : PRESERVE_CUSTOM_ATTRIBUTES ,
130
+ ELEMENTS_WITH_NO_TEXT_CHILDREN : ELEMENTS_WITH_NO_TEXT_CHILDREN ,
129
131
invertObject : invertObject ,
130
132
isCustomComponent : isCustomComponent ,
131
133
setStyleProp : setStyleProp ,
132
134
canTextBeChildOfNode : canTextBeChildOfNode ,
133
- elementsWithNoTextChildren : elementsWithNoTextChildren ,
134
135
returnFirstArg : returnFirstArg
135
136
} ;
0 commit comments