Skip to content

Commit

Permalink
Use recast.parse and .print for require("vendor/constants").propagate.
Browse files Browse the repository at this point in the history
This removes the need to pass a callback, which is a nice improvement.
  • Loading branch information
benjamn committed Jun 17, 2013
1 parent 0f87e8e commit 000928f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
13 changes: 4 additions & 9 deletions bin/jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@ require("commoner").resolve(function(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;

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);
});
});
// Constant propagation means removing any obviously dead code after
// replacing constant expressions with literal (boolean) values.
return propagate(constants, source);
});
12 changes: 4 additions & 8 deletions vendor/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@

var recast = require('recast');

exports.propagate = function(constants, source, writeback) {
recast.runString(
source,
function(ast, callback) {
callback(new ConstantVisitor(constants).visit(ast));
},
{ writeback: writeback }
);
exports.propagate = function(constants, source) {
var ast = recast.parse(source);
ast = new ConstantVisitor(constants).visit(ast);
return recast.print(ast);
};

var ConstantVisitor = recast.Visitor.extend({
Expand Down

0 comments on commit 000928f

Please sign in to comment.