0

I am trying to use UglifyJS for the first time. Iwould like to tranform the below code using UglifyJS

function someFn(){
        var someVar="test";    
        if(browser=="IE7"){
        ....
        console.log("something");
        console.log("somethingelse");
        .....
        }
        else{
        ....
        console.log("nothing");
        console.log("nothingelse");

        .....

        }
}

to produce below output

function someFn(){
        var someVar="test";
        ....
        console.log("something");
        console.log("somethingelse");
        .....
}

What I have tried is below

if (node instanceof UglifyJS.AST_If){
return node.body;
}

but this gives below output

function someFn(){
                var someVar="test";
              {
                ....
                console.log("something");
                console.log("somethingelse");
                .....
               }
        }
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
zigzag.bond
  • 308
  • 3
  • 15
  • apart from the extra block (2 chars), there is not really any difference between the two. – John Dvorak Jul 28 '13 at 15:01
  • you can nootice that there is no else block, also the if condition should be removed..my whole idea is to make the code specific to IE7 if I find an if condition which matches IE7..hope I am clear..you can also see that I am getting "{" braces – zigzag.bond Jul 28 '13 at 15:03
  • there is no `if` or the corresponding `else` block in the output as shown. The only difference is a pair of braces – John Dvorak Jul 28 '13 at 15:12
  • yes, you are right.. I am unable to remove those braces thru UglifyJS – zigzag.bond Jul 28 '13 at 15:20
  • @Jan Dvorak any solution? – zigzag.bond Jul 30 '13 at 06:36
  • My only suggestion is not to care, sorry. Why do you mind them? – John Dvorak Jul 30 '13 at 06:39
  • @JanDvorak since I am doing a transformation to other file there will be these extra braces which I want to get rid of them..also, node.body is an object can't I get only content out of it?? – zigzag.bond Jul 30 '13 at 07:12

1 Answers1

0

UglifuJS provides a method to do it as below

return UglifyJS.MAP.splice(node.body.body);

The above code will remove those extra braces.

zigzag.bond
  • 308
  • 3
  • 15