diff --git a/Libraries/LogBox/Data/__tests__/LogBoxLog-test.js b/Libraries/LogBox/Data/__tests__/LogBoxLog-test.js index 12d72cd41e5..189d27e7730 100644 --- a/Libraries/LogBox/Data/__tests__/LogBoxLog-test.js +++ b/Libraries/LogBox/Data/__tests__/LogBoxLog-test.js @@ -26,7 +26,7 @@ function getLogBoxLog() { [{component: 'LogBoxLog', location: 'LogBoxLog.js:1'}], { fileName: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js', - location: '(199:0)', + location: {row: 199, column: 0}, content: '', }, ); @@ -70,7 +70,7 @@ describe('LogBoxLog', () => { ]); expect(log.codeFrame).toEqual({ fileName: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js', - location: '(199:0)', + location: {row: 199, column: 0}, content: '', }); }); diff --git a/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js b/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js index dd297b8213c..8de7037b571 100644 --- a/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js +++ b/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js @@ -178,7 +178,7 @@ describe('parseLogBoxLog', () => { level: 'syntax', codeFrame: { fileName: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js', - location: '(199:0)', + location: {row: 199, column: 0}, content: ` 197 | }); 198 | > 199 | export default CrashReactApp; @@ -190,7 +190,7 @@ describe('parseLogBoxLog', () => { substitutions: [], }, stack: [], - category: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js (199:0)', + category: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js-199-0', }); }); diff --git a/Libraries/LogBox/Data/parseLogBoxLog.js b/Libraries/LogBox/Data/parseLogBoxLog.js index d9f07c2051e..d417e05b64d 100644 --- a/Libraries/LogBox/Data/parseLogBoxLog.js +++ b/Libraries/LogBox/Data/parseLogBoxLog.js @@ -19,7 +19,10 @@ import type {Stack} from './LogBoxSymbolication'; export type Category = string; export type CodeFrame = $ReadOnly<{| content: string, - location: string, + location: { + row: number, + column: number, + }, fileName: string, |}>; export type Message = $ReadOnly<{| @@ -146,7 +149,7 @@ export function parseLogBoxException( const message = error.originalMessage != null ? error.originalMessage : 'Unknown'; const match = message.match( - /(?:TransformError )?(?:SyntaxError: )(.*): (.*) (.*)\n\n([\s\S]+)/, + /(?:TransformError )?(?:SyntaxError: )(.*): (.*) \((\d+):(\d+)\)\n\n([\s\S]+)/, ); if (!match) { @@ -161,20 +164,23 @@ export function parseLogBoxException( }; } - const [fileName, content, location, codeFrame] = match.slice(1); + const [fileName, content, row, column, codeFrame] = match.slice(1); return { level: 'syntax', stack: [], codeFrame: { fileName, - location, + location: { + row: parseInt(row, 10), + column: parseInt(column, 10), + }, content: codeFrame, }, message: { content, substitutions: [], }, - category: `${fileName} ${location}`, + category: `${fileName}-${row}-${column}`, }; } diff --git a/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js b/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js index cfb9c1b44df..a23ee4f0eaf 100644 --- a/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js +++ b/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow * @format */ @@ -17,6 +17,9 @@ import Text from '../../Text/Text'; import View from '../../Components/View/View'; import * as LogBoxStyle from './LogBoxStyle'; import type {CodeFrame} from '../Data/parseLogBoxLog'; +import LogBoxButton from './LogBoxButton'; +import openFileInEditor from '../../Core/Devtools/openFileInEditor'; +import stripAnsi from 'strip-ansi'; type Props = $ReadOnly<{| codeFrame: ?CodeFrame, @@ -38,30 +41,55 @@ function LogBoxInspectorCodeFrame(props: Props): React.Node { } return ( - - - - {codeFrame.content} - + + + Location + + + + + {stripAnsi(codeFrame.content)} + + + { + openFileInEditor(codeFrame.fileName, codeFrame.location?.row ?? 0); + }}> + + {getFileName()} ({codeFrame.location.row}: + {codeFrame.location.column}) + + - - {getFileName()} {codeFrame.location} - ); } -const metaStyles = StyleSheet.create({ +const styles = StyleSheet.create({ section: { - marginTop: 30, - marginBottom: 20, + marginTop: 20, + marginBottom: 10, }, box: { backgroundColor: LogBoxStyle.getBackgroundColor(), marginLeft: 10, marginRight: 10, + marginTop: 5, borderRadius: 3, + }, + frame: { padding: 10, + borderBottomColor: LogBoxStyle.getTextColor(0.1), + borderBottomWidth: 1, + }, + button: { + paddingTop: 10, + paddingBottom: 10, }, heading: { alignItems: 'center', @@ -70,6 +98,14 @@ const metaStyles = StyleSheet.create({ marginBottom: 10, }, headingText: { + color: LogBoxStyle.getTextColor(1), + flex: 1, + fontSize: 20, + fontWeight: '600', + includeFontPadding: false, + lineHeight: 20, + }, + content: { color: LogBoxStyle.getTextColor(1), flex: 1, fontSize: 12, @@ -83,27 +119,9 @@ const metaStyles = StyleSheet.create({ flex: 1, fontSize: 12, includeFontPadding: false, - lineHeight: 20, + lineHeight: 16, fontFamily: Platform.select({android: 'monospace', ios: 'Menlo'}), }, - body: { - paddingLeft: 25, - paddingRight: 25, - paddingBottom: 100, - flexDirection: 'row', - justifyContent: 'space-between', - }, - bodyItem: { - flex: 0, - }, - bodyText: { - color: LogBoxStyle.getTextColor(1), - fontSize: 14, - includeFontPadding: false, - lineHeight: 20, - flex: 0, - flexGrow: 0, - }, }); export default LogBoxInspectorCodeFrame; diff --git a/Libraries/LogBox/UI/__tests__/LogBoxContainer-test.js b/Libraries/LogBox/UI/__tests__/LogBoxContainer-test.js index f70ba9e2667..7eeead80044 100644 --- a/Libraries/LogBox/UI/__tests__/LogBoxContainer-test.js +++ b/Libraries/LogBox/UI/__tests__/LogBoxContainer-test.js @@ -304,7 +304,7 @@ describe('LogBoxContainer', () => { { fileName: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js', - location: '(199:0)', + location: {row: 199, column: 0}, content: ` 197 | }); 198 | > 199 | export default CrashReactApp; @@ -324,7 +324,7 @@ describe('LogBoxContainer', () => { { fileName: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js', - location: '(199:0)', + location: {row: 199, column: 0}, content: ` 197 | }); 198 | > 199 | export default CrashReactApp; @@ -361,7 +361,7 @@ describe('LogBoxContainer', () => { { fileName: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js', - location: '(199:0)', + location: {row: 199, column: 0}, content: ` 197 | }); 198 | > 199 | export default CrashReactApp; diff --git a/Libraries/LogBox/UI/__tests__/LogBoxInspectorCodeFrame-test.js b/Libraries/LogBox/UI/__tests__/LogBoxInspectorCodeFrame-test.js index eca23e47cd3..7228553951f 100644 --- a/Libraries/LogBox/UI/__tests__/LogBoxInspectorCodeFrame-test.js +++ b/Libraries/LogBox/UI/__tests__/LogBoxInspectorCodeFrame-test.js @@ -29,7 +29,7 @@ describe('LogBoxInspectorCodeFrame', () => { 199 | export default CrashReactApp; diff --git a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxContainer-test.js.snap b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxContainer-test.js.snap index b901f398ee4..d47d1a24a0d 100644 --- a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxContainer-test.js.snap +++ b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxContainer-test.js.snap @@ -298,7 +298,10 @@ exports[`LogBoxContainer should render most recent syntax error 1`] = ` | ^ 200 |", "fileName": "/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js", - "location": "(199:0)", + "location": Object { + "column": 0, + "row": 199, + }, }, "componentStack": Array [], "count": 1, @@ -323,7 +326,10 @@ exports[`LogBoxContainer should render most recent syntax error 1`] = ` | ^ 200 |", "fileName": "/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js", - "location": "(199:0)", + "location": Object { + "column": 0, + "row": 199, + }, }, "componentStack": Array [], "count": 1, @@ -378,7 +384,10 @@ exports[`LogBoxContainer should render syntax error even when disabled 1`] = ` | ^ 200 |", "fileName": "/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js", - "location": "(199:0)", + "location": Object { + "column": 0, + "row": 199, + }, }, "componentStack": Array [], "count": 1, diff --git a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap index 38b0561339e..76f4a80910b 100644 --- a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap +++ b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap @@ -4,11 +4,36 @@ exports[`LogBoxInspectorCodeFrame should render a code frame 1`] = ` + + + Location + + - - + - 197 | }); + + 197 | }); 198 | > 199 | export default CrashReactApp; | ^ 200 | - - - - + + + - CrashReactApp.js - - (199:0) - + onPress={[Function]} + style={ + Object { + "paddingBottom": 10, + "paddingTop": 10, + } + } + > + + CrashReactApp.js + ( + 199 + : + 0 + ) + + + `;