Skip to content

Commit adaf5eb

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
Fix component stacks for tsx, ts, and jsx files (facebook#43370)
Summary: Pull Request resolved: facebook#43370 Component stacks with files ending in .ts, .tsx, or .jsx were skipped in LogBox reporting. This diff fixes the regex. Changelog: [General][Fixed] - Support .tsx, .ts, and .jsx in component stacks Reviewed By: yungsters Differential Revision: D54638526 fbshipit-source-id: a5271daaa7b687e8e075be3f94ab9b9c03f79b66
1 parent 2d547a3 commit adaf5eb

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,54 @@ Please follow the instructions at: fburl.com/rn-remote-assets`,
12871287
});
12881288
});
12891289

1290+
it('detects a component stack for ts, tsx, jsx, and js files', () => {
1291+
expect(
1292+
parseLogBoxLog([
1293+
'Some kind of message\n in MyTSComponent (at MyTSXComponent.ts:1)\n in MyTSXComponent (at MyTSCComponent.tsx:1)\n in MyJSXComponent (at MyJSXComponent.jsx:1)\n in MyJSComponent (at MyJSComponent.js:1)',
1294+
]),
1295+
).toEqual({
1296+
componentStack: [
1297+
{
1298+
content: 'MyTSComponent',
1299+
fileName: 'MyTSXComponent.ts',
1300+
location: {
1301+
column: -1,
1302+
row: 1,
1303+
},
1304+
},
1305+
{
1306+
content: 'MyTSXComponent',
1307+
fileName: 'MyTSCComponent.tsx',
1308+
location: {
1309+
column: -1,
1310+
row: 1,
1311+
},
1312+
},
1313+
{
1314+
content: 'MyJSXComponent',
1315+
fileName: 'MyJSXComponent.jsx',
1316+
location: {
1317+
column: -1,
1318+
row: 1,
1319+
},
1320+
},
1321+
{
1322+
content: 'MyJSComponent',
1323+
fileName: 'MyJSComponent.js',
1324+
location: {
1325+
column: -1,
1326+
row: 1,
1327+
},
1328+
},
1329+
],
1330+
category: 'Some kind of message',
1331+
message: {
1332+
content: 'Some kind of message',
1333+
substitutions: [],
1334+
},
1335+
});
1336+
});
1337+
12901338
it('detects a component stack in the first argument (JSC)', () => {
12911339
expect(
12921340
parseLogBoxLog([

packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function parseComponentStack(message: string): ComponentStack {
192192
if (!s) {
193193
return null;
194194
}
195-
const match = s.match(/(.*) \(at (.*\.js):([\d]+)\)/);
195+
const match = s.match(/(.*) \(at (.*\.(?:js|jsx|ts|tsx)):([\d]+)\)/);
196196
if (match) {
197197
let [content, fileName, row] = match.slice(1);
198198
return {

0 commit comments

Comments
 (0)