8
8
*/
9
9
10
10
import {
11
- getPropertyInfo ,
12
- shouldIgnoreAttribute ,
13
- shouldRemoveAttribute ,
14
- isAttributeNameSafe ,
15
- BOOLEAN ,
16
- OVERLOADED_BOOLEAN ,
17
- } from '../shared/DOMProperty' ;
11
+ getPropertyInfo ,
12
+ shouldIgnoreAttribute ,
13
+ shouldRemoveAttribute ,
14
+ isAttributeNameSafe ,
15
+ BOOLEAN ,
16
+ OVERLOADED_BOOLEAN } from
17
+ '../shared/DOMProperty' ;
18
18
19
- import type { PropertyInfo } from '../shared/DOMProperty' ;
19
+ import { PropertyInfo } from '../shared/DOMProperty' ;
20
20
21
21
/**
22
- * Get the value for a property on a node. Only used in DEV for SSR validation.
23
- * The "expected" argument is used as a hint of what the expected value is.
24
- * Some properties have multiple equivalent values.
25
- */
22
+ * Get the value for a property on a node. Only used in DEV for SSR validation.
23
+ * The "expected" argument is used as a hint of what the expected value is.
24
+ * Some properties have multiple equivalent values.
25
+ */
26
26
export function getValueForProperty (
27
- node : Element ,
28
- name : string ,
29
- expected : mixed ,
30
- propertyInfo : PropertyInfo ,
31
- ) : mixed {
27
+ node : Element ,
28
+ name : string ,
29
+ expected : unknown ,
30
+ propertyInfo : PropertyInfo )
31
+ : unknown {
32
32
if ( __DEV__ ) {
33
33
if ( propertyInfo . mustUseProperty ) {
34
- const { propertyName} = propertyInfo ;
35
- return ( node : any ) [ propertyName ] ;
34
+ const { propertyName } = propertyInfo ;
35
+ return ( node as any ) [ propertyName ] ;
36
36
} else {
37
37
const attributeName = propertyInfo . attributeName ;
38
38
@@ -47,7 +47,7 @@ export function getValueForProperty(
47
47
if ( shouldRemoveAttribute ( name , expected , propertyInfo , false ) ) {
48
48
return value ;
49
49
}
50
- if ( value === '' + ( expected : any ) ) {
50
+ if ( value === '' + ( expected as any ) ) {
51
51
return expected ;
52
52
}
53
53
return value ;
@@ -72,7 +72,7 @@ export function getValueForProperty(
72
72
73
73
if ( shouldRemoveAttribute ( name , expected , propertyInfo , false ) ) {
74
74
return stringValue === null ? expected : stringValue ;
75
- } else if ( stringValue === '' + ( expected : any ) ) {
75
+ } else if ( stringValue === '' + ( expected as any ) ) {
76
76
return expected ;
77
77
} else {
78
78
return stringValue ;
@@ -82,15 +82,15 @@ export function getValueForProperty(
82
82
}
83
83
84
84
/**
85
- * Get the value for a attribute on a node. Only used in DEV for SSR validation.
86
- * The third argument is used as a hint of what the expected value is. Some
87
- * attributes have multiple equivalent values.
88
- */
85
+ * Get the value for a attribute on a node. Only used in DEV for SSR validation.
86
+ * The third argument is used as a hint of what the expected value is. Some
87
+ * attributes have multiple equivalent values.
88
+ */
89
89
export function getValueForAttribute (
90
- node : Element ,
91
- name : string ,
92
- expected : mixed ,
93
- ) : mixed {
90
+ node : Element ,
91
+ name : string ,
92
+ expected : unknown )
93
+ : unknown {
94
94
if ( __DEV__ ) {
95
95
if ( ! isAttributeNameSafe ( name ) ) {
96
96
return ;
@@ -99,26 +99,26 @@ export function getValueForAttribute(
99
99
return expected === undefined ? undefined : null ;
100
100
}
101
101
const value = node . getAttribute ( name ) ;
102
- if ( value === '' + ( expected : any ) ) {
102
+ if ( value === '' + ( expected as any ) ) {
103
103
return expected ;
104
104
}
105
105
return value ;
106
106
}
107
107
}
108
108
109
109
/**
110
- * Sets the value for a property on a node.
111
- *
112
- * @param {DOMElement } node
113
- * @param {string } name
114
- * @param {* } value
115
- */
110
+ * Sets the value for a property on a node.
111
+ *
112
+ * @param {DOMElement } node
113
+ * @param {string } name
114
+ * @param {* } value
115
+ */
116
116
export function setValueForProperty (
117
- node : Element ,
118
- name : string ,
119
- value : mixed ,
120
- isCustomComponentTag : boolean ,
121
- ) {
117
+ node : Element ,
118
+ name : string ,
119
+ value : unknown ,
120
+ isCustomComponentTag : boolean )
121
+ {
122
122
const propertyInfo = getPropertyInfo ( name ) ;
123
123
if ( shouldIgnoreAttribute ( name , propertyInfo , isCustomComponentTag ) ) {
124
124
return ;
@@ -133,37 +133,37 @@ export function setValueForProperty(
133
133
if ( value === null ) {
134
134
node . removeAttribute ( attributeName ) ;
135
135
} else {
136
- node . setAttribute ( attributeName , '' + ( value : any ) ) ;
136
+ node . setAttribute ( attributeName , '' + ( value as any ) ) ;
137
137
}
138
138
}
139
139
return ;
140
140
}
141
- const { mustUseProperty} = propertyInfo ;
141
+ const { mustUseProperty } = propertyInfo ;
142
142
if ( mustUseProperty ) {
143
- const { propertyName} = propertyInfo ;
143
+ const { propertyName } = propertyInfo ;
144
144
if ( value === null ) {
145
- const { type} = propertyInfo ;
146
- ( node : any ) [ propertyName ] = type === BOOLEAN ? false : '' ;
145
+ const { type } = propertyInfo ;
146
+ ( node as any ) [ propertyName ] = type === BOOLEAN ? false : '' ;
147
147
} else {
148
148
// Contrary to `setAttribute`, object properties are properly
149
149
// `toString`ed by IE8/9.
150
- ( node : any ) [ propertyName ] = value ;
150
+ ( node as any ) [ propertyName ] = value ;
151
151
}
152
152
return ;
153
153
}
154
154
// The rest are treated as attributes with special cases.
155
- const { attributeName, attributeNamespace} = propertyInfo ;
155
+ const { attributeName, attributeNamespace } = propertyInfo ;
156
156
if ( value === null ) {
157
157
node . removeAttribute ( attributeName ) ;
158
158
} else {
159
- const { type} = propertyInfo ;
159
+ const { type } = propertyInfo ;
160
160
let attributeValue ;
161
- if ( type === BOOLEAN || ( type === OVERLOADED_BOOLEAN && value === true ) ) {
161
+ if ( type === BOOLEAN || type === OVERLOADED_BOOLEAN && value === true ) {
162
162
attributeValue = '' ;
163
163
} else {
164
164
// `setAttribute` with objects becomes only `[object]` in IE8/9,
165
165
// ('' + value) makes it output the correct toString()-value.
166
- attributeValue = '' + ( value : any ) ;
166
+ attributeValue = '' + ( value as any ) ;
167
167
}
168
168
if ( attributeNamespace ) {
169
169
node . setAttributeNS ( attributeNamespace , attributeName , attributeValue ) ;
0 commit comments