parcel: V2: Scope Hoisting Static Class Property not Working

šŸ› bug report

When using a static class property within the class itself or outside/ in another file, the reference to its class is not renamed properly.

šŸŽ› Configuration (.babelrc, package.json, cli command)

.babelrc

{
  "plugins": [
    ["@babel/plugin-proposal-class-properties", { "loose": true }]
  ]
}

package.json

{
  ...
  "browserslist": ["last 2 Chrome versions", "last 2 Firefox versions"],
  ...
}

šŸ¤” Expected Behavior

Should rename static properties within classes properly.

😯 Current Behavior

Does not rename static property which results in Uncaught ReferenceError: $c4ee6a119cd77881a886bf5cd2629a0$var$A is not defined at runtime.

šŸ’» Code Sample

index.js

class A {
  static getTest = () => 'test';

  render() {
    return A.getTest;
  }
}

const a = new A();
a.render();
parcel build index.js

dist/index.js

!function(){class e{render(){return $c4ee6a119cd77881a886bf5cd2629a0$var$A.getTest}}e.getTest=()=>"test",(new e).render()}();

šŸŒ Your Environment

Software Version(s)
Parcel v2 (eedc965377940034cf78a026d581f12098df724e)
Node v12.8.1
npm v6.11.2
Operating System Windows 10/ WSL

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 17 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Checked it now as well. I see the same as @regiontog with the latest v2 branch of Parcel, even though it installs @babel/traverse@7.8.3 for me. After updating the yarn.lock by hand it works like a charm!

@mischnic Just ran the version without mangling again and checked the dist file, it contains a lot of variables like $ea4db19cc89d54676751edeac66eb44$var$SHARED even though the file is minified, so I guess the renaming is not working!?

Do I need to activate this somewhere else?

@garthenweb I’m happy we already have a fix en route, this is great! Thank you! 😃

@flisboac thanks for the investigation! As far as I understand this was a bug in Babel which should be solved, but we are waiting for the next release, v7.8.4.

See https://github.com/babel/babel/pull/11011#pullrequestreview-343235268