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

Provide AST count information without a separate visitor pass #9401

Open
DavidHancu opened this issue Aug 8, 2024 · 2 comments
Open

Provide AST count information without a separate visitor pass #9401

DavidHancu opened this issue Aug 8, 2024 · 2 comments

Comments

@DavidHancu
Copy link

DavidHancu commented Aug 8, 2024

Describe the feature

When implementing a library that builds on top of SWC, we need to generate intermediary representations. This probably includes HashMaps or Vecs, which can benefit from a performance increase when initialized with the right capacity.

SWC should provide at least the following counts:

  • node count (a count for all AST nodes)
  • definition count (a count for all definitions, like functions and classes)
  • export count (a count for all export specifiers)

Babel plugin or link to the feature description

No response

Additional context

This should not be implemented as a separate pass because it would be wasteful. This should be implemented at the parser level and I'm willing to contribute this.

@kdy1
Copy link
Member

kdy1 commented Aug 9, 2024

I think this is a good idea, but I'm not sure where we should store the metadata, and I'm not sure about the API, either.

@DavidHancu
Copy link
Author

DavidHancu commented Aug 9, 2024

I think that a new function on the Parser could do: parse_module_with_metadata. This would return a struct with a Module field and a Metadata field. In the parser implementation, this would use a const boolean generic to ensure that the compiler optimizes the metadata creation out if it wasn't requested

@magic-akari magic-akari mentioned this issue Aug 12, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants