forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsx
executable file
·41 lines (33 loc) · 1.37 KB
/
jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
"use strict";
var visitors = require('../vendor/fbtransform/visitors').transformVisitors;
var transform = require('../vendor/fbtransform/lib/transform').transform;
var propagate = require("../vendor/constants").propagate;
require("commoner").resolve(function(id) {
var context = this;
// Note that the result of context.getProvidedP() is cached for the
// duration of the build, so it is both consistent and cheap to
// evaluate multiple times.
return context.getProvidedP().then(function(idToPath) {
// If a module declares its own identifier using @providesModule
// then that identifier will be a key in the idToPath object.
if (idToPath.hasOwnProperty(id)) {
return context.readFileP(idToPath[id]);
}
// Otherwise assume the identifier maps directly to a path in the
// filesystem.
return context.readModuleP(id);
});
}).process(function(id, source) {
var context = this;
// This is where JSX, ES6, etc. desugaring happens.
source = transform(visitors.react, source).code;
return context.makePromise(function(callback) {
var constants = context.config.constants || {};
// Constant propagation means removing dead code after replacing
// constant conditional expressions with literal (boolean) values.
propagate(constants, source, function(source) {
callback(null, source);
});
});
});