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

The scopes of traverse_mut are empty. #8087

Open
anguish-huihuang opened this issue Dec 24, 2024 · 2 comments
Open

The scopes of traverse_mut are empty. #8087

anguish-huihuang opened this issue Dec 24, 2024 · 2 comments
Labels
Docs-todo Docs - Docs need to be updated based on info in this issue

Comments

@anguish-huihuang
Copy link

I have defined a HandleVariableDeclaration structure and employed traverse_mut to iterate through the nodes in the program. Within the HandleVariableDeclaration structure, I used Traverse and created the enter_program function, where I defined two new structures. If I wish to continue traversing the nodes using either the traverse_mut_with_ctx method or the traverse_mut method, I need to extract scopes and symbols from ctx. This situation results in ctx.scoping() being empty within the HandleVariableDeclaration structure, and the scopes returned by the external traverse_mut are also empty. How can this issue be resolved?
微信图片_20241224110102
微信图片_20241224110055

@anguish-huihuang anguish-huihuang added the C-enhancement Category - New feature or request label Dec 24, 2024
@Boshen
Copy link
Member

Boshen commented Dec 24, 2024

You need to run oxc_semantic prior to traverse.

TODO:

  • update docs
  • better panic error message, preferably a debug_assert prior to` run.

@Boshen Boshen added Docs-todo Docs - Docs need to be updated based on info in this issue and removed C-enhancement Category - New feature or request labels Dec 24, 2024
@anguish-huihuang
Copy link
Author

Yes, I had run semantic analysis before executing Traverse, and the issue arises because in the enter_program method of the HandleVariableDeclaration structure, I extracted the scopes from ctx and assigned them to a new variable. This resulted in ctx.scopes being empty. The current solution is to convert ReusableTraverseCtx back into TraverseCtx and reassign it to ctx at the end. Is there perhaps a better method?
微信图片_20241224123454
微信图片_20241224123459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs-todo Docs - Docs need to be updated based on info in this issue
Projects
None yet
Development

No branches or pull requests

2 participants