@@ -2,6 +2,7 @@ use std::{collections::BTreeSet, sync::LazyLock};
2
2
3
3
use anyhow:: { Context , Result } ;
4
4
use regex:: Regex ;
5
+ use serde:: Serialize ;
5
6
use turbo_esregex:: EsRegex ;
6
7
use turbo_rcstr:: { RcStr , rcstr} ;
7
8
use turbo_tasks:: { ResolvedVc , Vc } ;
@@ -16,7 +17,7 @@ use turbopack_core::{
16
17
use turbopack_node:: transforms:: webpack:: WebpackLoaderItem ;
17
18
18
19
use crate :: {
19
- next_config:: { NextConfig , ReactCompilerCompilationMode } ,
20
+ next_config:: { NextConfig , ReactCompilerCompilationMode , ReactCompilerOptions } ,
20
21
next_import_map:: try_get_next_package,
21
22
next_shared:: webpack_rules:: {
22
23
ManuallyConfiguredBuiltinLoaderIssue , WebpackLoaderBuiltinCondition ,
@@ -145,15 +146,38 @@ pub async fn get_babel_loader_rules(
145
146
}
146
147
147
148
let mut loader_conditions = Vec :: new ( ) ;
148
- if let Some ( react_compiler_options) = & * react_compiler_options
149
+ if let Some ( react_compiler_options) = react_compiler_options. as_ref ( )
149
150
&& let Some ( babel_plugin_path) =
150
151
resolve_babel_plugin_react_compiler ( next_config, project_path) . await ?
151
152
{
152
153
let react_compiler_options = react_compiler_options. await ?;
154
+
155
+ // we don't want to accept user-supplied `environment` options, but we do want to pass
156
+ // `enableNameAnonymousFunctions` down to the babel plugin based on dev/prod.
157
+ #[ derive( Serialize ) ]
158
+ #[ serde( rename_all = "camelCase" ) ]
159
+ struct EnvironmentOptions {
160
+ enable_name_anonymous_functions : bool ,
161
+ }
162
+
163
+ #[ derive( Serialize ) ]
164
+ struct ResolvedOptions < ' a > {
165
+ #[ serde( flatten) ]
166
+ base : & ' a ReactCompilerOptions ,
167
+ environment : EnvironmentOptions ,
168
+ }
169
+
170
+ let resolved_options = ResolvedOptions {
171
+ base : & react_compiler_options,
172
+ environment : EnvironmentOptions {
173
+ enable_name_anonymous_functions : builtin_conditions
174
+ . contains ( & WebpackLoaderBuiltinCondition :: Development ) ,
175
+ } ,
176
+ } ;
153
177
let react_compiler_plugins =
154
178
serde_json:: Value :: Array ( vec ! [ serde_json:: Value :: Array ( vec![
155
179
serde_json:: Value :: String ( babel_plugin_path. into_owned( ) ) ,
156
- serde_json:: to_value( & * react_compiler_options )
180
+ serde_json:: to_value( resolved_options )
157
181
. expect( "react compiler options JSON serialization should never fail" ) ,
158
182
] ) ] ) ;
159
183
0 commit comments