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

[Bug]: Parameter decorator (legacy mode) is not transpiled when there's also a method decorator #14292

Open
1 task
kobiburnley opened this issue Feb 21, 2022 · 3 comments

Comments

@kobiburnley
Copy link

kobiburnley commented Feb 21, 2022

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

const { Controller, GET, POST, BodyParam, UrlParam } = { };

@Controller('/api')
class DemoController {
  @POST
  async events(@BodyParam body) {
    return body;
  }
}

Configuration file name

No response

Configuration

repl - need to change decorators version to "legacy"

Current and expected behavior

Current behavior - output still contains the parameter decorator @BodyParam:
Expected behavior - parameter decorator should be transpiled

"use strict";

var _dec, _class, _class2;

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }

const {
  Controller,
  GET,
  POST,
  BodyParam,
  UrlParam
} = {};
let DemoController = (_dec = Controller('/api'), _dec(_class = (_class2 = class DemoController {
  async events(@BodyParam
  body) {
    return body;
  }

}, (_applyDecoratedDescriptor(_class2.prototype, "events", [POST], Object.getOwnPropertyDescriptor(_class2.prototype, "events"), _class2.prototype)), _class2)) || _class);

Environment

System:
OS: macOS 10.15.7
Binaries:
Node: 14.15.4 - /var/folders/g_/lf5b_ch11fgdwmbg3s90jxt80000gn/T/fnm-shell-1243492/bin/node
Yarn: 1.22.17 - /var/folders/g_/lf5b_ch11fgdwmbg3s90jxt80000gn/T/fnm-shell-1243492/bin/yarn
npm: 6.14.10 - /var/folders/g_/lf5b_ch11fgdwmbg3s90jxt80000gn/T/fnm-shell-1243492/bin/npm

Possible solution

No response

Additional context

No response

@babel-bot
Copy link
Collaborator

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

@kobiburnley kobiburnley changed the title [Bug]: Parameter decorator (legacy mode) is not transpiled when there's also a function decorator [Bug]: Parameter decorator (legacy mode) is not transpiled when there's also a method decorator Feb 21, 2022
@Yokubjon-J
Copy link
Contributor

Yokubjon-J commented Mar 15, 2022

how can babel know whether it should transpile to legacy or current mode? do we need a config file for it?

@nicolo-ribaudo
Copy link
Member

Yes, you must pass a "version" option to @babel/plugin-proposal-decorators.

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

No branches or pull requests

4 participants