@@ -43,6 +43,10 @@ public class JsxTransformer : IJsxTransformer
4343 /// Hash algorithm for file-based cache
4444 /// </summary>
4545 private readonly IFileCacheHash _fileCacheHash ;
46+ /// <summary>
47+ /// Site-wide configuration
48+ /// </summary>
49+ private readonly IReactSiteConfiguration _config ;
4650
4751 /// <summary>
4852 /// Initializes a new instance of the <see cref="JsxTransformer"/> class.
@@ -51,20 +55,23 @@ public class JsxTransformer : IJsxTransformer
5155 /// <param name="cache">The cache to use for JSX compilation</param>
5256 /// <param name="fileSystem">File system wrapper</param>
5357 /// <param name="fileCacheHash">Hash algorithm for file-based cache</param>
54- public JsxTransformer ( IReactEnvironment environment , ICache cache , IFileSystem fileSystem , IFileCacheHash fileCacheHash )
58+ /// <param name="siteConfig">Site-wide configuration</param>
59+ public JsxTransformer ( IReactEnvironment environment , ICache cache , IFileSystem fileSystem , IFileCacheHash fileCacheHash , IReactSiteConfiguration siteConfig )
5560 {
5661 _environment = environment ;
5762 _cache = cache ;
5863 _fileSystem = fileSystem ;
5964 _fileCacheHash = fileCacheHash ;
65+ _config = siteConfig ;
6066 }
6167
6268 /// <summary>
6369 /// Transforms a JSX file. Results of the JSX to JavaScript transformation are cached.
6470 /// </summary>
6571 /// <param name="filename">Name of the file to load</param>
72+ /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
6673 /// <returns>JavaScript</returns>
67- public string TransformJsxFile ( string filename )
74+ public string TransformJsxFile ( string filename , bool ? useHarmony = null )
6875 {
6976 var fullPath = _fileSystem . MapPath ( filename ) ;
7077
@@ -91,7 +98,7 @@ public string TransformJsxFile(string filename)
9198 }
9299
93100 // 3. Not cached, perform the transformation
94- return TransformJsxWithHeader ( contents , hash ) ;
101+ return TransformJsxWithHeader ( contents , hash , useHarmony ) ;
95102 }
96103 ) ;
97104 }
@@ -102,23 +109,25 @@ public string TransformJsxFile(string filename)
102109 /// </summary>
103110 /// <param name="contents">Contents of the input file</param>
104111 /// <param name="hash">Hash of the input. If null, it will be calculated</param>
112+ /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
105113 /// <returns>JavaScript</returns>
106- private string TransformJsxWithHeader ( string contents , string hash = null )
114+ private string TransformJsxWithHeader ( string contents , string hash = null , bool ? useHarmony = null )
107115 {
108116 if ( string . IsNullOrEmpty ( hash ) )
109117 {
110118 hash = _fileCacheHash . CalculateHash ( contents ) ;
111119 }
112- return GetFileHeader ( hash ) + TransformJsx ( contents ) ;
120+ return GetFileHeader ( hash ) + TransformJsx ( contents , useHarmony ) ;
113121 }
114122
115123 /// <summary>
116124 /// Transforms JSX into regular JavaScript. The result is not cached. Use
117125 /// <see cref="TransformJsxFile"/> if loading from a file since this will cache the result.
118126 /// </summary>
119127 /// <param name="input">JSX</param>
128+ /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
120129 /// <returns>JavaScript</returns>
121- public string TransformJsx ( string input )
130+ public string TransformJsx ( string input , bool ? useHarmony = null )
122131 {
123132 // Just return directly if there's no JSX annotation
124133 if ( ! input . Contains ( "@jsx" ) )
@@ -131,7 +140,8 @@ public string TransformJsx(string input)
131140 {
132141 var output = _environment . ExecuteWithLargerStackIfRequired < string > (
133142 "ReactNET_transform" ,
134- input
143+ input ,
144+ useHarmony . HasValue ? useHarmony . Value : _config . UseHarmony
135145 ) ;
136146 return output ;
137147 }
@@ -177,12 +187,13 @@ public string GetJsxOutputPath(string path)
177187 /// alongside the original file.
178188 /// </summary>
179189 /// <param name="filename">Name of the file to load</param>
190+ /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
180191 /// <returns>File contents</returns>
181- public string TransformAndSaveJsxFile ( string filename )
192+ public string TransformAndSaveJsxFile ( string filename , bool ? useHarmony = null )
182193 {
183194 var outputPath = GetJsxOutputPath ( filename ) ;
184195 var contents = _fileSystem . ReadAsString ( filename ) ;
185- var result = TransformJsxWithHeader ( contents ) ;
196+ var result = TransformJsxWithHeader ( contents , useHarmony : useHarmony ) ;
186197 _fileSystem . WriteAsString ( outputPath , result ) ;
187198 return outputPath ;
188199 }
0 commit comments