react/compiler/packages
Joseph Savona 8ad773b1f3
[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.
2025-09-24 11:17:42 -07:00
..
babel-plugin-react-compiler [compiler] Add support for commonjs (#34589) 2025-09-24 11:17:42 -07:00
eslint-plugin-react-compiler [compiler] Export PluginOptions as a type that can be used in input positions (#34550) 2025-09-22 18:28:19 +02:00
make-read-only-util [compiler] Add missing copyrights (#33004) 2025-04-23 22:04:44 -04:00
react-compiler-healthcheck [compiler] Export PluginOptions as a type that can be used in input positions (#34550) 2025-09-22 18:28:19 +02:00
react-compiler-runtime [compiler] Add missing copyrights (#33004) 2025-04-23 22:04:44 -04:00
react-forgive [forgive][ez] Tweak logging (#33011) 2025-04-24 13:30:16 -04:00
react-mcp-server [compiler] Export PluginOptions as a type that can be used in input positions (#34550) 2025-09-22 18:28:19 +02:00
snap [compiler] Add support for commonjs (#34589) 2025-09-24 11:17:42 -07:00