Skip to content

Commit 03fda05

Browse files
authored
[DevTools] Fix display of stack frames with anonymous sources (facebook#34237)
1 parent 0bc71e6 commit 03fda05

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

packages/react-devtools-shared/src/backend/utils/parseStackTrace.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ function parseStackTraceFromChromeStack(
5252
if (filename === '<anonymous>') {
5353
filename = '';
5454
}
55-
const line = +(parsed[3] || parsed[6]);
56-
const col = +(parsed[4] || parsed[7]);
55+
const line = +(parsed[3] || parsed[6] || 0);
56+
const col = +(parsed[4] || parsed[7] || 0);
5757
parsedFrames.push([name, filename, line, col, 0, 0, isAsync]);
5858
}
5959
return parsedFrames;
@@ -235,6 +235,7 @@ function collectStackTrace(
235235
// at name (filename:0:0)
236236
// at filename:0:0
237237
// at async filename:0:0
238+
// at Array.map (<anonymous>)
238239
const chromeFrameRegExp =
239240
/^ *at (?:(.+) \((?:(.+):(\d+):(\d+)|\<anonymous\>)\)|(?:async )?(.+):(\d+):(\d+)|\<anonymous\>)$/;
240241

packages/react-devtools-shared/src/devtools/views/Components/StackTraceView.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,18 @@ export function CallSiteView({
6363
return (
6464
<div className={styles.CallSite}>
6565
{functionName || virtualFunctionName}
66-
{' @ '}
67-
<span
68-
className={linkIsEnabled ? styles.Link : null}
69-
onClick={viewSource}
70-
title={url + ':' + line}>
71-
{formatLocationForDisplay(url, line, column)}
72-
</span>
66+
{url !== '' && (
67+
<>
68+
{' @ '}
69+
<span
70+
className={linkIsEnabled ? styles.Link : null}
71+
onClick={viewSource}
72+
title={url + ':' + line}>
73+
{formatLocationForDisplay(url, line, column)}
74+
</span>
75+
</>
76+
)}
77+
7378
<ElementBadges environmentName={environmentName} />
7479
</div>
7580
);

packages/react-devtools-shared/src/devtools/views/Components/formatLocationForDisplay.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ export default function formatLocationForDisplay(
4040
}
4141
}
4242

43+
if (line === 0) {
44+
return nameOnly;
45+
}
46+
4347
return `${nameOnly}:${line}`;
4448
}

0 commit comments

Comments
 (0)