File tree 4 files changed +25
-17
lines changed
4 files changed +25
-17
lines changed Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ protected virtual JavaScriptWithSourceMap TransformWithHeader(
243
243
/// <returns>JavaScript</returns>
244
244
public virtual string Transform ( string input , string filename = "unknown" )
245
245
{
246
- EnsureBabelLoaded ( ) ;
246
+ _environment . EnsureBabelLoaded ( ) ;
247
247
try
248
248
{
249
249
var output = _environment . ExecuteWithLargerStackIfRequired < string > (
@@ -272,7 +272,7 @@ public virtual JavaScriptWithSourceMap TransformWithSourceMap(
272
272
string filename = "unknown"
273
273
)
274
274
{
275
- EnsureBabelLoaded ( ) ;
275
+ _environment . EnsureBabelLoaded ( ) ;
276
276
try
277
277
{
278
278
return _environment . ExecuteWithLargerStackIfRequired < JavaScriptWithSourceMap > (
@@ -347,16 +347,5 @@ string filename
347
347
_fileSystem . WriteAsString ( sourceMapPath , result . SourceMap == null ? string . Empty : result . SourceMap . ToJson ( ) ) ;
348
348
return outputPath ;
349
349
}
350
-
351
- /// <summary>
352
- /// Ensures that Babel has been loaded into the JavaScript engine.
353
- /// </summary>
354
- private void EnsureBabelLoaded ( )
355
- {
356
- if ( ! _config . LoadBabel )
357
- {
358
- throw new BabelNotLoadedException ( ) ;
359
- }
360
- }
361
350
}
362
351
}
Original file line number Diff line number Diff line change @@ -91,5 +91,10 @@ public interface IReactEnvironment
91
91
/// Gets the JSX Transformer for this environment.
92
92
/// </summary>
93
93
IBabel Babel { get ; }
94
+
95
+ /// <summary>
96
+ /// Ensures that Babel has been loaded into the JavaScript engine.
97
+ /// </summary>
98
+ void EnsureBabelLoaded ( ) ;
94
99
}
95
100
}
Original file line number Diff line number Diff line change @@ -101,10 +101,6 @@ protected virtual void InitialiseEngine(IJsEngine engine)
101
101
engine . ExecuteResource ( "React.Resources.react-with-addons.js" , thisAssembly ) ;
102
102
engine . Execute ( "React = global.React" ) ;
103
103
}
104
- if ( _config . LoadBabel )
105
- {
106
- engine . ExecuteResource ( "React.node_modules.babel_core.browser.js" , thisAssembly ) ;
107
- }
108
104
109
105
LoadUserScripts ( engine ) ;
110
106
if ( ! _config . LoadReact )
Original file line number Diff line number Diff line change @@ -413,5 +413,23 @@ public virtual IReactSiteConfiguration Configuration
413
413
{
414
414
get { return _config ; }
415
415
}
416
+
417
+ /// <summary>
418
+ /// Ensures that Babel has been loaded into the JavaScript engine.
419
+ /// </summary>
420
+ public void EnsureBabelLoaded ( )
421
+ {
422
+ // If Babel is disabled in the config, don't even try loading it
423
+ if ( ! _config . LoadBabel )
424
+ {
425
+ throw new BabelNotLoadedException ( ) ;
426
+ }
427
+
428
+ var babelLoaded = Engine . Evaluate < bool > ( "typeof global.Babel !== 'undefined'" ) ;
429
+ if ( ! babelLoaded )
430
+ {
431
+ Engine . ExecuteResource ( "React.node_modules.babel_core.browser.js" , typeof ( ReactEnvironment ) . Assembly ) ;
432
+ }
433
+ }
416
434
}
417
435
}
You can’t perform that action at this time.
0 commit comments