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

traverse/scope: explicit scope.crawl() misses referencePath #9327

Closed
mischnic opened this issue Jan 13, 2019 · 1 comment
Closed

traverse/scope: explicit scope.crawl() misses referencePath #9327

mischnic opened this issue Jan 13, 2019 · 1 comment
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@mischnic
Copy link
Contributor

mischnic commented Jan 13, 2019

Bug Report

Current Behavior
Running path.scope.crawl() removes a reference to a class when it is used in the class body itself.
The reference is correctly listed in getBinding().referencePath when crawl() isn't called.

Input Code
https://astexplorer.net/#/gist/e3682e9577f38305e86fb2e13d87246f/a285511da5ad7370d42a3ac87f23e2441c657a68

class Foo {
    copy() {
        return new Foo();
    }
}

new Foo();

visitor:

{
  Program(path) {
    path.scope.crawl();
    
    const binding = path.scope.getBinding("Foo");
    
    binding.referencePaths.forEach(p =>
      p.node.name = "XXX"
    );
  }
}

Output

class Foo {
  copy() {
    return new Foo(); // <---- should be XXX as well
  }}


new XXX();

Expected behavior/code
The reference to the class should exist in scope.getBinding().referencePaths.

Environment

  • Babel version(s): 7.2.2
  • Node/npm version: Node 11
  • OS: macOS

Additional context/Screenshots
Causes a bug in Parcel's scope hoisting code: parcel-bundler/parcel#2513.

@babel-bot
Copy link
Collaborator

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

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Apr 12, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

2 participants