Skip to content

Commit

Permalink
Should not show __webpack_exports__ when exporting anonymous arrow fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
Hannes Bornö committed Dec 5, 2022
1 parent 0bd3422 commit e0811af
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/react-dev-overlay/src/middleware.ts
Expand Up @@ -216,7 +216,9 @@ export async function createOriginalStackFrame({
sourcePosition.name ||
// default is not a valid identifier in JS so webpack uses a custom variable when it's an unnamed default export
// Resolve it back to `default` for the method name if the source position didn't have the method.
frame.methodName?.replace('__WEBPACK_DEFAULT_EXPORT__', 'default'),
frame.methodName
?.replace('__WEBPACK_DEFAULT_EXPORT__', 'default')
?.replace('__webpack_exports__', 'exports'),
arguments: [],
}

Expand Down
23 changes: 23 additions & 0 deletions test/development/acceptance-app/ReactRefreshLogBox.test.ts
Expand Up @@ -1062,4 +1062,27 @@ describe('ReactRefreshLogBox app', () => {

await cleanup()
})

test('Should not show __webpack_exports__ when exporting anonymous arrow function', async () => {
const { session, cleanup } = await sandbox(next)

await session.patch(
'index.js',
`
export default () => {
if (typeof window !== 'undefined') {
throw new Error('test')
}
return null
}
`
)

expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchSnapshot()

await cleanup()
})
})
@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ReactRefreshLogBox app Should not show __webpack_exports__ when exporting anonymous arrow function 1`] = `
"index.js (4:16) @ exports.default
2 | export default () => {
3 | if (typeof window !== 'undefined') {
> 4 | throw new Error('test')
| ^
5 | }
6 |
7 | return null"
`;
exports[`ReactRefreshLogBox app boundaries 1`] = `
"FunctionDefault.js (1:50) @ FunctionDefault
Expand Down

0 comments on commit e0811af

Please sign in to comment.