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

Double whammy issue: new parcel can't hit targets and gets confused by calling a function #get #6282

Closed
danieltroger opened this issue May 13, 2021 · 3 comments · Fixed by #6289

Comments

@danieltroger
Copy link
Contributor

🐛 bug report

I was able to create simple input code which makes double wrong output!

  1. SWC thinks newest firefox supports private class fields which it does not
  2. Parcel produces invalid output both when running parcel serve and parcel build if a class contains a private method called #get.

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

Please see attached .zip file

Sample code

class myclass {
  #get(){
    console.log("Hi from a method with a private identifier called #get");
  }
  constructor(){
    this.#get();
  }
}

const instance = new myclass();

🤔 Expected Behavior

The same (or identically behaving) output as good old 2.0.0-nightly.650+dc79abcd gives me:

! function() {
  var t = 0;

  function e(e) {
    return "__private_" + t++ + "_" + e
  }
  var r = e("get");

  function n() {
    console.log("Hi from a method with a private identifier called #get")
  }
  new class {
    constructor() {
      Object.defineProperty(this, r, {
        value: n
      }), ((t, e) => {
        if (!Object.prototype.hasOwnProperty.call(t, e)) throw new TypeError("attempted to use private field on non-instance");
        return t
      })(this, r)[r]()
    }
  }
}();

-> logs Hi from a method with a private identifier called #get to the console when ran

😯 Current Behavior

new class {
  #get() {
    console.log("Hi from a method with a private identifier called #get")
  }
  constructor() {
    (function(t, e) {
      if (!e.has(t)) throw new TypeError("attempted to get private field on non-instance");
      return e.get(t).value
    })(this, _get).call(this)
  }
};

In firefox (which was my build target) -> Uncaught SyntaxError: private fields are not currently supported
In chrome: VM450:9 Uncaught ReferenceError: _get is not defined

💁 Possible Solution

Make it work correctly like it did before.

🔦 Context

I was, after already reporting multiple issues with the new SWC thing just by trying to use it and read the code, finally daring to run just a portion of the output code and it failed lol.

💻 Code Sample

parcel-hashtag-get.zip

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.660+177f8eec
Node v16.1.0
npm/Yarn yarn 1.22.10
Operating System macOS 10.15.7 (19H1030)
@mischnic
Copy link
Member

See swc-project/swc#1694.

I think that swc does realize that Firefox 88 doesn't support them (because this.#get(); is indeed transpiled), and the declaration #get() { ... } is just not transpiled for some reason.

@danieltroger
Copy link
Contributor Author

@mischnic it seems to work now I think

@danieltroger
Copy link
Contributor Author

WTF, now it doesn't work?? I swear it worked yesterday lol. I tried it on my actual code now and it still contained a bunch of hashtags

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

Successfully merging a pull request may close this issue.

2 participants