Commit 47157c6
committed
[compiler] Add support for commonjs (#34589)
We previously always generated import statements for any modules that
had to be required, notably the `import {c} from
'react/compiler-runtime'` for the memo cache function. However, this
obviously doesn't work when the source is using commonjs. Now we check
the sourceType of the module and generate require() statements if the
source type is 'script'.
I initially explored using
https://babeljs.io/docs/babel-helper-module-imports, but the API design
was unfortunately not flexible enough for our use-case. Specifically,
our pipeline is as follows:
* Compile individual functions. Generate candidate imports,
pre-allocating the local names for those imports.
* If the file is compiled successfully, actually add the imports to the
program.
Ie we need to pre-allocate identifier names for the imports before we
add them to the program — but that isn't supported by
babel-helper-module-imports. So instead we generate our own require()
calls if the sourceType is script.
DiffTrain build for [8ad773b](8ad773b)1 parent c6a7213 commit 47157c6
File tree
26 files changed
+113
-91
lines changed- compiled-rn
- facebook-fbsource/xplat/js
- RKJSModules/vendor/react
- react-dom/cjs
- react-test-renderer/cjs
- react/cjs
- react-native-github/Libraries/Renderer
- implementations
- tools/eslint-plugin-react-hooks
- cjs
26 files changed
+113
-91
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
408 | 408 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
29920 | 29920 | | |
29921 | 29921 | | |
29922 | 29922 | | |
29923 | | - | |
| 29923 | + | |
29924 | 29924 | | |
29925 | 29925 | | |
29926 | 29926 | | |
29927 | | - | |
| 29927 | + | |
29928 | 29928 | | |
29929 | 29929 | | |
29930 | 29930 | | |
| |||
29961 | 29961 | | |
29962 | 29962 | | |
29963 | 29963 | | |
29964 | | - | |
| 29964 | + | |
29965 | 29965 | | |
29966 | 29966 | | |
29967 | | - | |
| 29967 | + | |
29968 | 29968 | | |
29969 | 29969 | | |
29970 | 29970 | | |
| |||
30113 | 30113 | | |
30114 | 30114 | | |
30115 | 30115 | | |
30116 | | - | |
| 30116 | + | |
30117 | 30117 | | |
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
17529 | 17529 | | |
17530 | 17530 | | |
17531 | 17531 | | |
17532 | | - | |
| 17532 | + | |
17533 | 17533 | | |
17534 | 17534 | | |
17535 | 17535 | | |
17536 | 17536 | | |
17537 | 17537 | | |
17538 | 17538 | | |
17539 | | - | |
| 17539 | + | |
17540 | 17540 | | |
17541 | 17541 | | |
17542 | 17542 | | |
| |||
17558 | 17558 | | |
17559 | 17559 | | |
17560 | 17560 | | |
17561 | | - | |
| 17561 | + | |
17562 | 17562 | | |
17563 | 17563 | | |
17564 | | - | |
| 17564 | + | |
17565 | 17565 | | |
17566 | 17566 | | |
17567 | 17567 | | |
| |||
17668 | 17668 | | |
17669 | 17669 | | |
17670 | 17670 | | |
17671 | | - | |
| 17671 | + | |
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
19622 | 19622 | | |
19623 | 19623 | | |
19624 | 19624 | | |
19625 | | - | |
| 19625 | + | |
19626 | 19626 | | |
19627 | 19627 | | |
19628 | 19628 | | |
19629 | 19629 | | |
19630 | 19630 | | |
19631 | 19631 | | |
19632 | | - | |
| 19632 | + | |
19633 | 19633 | | |
19634 | 19634 | | |
19635 | 19635 | | |
| |||
19651 | 19651 | | |
19652 | 19652 | | |
19653 | 19653 | | |
19654 | | - | |
| 19654 | + | |
19655 | 19655 | | |
19656 | 19656 | | |
19657 | | - | |
| 19657 | + | |
19658 | 19658 | | |
19659 | 19659 | | |
19660 | 19660 | | |
| |||
19777 | 19777 | | |
19778 | 19778 | | |
19779 | 19779 | | |
19780 | | - | |
| 19780 | + | |
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
29976 | 29976 | | |
29977 | 29977 | | |
29978 | 29978 | | |
29979 | | - | |
| 29979 | + | |
29980 | 29980 | | |
29981 | 29981 | | |
29982 | 29982 | | |
29983 | | - | |
| 29983 | + | |
29984 | 29984 | | |
29985 | 29985 | | |
29986 | 29986 | | |
| |||
30017 | 30017 | | |
30018 | 30018 | | |
30019 | 30019 | | |
30020 | | - | |
| 30020 | + | |
30021 | 30021 | | |
30022 | 30022 | | |
30023 | | - | |
| 30023 | + | |
30024 | 30024 | | |
30025 | 30025 | | |
30026 | 30026 | | |
| |||
30485 | 30485 | | |
30486 | 30486 | | |
30487 | 30487 | | |
30488 | | - | |
| 30488 | + | |
30489 | 30489 | | |
30490 | 30490 | | |
30491 | 30491 | | |
| |||
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
17540 | 17540 | | |
17541 | 17541 | | |
17542 | 17542 | | |
17543 | | - | |
| 17543 | + | |
17544 | 17544 | | |
17545 | 17545 | | |
17546 | 17546 | | |
17547 | 17547 | | |
17548 | 17548 | | |
17549 | 17549 | | |
17550 | | - | |
| 17550 | + | |
17551 | 17551 | | |
17552 | 17552 | | |
17553 | 17553 | | |
| |||
17569 | 17569 | | |
17570 | 17570 | | |
17571 | 17571 | | |
17572 | | - | |
| 17572 | + | |
17573 | 17573 | | |
17574 | 17574 | | |
17575 | | - | |
| 17575 | + | |
17576 | 17576 | | |
17577 | 17577 | | |
17578 | 17578 | | |
| |||
17832 | 17832 | | |
17833 | 17833 | | |
17834 | 17834 | | |
17835 | | - | |
| 17835 | + | |
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
19637 | 19637 | | |
19638 | 19638 | | |
19639 | 19639 | | |
19640 | | - | |
| 19640 | + | |
19641 | 19641 | | |
19642 | 19642 | | |
19643 | 19643 | | |
19644 | 19644 | | |
19645 | 19645 | | |
19646 | 19646 | | |
19647 | | - | |
| 19647 | + | |
19648 | 19648 | | |
19649 | 19649 | | |
19650 | 19650 | | |
| |||
19666 | 19666 | | |
19667 | 19667 | | |
19668 | 19668 | | |
19669 | | - | |
| 19669 | + | |
19670 | 19670 | | |
19671 | 19671 | | |
19672 | | - | |
| 19672 | + | |
19673 | 19673 | | |
19674 | 19674 | | |
19675 | 19675 | | |
| |||
19945 | 19945 | | |
19946 | 19946 | | |
19947 | 19947 | | |
19948 | | - | |
| 19948 | + | |
19949 | 19949 | | |
19950 | 19950 | | |
19951 | 19951 | | |
| |||
0 commit comments