Skip to content

Commit b5537fd

Browse files
author
Dustin Masters
committed
Make Babel 7 the default
Fixes reactjs#798
1 parent 6215ccc commit b5537fd

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

src/React.Core/Babel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Babel(IReactEnvironment environment, ICache cache, IFileSystem fileSystem
7474
_fileSystem = fileSystem;
7575
_fileCacheHash = fileCacheHash;
7676
_config = siteConfig;
77-
_babelConfig = siteConfig.BabelConfig.Serialize(_config.BabelVersion);
77+
_babelConfig = siteConfig.BabelConfig.Serialize(_config.BabelVersion ?? BabelVersions.Babel7);
7878
}
7979

8080
/// <summary>
@@ -250,7 +250,7 @@ protected virtual JavaScriptWithSourceMap TransformWithHeader(
250250
/// <param name="input">JavaScript</param>
251251
/// <param name="filename">Name of the file being transformed</param>
252252
/// <returns>JavaScript</returns>
253-
public virtual string Transform(string input, string filename = "unknown")
253+
public virtual string Transform(string input, string filename = "unknown.jsx")
254254
{
255255
try
256256
{

src/React.Core/IBabel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) Facebook, Inc. and its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
@@ -40,7 +40,7 @@ JavaScriptWithSourceMap TransformFileWithSourceMap(
4040
/// <param name="input">JavaScript</param>
4141
/// <param name="filename">Name of the file being transformed</param>
4242
/// <returns>JavaScript</returns>
43-
string Transform(string input, string filename = "unknown");
43+
string Transform(string input, string filename = "unknown.jsx");
4444

4545
/// <summary>
4646
/// Transforms JavaScript via Babel and also returns a source map to map the compiled

src/React.Core/ReactEnvironment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ private void EnsureBabelLoaded(IJsEngine engine)
480480
#else
481481
var assembly = typeof(ReactEnvironment).GetTypeInfo().Assembly;
482482
#endif
483-
string resourceName = _config.BabelVersion == BabelVersions.Babel7
483+
string resourceName = _config.BabelVersion == BabelVersions.Babel7 || _config.BabelVersion == null
484484
? "React.Core.Resources.babel.generated.min.js"
485-
: _config.BabelVersion == BabelVersions.Babel6 || _config.BabelVersion == null
485+
: _config.BabelVersion == BabelVersions.Babel6
486486
? "React.Core.Resources.babel-legacy.generated.min.js"
487487
: throw new ReactConfigurationException("BabelVersion was not null, but did not contain a valid value.");
488488

tests/React.Tests.Integration/ServerRenderTests.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,12 @@ public void RendersPrecompiledScript(bool withPrecompilation)
8080
}
8181
}
8282

83-
[Theory]
84-
[InlineData(null)]
85-
[InlineData("babel-6")]
86-
public void BabelTransformsJSX(string babelVersion)
83+
[Fact]
84+
public void Babel6TransformsJSX()
8785
{
8886
ReactEnvironment.Current.Configuration
8987
.SetLoadBabel(true)
90-
.SetBabelVersion(babelVersion);
88+
.SetBabelVersion(BabelVersions.Babel6);
9189

9290
Assert.Equal(@"React.createElement(
9391
""div"",
@@ -96,6 +94,18 @@ public void BabelTransformsJSX(string babelVersion)
9694
);", ReactEnvironment.Current.Babel.Transform("<div>Hello</div>"));
9795
}
9896

97+
[Theory]
98+
[InlineData(null)]
99+
[InlineData("babel-7")]
100+
public void BabelTransformsJSX(string babelVersion)
101+
{
102+
ReactEnvironment.Current.Configuration
103+
.SetLoadBabel(true)
104+
.SetBabelVersion(babelVersion);
105+
106+
Assert.Equal(@"React.createElement(""div"", null, ""Hello"");", ReactEnvironment.Current.Babel.Transform("<div>Hello</div>"));
107+
}
108+
99109
[Fact]
100110
public void BabelTransformsTypescript()
101111
{

tests/React.Tests/Core/BabelTransformerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) Facebook, Inc. and its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
@@ -53,7 +53,7 @@ public void ShouldTransformJsx()
5353
"ReactNET_transform",
5454
"<div>Hello World</div>",
5555
It.IsAny<string>(),
56-
"unknown" // file name
56+
"unknown.jsx" // file name
5757
));
5858
}
5959

@@ -64,7 +64,7 @@ public void ShouldWrapExceptionsInJsxExeption()
6464
"ReactNET_transform",
6565
"<div>Hello World</div>",
6666
It.IsAny<string>(),
67-
"unknown" // file name
67+
"unknown.jsx" // file name
6868
)).Throws(new Exception("Something broke..."));
6969

7070
const string input = "<div>Hello World</div>";

0 commit comments

Comments
 (0)