Skip to content

Commit 1b2646a

Browse files
link-alexgaearon
authored andcommitted
Fix warning without stack for ie9 (#13620)
* Fix warning without stack for ie9 Where console methods like log, error etc. don't have 'apply' method. Because of the lot of tests already expect that exactly console['method'] will be called - had to reapply references for console.error method #13610 * pass parameters explicitly to avoid using .apply which is not supported for console methods in ie9 * Minor tweaks
1 parent dde0645 commit 1b2646a

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

packages/shared/warningWithoutStack.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,54 @@ if (__DEV__) {
2222
'message argument',
2323
);
2424
}
25+
if (args.length > 8) {
26+
// Check before the condition to catch violations early.
27+
throw new Error(
28+
'warningWithoutStack() currently supports at most 8 arguments.',
29+
);
30+
}
2531
if (condition) {
2632
return;
2733
}
2834
if (typeof console !== 'undefined') {
29-
const stringArgs = args.map(item => '' + item);
30-
console.error('Warning: ' + format, ...stringArgs);
35+
const [a, b, c, d, e, f, g, h] = args.map(item => '' + item);
36+
const message = 'Warning: ' + format;
37+
38+
// We intentionally don't use spread (or .apply) because it breaks IE11:
39+
// https://github.com/facebook/react/issues/13610
40+
switch (args.length) {
41+
case 0:
42+
console.error(message);
43+
break;
44+
case 1:
45+
console.error(message, a);
46+
break;
47+
case 2:
48+
console.error(message, a, b);
49+
break;
50+
case 3:
51+
console.error(message, a, b, c);
52+
break;
53+
case 4:
54+
console.error(message, a, b, c, d);
55+
break;
56+
case 5:
57+
console.error(message, a, b, c, d, e);
58+
break;
59+
case 6:
60+
console.error(message, a, b, c, d, e, f);
61+
break;
62+
case 7:
63+
console.error(message, a, b, c, d, e, f, g);
64+
break;
65+
case 8:
66+
console.error(message, a, b, c, d, e, f, g, h);
67+
break;
68+
default:
69+
throw new Error(
70+
'warningWithoutStack() currently supports at most 8 arguments.',
71+
);
72+
}
3173
}
3274
try {
3375
// --- Welcome to debugging React ---

0 commit comments

Comments
 (0)