Skip to content

Commit

Permalink
Add an IIFE test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gaearon committed Mar 30, 2021
1 parent 77a9ef3 commit d2a2045
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,16 @@ describe('ReactFreshBabelPlugin', () => {
'". If you want to override this check, pass {skipEnvCheck: true} as plugin options.',
);
});

it('does not get tripped by IIFEs', () => {
expect(
transform(`
while (item) {
(item => {
useFoo();
})(item);
}
`),
).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ var _c;
$RefreshReg$(_c, "App");
`;

exports[`ReactFreshBabelPlugin does not get tripped by IIFEs 1`] = `
while (item) {
var _s = $RefreshSig$();
_s(_s(item => {
_s();
useFoo();
}, "useFoo{}", true)(item), "useFoo{}", true);
}
`;

exports[`ReactFreshBabelPlugin generates signatures for function declarations calling hooks 1`] = `
var _s = $RefreshSig$();
Expand Down

0 comments on commit d2a2045

Please sign in to comment.