Вопрос

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");
                .....
               }
        }
Это было полезно?

Решение

UglifuJS provides a method to do it as below

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

The above code will remove those extra braces.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top