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 throws when a PrivateName matches an import name. #9859

Closed
coreyfarrell opened this Issue Apr 14, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@coreyfarrell
Copy link
Contributor

commented Apr 14, 2019

Bug Report

Current Behavior
TypeError: Property id of PrivateName expected node to be of a type ["Identifier"] but instead got "MemberExpression"

Input Code
REPL

import {test1, test2, test3} from './anywhere';

export class Example {
  #test1 = test1;
  #test2() { return test2}
  get #test3() { return test3; }
}

In this example each of these private declarations can independently cause the error.

Expected behavior/code
PrivateName's should not be seen by the ReferencedIdentifier visitor method.

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
Return false for parent.type === 'PrivateName' from @babel/types/src/validators/isReferenced.js

I have a commit prepared locally including a test, this commit is a followup to #9857 (due to sharing the new test fixture directory). I'm very confident about what I've already posted to #9857, I don't want to add to that commit without feedback on my proposed fix.

Interesting note https://github.com/babel/babel/blob/master/packages/babel-helper-module-transforms/src/rewrite-live-references.js#L83-L88 has code to skip ClassProperty and Function paths, though I think this is ineffective and unneeded (these paths do not hit the ReferencedIdentifier visitor method even if path.skip is removed).

@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 added a commit to coreyfarrell/babel that referenced this issue Apr 15, 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.