@@ -2,7 +2,9 @@ use crate::build::packages;
22use crate :: helpers:: deserialize:: * ;
33use anyhow:: { Result , bail} ;
44use convert_case:: { Case , Casing } ;
5- use serde:: Deserialize ;
5+ use serde:: de:: { Error as DeError , Visitor } ;
6+ use serde:: { Deserialize , Deserializer } ;
7+ use std:: collections:: HashMap ;
68use std:: fs;
79use std:: path:: { Path , PathBuf } ;
810
@@ -222,6 +224,39 @@ pub enum DeprecationWarning {
222224 BscFlags ,
223225}
224226
227+ #[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
228+ pub enum ExperimentalFeature {
229+ LetUnwrap ,
230+ }
231+
232+ impl < ' de > serde:: Deserialize < ' de > for ExperimentalFeature {
233+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
234+ where
235+ D : Deserializer < ' de > ,
236+ {
237+ struct EFVisitor ;
238+ impl < ' de > Visitor < ' de > for EFVisitor {
239+ type Value = ExperimentalFeature ;
240+ fn expecting ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
241+ write ! ( f, "a valid experimental feature id (e.g. LetUnwrap)" )
242+ }
243+ fn visit_str < E > ( self , v : & str ) -> Result < Self :: Value , E >
244+ where
245+ E : DeError ,
246+ {
247+ match v {
248+ "LetUnwrap" => Ok ( ExperimentalFeature :: LetUnwrap ) ,
249+ other => Err ( DeError :: custom ( format ! (
250+ "Unknown experimental feature '{}'. Available features: LetUnwrap" ,
251+ other
252+ ) ) ) ,
253+ }
254+ }
255+ }
256+ deserializer. deserialize_any ( EFVisitor )
257+ }
258+ }
259+
225260/// # rescript.json representation
226261/// This is tricky, there is a lot of ambiguity. This is probably incomplete.
227262#[ derive( Deserialize , Debug , Clone , Default ) ]
@@ -254,6 +289,8 @@ pub struct Config {
254289
255290 pub namespace : Option < NamespaceConfig > ,
256291 pub jsx : Option < JsxSpecs > ,
292+ #[ serde( rename = "experimentalFeatures" ) ]
293+ pub experimental_features : Option < HashMap < ExperimentalFeature , bool > > ,
257294 #[ serde( rename = "gentypeconfig" ) ]
258295 pub gentype_config : Option < GenTypeConfig > ,
259296 // this is a new feature of rewatch, and it's not part of the rescript.json spec
@@ -491,6 +528,25 @@ impl Config {
491528 }
492529 }
493530
531+ pub fn get_experimental_features_args ( & self ) -> Vec < String > {
532+ match & self . experimental_features {
533+ None => vec ! [ ] ,
534+ Some ( map) => map
535+ . iter ( )
536+ . filter_map ( |( k, v) | if * v { Some ( k) } else { None } )
537+ . flat_map ( |feature| {
538+ vec ! [
539+ "-enable-experimental" . to_string( ) ,
540+ match feature {
541+ ExperimentalFeature :: LetUnwrap => "LetUnwrap" ,
542+ }
543+ . to_string( ) ,
544+ ]
545+ } )
546+ . collect ( ) ,
547+ }
548+ }
549+
494550 pub fn get_gentype_arg ( & self ) -> Vec < String > {
495551 match & self . gentype_config {
496552 Some ( _) => vec ! [ "-bs-gentype" . to_string( ) ] ,
0 commit comments