Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use screw-ie8 from programmatic API? #1213

Closed
qyoz opened this issue Jul 17, 2016 · 4 comments
Closed

How to use screw-ie8 from programmatic API? #1213

qyoz opened this issue Jul 17, 2016 · 4 comments

Comments

@qyoz
Copy link
Contributor

qyoz commented Jul 17, 2016

After this change, I'm trying the disable it, using this example from issue #409 :

var code = 'bad = function(e){return function(error){try {e();}catch(e){error(e);}};};';
var options = {
    fromString: true,
    warnings: false,
    mangle: true,
    screw_ie8: false, // <== doesn't work
    support_ie8: true, // <== doesn't work
    compress: {
        hoist_funs: false,
        if_return: false,
        screw_ie8: false, // <== doesn't work
    },
    output: {
        comments: /^!/,
        beautify: true
    }       

};

UglifyJs.minify(code, options).code;

(In 2.7.0) Toggling the screw_ie8 option produces this output on both occasions:

bad = function(n) {
    return function(t) {
        try {
            n();
        } catch (n) {
            t(n);
        }
    };
};

What I'm expecting is (2.6.4):

bad = function(n) {
    return function(n) {
        try {
            t();
        } catch (t) {
            n(t);
        }
    };
};

Maybe I'm misusing the API, but this option does not work in the current configuration.

@kzc
Copy link
Contributor

kzc commented Jul 17, 2016

Adapted from: #1201 (comment)

cat ug.js

function ug(src, screw_ie8) {
    console.log("\n// screw_ie8 =", screw_ie8);
    console.log(U.minify(src, {
        fromString: true,
        compress: { screw_ie8: screw_ie8 },
        mangle:   { screw_ie8: screw_ie8 },
        output:   { screw_ie8: screw_ie8, beautify: true },
    }).code);
}
var U = require('uglify-js');
var src = "bad=function(e){return function(error){try{e()}catch(e){error(e)}}};";
ug(src, true);
ug(src, false);

node ug.js

// screw_ie8 = true
bad = function(n) {
    return function(t) {
        try {
            n();
        } catch (n) {
            t(n);
        }
    };
};

// screw_ie8 = false
bad = function(n) {
    return function(n) {
        try {
            t();    // Edit: note incorrect code generated with screw_ie8 = false
        } catch (t) {
            n(t);
        }
    };
};

@qyoz
Copy link
Contributor Author

qyoz commented Jul 17, 2016

@kzc so I'm not the only one who was confused by this.
I don't mind updating the docs again (in this PR) but this API is just ugly. Is there a reason why its not merged into one option?

@kzc
Copy link
Contributor

kzc commented Jul 17, 2016

It's not a great API. You have to look at the bin/uglifyjs source code to find out what needs to be set. An additional top level screw_ie8 option for minify() that sets the options in compress, mangle and output would be good. Only set the lower level options if typeof top level screw_ie8 is "boolean" and the lower level options are not set (i.e., undefined). The old options must remain for backwards compatibility. keep_fnames has the exact same problem for compress and mangle. Might be other options with similar issues. Pull requests welcome.

@kzc
Copy link
Contributor

kzc commented Jul 17, 2016

@qyoz for keep_fnames - see: #1187 (comment) and #1210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants