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

transform-module-commonjs breaks this in private class property values by default #9856

Closed
coreyfarrell opened this Issue Apr 14, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@coreyfarrell
Copy link
Contributor

commented Apr 14, 2019

Bug Report

Current Behavior
@babel/plugin-transform-module-commonjs views private class properties as being in 'top-level' scope, replaces this with void 0. Issue found when testing code against node.js 12 which has native support for class properties.

Input Code
REPL

export class Example {
  notPrivate = this;
  #private = this;
}

Expected behavior/code
The value set to #private is not a "top-level this" so should be untouched by default, just as the value of notPrivate is untouched.

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

{
	"plugins": [
		"@babel/plugin-transform-modules-commonjs",
		"@babel/plugin-syntax-class-properties"
	]
}

Environment

  • Babel version(s): 7.4.3
  • Node/npm version: node 10.15.3, npm 6.4.1 / node v12.0.0-nightly20190411655c90b287, npm 6.9.0
  • OS: Fedora 28
  • Monorepo: no
  • How you are using Babel: tested with CLI, register and REPL.

Possible Solution
A work-around is to set allowTopLevelThis: true option to @babel/plugin-transform-modules-commonjs.

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Apr 14, 2019

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

@coreyfarrell

This comment has been minimized.

Copy link
Contributor Author

commented Apr 14, 2019

I found the cause of this in @babel/helper-module-transforms, created a fix and manually tested. I'm just working on adding automated tests before opening a PR.

coreyfarrell added a commit to coreyfarrell/babel that referenced this issue Apr 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.