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

Fix node name for TS parser #102

Closed
5 tasks done
ArnaudBarre opened this issue Nov 21, 2024 · 1 comment
Closed
5 tasks done

Fix node name for TS parser #102

ArnaudBarre opened this issue Nov 21, 2024 · 1 comment

Comments

@ArnaudBarre
Copy link
Contributor

ArnaudBarre commented Nov 21, 2024

Describe the bug

Thank you so much for this tool!

Because TS have some markers on SyntaxKind like FirstStatement and LastStatement to allow people to check if a syntax kind is a statement by checking if the value is in that range, doing SyntaxKind[node.kind] will give the marker name for node that are a boundary.

This is because all boundaries are at the end of the enum

I worked around in a project by keeping only the first value like this:

const syntaxKinds = {} as Record<SyntaxKind, string>;
for (const [key, value] of Object.entries(SyntaxKind)) {
  if (typeof value === "number" && !syntaxKinds[value]) {
    syntaxKinds[value] = key;
  }
}

Then replace SyntaxKind[node.kind] by syntaxKinds[node.kind]

I think adding this to [this file])(

return this.SyntaxKind[kind]
) should do the trick?

Reproduction

https://ast.sxzz.moe/#eNo9yLEKgCAQBuBXOf65oTWj12hyOUTEkFPUghDfvZtav4EEg4sfbq7G0rGgKPS3+B+cgsvSOjEdtO5KWWlYIbJILOHm4E9fW8xiYWjbrEzMD0YPHQ8=

System Info

Chrome

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@sxzz sxzz closed this as completed in 90b634e Nov 21, 2024
@sxzz
Copy link
Owner

sxzz commented Nov 21, 2024

Thanks for your code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants