From 0d994df04d6489128d243a2747b010e32ca33fb9 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Fri, 22 Nov 2019 03:46:30 -0800 Subject: [PATCH] LogBox - Add ReferenceError to transform error regex Summary: Adds handling for reference errors so when we throw them in the next diff they're handled as syntax errors. Changelog: [Internal] Reviewed By: cpojer Differential Revision: D18644642 fbshipit-source-id: 2b751578c616c27d5b1ec6255aca56063bfd9d16 --- .../Data/__tests__/parseLogBoxLog-test.js | 46 +++++++++++++++++++ Libraries/LogBox/Data/parseLogBoxLog.js | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js b/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js index 11ee0b991c..889ec9ef79 100644 --- a/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js +++ b/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js @@ -223,6 +223,52 @@ describe('parseLogBoxLog', () => { }); }); + it('parses a reference error', () => { + const error = { + message: ` + + 197 | }); + 198 | +> 199 | export default CrashReactApp; + | ^ + 200 |`, + originalMessage: `TransformError ReferenceError: /path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js: 'import' and 'export' may only appear at the top level (199:0) + + 197 | }); + 198 | +> 199 | export default CrashReactApp; + | ^ + 200 |`, + name: '', + isComponentError: false, + componentStack: '', + stack: [], + id: 0, + isFatal: true, + }; + + expect(parseLogBoxException(error)).toEqual({ + level: 'syntax', + isComponentError: false, + codeFrame: { + fileName: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js', + location: {row: 199, column: 0}, + content: ` 197 | }); + 198 | +> 199 | export default CrashReactApp; + | ^ + 200 |`, + }, + message: { + content: "'import' and 'export' may only appear at the top level", + substitutions: [], + }, + stack: [], + componentStack: [], + category: '/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js-199-0', + }); + }); + it('parses a error log', () => { const error = { id: 0, diff --git a/Libraries/LogBox/Data/parseLogBoxLog.js b/Libraries/LogBox/Data/parseLogBoxLog.js index 095ad59199..6a601759cc 100644 --- a/Libraries/LogBox/Data/parseLogBoxLog.js +++ b/Libraries/LogBox/Data/parseLogBoxLog.js @@ -146,7 +146,7 @@ export function parseLogBoxException( const message = error.originalMessage != null ? error.originalMessage : 'Unknown'; const match = message.match( - /(?:TransformError )?(?:SyntaxError: )(.*): (.*) \((\d+):(\d+)\)\n\n([\s\S]+)/, + /(?:TransformError )?(?:SyntaxError: |ReferenceError: )(.*): (.*) \((\d+):(\d+)\)\n\n([\s\S]+)/, ); if (!match) {