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

Using a decorator breaks the enumerability of non-decorated fields #8760

Closed
mweststrate opened this issue Sep 24, 2018 · 2 comments · Fixed by #8761
Closed

Using a decorator breaks the enumerability of non-decorated fields #8760

mweststrate opened this issue Sep 24, 2018 · 2 comments · Fixed by #8761
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Decorators

Comments

@mweststrate
Copy link

v7 Regression

Potential Commit/PR that introduced the regression

Probably #7976, but didn't verify

Describe the regression

If @babel/plugin-proposal-class-properties is used to initialize a class field, the field becomes non-enumerable if there are decorators used in the same class. (Despite being applied to different fields)

  • This happens only when legacy: false is used for @babel/plugin-proposal-decorators (it succeeds in legacy mode)
  • This happens both when using loose and non-loose mode for proposal-class-properties
  • This does not happen in Babel 6

Input Code
(Could not verify in Repl as it still uses babel 6)

    class Todo1 {
        id = 1
    }

    function dec(el) {
        return el
    }
    class Todo2 {
        id = 1;
        @dec x
    }

    const t1 = new Todo1()
    expect(Object.getOwnPropertyDescriptor(t1, "id").enumerable).toBe(true)

    const t2 = new Todo2()
    expect(Object.getOwnPropertyDescriptor(t2, "id").enumerable).toBe(true) // this test fails, just by introducing the unrelated `@dec x` field

Babel Configuration (.babelrc, package.json, cli command)

{
    "presets": ["@babel/preset-env"],
    "plugins": [
        ["@babel/plugin-proposal-decorators", { "legacy": false, "decoratorsBeforeExport": true }],
        ["@babel/plugin-proposal-class-properties", { "loose": true }]
    ]
}

Expected behavior/code
A clear and concise description of what you expected to happen (or code).

Environment

  • Babel version(s): [7.1.0]
  • Node/npm version: [8.11.3]
  • OS: [Ubuntu]
  • Monorepo [no]
  • How you are using Babel: [babel-jest]
@babel-bot
Copy link
Collaborator

Hey @mweststrate! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@mweststrate
Copy link
Author

Thanks @nicolo-ribaudo!

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 25, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Dec 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Decorators
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants