Skip to content

Commit d2a2045

Browse files
committed
Add an IIFE test
This is not a case that is important for Fast Refresh, but we shouldn't change the code semantics. This case shows the transform isn't quite correct. It's wrapping the call at the wrong place.
1 parent 77a9ef3 commit d2a2045

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,4 +524,16 @@ describe('ReactFreshBabelPlugin', () => {
524524
'". If you want to override this check, pass {skipEnvCheck: true} as plugin options.',
525525
);
526526
});
527+
528+
it('does not get tripped by IIFEs', () => {
529+
expect(
530+
transform(`
531+
while (item) {
532+
(item => {
533+
useFoo();
534+
})(item);
535+
}
536+
`),
537+
).toMatchSnapshot();
538+
});
527539
});

packages/react-refresh/src/__tests__/__snapshots__/ReactFreshBabelPlugin-test.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ var _c;
8686
$RefreshReg$(_c, "App");
8787
`;
8888

89+
exports[`ReactFreshBabelPlugin does not get tripped by IIFEs 1`] = `
90+
while (item) {
91+
var _s = $RefreshSig$();
92+
93+
_s(_s(item => {
94+
_s();
95+
96+
useFoo();
97+
}, "useFoo{}", true)(item), "useFoo{}", true);
98+
}
99+
`;
100+
89101
exports[`ReactFreshBabelPlugin generates signatures for function declarations calling hooks 1`] = `
90102
var _s = $RefreshSig$();
91103

0 commit comments

Comments
 (0)