Skip to content

Commit a5fed98

Browse files
authored
Register more node types that are used later as JSXIdentifiers (#19514)
1 parent 50893db commit a5fed98

File tree

3 files changed

+57
-25
lines changed

3 files changed

+57
-25
lines changed

packages/react-refresh/src/ReactFreshBabelPlugin.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ export default function(babel, opts = {}) {
140140
} else if (calleeType === 'MemberExpression') {
141141
// Could be something like React.forwardRef(...)
142142
// Pass through.
143-
} else {
144-
// More complicated call.
145-
return false;
146143
}
147144
break;
148145
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,18 @@ describe('ReactFreshBabelPlugin', () => {
261261
Store.subscribe();
262262
263263
const Header = styled.div\`color: red\`
264-
const Factory = funny.factory\`\`;
264+
const StyledFactory1 = styled('div')\`color: hotpink\`
265+
const StyledFactory2 = styled('div')({ color: 'hotpink' })
266+
const StyledFactory3 = styled(A)({ color: 'hotpink' })
267+
const FunnyFactory = funny.factory\`\`;
265268
266269
let Alias1 = A;
267270
let Alias2 = A.Foo;
268271
const Dict = {};
269272
270273
function Foo() {
271274
return (
272-
<div><A /><B /><Alias1 /><Alias2 /><Header /><Dict.X /></div>
275+
<div><A /><B /><StyledFactory1 /><StyledFactory2 /><StyledFactory3 /><Alias1 /><Alias2 /><Header /><Dict.X /></div>
273276
);
274277
}
275278
@@ -294,7 +297,10 @@ describe('ReactFreshBabelPlugin', () => {
294297
Store.subscribe();
295298
296299
const Header = styled.div\`color: red\`
297-
const Factory = funny.factory\`\`;
300+
const StyledFactory1 = styled('div')\`color: hotpink\`
301+
const StyledFactory2 = styled('div')({ color: 'hotpink' })
302+
const StyledFactory3 = styled(A)({ color: 'hotpink' })
303+
const FunnyFactory = funny.factory\`\`;
298304
299305
let Alias1 = A;
300306
let Alias2 = A.Foo;
@@ -304,6 +310,9 @@ describe('ReactFreshBabelPlugin', () => {
304310
return [
305311
React.createElement(A),
306312
React.createElement(B),
313+
React.createElement(StyledFactory1),
314+
React.createElement(StyledFactory2),
315+
React.createElement(StyledFactory3),
307316
React.createElement(Alias1),
308317
React.createElement(Alias2),
309318
jsx(Header),
@@ -408,7 +417,7 @@ describe('ReactFreshBabelPlugin', () => {
408417
transform(
409418
`
410419
import {useFancyState} from './hooks';
411-
420+
412421
export default function App() {
413422
const bar = useFancyState();
414423
return <h1>{bar}</h1>;

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

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -347,29 +347,42 @@ import Store from './Store';
347347
Store.subscribe();
348348
const Header = styled.div\`color: red\`;
349349
_c = Header;
350-
const Factory = funny.factory\`\`;
350+
const StyledFactory1 = styled('div')\`color: hotpink\`;
351+
_c2 = StyledFactory1;
352+
const StyledFactory2 = styled('div')({
353+
color: 'hotpink'
354+
});
355+
_c3 = StyledFactory2;
356+
const StyledFactory3 = styled(A)({
357+
color: 'hotpink'
358+
});
359+
_c4 = StyledFactory3;
360+
const FunnyFactory = funny.factory\`\`;
351361
let Alias1 = A;
352362
let Alias2 = A.Foo;
353363
const Dict = {};
354364
355365
function Foo() {
356-
return <div><A /><B /><Alias1 /><Alias2 /><Header /><Dict.X /></div>;
366+
return <div><A /><B /><StyledFactory1 /><StyledFactory2 /><StyledFactory3 /><Alias1 /><Alias2 /><Header /><Dict.X /></div>;
357367
}
358368
359-
_c2 = Foo;
369+
_c5 = Foo;
360370
const B = hoc(A); // This is currently registered as a false positive:
361371
362-
_c3 = B;
372+
_c6 = B;
363373
const NotAComponent = wow(A); // We could avoid it but it also doesn't hurt.
364374
365-
_c4 = NotAComponent;
375+
_c7 = NotAComponent;
366376
367-
var _c, _c2, _c3, _c4;
377+
var _c, _c2, _c3, _c4, _c5, _c6, _c7;
368378
369379
$RefreshReg$(_c, "Header");
370-
$RefreshReg$(_c2, "Foo");
371-
$RefreshReg$(_c3, "B");
372-
$RefreshReg$(_c4, "NotAComponent");
380+
$RefreshReg$(_c2, "StyledFactory1");
381+
$RefreshReg$(_c3, "StyledFactory2");
382+
$RefreshReg$(_c4, "StyledFactory3");
383+
$RefreshReg$(_c5, "Foo");
384+
$RefreshReg$(_c6, "B");
385+
$RefreshReg$(_c7, "NotAComponent");
373386
`;
374387

375388
exports[`ReactFreshBabelPlugin registers identifiers used in React.createElement at definition site 1`] = `
@@ -378,30 +391,43 @@ import Store from './Store';
378391
Store.subscribe();
379392
const Header = styled.div\`color: red\`;
380393
_c = Header;
381-
const Factory = funny.factory\`\`;
394+
const StyledFactory1 = styled('div')\`color: hotpink\`;
395+
_c2 = StyledFactory1;
396+
const StyledFactory2 = styled('div')({
397+
color: 'hotpink'
398+
});
399+
_c3 = StyledFactory2;
400+
const StyledFactory3 = styled(A)({
401+
color: 'hotpink'
402+
});
403+
_c4 = StyledFactory3;
404+
const FunnyFactory = funny.factory\`\`;
382405
let Alias1 = A;
383406
let Alias2 = A.Foo;
384407
const Dict = {};
385408
386409
function Foo() {
387-
return [React.createElement(A), React.createElement(B), React.createElement(Alias1), React.createElement(Alias2), jsx(Header), React.createElement(Dict.X)];
410+
return [React.createElement(A), React.createElement(B), React.createElement(StyledFactory1), React.createElement(StyledFactory2), React.createElement(StyledFactory3), React.createElement(Alias1), React.createElement(Alias2), jsx(Header), React.createElement(Dict.X)];
388411
}
389412
390-
_c2 = Foo;
413+
_c5 = Foo;
391414
React.createContext(Store);
392415
const B = hoc(A); // This is currently registered as a false positive:
393416
394-
_c3 = B;
417+
_c6 = B;
395418
const NotAComponent = wow(A); // We could avoid it but it also doesn't hurt.
396419
397-
_c4 = NotAComponent;
420+
_c7 = NotAComponent;
398421
399-
var _c, _c2, _c3, _c4;
422+
var _c, _c2, _c3, _c4, _c5, _c6, _c7;
400423
401424
$RefreshReg$(_c, "Header");
402-
$RefreshReg$(_c2, "Foo");
403-
$RefreshReg$(_c3, "B");
404-
$RefreshReg$(_c4, "NotAComponent");
425+
$RefreshReg$(_c2, "StyledFactory1");
426+
$RefreshReg$(_c3, "StyledFactory2");
427+
$RefreshReg$(_c4, "StyledFactory3");
428+
$RefreshReg$(_c5, "Foo");
429+
$RefreshReg$(_c6, "B");
430+
$RefreshReg$(_c7, "NotAComponent");
405431
`;
406432

407433
exports[`ReactFreshBabelPlugin registers likely HOCs with inline functions 1`] = `

0 commit comments

Comments
 (0)