Move fragment type check to normalizer (#2462)

Should result in more informative stack traces.

Fixes #2461
This commit is contained in:
Isiah Meadows 2019-07-07 17:16:56 -04:00 committed by GitHub
parent b2f82e3abc
commit db277217f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 27 deletions

View file

@ -11,8 +11,19 @@ Vnode.normalize = function(node) {
}
Vnode.normalizeChildren = function(input) {
var children = []
for (var i = 0; i < input.length; i++) {
children[i] = Vnode.normalize(input[i])
if (input.length) {
var isKeyed = input[0] != null && input[0].key != null
// Note: this is a *very* perf-sensitive check.
// Fun fact: merging the loop like this is somehow faster than splitting
// it, noticeably so.
for (var i = 1; i < input.length; i++) {
if ((input[i] != null && input[i].key != null) !== isKeyed) {
throw new TypeError("Vnodes must either always have keys or never have keys!")
}
}
for (var i = 0; i < input.length; i++) {
children[i] = Vnode.normalize(input[i])
}
}
return children
}