Simplify bin/jsx to perform just the JSX transform.
We will continue using `bin/jsx-internal`, well, internally. Note that this version no longer respects `@providesModule`, and it doesn't do anything special with constants like `__DEV__`, so we can no longer get to claim that `bin/jsx` can be used to build the core. I'm happy about this, personally, because it demonstrates the flexibility of Commoner.
Ben Newman committed
Sep 6, 2013 at 16:09 UTC
658f41cb30765185ef04611da43b9ece5b66568c
5 files changed
+62
-50
bin/jsx
+2
-45
@@ -3,53 +3,10 @@
3
4
var visitors = require('../vendor/fbtransform/visitors').transformVisitors;
5
var transform = require('jstransform').transform;
6
-var propagate = require("../vendor/constants").propagate;
6
7
require("commoner").resolve(function(id) {
9
- var context = this;
10
-
11
- // Note that the result of context.getProvidedP() is cached for the
12
- // duration of the build, so it is both consistent and cheap to
13
- // evaluate multiple times.
14
- return context.getProvidedP().then(function(idToPath) {
15
- // If a module declares its own identifier using @providesModule
16
- // then that identifier will be a key in the idToPath object.
17
- if (idToPath.hasOwnProperty(id)) {
18
- return context.readFileP(idToPath[id]);
19
- }
20
-
21
- // Otherwise assume the identifier maps directly to a path in the
22
- // filesystem.
23
- return context.readModuleP(id);
24
- });
25
-
8
+ return this.readModuleP(id);
9
}).process(function(id, source) {
27
- var context = this;
28
- var constants = context.config.constants || {};
29
-
10
// This is where JSX, ES6, etc. desugaring happens.
31
- source = transform(visitors.react, source).code;
32
-
33
- // Constant propagation means removing any obviously dead code after
34
- // replacing constant expressions with literal (boolean) values.
35
- source = propagate(constants, source);
36
-
37
- if (context.config.mocking) {
38
- // Make sure there is exactly one newline at the end of the module.
39
- source = source.replace(/\s+$/m, "\n");
40
-
41
- return context.getProvidedP().then(function(idToPath) {
42
- if (id !== "mock-modules" &&
43
- id !== "mocks" &&
44
- id !== "test/all" &&
45
- idToPath.hasOwnProperty("mock-modules")) {
46
- return source + '\nrequire("mock-modules").register(' +
47
- JSON.stringify(id) + ', module);\n';
48
- }
49
-
50
- return source;
51
- });
52
- }
53
-
54
- return source;
11
+ return transform(visitors.react, source).code;
12
});
bin/jsx-internal
new
+55
@@ -0,0 +1,55 @@
1
+#!/usr/bin/env node
2
+"use strict";
3
+
4
+var visitors = require('../vendor/fbtransform/visitors').transformVisitors;
5
+var transform = require('jstransform').transform;
6
+var propagate = require("../vendor/constants").propagate;
7
+
8
+require("commoner").resolve(function(id) {
9
+ var context = this;
10
+
11
+ // Note that the result of context.getProvidedP() is cached for the
12
+ // duration of the build, so it is both consistent and cheap to
13
+ // evaluate multiple times.
14
+ return context.getProvidedP().then(function(idToPath) {
15
+ // If a module declares its own identifier using @providesModule
16
+ // then that identifier will be a key in the idToPath object.
17
+ if (idToPath.hasOwnProperty(id)) {
18
+ return context.readFileP(idToPath[id]);
19
+ }
20
+
21
+ // Otherwise assume the identifier maps directly to a path in the
22
+ // filesystem.
23
+ return context.readModuleP(id);
24
+ });
25
+
26
+}).process(function(id, source) {
27
+ var context = this;
28
+ var constants = context.config.constants || {};
29
+
30
+ // This is where JSX, ES6, etc. desugaring happens.
31
+ source = transform(visitors.react, source).code;
32
+
33
+ // Constant propagation means removing any obviously dead code after
34
+ // replacing constant expressions with literal (boolean) values.
35
+ source = propagate(constants, source);
36
+
37
+ if (context.config.mocking) {
38
+ // Make sure there is exactly one newline at the end of the module.
39
+ source = source.replace(/\s+$/m, "\n");
40
+
41
+ return context.getProvidedP().then(function(idToPath) {
42
+ if (id !== "mock-modules" &&
43
+ id !== "mocks" &&
44
+ id !== "test/all" &&
45
+ idToPath.hasOwnProperty("mock-modules")) {
46
+ return source + '\nrequire("mock-modules").register(' +
47
+ JSON.stringify(id) + ', module);\n';
48
+ }
49
+
50
+ return source;
51
+ });
52
+ }
53
+
54
+ return source;
55
+});
grunt/tasks/jsx.js
+1
-1
@@ -27,7 +27,7 @@ module.exports = function() {
27
args.push("--config", config.configFile);
28
29
var child = spawn({
30
- cmd: "bin/jsx",
30
+ cmd: "bin/jsx-internal",
31
args: args
32
}, function(error, result, code) {
33
if (error) {
grunt/tasks/npm.js
+2
-2
@@ -64,8 +64,8 @@ module.exports = function() {
64
var pkgDir = path.join(nodePath, pkg.name);
65
var doneCount = 2;
66
67
- // Make sure that bin/jsx is runnable by echoing main.js.
68
- run("bin/jsx", ["main.js"], {
67
+ // Make sure that bin/jsx-internal is runnable by echoing main.js.
68
+ run("bin/jsx-internal", ["main.js"], {
69
cwd: pkgDir
70
}, function(result) {
71
assert.ok(result.stdout.indexOf("transform") >= 0, result.stdout);
package.json
+2
-2
@@ -38,8 +38,7 @@
38
"dependencies": {
39
"commoner": "~0.8.4",
40
"esprima-fb": "1001.1001.1000-dev-harmony-fb",
41
- "jstransform": "~1.0.0",
42
- "recast": "~0.4.8"
41
+ "jstransform": "~1.0.0"
42
},
43
"devDependencies": {
44
"browserify": "~2.29.0",
@@ -51,6 +50,7 @@
50
"grunt-contrib-jshint": "~0.6.0",
51
"optimist": "~0.6.0",
52
"phantomjs": "~1.9.1-4",
53
+ "recast": "~0.4.8",
54
"semver": "~2.1.0",
55
"uglify-js": "~2.4.0",
56
"grunt-contrib-clean": "~0.5.0",