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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: decorators are broken and when applied, they override the preceding value. #16198

Closed
1 task
amirmohsen opened this issue Dec 30, 2023 · 2 comments 路 Fixed by #16199
Closed
1 task

[Bug]: decorators are broken and when applied, they override the preceding value. #16198

amirmohsen opened this issue Dec 30, 2023 · 2 comments 路 Fixed by #16199
Assignees
Labels
i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Decorators

Comments

@amirmohsen
Copy link

馃捇

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

I've created a test repo with a basic example here. You can also see it below:

function decorateA(target) {
  return class extends target {
    a() {
      console.log("a");
    }
  };
}

function decorateB(target) {
  return class extends target {
    b() {
      console.log("b");
    }
  };
}

@decorateB
@decorateA
class Target {}

const target = new Target();

target.b();

target.a(); // This throws an error: TypeError: target.a is not a function

I only checked class decorators. This bug may exist for function decorators as well but I haven't checked.

Configuration file name

No response

Configuration

module.exports = (api) => {
  api.cache(true);
  return {
    presets: [
      [
        "@babel/preset-env",
        {
          modules: false,
          targets: {
            node: 20,
          },
        },
      ],
    ],
    plugins: [["@babel/plugin-proposal-decorators", { version: "2023-05" }]],
  };
};

Current and expected behavior

Instead of passing the result of one decorator to the next, the original value of the Target class gets passed to each decorator and as a result, the last applied decorator result overrides the preceding ones.

Environment

Babel package versions:

"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.7",
"@babel/plugin-proposal-decorators": "^7.23.7",
"@babel/preset-env": "^7.23.7",

Node: 20.9.0
NPM: 10.1.0
Yarn: 1.22.19
Environment: Ubuntu 20.04.4 LTS (WSL2 on Windows)

Possible solution

No response

Additional context

This is a recent bug because I have a project that is using Babel version 7.23.2 and it's working fine. However, the bug doesn't seem to originate in Babel itself because simply reverting to an older version of the packages, doesn't fix anything. I think the problem might originate in a sub-dependency. I haven't had time to investigate further though.

@babel-bot
Copy link
Collaborator

Hey @amirmohsen! 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.

@liuxingbaoyu
Copy link
Member

Thank you for your report!
This is a regression for us, fixed in #16199.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Apr 4, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: regression 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