@@ -79,10 +79,14 @@ public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem f
79
79
/// </summary>
80
80
/// <param name="filename">Name of the file to load</param>
81
81
/// <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>
82
86
/// <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 )
84
88
{
85
- return TransformJsxFileWithSourceMap ( filename , false , useHarmony ) . Code ;
89
+ return TransformJsxFileWithSourceMap ( filename , false , useHarmony , stripTypes ) . Code ;
86
90
}
87
91
88
92
/// <summary>
@@ -95,8 +99,17 @@ public virtual string TransformJsxFile(string filename, bool? useHarmony = null)
95
99
/// <c>true</c> to re-transform the file if a cached version with no source map is available
96
100
/// </param>
97
101
/// <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>
98
106
/// <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
+ )
100
113
{
101
114
var cacheKey = string . Format ( JSX_CACHE_KEY , filename ) ;
102
115
@@ -118,7 +131,7 @@ public virtual JavaScriptWithSourceMap TransformJsxFileWithSourceMap(string file
118
131
// 3. Not cached, perform the transformation
119
132
try
120
133
{
121
- output = TransformJsxWithHeader ( filename , contents , hash , useHarmony ) ;
134
+ output = TransformJsxWithHeader ( filename , contents , hash , useHarmony , stripTypes ) ;
122
135
}
123
136
catch ( JsxException ex )
124
137
{
@@ -211,15 +224,25 @@ protected virtual JavaScriptWithSourceMap LoadJsxFromFileCache(string filename,
211
224
/// <param name="contents">Contents of the input file</param>
212
225
/// <param name="hash">Hash of the input. If null, it will be calculated</param>
213
226
/// <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>
214
231
/// <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
+ )
216
239
{
217
240
if ( string . IsNullOrEmpty ( hash ) )
218
241
{
219
242
hash = _fileCacheHash . CalculateHash ( contents ) ;
220
243
}
221
244
var header = GetFileHeader ( hash ) ;
222
- var result = TransformJsxWithSourceMap ( header + contents , useHarmony ) ;
245
+ var result = TransformJsxWithSourceMap ( header + contents , useHarmony , stripTypes ) ;
223
246
result . Hash = hash ;
224
247
if ( result . SourceMap != null )
225
248
{
@@ -240,16 +263,21 @@ protected virtual JavaScriptWithSourceMap TransformJsxWithHeader(string filename
240
263
/// </summary>
241
264
/// <param name="input">JSX</param>
242
265
/// <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>
243
270
/// <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 )
245
272
{
246
273
EnsureJsxTransformerSupported ( ) ;
247
274
try
248
275
{
249
276
var output = _environment . ExecuteWithLargerStackIfRequired < string > (
250
277
"ReactNET_transform" ,
251
278
input ,
252
- useHarmony ?? _config . UseHarmony
279
+ useHarmony ?? _config . UseHarmony ,
280
+ stripTypes ?? _config . StripTypes
253
281
) ;
254
282
return output ;
255
283
}
@@ -265,16 +293,25 @@ public virtual string TransformJsx(string input, bool? useHarmony = null)
265
293
/// </summary>
266
294
/// <param name="input">JSX</param>
267
295
/// <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>
268
300
/// <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
+ )
270
306
{
271
307
EnsureJsxTransformerSupported ( ) ;
272
308
try
273
309
{
274
310
return _environment . ExecuteWithLargerStackIfRequired < JavaScriptWithSourceMap > (
275
311
"ReactNET_transform_sourcemap" ,
276
312
input ,
277
- useHarmony ?? _config . UseHarmony
313
+ useHarmony ?? _config . UseHarmony ,
314
+ stripTypes ?? _config . StripTypes
278
315
) ;
279
316
}
280
317
catch ( Exception ex )
@@ -331,13 +368,21 @@ public virtual string GetSourceMapOutputPath(string path)
331
368
/// </summary>
332
369
/// <param name="filename">Name of the file to load</param>
333
370
/// <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>
334
375
/// <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
+ )
336
381
{
337
382
var outputPath = GetJsxOutputPath ( filename ) ;
338
383
var sourceMapPath = GetSourceMapOutputPath ( filename ) ;
339
384
var contents = _fileSystem . ReadAsString ( filename ) ;
340
- var result = TransformJsxWithHeader ( filename , contents , useHarmony : useHarmony ) ;
385
+ var result = TransformJsxWithHeader ( filename , contents , null , useHarmony , stripTypes ) ;
341
386
_fileSystem . WriteAsString ( outputPath , result . Code ) ;
342
387
_fileSystem . WriteAsString ( sourceMapPath , result . SourceMap == null ? string . Empty : result . SourceMap . ToJson ( ) ) ;
343
388
return outputPath ;
0 commit comments