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

Neat feature of typescript classes I don't know the name of is broken #7313

Closed
danieltroger opened this issue Nov 16, 2021 · 3 comments
Closed
Labels
Babel 鉁栵笍 Non-Parcel bug Bugs related to dependencies or plugins

Comments

@danieltroger
Copy link
Contributor

馃悰 bug report

So if you write private or public next to a constructor argument in typescript classes that apparently automatically makes it say this.argname = argname (how is this feature called??) however with a special concoction of config files that I happen to use, parcel breaks this feature.

It has something to do with babel as it doesn't happen when using swc with parcel, but I can't reproduce it with the babel REPL either which is why I put it here. Maybe it has to do with @parcel/babel-preset-env?

馃帥 Configuration (.babelrc, package.json, cli command)

Pls see attached .zip file. Target needs to be ie 11 and babel config file looks like this:

module.exports = {
  presets: ["@babel/preset-typescript", "@parcel/babel-preset-env"]
};

馃 Expected Behavior

馃憖 and then 4 is logged to the console.

馃槸 Current Behavior

undefined and then undefined is logged to the console.

馃拋 Possible Solution

Make so that it works correctly.

馃敠 Context

Figured out that my compatibility builds of sentry.io have been broken for months. Dived into it and this seems to be the issue, since they use this syntax/typescript feature and the code relying on it breaks.

馃捇 Code Sample

Run yarn install and then yarn build:

parcel_messed_up_classes.zip

The code:

const API_VERSION = 4;

class Bruh {
  public a_method(): void {
    console.log(this._version);
  }
  public constructor(
    public options: string,
    private readonly _version: number = API_VERSION
  ) {
    console.log(this.options);
  }
}
var instance = new Bruh("馃憖");
instance.a_method();

馃實 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.912+145bfb82
Node v17.0.1
npm/Yarn 3.1.0
Operating System macOS 10.15.7 (19H1419)
@mischnic
Copy link
Member

Transpiling it in your project using yarn babel index.ts -o index.js also produces a file that prints undefined twice. So this is a Babel bug.

It seems to ignore the public/private:

  function Bruh(options, _version = API_VERSION) {
    _classCallCheck(this, Bruh);

    console.log(this.options);
  }

Can you open a Babel issue for this?

@mischnic mischnic added 鉁栵笍 Non-Parcel bug Bugs related to dependencies or plugins Babel labels Nov 16, 2021
@mischnic
Copy link
Member

Also, they're apparently called parameter properties: https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties

@danieltroger
Copy link
Contributor Author

FML it's a feature or something, when changing the order of "@babel/preset-typescript", "@parcel/babel-preset-env" it works 馃槴
see babel/babel#12066

Thanks for the help troubleshooting though.

Would it match the parcel philosophy to warn about something like this?

Also unrelated question, will parcel automatically update babel once babel/babel#13961 lands in a release or do I need to open an issue about it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Babel 鉁栵笍 Non-Parcel bug Bugs related to dependencies or plugins
Projects
None yet
Development

No branches or pull requests

2 participants