Skip to content

Commit bbdf49d

Browse files
authored
standardize type checks (#3830)
1 parent 8096aa9 commit bbdf49d

File tree

8 files changed

+20
-17
lines changed

8 files changed

+20
-17
lines changed

compat/src/render.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ options.vnode = vnode => {
109109
let normalizedProps = props;
110110

111111
// only normalize props on Element nodes
112-
if (typeof type === 'string') {
112+
if (typeof type == 'string') {
113113
const nonCustomElement = type.indexOf('-') === -1;
114114
normalizedProps = {};
115115

116116
let style = props.style;
117-
if (typeof style === 'object') {
117+
if (typeof style == 'object') {
118118
for (i in style) {
119-
if (typeof style[i] === 'number' && !IS_NON_DIMENSIONAL.test(i)) {
119+
if (typeof style[i] == 'number' && !IS_NON_DIMENSIONAL.test(i)) {
120120
style[i] += 'px';
121121
}
122122
}
@@ -211,7 +211,7 @@ options.vnode = vnode => {
211211
if (props.className != null) normalizedProps.class = props.className;
212212
Object.defineProperty(normalizedProps, 'className', classNameDescriptor);
213213
}
214-
} else if (typeof type === 'function' && type.defaultProps) {
214+
} else if (typeof type == 'function' && type.defaultProps) {
215215
for (i in type.defaultProps) {
216216
if (normalizedProps[i] === undefined) {
217217
normalizedProps[i] = type.defaultProps[i];

compat/src/scheduler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ export function unstable_runWithPriority(priority, callback) {
1919
}
2020

2121
export const unstable_now =
22-
typeof performance === 'object' && typeof performance.now === 'function'
22+
typeof performance == 'object' && typeof performance.now == 'function'
2323
? performance.now.bind(performance)
2424
: () => Date.now();

src/create-element.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,19 @@ export function createElement(type, props, children) {
5656
*/
5757
export function normalizeToVNode(childVNode) {
5858
let type = typeof childVNode;
59-
if (childVNode == null || type === 'boolean') {
59+
if (childVNode == null || type == 'boolean') {
6060
return null;
6161
}
62-
if (type === 'object') {
62+
63+
if (type == 'object' || type == 'function') {
6364
if (Array.isArray(childVNode)) {
6465
return createElement(Fragment, null, childVNode);
6566
}
66-
} else if (type !== 'string' && type !== 'function') {
67-
return String(childVNode);
67+
68+
return childVNode;
6869
}
69-
return childVNode;
70+
71+
return String(childVNode);
7072
}
7173

7274
export function createRef() {

src/diff/children.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function findMatchingIndex(
184184
skewedIndex,
185185
remainingOldChildren
186186
) {
187-
const type = typeof childVNode === 'string' ? null : childVNode.type;
187+
const type = typeof childVNode == 'string' ? null : childVNode.type;
188188
const key = type !== null ? childVNode.key : UNDEFINED;
189189
let match = -1;
190190
let x = skewedIndex - 1; // i - 1;

src/diff/mount.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function mountElement(internal, dom) {
181181
newValue = value;
182182
} else if (
183183
value != null &&
184-
(isFullRender || typeof value === 'function')
184+
(isFullRender || typeof value == 'function')
185185
) {
186186
setProperty(dom, i, value, null, isSvg);
187187
}
@@ -392,7 +392,8 @@ function mountComponent(internal, startDom) {
392392
if (renderResult == null) {
393393
return startDom;
394394
}
395-
if (typeof renderResult === 'object') {
395+
396+
if (typeof renderResult == 'object') {
396397
// dissolve unkeyed root fragments:
397398
if (renderResult.type === Fragment && renderResult.key == null) {
398399
renderResult = renderResult.props.children;

src/diff/patch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ function patchComponent(internal, newVNode) {
305305

306306
if (renderResult == null) {
307307
renderResult = [];
308-
} else if (typeof renderResult === 'object') {
308+
} else if (typeof renderResult == 'object') {
309309
if (renderResult.type === Fragment && renderResult.key == null) {
310310
renderResult = renderResult.props.children;
311311
}

src/diff/props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
9292
// amount of exceptions would cost us too many bytes. On top of
9393
// that other VDOM frameworks also always stringify `false`.
9494

95-
if (typeof value === 'function') {
95+
if (typeof value == 'function') {
9696
// never serialize functions as attribute values
9797
} else if (value != null && (value !== false || name.indexOf('-') != -1)) {
9898
dom.setAttribute(name, value);

src/tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function createInternal(vnode, parentInternal) {
3131
// Text VNodes/Internals have an ID of 0 that is never used:
3232
let vnodeId = 0;
3333

34-
if (typeof vnode === 'string') {
34+
if (typeof vnode == 'string') {
3535
// type = null;
3636
flags |= TYPE_TEXT;
3737
props = vnode;
@@ -61,7 +61,7 @@ export function createInternal(vnode, parentInternal) {
6161

6262
// flags = typeof type === 'function' ? COMPONENT_NODE : ELEMENT_NODE;
6363
flags |=
64-
typeof type === 'function'
64+
typeof type == 'function'
6565
? type.prototype && type.prototype.render
6666
? TYPE_CLASS
6767
: props._parentDom

0 commit comments

Comments
 (0)