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

Computed properties results incorrect code evaluating in Safari #272

Closed
otakustay opened this issue Feb 18, 2019 · 4 comments
Closed

Computed properties results incorrect code evaluating in Safari #272

otakustay opened this issue Feb 18, 2019 · 4 comments
Labels

Comments

@otakustay
Copy link

Bug report or Feature request?

Bug

Version (complete output of terser -V)

terser 3.16.1

Complete CLI command or minify() options used

terser --compress -- in.js

terser input

(function() {
    function f(o) {
        return {[o.key]: o};
    }
    function g(o) {
        return o;
    }
    var obj = {key: 'xyz'.slice(1, -1)};
    var result = g(f(obj));
    console.log(result);
})();

terser output or error

!function(){var o,obj={key:"xyz".slice(1,-1)},result=function(o){return o}({[(o=obj).key]:o});console.log(result)}();

Expected result

This output code can be correctly evaluated in chrome 71.0.3578.98 which results:

{"y": {"key": "y"}}

image

In safari 12.0.2 (14606.3.4) it behaves incorrectly:

{"y": undefined}

image

It seems not safe to compress computed property key like this

@LeuisKen
Copy link

I run the following code in these browsers:

({[(console.log(1), 'x')]: (console.log(2), 1)})

In Chrome 72.0.3626.109 gets:

image

and Safari 12.0 (14606.1.36.1.9) gets:

image

@otakustay
Copy link
Author

I know this is actually a BUG of safari, however code introduced by tools like terser are unpredictable and hard to find root cause, it's better to avoid known compatibility issues in major browsers

@fabiosantoscode
Copy link
Collaborator

I think we can piggy-back on the options we already have for Safari 10/11 on this.

We also need to enable these options by default as Safari has a lot of usage. I don't think it's reasonable for Terser to produce code that fails on a very used browser that people don't test their code on enough.

@jridgewell jridgewell added the bug label Sep 7, 2021
@fabiosantoscode
Copy link
Collaborator

I'm preventing this inline step on all browsers. I suspect it'll have a small impact on output size.

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

No branches or pull requests

4 participants