@samitouri / QOS-React-2 / commits / 000928f9dc
Fork 0

The library for web and native user interfaces.

Use recast.parse and .print for require("vendor/constants").propagate.

This removes the need to pass a callback, which is a nice improvement.

Ben Newman committed Jun 17, 2013 at 16:27 UTC 000928f9dc8c44457814170a9e8642ae157c0d51
2 files changed +8 -17
bin/jsx
+4 -9
@@ -25,17 +25,12 @@ require("commoner").resolve(function(id) {
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
32 - return context.makePromise(function(callback) {
33 - var constants = context.config.constants || {};
34 -
35 - // Constant propagation means removing dead code after replacing
36 - // constant conditional expressions with literal (boolean) values.
37 - propagate(constants, source, function(source) {
38 - callback(null, source);
39 - });
40 - });
33 + // Constant propagation means removing any obviously dead code after
34 + // replacing constant expressions with literal (boolean) values.
35 + return propagate(constants, source);
36 });
vendor/constants.js
+4 -8
@@ -17,14 +17,10 @@
17
18 var recast = require('recast');
19
20 -exports.propagate = function(constants, source, writeback) {
21 - recast.runString(
22 - source,
23 - function(ast, callback) {
24 - callback(new ConstantVisitor(constants).visit(ast));
25 - },
26 - { writeback: writeback }
27 - );
20 +exports.propagate = function(constants, source) {
21 + var ast = recast.parse(source);
22 + ast = new ConstantVisitor(constants).visit(ast);
23 + return recast.print(ast);
24 };
25
26 var ConstantVisitor = recast.Visitor.extend({