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

ES6+ to ES5 transpilation should disallow get name() and set name() properties #2833

Open
patstuart opened this issue Mar 1, 2018 · 3 comments
Assignees

Comments

@patstuart
Copy link

patstuart commented Mar 1, 2018

Take the following example:

class Foo {
    get name() {
        return "bar";
    }
}

This transpiles to: (link)

var Foo=function(){};
$jscomp.global.Object.defineProperties(Foo , {
    name: {
        configurable: !0,
        enumerable: !0,
        get: function() {
            return "bar"
        }
    }
});

This is technically incorrect ES5, since the name property is not supposed to be configurable. According to this, this might break PhantomJs. We found this issue internally after a Safari 9 iPad threw the following error:
TypeError: Attempting to change configurable attribute of unconfigurable property. (I could not reproduce this error outside of our testing environment, so I'm guessing this is a browser quirk).

@MatrixFrog
Copy link
Contributor

Hm, maybe we just misread the spec. If we transpile to configurable: false instead of configurable: true then would that be correct?

@patstuart
Copy link
Author

@MatrixFrog Well I'm less of an expert than you, but I wouldn't think that would work, since the Function.name is already set and not configurable, and thus cannot be updated.

@MatrixFrog MatrixFrog self-assigned this Mar 5, 2018
@MatrixFrog
Copy link
Contributor

It looks like configurable: true is actually correct: Object.getOwnPropertyDescriptor({get name() { return 'name'; }}, 'name').configurable returns true. So I guess this is a bug in Safari, or in PhantomJS?

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

2 participants