11using System . Collections . Generic ;
22using Newtonsoft . Json ;
3+ using Newtonsoft . Json . Serialization ;
34
45namespace React
56{
@@ -10,52 +11,27 @@ namespace React
1011 public class BabelConfig
1112 {
1213 /// <summary>
13- /// Gets or sets whether Babel's "loose mode" is used for all transformers. See
14- /// http://babeljs.io/docs/advanced/loose/ for more information. Only one of
15- /// <see cref="AllLoose"/> or <see cref="Loose"/> can be used at a time.
14+ /// Gets or sets the Babel plugins to use. See http://babeljs.io/docs/plugins/ for a full
15+ /// list of plugins.
1616 /// </summary>
17- public bool AllLoose { get ; set ; }
17+ public ISet < string > Plugins { get ; set ; }
1818
1919 /// <summary>
20- /// Gets or sets the transformers to blacklist
20+ /// Gets or sets the Babel presets to use. See http://babeljs.io/docs/plugins/ for a full
21+ /// list of presets.
2122 /// </summary>
22- public IEnumerable < string > Blacklist { get ; set ; }
23-
24- /// <summary>
25- /// Gets or sets whether Babel should use a reference to babelHelpers instead of placing
26- /// helpers at the top of your code. Meant to be used in conjunction with external
27- /// helpers (http://babeljs.io/docs/advanced/external-helpers/)
28- /// </summary>
29- public bool ExternalHelpers { get ; set ; }
30-
31- /// <summary>
32- /// Gets or sets the transformers to use in Babel's "loose mode". See
33- /// http://babeljs.io/docs/advanced/loose/ for more information. Only one of
34- /// <see cref="AllLoose"/> or <see cref="Loose"/> can be used at a time.
35- /// </summary>
36- public IEnumerable < string > Loose { get ; set ; }
37-
38- /// <summary>
39- /// Gets or sets an transformers to optionally use. See
40- /// http://babeljs.io/docs/advanced/transformers/#optional for a full list of transformers
41- /// </summary>
42- public IEnumerable < string > Optional { get ; set ; }
43-
44- /// <summary>
45- /// Gets or sets the experimental proposal stage (http://babeljs.io/docs/usage/experimental/).
46- /// </summary>
47- public int Stage { get ; set ; }
23+ public ISet < string > Presets { get ; set ; }
4824
4925 /// <summary>
5026 /// Creates a new instance of <see cref="BabelConfig" />.
5127 /// </summary>
5228 public BabelConfig ( )
5329 {
54- // By default, we blacklist the " strict" transform, as it messes with the top-level "this".
55- // This is required since we're not actually using JavaScript modules directly in ReactJS.NET yet.
56- // See https://babeljs.io/docs/faq/#why-is-this-being-remapped-to-undefined-
57- Blacklist = new [ ] { "strict" } ;
58- Stage = 2 ;
30+ // Use es2015-no-commonjs by default so Babel doesn't prepend "use strict" to the start of the
31+ // output. This messes with the top-level "this", as we're not actually using JavaScript modules
32+ // in ReactJS.NET yet.
33+ Presets = new HashSet < string > { "es2015-no-commonjs" , "stage-1" , "react" } ;
34+ Plugins = new HashSet < string > ( ) ;
5935 }
6036
6137 /// <summary>
@@ -64,22 +40,10 @@ public BabelConfig()
6440 /// <returns></returns>
6541 public string Serialize ( )
6642 {
67- var config = new Dictionary < string , object >
68- {
69- { "blacklist" , Blacklist } ,
70- { "externalHelpers" , ExternalHelpers } ,
71- { "optional" , Optional } ,
72- { "stage" , Stage } ,
73- } ;
74- if ( AllLoose )
75- {
76- config . Add ( "loose" , "all" ) ;
77- }
78- else if ( Loose != null )
43+ return JsonConvert . SerializeObject ( this , new JsonSerializerSettings
7944 {
80- config . Add ( "loose" , Loose ) ;
81- }
82- return JsonConvert . SerializeObject ( config ) ;
45+ ContractResolver = new CamelCasePropertyNamesContractResolver ( ) ,
46+ } ) ;
8347 }
8448 }
8549}
0 commit comments