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

AST type inconsistencies #1008

Open
deakjahn opened this issue Sep 23, 2022 · 0 comments
Open

AST type inconsistencies #1008

deakjahn opened this issue Sep 23, 2022 · 0 comments

Comments

@deakjahn
Copy link

deakjahn commented Sep 23, 2022

I encountered the following source discrepancies while moving my AST->PHP writer from any types to strict typing. They are tolerable in JavaScript but cause problems in a type safe TypeScript:

  • continue and break aren't consistent in their level, one uses a plain number while the other a Number extended from Node.
  • empty extends Expression and uses an expression property but it isn't actually defined as such (empty.js fails to mention the property, consequently, it isn't generated into types.d.ts).
  • isset is the same with the variables property,
  • print is the same with the expression property,
  • unset is the same with the variables property.
  • namedargument is lowercase, all other node types have PascalCase names.
  • String normally contains the whole string, with the appropriate quotes, as dictated by isDoubleQuote. However, EncapsedPart can also contain a String fragment and that has no quotes of its own. Although I can work around this, the perfectly correct solution would require either an isQuoted property for String or a new node type like EncapsedString to be used just here.
  • Repeated case labels are stored rather problematically, they are empty Case branches with no relation to the actual branch they belong to. They should be consolidated into a single Case instead, with a test property of Expression[] instead of a single expression.
  • Property and Constant both are supposed to have a name of simple type string. In reality, they receive an Identifier.
  • UseGroup defines an item property but actually populates one named items.
  • The type field of Function can be null, too.

And something not actually an error but a very needed, very small addition: Node should have a parent property and it should be populated when the AST is generated. It's of paramount importance for any tree manipulation. I can also work around this by using my additional union type and populating it during my own traversal but it would be a very cheap addition to the core.

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

1 participant