@@ -4,7 +4,9 @@ use crate::helpers::deserialize::*;
44use crate :: project_context:: ProjectContext ;
55use anyhow:: { Result , bail} ;
66use convert_case:: { Case , Casing } ;
7- use serde:: Deserialize ;
7+ use serde:: de:: { Error as DeError , Visitor } ;
8+ use serde:: { Deserialize , Deserializer } ;
9+ use std:: collections:: HashMap ;
810use std:: fs;
911use std:: path:: { MAIN_SEPARATOR , Path , PathBuf } ;
1012
@@ -224,6 +226,39 @@ pub enum DeprecationWarning {
224226 BscFlags ,
225227}
226228
229+ #[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
230+ pub enum ExperimentalFeature {
231+ LetUnwrap ,
232+ }
233+
234+ impl < ' de > serde:: Deserialize < ' de > for ExperimentalFeature {
235+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
236+ where
237+ D : Deserializer < ' de > ,
238+ {
239+ struct EFVisitor ;
240+ impl < ' de > Visitor < ' de > for EFVisitor {
241+ type Value = ExperimentalFeature ;
242+ fn expecting ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
243+ write ! ( f, "a valid experimental feature id (e.g. LetUnwrap)" )
244+ }
245+ fn visit_str < E > ( self , v : & str ) -> Result < Self :: Value , E >
246+ where
247+ E : DeError ,
248+ {
249+ match v {
250+ "LetUnwrap" => Ok ( ExperimentalFeature :: LetUnwrap ) ,
251+ other => Err ( DeError :: custom ( format ! (
252+ "Unknown experimental feature '{}'. Available features: LetUnwrap" ,
253+ other
254+ ) ) ) ,
255+ }
256+ }
257+ }
258+ deserializer. deserialize_any ( EFVisitor )
259+ }
260+ }
261+
227262/// # rescript.json representation
228263/// This is tricky, there is a lot of ambiguity. This is probably incomplete.
229264#[ derive( Deserialize , Debug , Clone , Default ) ]
@@ -256,6 +291,8 @@ pub struct Config {
256291
257292 pub namespace : Option < NamespaceConfig > ,
258293 pub jsx : Option < JsxSpecs > ,
294+ #[ serde( rename = "experimentalFeatures" ) ]
295+ pub experimental_features : Option < HashMap < ExperimentalFeature , bool > > ,
259296 #[ serde( rename = "gentypeconfig" ) ]
260297 pub gentype_config : Option < GenTypeConfig > ,
261298 // this is a new feature of rewatch, and it's not part of the rescript.json spec
@@ -498,6 +535,25 @@ impl Config {
498535 }
499536 }
500537
538+ pub fn get_experimental_features_args ( & self ) -> Vec < String > {
539+ match & self . experimental_features {
540+ None => vec ! [ ] ,
541+ Some ( map) => map
542+ . iter ( )
543+ . filter_map ( |( k, v) | if * v { Some ( k) } else { None } )
544+ . flat_map ( |feature| {
545+ vec ! [
546+ "-enable-experimental" . to_string( ) ,
547+ match feature {
548+ ExperimentalFeature :: LetUnwrap => "LetUnwrap" ,
549+ }
550+ . to_string( ) ,
551+ ]
552+ } )
553+ . collect ( ) ,
554+ }
555+ }
556+
501557 pub fn get_gentype_arg ( & self ) -> Vec < String > {
502558 match & self . gentype_config {
503559 Some ( _) => vec ! [ "-bs-gentype" . to_string( ) ] ,
0 commit comments