feat(react-compiler): expose reactCompiler.environment.enableFunctionOutlining#12030
feat(react-compiler): expose reactCompiler.environment.enableFunctionOutlining#12030imjordanxd wants to merge 2 commits into
reactCompiler.environment.enableFunctionOutlining#12030Conversation
Add a curated `environment` object to the reactCompiler .swcrc config that currently exposes a single field, `enableFunctionOutlining`, wired through to the compiler's EnvironmentConfig. Unset fields leave compiler defaults intact. Re-export EnvironmentConfig from swc_ecma_react_compiler so the config layer can name the type. Tests: - unit test for parsing environment.enableFunctionOutlining - fixture -disabled: a closure capturing a local stays inline (correct) - fixture -enabled: a non-capturing closure is outlined to a top-level helper Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
reactCompiler.environment.enableFunctionOutlining
reactCompiler.environment.enableFunctionOutliningreactCompiler.environment.enableFunctionOutlining
Merging this PR will not alter performance
Comparing Footnotes
|
magic-akari
left a comment
There was a problem hiding this comment.
-
Please use identical input examples for the enabled and disabled fixtures, changing only
enableFunctionOutlining. The current inputs differ, so they cannot serve as a meaningful comparison.
I tested this locally by reversing theenableFunctionOutliningvalues, and both tests still passed without any output changes. -
The JavaScript configuration exposes only
enableFunctionOutlining, while the Rust API now publicly re-exports the entirereact_compiler_hir::environment_config::EnvironmentConfig. Could you explain why the broader Rust API exposure is necessary?
Respond to review feedback on the enableFunctionOutlining exposure: - Make the enabled/disabled function-outlining fixtures use an identical input so they differ only by the flag, and produce genuinely different output (inline callback vs. outlined top-level helper). The previous inputs differed, so they were not a meaningful comparison. - Stop publicly re-exporting the upstream `react_compiler_hir::environment_config::EnvironmentConfig`; instead the config layer applies overrides via `&mut PluginOptions`, so only the curated field is exposed. - Expose `environment.enableFunctionOutlining` in the `@swc/types` Node API so the typed surface matches the Rust `.swcrc` config. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks for the review @magic-akari — you raised some good points! 1. Identical fixture inputs You were right — the two fixtures used different inputs, so they never formed a real comparison. Both
On the "flipping the values changed nothing" observation — that's on me twice over: the old inputs were a poor demonstrator, and I hadn't documented that these fixtures only run under 2. Rust API surface Agreed — re-exporting the whole Your question here also made me check the Node side, and I found Pushed in |
Description:
The Babel React Compiler lets consumers configure
environmentoptions, but SWC'sreactCompilerconfig previously exposed none of them — the compiler'sEnvironmentConfigwas always left at its defaults, unreachable from.swcrc.This adds a curated
environmentobject to thereactCompilerconfig that mirrors Babel'sreactCompiler.environmentshape. It currently exposes a single field,enableFunctionOutlining, wired through toEnvironmentConfig::enable_function_outlining:{ "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.EnvironmentConfigis re-exported fromswc_ecma_react_compilerso the config layer can name the type (it was already reachable via the publicPluginOptions.environment).Tests:
environment.enableFunctionOutliningdeserialization;environment-function-outlining-disabled: with outlining off, aclosure that captures a local binding stays inline;
environment-function-outlining-enabled: with outlining on (default),a closure that captures nothing is outlined into a top-level helper.
BREAKING CHANGE:
None.
environmentis a new optional field; existing configs are unaffected.Related issue (if exists):
N/A