mirror of
https://github.com/hanzoai/swc.git
synced 2026-10-30 19:42:53 +00:00
**Description:**
The Babel React Compiler lets consumers configure `environment` options,
but SWC's `reactCompiler` config previously exposed none of them — the
compiler's `EnvironmentConfig` was always left at its defaults,
unreachable from `.swcrc`.
This adds a curated `environment` object to the `reactCompiler` config
that mirrors Babel's `reactCompiler.environment` shape. It currently
exposes a single field, `enableFunctionOutlining`, wired through to
`EnvironmentConfig::enable_function_outlining`:
```json
{
"jsc": {
"transform": {
"reactCompiler": {
"environment": { "enableFunctionOutlining": false }
}
}
}
}
```
The object is a deliberate allowlist rather than a passthrough of the
full `EnvironmentConfig`: unset fields leave the compiler defaults
untouched, so a partial object overrides only what it names, and the
public surface stays small and intentional. New fields can be added one
at a time as they are wired and tested.
`EnvironmentConfig` is re-exported from `swc_ecma_react_compiler` so the
config layer can name the type (it was already reachable via the public
`PluginOptions.environment`).
Tests:
- unit test covering `environment.enableFunctionOutlining`
deserialization;
- fixture `environment-function-outlining-disabled`: with outlining off,
a
closure that captures a local binding stays inline;
- fixture `environment-function-outlining-enabled`: with outlining on
(default),
a closure that captures nothing is outlined into a top-level helper.
**BREAKING CHANGE:**
None. `environment` is a new optional field; existing configs are
unaffected.
**Related issue (if exists):**
N/A
---------
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
@swc/types
Typings for @swc/core APIs. This is a separate package because SWC is used by various tools but not all of them want to depend on @swc/core.
This package is very cheap, so feel free to depend on this.