From f3e82d8bc80a18304ba2552b15ecdd2b60b66f94 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Thu, 28 Sep 2017 17:21:24 -0400 Subject: [PATCH] Improve YellowBox output format --- Libraries/ReactNative/YellowBox.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Libraries/ReactNative/YellowBox.js b/Libraries/ReactNative/YellowBox.js index e36681458d716e..88e786ab0d7d5b 100644 --- a/Libraries/ReactNative/YellowBox.js +++ b/Libraries/ReactNative/YellowBox.js @@ -106,17 +106,22 @@ function sprintf(format, ...args) { return format.replace(/%s/g, match => args[index++]); } -function updateWarningMap(format, ...args): void { +function updateWarningMap(...args): void { if (console.disableYellowBox) { return; } - format = String(format); - const argCount = (format.match(/%s/g) || []).length; - const warning = [ - sprintf(format, ...args.slice(0, argCount)), - ...args.slice(argCount).map(stringifySafe), - ].join(' '); + let warning; + if (typeof args[0] === 'string') { + const [format, ...formatArgs] = args; + const argCount = (format.match(/%s/g) || []).length; + warning = [ + sprintf(format, ...formatArgs.slice(0, argCount).map(stringifySafe)), + ...formatArgs.slice(argCount).map(stringifySafe), + ].join(' '); + } else { + warning = args.map(stringifySafe).join(' '); + } if (warning.startsWith('(ADVICE)')) { return;