Skip to content

Commit 55a84ab

Browse files
committed
The Great JsxTransformer Renaming of 2015
Renamed JsxTransformer and friends to BabelTransformer, now that we're using Babel (which does a whole lot more than JsxTransformer did). Closes reactjs#168
1 parent f9affe0 commit 55a84ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+242
-259
lines changed

src/Cassette.React/JsxBundleProcessor.cs src/Cassette.React/BabelBundleProcessor.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@
1414
namespace Cassette.React
1515
{
1616
/// <summary>
17-
/// Handles processing of script bundles in Cassette. Adds a <see cref="JsxCompiler" />
18-
/// for all .jsx files.
17+
/// Handles processing of script bundles in Cassette. Adds a <see cref="BabelCompiler" />
18+
/// for all .js and .jsx files.
1919
/// </summary>
20-
public class JsxBundleProcessor : IBundleProcessor<ScriptBundle>
20+
public class BabelBundleProcessor : IBundleProcessor<ScriptBundle>
2121
{
2222
private readonly CassetteSettings _settings;
2323
private readonly IReactEnvironment _environment;
2424

2525
/// <summary>
26-
/// Initializes a new instance of the <see cref="JsxBundleProcessor"/> class.
26+
/// Initializes a new instance of the <see cref="BabelBundleProcessor"/> class.
2727
/// </summary>
2828
/// <param name="settings">Cassette settings.</param>
2929
/// <param name="environment">The ReactJS.NET environment</param>
30-
public JsxBundleProcessor(CassetteSettings settings, IReactEnvironment environment)
30+
public BabelBundleProcessor(CassetteSettings settings, IReactEnvironment environment)
3131
{
3232
_settings = settings;
3333
_environment = environment;
3434
}
3535

3636
/// <summary>
37-
/// Processes the specified bundle. Adds a <see cref="JsxCompiler"/> for all files.
37+
/// Processes the specified bundle. Adds a <see cref="BabelCompiler"/> for all files.
3838
/// </summary>
3939
/// <param name="bundle">The bundle.</param>
4040
public void Process(ScriptBundle bundle)
4141
{
4242
foreach (var asset in bundle.Assets)
4343
{
4444
asset.AddAssetTransformer(
45-
new CompileAsset(new JsxCompiler(_environment), _settings.SourceDirectory)
45+
new CompileAsset(new BabelCompiler(_environment), _settings.SourceDirectory)
4646
);
4747
}
4848
}

src/Cassette.React/JsxCompiler.cs src/Cassette.React/BabelCompiler.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@
1414
namespace Cassette.React
1515
{
1616
/// <summary>
17-
/// Handles compilation of JSX in Cassette
17+
/// Handles compilation of JavaScript files via Babel in Cassette
1818
/// </summary>
19-
public class JsxCompiler : ICompiler
19+
public class BabelCompiler : ICompiler
2020
{
2121
private readonly IReactEnvironment _environment;
2222

2323
/// <summary>
24-
/// Initializes a new instance of the <see cref="JsxCompiler"/> class.
24+
/// Initializes a new instance of the <see cref="BabelCompiler"/> class.
2525
/// </summary>
2626
/// <param name="environment">The ReactJS.NET environment</param>
27-
public JsxCompiler(IReactEnvironment environment)
27+
public BabelCompiler(IReactEnvironment environment)
2828
{
2929
_environment = environment;
3030
}
3131

3232
/// <summary>
33-
/// Compiles the specified JSX file into JavaScript
33+
/// Compiles the specified JavaScript file via Babel
3434
/// </summary>
3535
/// <param name="source">The source.</param>
3636
/// <param name="context">The context.</param>
3737
/// <returns>JavaScript</returns>
3838
public CompileResult Compile(string source, CompileContext context)
3939
{
40-
var output = _environment.JsxTransformer.TransformJsx(
40+
var output = _environment.Babel.Transform(
4141
source,
4242
Path.GetFileName(context.SourceFilePath)
4343
);

src/Cassette.React/Cassette.React.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
<Compile Include="AssemblyRegistration.cs" />
6262
<Compile Include="CassetteMSBuildStartup.cs" />
6363
<Compile Include="InsertIntoPipelineJsxBundleProcessor.cs" />
64-
<Compile Include="JsxBundleProcessor.cs" />
65-
<Compile Include="JsxCompiler.cs" />
64+
<Compile Include="BabelBundleProcessor.cs" />
65+
<Compile Include="BabelCompiler.cs" />
6666
<Compile Include="JsxFileSearchModifier.cs" />
6767
<Compile Include="MSBuildUtils.cs" />
6868
<Compile Include="Properties\AssemblyInfo.cs" />

src/Cassette.React/InsertIntoPipelineJsxBundleProcessor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace Cassette.React
1414
{
1515
/// <summary>
16-
/// Inserts the <see cref="JsxBundleProcessor" /> into the script bundle pipeline
16+
/// Inserts the <see cref="BabelBundleProcessor" /> into the script bundle pipeline
1717
/// </summary>
1818
public class InsertIntoPipelineJsxBundleProcessor : IBundlePipelineModifier<ScriptBundle>
1919
{
@@ -25,7 +25,7 @@ public class InsertIntoPipelineJsxBundleProcessor : IBundlePipelineModifier<Scri
2525
public IBundlePipeline<ScriptBundle> Modify(IBundlePipeline<ScriptBundle> pipeline)
2626
{
2727
var index = pipeline.IndexOf<ParseJavaScriptReferences>();
28-
pipeline.Insert<JsxBundleProcessor>(index + 1);
28+
pipeline.Insert<BabelBundleProcessor>(index + 1);
2929
return pipeline;
3030
}
3131
}

src/React.AspNet/JsxFileMiddleware.cs src/React.AspNet/BabelFileMiddleware.cs

+15-14
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@
1919
namespace React.AspNet
2020
{
2121
/// <summary>
22-
/// Enables serving static JSX files transformed to pure JavaScript. Wraps around StaticFileMiddleware.
22+
/// Enables serving static JavaScript files compiled via Babel. Wraps around StaticFileMiddleware.
2323
/// </summary>
24-
public class JsxFileMiddleware
24+
public class BabelFileMiddleware
2525
{
2626
private readonly RequestDelegate _next;
2727
private readonly IHostingEnvironment _hostingEnv;
2828
private readonly ILoggerFactory _loggerFactory;
29-
private readonly JsxFileOptions _options;
29+
private readonly BabelFileOptions _options;
3030

3131
/// <summary>
32-
/// Creates a new instance of the JsxFileMiddleware.
32+
/// Creates a new instance of the BabelFileMiddleware.
3333
/// </summary>
3434
/// <param name="next">The next middleware in the pipeline.</param>
3535
/// <param name="options">The configuration options.</param>
3636
/// <param name="hostingEnv">The hosting environment.</param>
3737
/// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
38-
public JsxFileMiddleware(RequestDelegate next, JsxFileOptions options, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory)
38+
public BabelFileMiddleware(RequestDelegate next, BabelFileOptions options, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory)
3939
{
4040
if (next == null)
4141
throw new ArgumentNullException("next");
@@ -45,33 +45,34 @@ public JsxFileMiddleware(RequestDelegate next, JsxFileOptions options, IHostingE
4545
_loggerFactory = loggerFactory;
4646

4747
// Default values
48-
_options = options ?? new JsxFileOptions();
48+
_options = options ?? new BabelFileOptions();
4949
}
5050

5151
/// <summary>
52-
/// Processes a request to determine if it matches a known JSX file, and if so, serves it compiled to JavaScript.
52+
/// Processes a request to determine if it matches a known JavaScript file, and if so, transforms
53+
/// it via Babel and serves it
5354
/// </summary>
5455
/// <param name="context">ASP.NET HTTP context</param>
5556
public async Task Invoke(HttpContext context)
5657
{
5758
if (!context.Request.Path.HasValue || !_options.Extensions.Any(context.Request.Path.Value.EndsWith))
5859
{
59-
// Not a request for a JSX file, so just pass through to the next middleware
60+
// Not a request for a JavaScript file, so just pass through to the next middleware
6061
await _next(context);
6162
return;
6263
}
6364

6465
var reactEnvironment = React.AssemblyRegistration.Container.Resolve<IReactEnvironment>();
65-
var internalStaticMiddleware = CreateFileMiddleware(reactEnvironment.JsxTransformer);
66+
var internalStaticMiddleware = CreateFileMiddleware(reactEnvironment.Babel);
6667
await internalStaticMiddleware.Invoke(context);
6768
}
6869

6970
/// <summary>
70-
/// Creates the internal <see cref="StaticFileMiddleware"/> used to serve JSX files.
71+
/// Creates the internal <see cref="StaticFileMiddleware"/> used to serve files.
7172
/// </summary>
72-
/// <param name="jsxTransformer"></param>
73+
/// <param name="babel"></param>
7374
/// <returns></returns>
74-
private StaticFileMiddleware CreateFileMiddleware(IJsxTransformer jsxTransformer)
75+
private StaticFileMiddleware CreateFileMiddleware(IBabel babel)
7576
{
7677
return new StaticFileMiddleware(
7778
_next,
@@ -83,8 +84,8 @@ private StaticFileMiddleware CreateFileMiddleware(IJsxTransformer jsxTransformer
8384
OnPrepareResponse = _options.StaticFileOptions.OnPrepareResponse,
8485
RequestPath = _options.StaticFileOptions.RequestPath,
8586
ServeUnknownFileTypes = _options.StaticFileOptions.ServeUnknownFileTypes,
86-
FileProvider = new JsxFileSystem(
87-
jsxTransformer,
87+
FileProvider = new BabelFileSystem(
88+
babel,
8889
_options.StaticFileOptions.FileProvider ?? _hostingEnv.WebRootFileProvider,
8990
_options.Extensions
9091
)

src/React.AspNet/JsxFileOptions.cs src/React.AspNet/BabelFileOptions.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ namespace React.AspNet
2121
#endif
2222
{
2323
/// <summary>
24-
/// Options for serving JSX files.
24+
/// Options for serving JavaScript files transformed via Babel.
2525
/// </summary>
26-
public class JsxFileOptions
26+
public class BabelFileOptions
2727
{
2828
/// <summary>
29-
/// Collection of extensions that will be treated as JSX files. Defaults to ".jsx" and ".js".
29+
/// Collection of extensions that will be handled. Defaults to ".jsx" and ".js".
3030
/// </summary>
3131
public IEnumerable<string> Extensions { get; set; }
3232

3333
/// <summary>
34-
/// Options for static file middleware used to server JSX files.
34+
/// Options for static file middleware used to serve JavaScript files.
3535
/// </summary>
3636
public StaticFileOptions StaticFileOptions { get; set; }
3737

3838
/// <summary>
39-
/// Creates a new instance of the <see cref="JsxFileOptions"/> class.
39+
/// Creates a new instance of the <see cref="BabelFileOptions"/> class.
4040
/// </summary>
41-
public JsxFileOptions()
41+
public BabelFileOptions()
4242
{
4343
Extensions = new[] { ".jsx", ".js" };
4444
StaticFileOptions = new StaticFileOptions();

src/React.AspNet/JsxFileSystem.cs src/React.AspNet/BabelFileSystem.cs

+21-21
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@ namespace React.AspNet
2929
#endif
3030
{
3131
/// <summary>
32-
/// File system that serves transformed JSX files.
32+
/// File system that serves transformed JavaScript files.
3333
/// </summary>
34-
public class JsxFileSystem : IOwinFileSystem
34+
public class BabelFileSystem : IOwinFileSystem
3535
{
36-
private readonly IJsxTransformer _transformer;
36+
private readonly IBabel _transformer;
3737
private readonly IOwinFileSystem _physicalFileSystem;
3838
private readonly string[] _extensions;
3939

4040
/// <summary>
41-
/// Creates a new instance of the JsxFileSystem.
41+
/// Creates a new instance of the BabelFileSystem.
4242
/// </summary>
43-
/// <param name="transformer">JSX transformer used to compile JSX files</param>
43+
/// <param name="transformer">Babel transformer used to compile files</param>
4444
/// <param name="root">The root directory</param>
45-
/// <param name="extensions">Extensions of files that will be treated as JSX files</param>
46-
public JsxFileSystem(IJsxTransformer transformer, string root, IEnumerable<string> extensions)
45+
/// <param name="extensions">Extensions of files that will be treated as JavaScript files</param>
46+
public BabelFileSystem(IBabel transformer, string root, IEnumerable<string> extensions)
4747
: this(transformer, new PhysicalFileSystem(root), extensions)
4848
{
4949
}
5050

5151
/// <summary>
52-
/// Creates a new instance of the JsxFileSystem.
52+
/// Creates a new instance of the BabelFileSystem.
5353
/// </summary>
54-
/// <param name="transformer">JSX transformer used to compile JSX files</param>
54+
/// <param name="transformer">Babel transformer used to compile files</param>
5555
/// <param name="fileSystem">File system used to look up files</param>
56-
/// <param name="extensions">Extensions of files that will be treated as JSX files</param>
57-
public JsxFileSystem(IJsxTransformer transformer, IOwinFileSystem fileSystem, IEnumerable<string> extensions)
56+
/// <param name="extensions">Extensions of files that will be treated as JavaScript files</param>
57+
public BabelFileSystem(IBabel transformer, IOwinFileSystem fileSystem, IEnumerable<string> extensions)
5858
{
5959
_transformer = transformer;
6060
_physicalFileSystem = fileSystem;
@@ -68,12 +68,12 @@ public JsxFileSystem(IJsxTransformer transformer, IOwinFileSystem fileSystem, IE
6868

6969
#if OWIN
7070
/// <summary>
71-
/// Locate a JSX file at the given path.
71+
/// Locate a JavaScript file at the given path.
7272
/// </summary>
7373
/// <param name="subpath">The path that identifies the file</param>
7474
/// <param name="fileInfo">The discovered file if any</param>
7575
/// <returns>
76-
/// True if a JSX file was located at the given path
76+
/// True if a JavaScript file was located at the given path
7777
/// </returns>
7878
public bool TryGetFileInfo(string subpath, out IFileInfo fileInfo)
7979
{
@@ -89,7 +89,7 @@ public bool TryGetFileInfo(string subpath, out IFileInfo fileInfo)
8989
if (internalFileInfo.IsDirectory)
9090
return false;
9191

92-
fileInfo = new JsxFileInfo(_transformer, internalFileInfo);
92+
fileInfo = new BabelFileInfo(_transformer, internalFileInfo);
9393
return true;
9494
}
9595

@@ -108,14 +108,14 @@ public bool TryGetDirectoryContents(string subpath, out IEnumerable<IFileInfo> c
108108
#else
109109

110110
/// <summary>
111-
/// Locate a JSX file at the given path.
111+
/// Locate a file at the given path.
112112
/// </summary>
113113
/// <param name="subpath">The path that identifies the file</param>
114114
/// <returns>The discovered file if any</returns>
115115
public IFileInfo GetFileInfo(string subpath)
116116
{
117117
var internalFileInfo = _physicalFileSystem.GetFileInfo(subpath);
118-
return new JsxFileInfo(_transformer, internalFileInfo);
118+
return new BabelFileInfo(_transformer, internalFileInfo);
119119
}
120120

121121
/// <summary>
@@ -143,19 +143,19 @@ IExpirationTrigger IOwinFileSystem.Watch(string filter)
143143
}
144144
#endif
145145

146-
private class JsxFileInfo : IFileInfo
146+
private class BabelFileInfo : IFileInfo
147147
{
148-
private readonly IJsxTransformer _jsxTransformer;
148+
private readonly IBabel _babel;
149149
private readonly IFileInfo _fileInfo;
150150
private readonly Lazy<byte[]> _content;
151151

152-
public JsxFileInfo(IJsxTransformer jsxTransformer, IFileInfo fileInfo)
152+
public BabelFileInfo(IBabel babel, IFileInfo fileInfo)
153153
{
154-
_jsxTransformer = jsxTransformer;
154+
_babel = babel;
155155
_fileInfo = fileInfo;
156156

157157
_content = new Lazy<byte[]>(
158-
() => Encoding.UTF8.GetBytes(_jsxTransformer.TransformJsxFile(fileInfo.PhysicalPath))
158+
() => Encoding.UTF8.GetBytes(_babel.TransformFile(fileInfo.PhysicalPath))
159159
);
160160
}
161161

src/React.AspNet/ReactBuilderExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public static class ReactBuilderExtensions
2727
/// </summary>
2828
/// <param name="app">ASP.NET application builder</param>
2929
/// <param name="configure">ReactJS.NET configuration</param>
30-
/// <param name="fileOptions">Options to use for serving JSX files</param>
30+
/// <param name="fileOptions">Options to use for serving files</param>
3131
/// <returns>The application builder (for chaining)</returns>
3232
public static IApplicationBuilder UseReact(
3333
this IApplicationBuilder app,
3434
Action<IReactSiteConfiguration> configure,
35-
JsxFileOptions fileOptions = null
35+
BabelFileOptions fileOptions = null
3636
)
3737
{
3838
EnsureServicesRegistered(app);
@@ -47,7 +47,7 @@ public static IApplicationBuilder UseReact(
4747
configure(ReactSiteConfiguration.Configuration);
4848

4949
// Allow serving of .jsx files
50-
app.UseMiddleware<JsxFileMiddleware>(fileOptions ?? new JsxFileOptions());
50+
app.UseMiddleware<BabelFileMiddleware>(fileOptions ?? new BabelFileOptions());
5151

5252
return app;
5353
}

0 commit comments

Comments
 (0)