Files
react/bin/jsx
Ben Newman 000928f9dc Use recast.parse and .print for require("vendor/constants").propagate.
This removes the need to pass a callback, which is a nice improvement.
2013-06-17 16:30:32 -04:00

37 lines
1.3 KiB
JavaScript
Executable File

#!/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;
var constants = context.config.constants || {};
// This is where JSX, ES6, etc. desugaring happens.
source = transform(visitors.react, source).code;
// Constant propagation means removing any obviously dead code after
// replacing constant expressions with literal (boolean) values.
return propagate(constants, source);
});