Skip to content

Commit 2240f18

Browse files
committed
Enable configuration of harmony support
1 parent 3cbdd58 commit 2240f18

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/React/IJsxTransformer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ public interface IJsxTransformer
1919
/// </summary>
2020
/// <param name="filename">Name of the file to load</param>
2121
/// <returns>JavaScript</returns>
22-
string TransformJsxFile(string filename);
22+
string TransformJsxFile(string filename, bool useHarmony = false);
2323

2424
/// <summary>
2525
/// Transforms JSX into regular JavaScript. The result is not cached. Use
2626
/// <see cref="TransformJsxFile"/> if loading from a file since this will cache the result.
2727
/// </summary>
2828
/// <param name="input">JSX</param>
2929
/// <returns>JavaScript</returns>
30-
string TransformJsx(string input);
30+
string TransformJsx(string input, bool useHarmony = false);
3131

3232
/// <summary>
3333
/// Transforms a JSX file to JavaScript, and saves the result into a ".generated.js" file
3434
/// alongside the original file.
3535
/// </summary>
3636
/// <param name="filename">Name of the file to load</param>
3737
/// <returns>File contents</returns>
38-
string TransformAndSaveJsxFile(string filename);
38+
string TransformAndSaveJsxFile(string filename, bool useHarmony = false);
3939

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

src/React/JsxTransformer.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem f
6464
/// </summary>
6565
/// <param name="filename">Name of the file to load</param>
6666
/// <returns>JavaScript</returns>
67-
public string TransformJsxFile(string filename)
67+
public string TransformJsxFile(string filename, bool useHarmony = false)
6868
{
6969
var fullPath = _fileSystem.MapPath(filename);
7070

@@ -91,7 +91,7 @@ public string TransformJsxFile(string filename)
9191
}
9292

9393
// 3. Not cached, perform the transformation
94-
return TransformJsxWithHeader(contents, hash);
94+
return TransformJsxWithHeader(contents, hash, useHarmony);
9595
}
9696
);
9797
}
@@ -103,13 +103,13 @@ public string TransformJsxFile(string filename)
103103
/// <param name="contents">Contents of the input file</param>
104104
/// <param name="hash">Hash of the input. If null, it will be calculated</param>
105105
/// <returns>JavaScript</returns>
106-
private string TransformJsxWithHeader(string contents, string hash = null)
106+
private string TransformJsxWithHeader(string contents, string hash = null, bool useHarmony = false)
107107
{
108108
if (string.IsNullOrEmpty(hash))
109109
{
110110
hash = _fileCacheHash.CalculateHash(contents);
111111
}
112-
return GetFileHeader(hash) + TransformJsx(contents);
112+
return GetFileHeader(hash) + TransformJsx(contents, useHarmony);
113113
}
114114

115115
/// <summary>
@@ -118,7 +118,7 @@ private string TransformJsxWithHeader(string contents, string hash = null)
118118
/// </summary>
119119
/// <param name="input">JSX</param>
120120
/// <returns>JavaScript</returns>
121-
public string TransformJsx(string input)
121+
public string TransformJsx(string input, bool useHarmony = false)
122122
{
123123
// Just return directly if there's no JSX annotation
124124
if (!input.Contains("@jsx"))
@@ -131,7 +131,8 @@ public string TransformJsx(string input)
131131
{
132132
var output = _environment.ExecuteWithLargerStackIfRequired<string>(
133133
"ReactNET_transform",
134-
input
134+
input,
135+
useHarmony
135136
);
136137
return output;
137138
}
@@ -178,11 +179,11 @@ public string GetJsxOutputPath(string path)
178179
/// </summary>
179180
/// <param name="filename">Name of the file to load</param>
180181
/// <returns>File contents</returns>
181-
public string TransformAndSaveJsxFile(string filename)
182+
public string TransformAndSaveJsxFile(string filename, bool useHarmony = false)
182183
{
183184
var outputPath = GetJsxOutputPath(filename);
184185
var contents = _fileSystem.ReadAsString(filename);
185-
var result = TransformJsxWithHeader(contents);
186+
var result = TransformJsxWithHeader(contents, useHarmony: useHarmony);
186187
_fileSystem.WriteAsString(outputPath, result);
187188
return outputPath;
188189
}

src/React/Resources/shims.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ if (!Object.freeze) {
1919
Object.freeze = function() { };
2020
}
2121

22-
function ReactNET_transform(input) {
23-
return global.JSXTransformer.transform(input, { harmony: true }).code;
22+
function ReactNET_transform(input, harmony) {
23+
return global.JSXTransformer.transform(input, { harmony: !!harmony }).code;
2424
}

0 commit comments

Comments
 (0)