Skip to content

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

@jezzgoodwin

Description

@jezzgoodwin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions