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: Constructor property shorthand not perserved with @babel/preset-env #8669

Closed
Retsam opened this Issue Sep 11, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@Retsam
Contributor

Retsam commented Sep 11, 2018

Bug Report

Current Behavior
When @babel/babel-preset-typescript is used with @babel/babel-preset-env, constructor shorthand properties (e.g. constructor(public someProp: type)) are not preserved in the output.

Input Code

  • REPL or Repo link if applicable: (I don't think the repl currently supports 7.0)
class Person {
    constructor(public name: string) {}
}

Expected behavior/code

This should compile to something like:

var Person = function Person(name) {
    _classCallCheck(this, Person);
    this.name = name;
}

instead, it compiles to

var Person = function Person(name) {
  _classCallCheck(this, Person);
};

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

{
    "presets": [
        // {modules: false}, only for cleaner output, does not affect bug
        ["@babel/preset-env", {"modules": false}],
        "@babel/preset-typescript"
    ]
}

Environment

  • Babel version(s): 7.0.0
  • Node/npm version: Node 8/npm 6
  • OS: OSX 10.13.6
  • Monorepo: ? (Not sure what this is asking)
  • How you are using Babel: cli & loader

Additional context/Screenshots
I've noticed this only happens when it's compiled with both the presets at the same time: if I compile it with the typescript preset first, then take the output and compile that with preset-env, I get the correct output.

@babel-bot

This comment has been minimized.

Show comment
Hide comment
@babel-bot

babel-bot Sep 11, 2018

Collaborator

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

Collaborator

babel-bot commented Sep 11, 2018

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

@babel babel deleted a comment from ajozwik Sep 11, 2018

@Retsam

This comment has been minimized.

Show comment
Hide comment
@Retsam

Retsam Sep 11, 2018

Contributor

I did a bit more digging, and this .babelrc also reproduces the issue:

{
    "presets": [
        "@babel/preset-typescript"
    ],
    "plugins": [
        "@babel/transform-classes"
    ]
}
Contributor

Retsam commented Sep 11, 2018

I did a bit more digging, and this .babelrc also reproduces the issue:

{
    "presets": [
        "@babel/preset-typescript"
    ],
    "plugins": [
        "@babel/transform-classes"
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment