1
1
using System . Collections . Generic ;
2
2
using Newtonsoft . Json ;
3
+ using Newtonsoft . Json . Serialization ;
3
4
4
5
namespace React
5
6
{
@@ -10,52 +11,27 @@ namespace React
10
11
public class BabelConfig
11
12
{
12
13
/// <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.
16
16
/// </summary>
17
- public bool AllLoose { get ; set ; }
17
+ public ISet < string > Plugins { get ; set ; }
18
18
19
19
/// <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.
21
22
/// </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 ; }
48
24
49
25
/// <summary>
50
26
/// Creates a new instance of <see cref="BabelConfig" />.
51
27
/// </summary>
52
28
public BabelConfig ( )
53
29
{
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 > ( ) ;
59
35
}
60
36
61
37
/// <summary>
@@ -64,22 +40,10 @@ public BabelConfig()
64
40
/// <returns></returns>
65
41
public string Serialize ( )
66
42
{
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
79
44
{
80
- config . Add ( "loose" , Loose ) ;
81
- }
82
- return JsonConvert . SerializeObject ( config ) ;
45
+ ContractResolver = new CamelCasePropertyNamesContractResolver ( ) ,
46
+ } ) ;
83
47
}
84
48
}
85
49
}
0 commit comments