Commit 69ac1d7
committed
[compiler] Add support for commonjs (facebook#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](facebook@8ad773b)1 parent 88489cf commit 69ac1d7
File tree
26 files changed
+1553
-1555
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
+1553
-1555
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: 186 additions & 189 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 9 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 | | |
| |||
4995 | 4995 | | |
4996 | 4996 | | |
4997 | 4997 | | |
4998 | | - | |
| 4998 | + | |
4999 | 4999 | | |
5000 | 5000 | | |
5001 | 5001 | | |
| |||
5848 | 5848 | | |
5849 | 5849 | | |
5850 | 5850 | | |
5851 | | - | |
| 5851 | + | |
5852 | 5852 | | |
5853 | 5853 | | |
5854 | 5854 | | |
| |||
11539 | 11539 | | |
11540 | 11540 | | |
11541 | 11541 | | |
11542 | | - | |
| 11542 | + | |
11543 | 11543 | | |
11544 | 11544 | | |
11545 | 11545 | | |
| |||
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 | + | |
0 commit comments