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

[TypeScript] Parameter decorators in constructors with public/private modifier removes imports #9838

Open
jezzgoodwin opened this Issue Apr 9, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@jezzgoodwin
Copy link

commented Apr 9, 2019

Bug Report

Current Behavior
When using parameter decorators in class constructors combined with the public or private keyword, Babel loses the import information.

If public/private is not used, it works correctly.

This is a similar issue to #8634 but specifically regarding the use of public/private.

Input Code

import { inject } from "./inject";
import { UserService } from "./UserService";

export class Store {
    constructor(@inject(UserService) private userService: UserService) {}
}

Expected behavior/code
I would expect an output along the lines of:

Object(_includes__WEBPACK_IMPORTED_MODULE_1__["inject"])(_PageStore__WEBPACK_IMPORTED_MODULE_2__["UserService"])(Store.prototype, "", 0);

But what I get is:

inject(UserService)(Store.prototype, "", 0);

Which doesn't work because inject and UserService aren't valid variables.

Babel Configuration

.babelrc

{
	"presets": [
		"@babel/preset-typescript",
		"@babel/react"
	],
	"plugins": [
		["@babel/proposal-decorators", { "legacy": true }],
		["@babel/proposal-class-properties", { "loose": true }],
		"./parameterDecorator.js" // plugin to add calls to parameter decorators: https://github.com/WarnerHooh/babel-plugin-parameter-decorator
	]
}

Environment

  • Babel version: 7.4.3
  • Node/npm version: Node 11.10.0, npm 6.7.0
  • OS: Windows 10
  • How you are using Babel: WebPack
@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Apr 9, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.