question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

V2: Scope Hoisting Static Class Property not Working

See original GitHub issue

🐛 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

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
garthenwebcommented, Jan 30, 2020

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!

2reactions
garthenwebcommented, Oct 26, 2019

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scope hoisting
This is called "scope hoisting". Parcel also statically analyzes the imports and exports of each module, and removes everything that isn't used.
Read more >
Why are ES6 classes not hoisted? - javascript
This is a problem for static properties, prototype mixins, decorators and everything. Also it is quite important for subclassing, which broke entirely in ......
Read more >
Static initialization blocks - JavaScript - MDN Web Docs
Static initialization blocks are a special feature of a class that enable ... are local to the block, any var declarations in the...
Read more >
JavaScript Hoisting
JavaScript Initializations are Not Hoisted. JavaScript only hoists declarations, not initializations. Example 1 does not give the same result as Example 2: ...
Read more >
Variable scope - Manual
A static variable exists only in a local function scope, but it does not lose ... static variables in methods now behave the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found