Skip to content

Commit f394e2a

Browse files
authored
Fix error message selection condition (#3037)
I have no idea how this eluded me when I first wrote this. Also, add tests to make sure the check was correct from the beginning.
1 parent efa4c88 commit f394e2a

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

render/tests/test-normalizeChildren.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,68 @@ o.spec("normalizeChildren", function() {
5353
])
5454
}).throws(TypeError)
5555
})
56+
o("disallows mixed keys, ending with null", function() {
57+
o(function() {
58+
Vnode.normalizeChildren([
59+
{key: 1},
60+
null,
61+
])
62+
}).throws(TypeError)
63+
})
64+
o("disallows mixed keys, starting with null", function() {
65+
o(function() {
66+
Vnode.normalizeChildren([
67+
{data: 1},
68+
null,
69+
])
70+
}).throws(TypeError)
71+
})
72+
o("disallows mixed keys, ending with undefined", function() {
73+
o(function() {
74+
Vnode.normalizeChildren([
75+
{key: 1},
76+
undefined,
77+
])
78+
}).throws(TypeError)
79+
})
80+
o("disallows mixed keys, starting with undefined", function() {
81+
o(function() {
82+
Vnode.normalizeChildren([
83+
{data: 1},
84+
undefined,
85+
])
86+
}).throws(TypeError)
87+
})
88+
o("disallows mixed keys, ending with false", function() {
89+
o(function() {
90+
Vnode.normalizeChildren([
91+
{key: 1},
92+
false,
93+
])
94+
}).throws(TypeError)
95+
})
96+
o("disallows mixed keys, starting with false", function() {
97+
o(function() {
98+
Vnode.normalizeChildren([
99+
{data: 1},
100+
false,
101+
])
102+
}).throws(TypeError)
103+
})
104+
o("disallows mixed keys, ending with true", function() {
105+
o(function() {
106+
Vnode.normalizeChildren([
107+
{key: 1},
108+
true,
109+
])
110+
}).throws(TypeError)
111+
})
112+
o("disallows mixed keys, starting with true", function() {
113+
o(function() {
114+
Vnode.normalizeChildren([
115+
{data: 1},
116+
true,
117+
])
118+
}).throws(TypeError)
119+
})
56120
})

render/vnode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Vnode.normalizeChildren = function(input) {
1919
for (var i = 1; i < input.length; i++) {
2020
if ((input[i] != null && input[i].key != null) !== isKeyed) {
2121
throw new TypeError(
22-
isKeyed && (input[i] != null || typeof input[i] === "boolean")
22+
isKeyed && (input[i] == null || typeof input[i] === "boolean")
2323
? "In fragments, vnodes must either all have keys or none have keys. You may wish to consider using an explicit keyed empty fragment, m.fragment({key: ...}), instead of a hole."
2424
: "In fragments, vnodes must either all have keys or none have keys."
2525
)

0 commit comments

Comments
 (0)