Skip to content

Commit

Permalink
pass parameters explicitely to avoid using .apply
Browse files Browse the repository at this point in the history
which is not supported for console methods in ie9
  • Loading branch information
link-alex committed Sep 11, 2018
1 parent f785a3d commit 92ec2a3
Showing 1 changed file with 54 additions and 9 deletions.
63 changes: 54 additions & 9 deletions packages/shared/warningWithoutStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
let warningWithoutStack = () => {};

if (__DEV__) {
const consoleError = Function.prototype.bind.call(console.error, console);

warningWithoutStack = function(condition, format, ...args) {
if (format === undefined) {
throw new Error(
Expand All @@ -28,15 +26,62 @@ if (__DEV__) {
return;
}
if (typeof console !== 'undefined') {
const stringArgs = args.map(item => '' + item);
const originalConsoleError = console.error;
const arr = args.map(item => '' + item);
const arrLength = arr.length;

if (typeof console.error.apply === 'undefined') {
console.error = consoleError;
if (arrLength === 0) {
console.error('Warning: ' + format);
} else if (arrLength === 1) {
console.error('Warning: ' + format, arr[0]);
} else if (arrLength === 2) {
console.error('Warning: ' + format, arr[0], arr[1]);
} else if (arrLength === 3) {
console.error('Warning: ' + format, arr[0], arr[1], arr[2]);
} else if (arrLength === 4) {
console.error('Warning: ' + format, arr[0], arr[1], arr[2], arr[3]);
} else if (arrLength === 5) {
console.error(
'Warning: ' + format,
arr[0],
arr[1],
arr[2],
arr[3],
arr[4],
);
} else if (arrLength === 6) {
console.error(
'Warning: ' + format,
arr[0],
arr[1],
arr[2],
arr[3],
arr[4],
arr[5],
);
} else if (arrLength === 7) {
console.error(
'Warning: ' + format,
arr[0],
arr[1],
arr[2],
arr[3],
arr[4],
arr[5],
arr[6],
);
} else if (arrLength === 8) {
console.error(
'Warning: ' + format,
arr[0],
arr[1],
arr[2],
arr[3],
arr[4],
arr[5],
arr[6],
arr[7],
);
}

console.error('Warning: ' + format, ...stringArgs);
console.error = originalConsoleError;
}
try {
// --- Welcome to debugging React ---
Expand Down

0 comments on commit 92ec2a3

Please sign in to comment.