Skip to content

Commit dd75222

Browse files
committedOct 11, 2015
Switch to Babel
- Remove JSXTransformer and instead use "browser" build of Babel - Remove useHarmony and stripTypes settings (no longer relevant) - Remove obsolete `LoadJsxFile` and `TransformJsx` from `IReactEnvironment` - These have been marked as obsolete for a long time now #138
1 parent 86c6212 commit dd75222

21 files changed

+58
-16190
lines changed
 

‎build.proj

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ of patent rights can be found in the PATENTS file in the same directory.
99
-->
1010
<Project ToolsVersion="4.0" DefaultTargets="Build;Test;Package" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1111
<PropertyGroup>
12-
<Major>1</Major>
13-
<Minor>5</Minor>
14-
<Build>6</Build>
12+
<Major>2</Major>
13+
<Minor>0</Minor>
14+
<Build>0</Build>
1515
<Revision>0</Revision>
1616
<DevNuGetServer>http://reactjs.net/packages/</DevNuGetServer>
1717
<MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\tools\MSBuildTasks</MSBuildCommunityTasksPath>
@@ -51,6 +51,11 @@ of patent rights can be found in the PATENTS file in the same directory.
5151
WorkingDirectory="$(MSBuildProjectDirectory)"
5252
Command="dnu restore --quiet --parallel"
5353
/>
54+
<!-- npm packages -->
55+
<Exec
56+
WorkingDirectory="src/React.Core"
57+
Command="npm install"
58+
/>
5459
</Target>
5560

5661
<Target Name="UpdateVersion">

‎src/React.AspNet/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.5.6-*",
2+
"version": "2.0.0-*",
33
"configurations": {
44
"Debug": {
55
"compilationOptions": {

‎src/React.Core/FileCacheHash.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class FileCacheHash : IFileCacheHash
2121
/// <summary>
2222
/// Prefix used for hash line in transformed file. Used for caching.
2323
/// </summary>
24-
private const string HASH_PREFIX = "// @hash v2-";
24+
private const string HASH_PREFIX = "// @hash v3-";
2525

2626
/// <summary>
2727
/// Althorithm for calculating file hashes

‎src/React.Core/IJsxTransformer.cs

+5-32
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ public interface IJsxTransformer
1818
/// Transforms a JSX file. Results of the JSX to JavaScript transformation are cached.
1919
/// </summary>
2020
/// <param name="filename">Name of the file to load</param>
21-
/// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
22-
/// <param name="stripTypes">
23-
/// Whether Flow types should be stripped out. Defaults to the value set in the site
24-
/// configuration.
25-
/// </param>
2621
/// <returns>JavaScript</returns>
27-
string TransformJsxFile(string filename, bool? useHarmony = null, bool? stripTypes = null);
22+
string TransformJsxFile(string filename);
2823

2924
/// <summary>
3025
/// Transforms a JSX file to regular JavaScript and also returns a source map to map the
@@ -35,57 +30,35 @@ public interface IJsxTransformer
3530
/// <param name="forceGenerateSourceMap">
3631
/// <c>true</c> to re-transform the file if a cached version with no source map is available
3732
/// </param>
38-
/// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
39-
/// <param name="stripTypes">
40-
/// Whether Flow types should be stripped out. Defaults to the value set in the site
41-
/// configuration.
42-
/// </param>
4333
/// <returns>JavaScript and source map</returns>
4434
JavaScriptWithSourceMap TransformJsxFileWithSourceMap(
4535
string filename,
46-
bool forceGenerateSourceMap = false,
47-
bool? useHarmony = null,
48-
bool? stripTypes = null
36+
bool forceGenerateSourceMap = false
4937
);
5038

5139
/// <summary>
5240
/// Transforms JSX into regular JavaScript. The result is not cached. Use
5341
/// <see cref="TransformJsxFile"/> if loading from a file since this will cache the result.
5442
/// </summary>
5543
/// <param name="input">JSX</param>
56-
/// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
57-
/// <param name="stripTypes">
58-
/// Whether Flow types should be stripped out. Defaults to the value set in the site
59-
/// configuration.
60-
/// </param>
6144
/// <returns>JavaScript</returns>
62-
string TransformJsx(string input, bool? useHarmony = null, bool? stripTypes = null);
45+
string TransformJsx(string input);
6346

6447
/// <summary>
6548
/// Transforms JSX to regular JavaScript and also returns a source map to map the compiled
6649
/// source to the original version. The result is not cached.
6750
/// </summary>
6851
/// <param name="input">JSX</param>
69-
/// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
70-
/// <param name="stripTypes">
71-
/// Whether Flow types should be stripped out. Defaults to the value set in the site
72-
/// configuration.
73-
/// </param>
7452
/// <returns>JavaScript and source map</returns>
75-
JavaScriptWithSourceMap TransformJsxWithSourceMap(string input, bool? useHarmony = null, bool? stripTypes = null);
53+
JavaScriptWithSourceMap TransformJsxWithSourceMap(string input);
7654

7755
/// <summary>
7856
/// Transforms a JSX file to JavaScript, and saves the result into a ".generated.js" file
7957
/// alongside the original file.
8058
/// </summary>
8159
/// <param name="filename">Name of the file to load</param>
82-
/// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
83-
/// <param name="stripTypes">
84-
/// Whether Flow types should be stripped out. Defaults to the value set in the site
85-
/// configuration.
86-
/// </param>
8760
/// <returns>File contents</returns>
88-
string TransformAndSaveJsxFile(string filename, bool? useHarmony = null, bool? stripTypes = null);
61+
string TransformAndSaveJsxFile(string filename);
8962

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

‎src/React.Core/IReactEnvironment.cs

-17
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,6 @@ public interface IReactEnvironment
9292
/// <returns>JavaScript for all components</returns>
9393
string GetInitJavaScript();
9494

95-
/// <summary>
96-
/// Loads a JSX file. Results of the JSX to JavaScript transformation are cached.
97-
/// </summary>
98-
/// <param name="filename">Name of the file to load</param>
99-
/// <returns>File contents</returns>
100-
[Obsolete("Use JsxTransformer.TransformJsxFile")]
101-
string LoadJsxFile(string filename);
102-
103-
/// <summary>
104-
/// Transforms JSX into regular JavaScript. The result is not cached. Use
105-
/// <see cref="LoadJsxFile"/> if loading from a file since this will cache the result.
106-
/// </summary>
107-
/// <param name="input">JSX</param>
108-
/// <returns>JavaScript</returns>
109-
[Obsolete("Use JsxTransformer.TransformJsx")]
110-
string TransformJsx(string input);
111-
11295
/// <summary>
11396
/// Gets the JSX Transformer for this environment.
11497
/// </summary>

‎src/React.Core/IReactSiteConfiguration.cs

-20
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ public interface IReactSiteConfiguration
5454
/// </summary>
5555
IEnumerable<string> ScriptsWithoutTransform { get; }
5656

57-
/// <summary>
58-
/// A value indicating if es6 syntax should be rewritten.
59-
/// </summary>
60-
/// <returns><c>true</c> if support for es6 syntax should be rewritten.</returns>
61-
bool UseHarmony { get; set; }
62-
63-
/// <summary>
64-
/// Specifies whether ES6 (harmony) syntax should be transformed
65-
/// </summary>
66-
IReactSiteConfiguration SetUseHarmony(bool useHarmony);
67-
6857
/// <summary>
6958
/// Gets or sets whether JavaScript engines should be reused across requests.
7059
/// </summary>
@@ -90,15 +79,6 @@ public interface IReactSiteConfiguration
9079
/// <param name="settings">The settings.</param>
9180
IReactSiteConfiguration SetJsonSerializerSettings(JsonSerializerSettings settings);
9281

93-
/// <summary>
94-
/// Gets or sets whether Flow types should be stripped out.
95-
/// </summary>
96-
bool StripTypes { get; set; }
97-
/// <summary>
98-
/// Sets whether Flow types should be stripped out.
99-
/// </summary>
100-
IReactSiteConfiguration SetStripTypes(bool stripTypes);
101-
10282
/// <summary>
10383
/// Gets or sets the number of engines to initially start when a pool is created.
10484
/// Defaults to <c>10</c>.

‎src/React.Core/JavaScriptEngineFactory.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ protected virtual void InitialiseEngine(IJsEngine engine)
100100
{
101101
engine.ExecuteResource("React.Resources.react-with-addons.js", thisAssembly);
102102
engine.Execute("React = global.React");
103-
engine.ExecuteResource("React.Resources.JSXTransformer.js", thisAssembly);
103+
// TODO: Make this configurable, so we don't load Babel if it's not needed.
104+
engine.ExecuteResource("React.node_modules.babel_core.browser.js", thisAssembly);
104105
}
105106

106107
LoadUserScripts(engine);

‎src/React.Core/JsxTransformer.cs

+13-55
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class JsxTransformer : IJsxTransformer
2222
/// <summary>
2323
/// Cache key for JSX to JavaScript compilation
2424
/// </summary>
25-
protected const string JSX_CACHE_KEY = "JSX_v2_{0}";
25+
protected const string JSX_CACHE_KEY = "JSX_v3_{0}";
2626
/// <summary>
2727
/// Suffix to append to compiled files
2828
/// </summary>
@@ -78,15 +78,10 @@ public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem f
7878
/// Transforms a JSX file. Results of the JSX to JavaScript transformation are cached.
7979
/// </summary>
8080
/// <param name="filename">Name of the file to load</param>
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>
8681
/// <returns>JavaScript</returns>
87-
public virtual string TransformJsxFile(string filename, bool? useHarmony = null, bool? stripTypes = null)
82+
public virtual string TransformJsxFile(string filename)
8883
{
89-
return TransformJsxFileWithSourceMap(filename, false, useHarmony, stripTypes).Code;
84+
return TransformJsxFileWithSourceMap(filename, false).Code;
9085
}
9186

9287
/// <summary>
@@ -98,17 +93,10 @@ public virtual string TransformJsxFile(string filename, bool? useHarmony = null,
9893
/// <param name="forceGenerateSourceMap">
9994
/// <c>true</c> to re-transform the file if a cached version with no source map is available
10095
/// </param>
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>
10696
/// <returns>JavaScript and source map</returns>
10797
public virtual JavaScriptWithSourceMap TransformJsxFileWithSourceMap(
10898
string filename,
109-
bool forceGenerateSourceMap = false,
110-
bool? useHarmony = null,
111-
bool? stripTypes = null
99+
bool forceGenerateSourceMap = false
112100
)
113101
{
114102
var cacheKey = string.Format(JSX_CACHE_KEY, filename);
@@ -131,7 +119,7 @@ public virtual JavaScriptWithSourceMap TransformJsxFileWithSourceMap(
131119
// 3. Not cached, perform the transformation
132120
try
133121
{
134-
output = TransformJsxWithHeader(filename, contents, hash, useHarmony, stripTypes);
122+
output = TransformJsxWithHeader(filename, contents, hash);
135123
}
136124
catch (JsxException ex)
137125
{
@@ -223,26 +211,19 @@ protected virtual JavaScriptWithSourceMap LoadJsxFromFileCache(string filename,
223211
/// <param name="filename">Name of the file being transformed</param>
224212
/// <param name="contents">Contents of the input file</param>
225213
/// <param name="hash">Hash of the input. If null, it will be calculated</param>
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>
231214
/// <returns>JavaScript</returns>
232215
protected virtual JavaScriptWithSourceMap TransformJsxWithHeader(
233216
string filename,
234217
string contents,
235-
string hash = null,
236-
bool? useHarmony = null,
237-
bool? stripTypes = null
218+
string hash = null
238219
)
239220
{
240221
if (string.IsNullOrEmpty(hash))
241222
{
242223
hash = _fileCacheHash.CalculateHash(contents);
243224
}
244225
var header = GetFileHeader(hash);
245-
var result = TransformJsxWithSourceMap(header + contents, useHarmony, stripTypes);
226+
var result = TransformJsxWithSourceMap(header + contents);
246227
result.Hash = hash;
247228
if (result.SourceMap != null)
248229
{
@@ -262,21 +243,14 @@ protected virtual JavaScriptWithSourceMap TransformJsxWithHeader(
262243
/// <see cref="TransformJsxFile"/> if loading from a file since this will cache the result.
263244
/// </summary>
264245
/// <param name="input">JSX</param>
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>
270246
/// <returns>JavaScript</returns>
271-
public virtual string TransformJsx(string input, bool? useHarmony = null, bool? stripTypes = null)
247+
public virtual string TransformJsx(string input)
272248
{
273249
try
274250
{
275251
var output = _environment.ExecuteWithLargerStackIfRequired<string>(
276252
"ReactNET_transform",
277-
input,
278-
useHarmony ?? _config.UseHarmony,
279-
stripTypes ?? _config.StripTypes
253+
input
280254
);
281255
return output;
282256
}
@@ -291,25 +265,16 @@ public virtual string TransformJsx(string input, bool? useHarmony = null, bool?
291265
/// source to the original version. The result is not cached.
292266
/// </summary>
293267
/// <param name="input">JSX</param>
294-
/// <param name="useHarmony"><c>true</c> if support for ES6 syntax should be enabled</param>
295-
/// <param name="stripTypes">
296-
/// Whether Flow types should be stripped out. Defaults to the value set in the site
297-
/// configuration.
298-
/// </param>
299268
/// <returns>JavaScript and source map</returns>
300269
public virtual JavaScriptWithSourceMap TransformJsxWithSourceMap(
301-
string input,
302-
bool? useHarmony = null,
303-
bool? stripTypes = null
270+
string input
304271
)
305272
{
306273
try
307274
{
308275
return _environment.ExecuteWithLargerStackIfRequired<JavaScriptWithSourceMap>(
309276
"ReactNET_transform_sourcemap",
310-
input,
311-
useHarmony ?? _config.UseHarmony,
312-
stripTypes ?? _config.StripTypes
277+
input
313278
);
314279
}
315280
catch (Exception ex)
@@ -365,22 +330,15 @@ public virtual string GetSourceMapOutputPath(string path)
365330
/// alongside the original file.
366331
/// </summary>
367332
/// <param name="filename">Name of the file to load</param>
368-
/// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
369-
/// <param name="stripTypes">
370-
/// Whether Flow types should be stripped out. Defaults to the value set in the site
371-
/// configuration.
372-
/// </param>
373333
/// <returns>File contents</returns>
374334
public virtual string TransformAndSaveJsxFile(
375-
string filename,
376-
bool? useHarmony = null,
377-
bool? stripTypes = null
335+
string filename
378336
)
379337
{
380338
var outputPath = GetJsxOutputPath(filename);
381339
var sourceMapPath = GetSourceMapOutputPath(filename);
382340
var contents = _fileSystem.ReadAsString(filename);
383-
var result = TransformJsxWithHeader(filename, contents, null, useHarmony, stripTypes);
341+
var result = TransformJsxWithHeader(filename, contents, null);
384342
_fileSystem.WriteAsString(outputPath, result.Code);
385343
_fileSystem.WriteAsString(sourceMapPath, result.SourceMap == null ? string.Empty : result.SourceMap.ToJson());
386344
return outputPath;

‎src/React.Core/React.Core.csproj

+3-4
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@
128128
<Compile Include="TinyIoCExtensions.cs" />
129129
<Compile Include="TinyIoC\TinyIoC.cs" />
130130
</ItemGroup>
131-
<ItemGroup>
132-
<EmbeddedResource Include="Resources\JSXTransformer.js" />
133-
</ItemGroup>
134131
<ItemGroup>
135132
<None Include="packages.config" />
136133
<Compile Include="SimpleFileSystem.cs" />
@@ -142,7 +139,9 @@
142139
<ItemGroup>
143140
<EmbeddedResource Include="Resources\shims.js" />
144141
</ItemGroup>
145-
<ItemGroup />
142+
<ItemGroup>
143+
<EmbeddedResource Include="node_modules\babel-core\browser.js" />
144+
</ItemGroup>
146145
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
147146
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
148147
Other similar extension points exist, see Microsoft.Common.targets.

‎src/React.Core/ReactEnvironment.cs

-23
Original file line numberDiff line numberDiff line change
@@ -304,29 +304,6 @@ public virtual string GetInitJavaScript()
304304
return fullScript.ToString();
305305
}
306306

307-
/// <summary>
308-
/// Loads a JSX file. Results of the JSX to JavaScript transformation are cached.
309-
/// </summary>
310-
/// <param name="filename">Name of the file to load</param>
311-
/// <returns>File contents</returns>
312-
[Obsolete("Use JsxTransformer.TransformJsxFile")]
313-
public string LoadJsxFile(string filename)
314-
{
315-
return JsxTransformer.TransformJsxFile(filename);
316-
}
317-
318-
/// <summary>
319-
/// Transforms JSX into regular JavaScript. The result is not cached. Use
320-
/// <see cref="LoadJsxFile"/> if loading from a file since this will cache the result.
321-
/// </summary>
322-
/// <param name="input">JSX</param>
323-
/// <returns>JavaScript</returns>
324-
[Obsolete("Use JsxTransformer.TransformJsx")]
325-
public string TransformJsx(string input)
326-
{
327-
return JsxTransformer.TransformJsx(input);
328-
}
329-
330307
/// <summary>
331308
/// Attempts to execute the provided JavaScript code using the current engine. If an
332309
/// exception is thrown, retries the execution using a new thread (and hence a new engine)

0 commit comments

Comments
 (0)