Skip to content

Commit d68db4e

Browse files
committed
Tabs and usage of UseHarmony
1 parent 42b6779 commit d68db4e

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

src/React.Tests/Core/JsxTransformerTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public void ShouldTransformJsxIfAnnotationPresent()
6262
_environment.Verify(x => x.ExecuteWithLargerStackIfRequired<string>(
6363
"ReactNET_transform",
6464
"/** @jsx React.DOM */ <div>Hello World</div>",
65-
false
66-
));
65+
false
66+
));
6767
}
6868

6969
[Test]
@@ -72,8 +72,8 @@ public void ShouldWrapExceptionsInJsxExeption()
7272
_environment.Setup(x => x.ExecuteWithLargerStackIfRequired<string>(
7373
"ReactNET_transform",
7474
"/** @jsx React.DOM */ <div>Hello World</div>",
75-
false
76-
)).Throws(new Exception("Something broke..."));
75+
false
76+
)).Throws(new Exception("Something broke..."));
7777

7878
const string input = "/** @jsx React.DOM */ <div>Hello World</div>";
7979
Assert.Throws<JsxException>(() => _jsxTransformer.TransformJsx(input));
@@ -98,7 +98,7 @@ public void ShouldUseCacheProvider()
9898
/*slidingExpiration*/ It.IsAny<TimeSpan>(),
9999
/*getData*/ It.IsAny<Func<string>>(),
100100
/*cacheDependencyKeys*/ It.IsAny<IEnumerable<string>>(),
101-
/*cacheDependencyFiles*/ It.IsAny<IEnumerable<string>>()
101+
/*cacheDependencyFiles*/ It.IsAny<IEnumerable<string>>()
102102
)).Returns("/* cached */");
103103

104104
var result = _jsxTransformer.TransformJsxFile("foo.jsx");
@@ -130,8 +130,8 @@ public void ShouldTransformJsxIfFileCacheHashInvalid()
130130
_environment.Verify(x => x.ExecuteWithLargerStackIfRequired<string>(
131131
"ReactNET_transform",
132132
"/** @jsx React.DOM */ <div>Hello World</div>",
133-
false
134-
));
133+
false
134+
));
135135
}
136136

137137
[Test]
@@ -145,8 +145,8 @@ public void ShouldTransformJsxIfNoCache()
145145
_environment.Verify(x => x.ExecuteWithLargerStackIfRequired<string>(
146146
"ReactNET_transform",
147147
"/** @jsx React.DOM */ <div>Hello World</div>",
148-
false
149-
));
148+
false
149+
));
150150
}
151151

152152
[Test]
@@ -156,7 +156,7 @@ public void ShouldSaveTransformationResult()
156156
_environment.Setup(x => x.ExecuteWithLargerStackIfRequired<string>(
157157
"ReactNET_transform",
158158
"/** @jsx React.DOM */ <div>Hello World</div>",
159-
false
159+
false
160160
)).Returns("React.DOM.div('Hello World')");
161161

162162
string result = null;

src/React/IJsxTransformer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public interface IJsxTransformer
2020
/// <param name="filename">Name of the file to load</param>
2121
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
2222
/// <returns>JavaScript</returns>
23-
string TransformJsxFile(string filename, bool useHarmony = false);
23+
string TransformJsxFile(string filename, bool? useHarmony = null);
2424

2525
/// <summary>
2626
/// Transforms JSX into regular JavaScript. The result is not cached. Use
@@ -29,7 +29,7 @@ public interface IJsxTransformer
2929
/// <param name="input">JSX</param>
3030
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
3131
/// <returns>JavaScript</returns>
32-
string TransformJsx(string input, bool useHarmony = false);
32+
string TransformJsx(string input, bool? useHarmony = null);
3333

3434
/// <summary>
3535
/// Transforms a JSX file to JavaScript, and saves the result into a ".generated.js" file
@@ -38,7 +38,7 @@ public interface IJsxTransformer
3838
/// <param name="filename">Name of the file to load</param>
3939
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
4040
/// <returns>File contents</returns>
41-
string TransformAndSaveJsxFile(string filename, bool useHarmony = false);
41+
string TransformAndSaveJsxFile(string filename, bool? useHarmony = null);
4242

4343
/// <summary>
4444
/// Returns the path the specified JSX file's compilation will be cached to

src/React/IReactEnvironment.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public interface IReactEnvironment
7070
/// <returns>The component</returns>
7171
IReactComponent CreateComponent<T>(string componentName, T props);
7272

73+
/// <summary>
74+
/// The current site configuration.
75+
/// </summary>
76+
/// <returns>The current site configuration.</returns>
77+
IReactSiteConfiguration SiteConfiguration { get; }
78+
7379
/// <summary>
7480
/// Renders the JavaScript required to initialise all components client-side. This will
7581
/// attach event handlers to the server-rendered HTML.

src/React/JsxTransformer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem f
6565
/// <param name="filename">Name of the file to load</param>
6666
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
6767
/// <returns>JavaScript</returns>
68-
public string TransformJsxFile(string filename, bool useHarmony = false)
68+
public string TransformJsxFile(string filename, bool? useHarmony = null)
6969
{
7070
var fullPath = _fileSystem.MapPath(filename);
7171

@@ -105,7 +105,7 @@ public string TransformJsxFile(string filename, bool useHarmony = false)
105105
/// <param name="hash">Hash of the input. If null, it will be calculated</param>
106106
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
107107
/// <returns>JavaScript</returns>
108-
private string TransformJsxWithHeader(string contents, string hash = null, bool useHarmony = false)
108+
private string TransformJsxWithHeader(string contents, string hash = null, bool? useHarmony = null)
109109
{
110110
if (string.IsNullOrEmpty(hash))
111111
{
@@ -121,7 +121,7 @@ private string TransformJsxWithHeader(string contents, string hash = null, bool
121121
/// <param name="input">JSX</param>
122122
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
123123
/// <returns>JavaScript</returns>
124-
public string TransformJsx(string input, bool useHarmony = false)
124+
public string TransformJsx(string input, bool? useHarmony = null)
125125
{
126126
// Just return directly if there's no JSX annotation
127127
if (!input.Contains("@jsx"))
@@ -135,7 +135,7 @@ public string TransformJsx(string input, bool useHarmony = false)
135135
var output = _environment.ExecuteWithLargerStackIfRequired<string>(
136136
"ReactNET_transform",
137137
input,
138-
useHarmony
138+
useHarmony.HasValue ? useHarmony.Value : _environment.SiteConfiguration.UseHarmony
139139
);
140140
return output;
141141
}
@@ -183,7 +183,7 @@ public string GetJsxOutputPath(string path)
183183
/// <param name="filename">Name of the file to load</param>
184184
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
185185
/// <returns>File contents</returns>
186-
public string TransformAndSaveJsxFile(string filename, bool useHarmony = false)
186+
public string TransformAndSaveJsxFile(string filename, bool? useHarmony = null)
187187
{
188188
var outputPath = GetJsxOutputPath(filename);
189189
var contents = _fileSystem.ReadAsString(filename);

src/React/ReactEnvironment.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ private IJsEngine Engine
114114
}
115115
}
116116

117+
/// <summary>
118+
/// The current site configuration.
119+
/// </summary>
120+
/// <returns>The current site configuration.</returns>
121+
public IReactSiteConfiguration SiteConfiguration
122+
{
123+
get
124+
{
125+
return _config;
126+
}
127+
}
128+
117129
/// <summary>
118130
/// Gets the JSX Transformer for this environment.
119131
/// </summary>

0 commit comments

Comments
 (0)