@@ -2,6 +2,7 @@ use std::{collections::BTreeSet, sync::LazyLock};
22
33use anyhow:: { Context , Result } ;
44use regex:: Regex ;
5+ use serde:: Serialize ;
56use turbo_esregex:: EsRegex ;
67use turbo_rcstr:: { RcStr , rcstr} ;
78use turbo_tasks:: { ResolvedVc , Vc } ;
@@ -16,7 +17,7 @@ use turbopack_core::{
1617use turbopack_node:: transforms:: webpack:: WebpackLoaderItem ;
1718
1819use crate :: {
19- next_config:: { NextConfig , ReactCompilerCompilationMode } ,
20+ next_config:: { NextConfig , ReactCompilerCompilationMode , ReactCompilerOptions } ,
2021 next_import_map:: try_get_next_package,
2122 next_shared:: webpack_rules:: {
2223 ManuallyConfiguredBuiltinLoaderIssue , WebpackLoaderBuiltinCondition ,
@@ -145,15 +146,38 @@ pub async fn get_babel_loader_rules(
145146 }
146147
147148 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 ( )
149150 && let Some ( babel_plugin_path) =
150151 resolve_babel_plugin_react_compiler ( next_config, project_path) . await ?
151152 {
152153 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+ } ;
153177 let react_compiler_plugins =
154178 serde_json:: Value :: Array ( vec ! [ serde_json:: Value :: Array ( vec![
155179 serde_json:: Value :: String ( babel_plugin_path. into_owned( ) ) ,
156- serde_json:: to_value( & * react_compiler_options )
180+ serde_json:: to_value( resolved_options )
157181 . expect( "react compiler options JSON serialization should never fail" ) ,
158182 ] ) ] ) ;
159183
0 commit comments