File tree Expand file tree Collapse file tree 2 files changed +11
-21
lines changed Expand file tree Collapse file tree 2 files changed +11
-21
lines changed Original file line number Diff line number Diff line change 3
3
4
4
var visitors = require ( '../vendor/fbtransform/visitors' ) . transformVisitors ;
5
5
var transform = require ( '../vendor/fbtransform/lib/transform' ) . transform ;
6
- var debranch = require ( "../vendor/woodchipper " ) . debranch ;
6
+ var propagate = require ( "../vendor/constants " ) . propagate ;
7
7
8
8
require ( "commoner" ) . resolve ( function ( id ) {
9
9
var context = this ;
@@ -25,18 +25,12 @@ require("commoner").resolve(function(id) {
25
25
26
26
} ) . process ( function ( id , source ) {
27
27
var context = this ;
28
+ var constants = context . config . constants || { } ;
28
29
29
30
// This is where JSX, ES6, etc. desugaring happens.
30
31
source = transform ( visitors . react , source ) . code ;
31
32
32
- return context . makePromise ( function ( callback ) {
33
- var constants = context . config . constants || { } ;
34
-
35
- // Debranching means removing any obviously dead code after
36
- // replacing constant conditional expressions with literal
37
- // (boolean) values.
38
- debranch ( constants , source , function ( source ) {
39
- callback ( null , source ) ;
40
- } ) ;
41
- } ) ;
33
+ // Constant propagation means removing any obviously dead code after
34
+ // replacing constant expressions with literal (boolean) values.
35
+ return propagate ( constants , source ) ;
42
36
} ) ;
Original file line number Diff line number Diff line change 17
17
18
18
var recast = require ( 'recast' ) ;
19
19
20
- exports . debranch = function ( constants , source , writeback ) {
21
- recast . runString (
22
- source ,
23
- function ( ast , callback ) {
24
- callback ( new Woodchipper ( 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 ) ;
28
24
} ;
29
25
30
- var Woodchipper = recast . Visitor . extend ( {
26
+ var ConstantVisitor = recast . Visitor . extend ( {
31
27
init : function ( constants ) {
32
28
this . constants = constants || { } ;
33
29
} ,
@@ -57,6 +53,6 @@ var Woodchipper = recast.Visitor.extend({
57
53
if ( ! module . parent ) {
58
54
var constants = JSON . parse ( process . argv [ 3 ] ) ;
59
55
recast . run ( function ( ast , callback ) {
60
- callback ( new Woodchipper ( constants ) . visit ( ast ) ) ;
56
+ callback ( new ConstantVisitor ( constants ) . visit ( ast ) ) ;
61
57
} ) ;
62
58
}
You can’t perform that action at this time.
0 commit comments