-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Missing referencePaths after crawl #10896
Comments
Hey @regiontog! 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." |
Hi @regiontog, thanks for your report! This issue comes from how babel registers bindings for the id of ClassDeclaration babel/packages/babel-traverse/src/scope/index.js Lines 134 to 140 in 09cb427
As you can see the Now let's take a look at your example const path = getPath("class a { build() { return new a(); } }");
path.scope.crawl(); Before crawling, the binding
Keep in mind that
But We can walk up from |
@JLHwung sidenote, fantastic explanation :) |
I'll close my old issue #9327 as a duplicate. |
friendly ping @regiontog, let me know if you are working on this. Should you have questions on developing a fix, please ask in the |
Thanks, I've been busy this week, but I was planning on taking a look tomorrow since I have the day off. I don't mind if someone else wants to take a look either. |
@JLHwung You were right, the fix is exactly as you suggested. The only thing that is not entirely clear to me is when the parent scope gets the Nevertheless my test passes now, I'll check if the bug in parcel is resolved by the same change. I can submit a PR with the fix and the test if you guys are ok with the change. Edit: https://github.com/regiontog/parcel2-bug builds fine with this fix applied to babel. |
The parent scope will get the babel/packages/babel-traverse/src/scope/index.js Lines 62 to 75 in 09cb427
ClassDeclaration is also Declaration . Its parent scope will be registered with newly created binding info.
Looking into this code I think it maybe more clear to merge |
My only problem with the current approach that it presumably depends on the |
The
I admit that this is too subtle and essentially the object keys are unordered. So here we are on the same page. I propose to merge the Declaration(path) {
// register binding on parent scope
// ...
// register class identifier binding in class scope
if (t.isClassDeclaration(path)) {
// ...
}
} and then we don't have to worry about the execution order of |
* Bug replication test * Simplify test * Fixes #10896 * Merge path.crawl `ClassDeclaration` and `Declaration` visitors Merged to avoid subtle assumption that `Declaration` is called before `ClassDeclaration` * Move registartion of class id in crawl to BlockScoped * Add some assertions to crawl test
Bug Report
Current Behavior
scope.crawl()
does not add references to bindings correctly in some cases. In particular I get the bug when referencing a class inside a class method.Input Code
regiontog/babel@master...bug/missing-references-after-crawl
Expected behavior/code
I expect the binding
a
to have 1 reference inside the scope of thebuild
class method after acrawl
. The binding has 1 reference before thecrawl
call is made.Environment
Possible Solution
It seems suspect to me to add the reference to a binding in the references own scope here
Additional context/Screenshots
Output of test linked above:
The text was updated successfully, but these errors were encountered: