From 28a3b25c3104e69836b73baefb4a91bac009dcf4 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Mon, 11 Nov 2019 07:38:24 -0800 Subject: [PATCH] LogBox - Display code frame column number correctly Summary: Code frame columns are returned 0 based but displayed in editors 1 based, this diff bumps the column we display by one to match. Changelog: [Internal] Reviewed By: cpojer Differential Revision: D18426163 fbshipit-source-id: 2c6aefb6fe7ce161cd768b6748b7739d486ed438 --- Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js | 4 +++- Libraries/LogBox/UI/LogBoxInspectorStackFrame.js | 5 +++-- .../__snapshots__/LogBoxInspectorCodeFrame-test.js.snap | 2 +- .../__snapshots__/LogBoxInspectorStackFrame-test.js.snap | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js b/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js index a23ee4f0eaf..18a675e94e0 100644 --- a/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js +++ b/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js @@ -62,7 +62,9 @@ function LogBoxInspectorCodeFrame(props: Props): React.Node { }}> {getFileName()} ({codeFrame.location.row}: - {codeFrame.location.column}) + {codeFrame.location.column + + 1 /* Code frame columns are zero indexed */} + ) diff --git a/Libraries/LogBox/UI/LogBoxInspectorStackFrame.js b/Libraries/LogBox/UI/LogBoxInspectorStackFrame.js index c592a3fb9e9..0c4c198cc8c 100644 --- a/Libraries/LogBox/UI/LogBoxInspectorStackFrame.js +++ b/Libraries/LogBox/UI/LogBoxInspectorStackFrame.js @@ -65,11 +65,12 @@ function formatFrameLocation(frame: StackFrame): string { location = location + ':' + lineNumber; - if (column == null) { + if (column == null || isNaN(parseInt(column, 10))) { return location; } - return location + ':' + column; + // Stack frame columns are zero indexed but editors start at one. + return location + ':' + (parseInt(column, 10) + 1); } const styles = StyleSheet.create({ diff --git a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap index 76f4a80910b..600c95b2480 100644 --- a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap +++ b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap @@ -109,7 +109,7 @@ exports[`LogBoxInspectorCodeFrame should render a code frame 1`] = ` ( 199 : - 0 + 1 ) diff --git a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorStackFrame-test.js.snap b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorStackFrame-test.js.snap index 8d930471317..d1cb91e3bd6 100644 --- a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorStackFrame-test.js.snap +++ b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorStackFrame-test.js.snap @@ -52,7 +52,7 @@ exports[`LogBoxInspectorStackFrame should render collapsed stack frame with dimm ] } > - app.js:1:1 + app.js:1:2 `; @@ -105,7 +105,7 @@ exports[`LogBoxInspectorStackFrame should render stack frame 1`] = ` ] } > - app.js:1:1 + app.js:1:2 `;