Terser: Computed properties results incorrect code evaluating in Safari

Created on 18 Feb 2019  路  3Comments  路  Source: terser/terser

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

Most helpful comment

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

All 3 comments

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

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

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.

Was this page helpful?
0 / 5 - 0 ratings