@@ -79,10 +79,14 @@ public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem f
7979 /// </summary>
8080 /// <param name="filename">Name of the file to load</param>
8181 /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
82+ /// <param name="stripTypes">
83+ /// Whether Flow types should be stripped out. Defaults to the value set in the site
84+ /// configuration.
85+ /// </param>
8286 /// <returns>JavaScript</returns>
83- public virtual string TransformJsxFile ( string filename , bool ? useHarmony = null )
87+ public virtual string TransformJsxFile ( string filename , bool ? useHarmony = null , bool ? stripTypes = null )
8488 {
85- return TransformJsxFileWithSourceMap ( filename , false , useHarmony ) . Code ;
89+ return TransformJsxFileWithSourceMap ( filename , false , useHarmony , stripTypes ) . Code ;
8690 }
8791
8892 /// <summary>
@@ -95,8 +99,17 @@ public virtual string TransformJsxFile(string filename, bool? useHarmony = null)
9599 /// <c>true</c> to re-transform the file if a cached version with no source map is available
96100 /// </param>
97101 /// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
102+ /// <param name="stripTypes">
103+ /// Whether Flow types should be stripped out. Defaults to the value set in the site
104+ /// configuration.
105+ /// </param>
98106 /// <returns>JavaScript and source map</returns>
99- public virtual JavaScriptWithSourceMap TransformJsxFileWithSourceMap ( string filename , bool forceGenerateSourceMap = false , bool ? useHarmony = null )
107+ public virtual JavaScriptWithSourceMap TransformJsxFileWithSourceMap (
108+ string filename ,
109+ bool forceGenerateSourceMap = false ,
110+ bool ? useHarmony = null ,
111+ bool ? stripTypes = null
112+ )
100113 {
101114 var cacheKey = string . Format ( JSX_CACHE_KEY , filename ) ;
102115
@@ -118,7 +131,7 @@ public virtual JavaScriptWithSourceMap TransformJsxFileWithSourceMap(string file
118131 // 3. Not cached, perform the transformation
119132 try
120133 {
121- output = TransformJsxWithHeader ( filename , contents , hash , useHarmony ) ;
134+ output = TransformJsxWithHeader ( filename , contents , hash , useHarmony , stripTypes ) ;
122135 }
123136 catch ( JsxException ex )
124137 {
@@ -211,15 +224,25 @@ protected virtual JavaScriptWithSourceMap LoadJsxFromFileCache(string filename,
211224 /// <param name="contents">Contents of the input file</param>
212225 /// <param name="hash">Hash of the input. If null, it will be calculated</param>
213226 /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
227+ /// <param name="stripTypes">
228+ /// Whether Flow types should be stripped out. Defaults to the value set in the site
229+ /// configuration.
230+ /// </param>
214231 /// <returns>JavaScript</returns>
215- protected virtual JavaScriptWithSourceMap TransformJsxWithHeader ( string filename , string contents , string hash = null , bool ? useHarmony = null )
232+ protected virtual JavaScriptWithSourceMap TransformJsxWithHeader (
233+ string filename ,
234+ string contents ,
235+ string hash = null ,
236+ bool ? useHarmony = null ,
237+ bool ? stripTypes = null
238+ )
216239 {
217240 if ( string . IsNullOrEmpty ( hash ) )
218241 {
219242 hash = _fileCacheHash . CalculateHash ( contents ) ;
220243 }
221244 var header = GetFileHeader ( hash ) ;
222- var result = TransformJsxWithSourceMap ( header + contents , useHarmony ) ;
245+ var result = TransformJsxWithSourceMap ( header + contents , useHarmony , stripTypes ) ;
223246 result . Hash = hash ;
224247 if ( result . SourceMap != null )
225248 {
@@ -240,16 +263,21 @@ protected virtual JavaScriptWithSourceMap TransformJsxWithHeader(string filename
240263 /// </summary>
241264 /// <param name="input">JSX</param>
242265 /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
266+ /// <param name="stripTypes">
267+ /// Whether Flow types should be stripped out. Defaults to the value set in the site
268+ /// configuration.
269+ /// </param>
243270 /// <returns>JavaScript</returns>
244- public virtual string TransformJsx ( string input , bool ? useHarmony = null )
271+ public virtual string TransformJsx ( string input , bool ? useHarmony = null , bool ? stripTypes = null )
245272 {
246273 EnsureJsxTransformerSupported ( ) ;
247274 try
248275 {
249276 var output = _environment . ExecuteWithLargerStackIfRequired < string > (
250277 "ReactNET_transform" ,
251278 input ,
252- useHarmony ?? _config . UseHarmony
279+ useHarmony ?? _config . UseHarmony ,
280+ stripTypes ?? _config . StripTypes
253281 ) ;
254282 return output ;
255283 }
@@ -265,16 +293,25 @@ public virtual string TransformJsx(string input, bool? useHarmony = null)
265293 /// </summary>
266294 /// <param name="input">JSX</param>
267295 /// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
296+ /// <param name="stripTypes">
297+ /// Whether Flow types should be stripped out. Defaults to the value set in the site
298+ /// configuration.
299+ /// </param>
268300 /// <returns>JavaScript and source map</returns>
269- public virtual JavaScriptWithSourceMap TransformJsxWithSourceMap ( string input , bool ? useHarmony )
301+ public virtual JavaScriptWithSourceMap TransformJsxWithSourceMap (
302+ string input ,
303+ bool ? useHarmony = null ,
304+ bool ? stripTypes = null
305+ )
270306 {
271307 EnsureJsxTransformerSupported ( ) ;
272308 try
273309 {
274310 return _environment . ExecuteWithLargerStackIfRequired < JavaScriptWithSourceMap > (
275311 "ReactNET_transform_sourcemap" ,
276312 input ,
277- useHarmony ?? _config . UseHarmony
313+ useHarmony ?? _config . UseHarmony ,
314+ stripTypes ?? _config . StripTypes
278315 ) ;
279316 }
280317 catch ( Exception ex )
@@ -331,13 +368,21 @@ public virtual string GetSourceMapOutputPath(string path)
331368 /// </summary>
332369 /// <param name="filename">Name of the file to load</param>
333370 /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
371+ /// <param name="stripTypes">
372+ /// Whether Flow types should be stripped out. Defaults to the value set in the site
373+ /// configuration.
374+ /// </param>
334375 /// <returns>File contents</returns>
335- public virtual string TransformAndSaveJsxFile ( string filename , bool ? useHarmony = null )
376+ public virtual string TransformAndSaveJsxFile (
377+ string filename ,
378+ bool ? useHarmony = null ,
379+ bool ? stripTypes = null
380+ )
336381 {
337382 var outputPath = GetJsxOutputPath ( filename ) ;
338383 var sourceMapPath = GetSourceMapOutputPath ( filename ) ;
339384 var contents = _fileSystem . ReadAsString ( filename ) ;
340- var result = TransformJsxWithHeader ( filename , contents , useHarmony : useHarmony ) ;
385+ var result = TransformJsxWithHeader ( filename , contents , null , useHarmony , stripTypes ) ;
341386 _fileSystem . WriteAsString ( outputPath , result . Code ) ;
342387 _fileSystem . WriteAsString ( sourceMapPath , result . SourceMap == null ? string . Empty : result . SourceMap . ToJson ( ) ) ;
343388 return outputPath ;
0 commit comments