GeezerVison is showing github.com — Register more node types that are used later as JSXIdentifiers (#19514) · react/react@a5fed98
File treeExpand file treeCollapse file tree Open diff view settings packages/react-refresh/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-refresh/src/ReactFreshBabelPlugin.js -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -140,9 +140,6 @@ export default function(babel, opts = {}) { | 140 | 140 | } else if (calleeType === 'MemberExpression') { | 141 | 141 | // Could be something like React.forwardRef(...) | 142 | 142 | // Pass through. | 143 | | - } else { | 144 | | - // More complicated call. | 145 | | - return false; | 146 | 143 | } | 147 | 144 | break; | 148 | 145 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js +13-4Lines changed: 13 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -261,15 +261,18 @@ describe('ReactFreshBabelPlugin', () => { | 261 | 261 | Store.subscribe(); | 262 | 262 |
| 263 | 263 | 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\`\`; | 265 | 268 |
| 266 | 269 | let Alias1 = A; | 267 | 270 | let Alias2 = A.Foo; | 268 | 271 | const Dict = {}; | 269 | 272 |
| 270 | 273 | function Foo() { | 271 | 274 | return ( | 272 | | - <div><A /><B /><Alias1 /><Alias2 /><Header /><Dict.X /></div> | | 275 | + <div><A /><B /><StyledFactory1 /><StyledFactory2 /><StyledFactory3 /><Alias1 /><Alias2 /><Header /><Dict.X /></div> | 273 | 276 | ); | 274 | 277 | } | 275 | 278 |
| @@ -294,7 +297,10 @@ describe('ReactFreshBabelPlugin', () => { | 294 | 297 | Store.subscribe(); | 295 | 298 |
| 296 | 299 | 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\`\`; | 298 | 304 |
| 299 | 305 | let Alias1 = A; | 300 | 306 | let Alias2 = A.Foo; | @@ -304,6 +310,9 @@ describe('ReactFreshBabelPlugin', () => { | 304 | 310 | return [ | 305 | 311 | React.createElement(A), | 306 | 312 | React.createElement(B), | | 313 | + React.createElement(StyledFactory1), | | 314 | + React.createElement(StyledFactory2), | | 315 | + React.createElement(StyledFactory3), | 307 | 316 | React.createElement(Alias1), | 308 | 317 | React.createElement(Alias2), | 309 | 318 | jsx(Header), | @@ -408,7 +417,7 @@ describe('ReactFreshBabelPlugin', () => { | 408 | 417 | transform( | 409 | 418 | ` | 410 | 419 | import {useFancyState} from './hooks'; | 411 | | - | | 420 | +
| 412 | 421 | export default function App() { | 413 | 422 | const bar = useFancyState(); | 414 | 423 | return <h1>{bar}</h1>; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-refresh/src/__tests__/__snapshots__/ReactFreshBabelPlugin-test.js.snap +44-18Lines changed: 44 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -347,29 +347,42 @@ import Store from './Store'; | 347 | 347 | Store.subscribe(); | 348 | 348 | const Header = styled.div\`color: red\`; | 349 | 349 | _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\`\`; | 351 | 361 | let Alias1 = A; | 352 | 362 | let Alias2 = A.Foo; | 353 | 363 | const Dict = {}; | 354 | 364 |
| 355 | 365 | 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>; | 357 | 367 | } | 358 | 368 |
| 359 | | -_c2 = Foo; | | 369 | +_c5 = Foo; | 360 | 370 | const B = hoc(A); // This is currently registered as a false positive: | 361 | 371 |
| 362 | | -_c3 = B; | | 372 | +_c6 = B; | 363 | 373 | const NotAComponent = wow(A); // We could avoid it but it also doesn't hurt. | 364 | 374 |
| 365 | | -_c4 = NotAComponent; | | 375 | +_c7 = NotAComponent; | 366 | 376 |
| 367 | | -var _c, _c2, _c3, _c4; | | 377 | +var _c, _c2, _c3, _c4, _c5, _c6, _c7; | 368 | 378 |
| 369 | 379 | $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"); | 373 | 386 | `; | 374 | 387 |
| 375 | 388 | exports[`ReactFreshBabelPlugin registers identifiers used in React.createElement at definition site 1`] = ` | @@ -378,30 +391,43 @@ import Store from './Store'; | 378 | 391 | Store.subscribe(); | 379 | 392 | const Header = styled.div\`color: red\`; | 380 | 393 | _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\`\`; | 382 | 405 | let Alias1 = A; | 383 | 406 | let Alias2 = A.Foo; | 384 | 407 | const Dict = {}; | 385 | 408 |
| 386 | 409 | 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)]; | 388 | 411 | } | 389 | 412 |
| 390 | | -_c2 = Foo; | | 413 | +_c5 = Foo; | 391 | 414 | React.createContext(Store); | 392 | 415 | const B = hoc(A); // This is currently registered as a false positive: | 393 | 416 |
| 394 | | -_c3 = B; | | 417 | +_c6 = B; | 395 | 418 | const NotAComponent = wow(A); // We could avoid it but it also doesn't hurt. | 396 | 419 |
| 397 | | -_c4 = NotAComponent; | | 420 | +_c7 = NotAComponent; | 398 | 421 |
| 399 | | -var _c, _c2, _c3, _c4; | | 422 | +var _c, _c2, _c3, _c4, _c5, _c6, _c7; | 400 | 423 |
| 401 | 424 | $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"); | 405 | 431 | `; | 406 | 432 |
| 407 | 433 | exports[`ReactFreshBabelPlugin registers likely HOCs with inline functions 1`] = ` | |
|