Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Add initial methods draft for js parser visitor#113

Merged
OlegDokuka merged 2 commits intomainfrom
main-parser-visitor
Sep 24, 2024
Merged

Add initial methods draft for js parser visitor#113
OlegDokuka merged 2 commits intomainfrom
main-parser-visitor

Conversation

@OlegDokuka
Copy link
Copy Markdown
Contributor

No description provided.

@@ -1,2 +1,3 @@
export * from './markers';
export * from './visitor';
export * from './tree';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should instead require client code to separately import the tree module. I am still uncertain about this, but we can discuss this on our weekly sync. I also don't really like how the WebStorm IDE adds imports, which has probably also influenced how I feel about this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually index ts imports all required bits for external users. in JS world in is unconvinient to import from internal subdiricotires

Comment thread openrewrite/src/javascript/parser.ts Outdated
return new J.Unknown(randomId(), Space.EMPTY, Markers.EMPTY, new Source(randomId(), Space.EMPTY, Markers.EMPTY, node.getText()));
}

visitEndOfFileToken(node: ts.Node) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in assuming that this class is generated? If so, we should also add the generator to the Git repo somewhere, so that we can rerun it when necessary. To that end I propose a few changes:

  • Create an interface in a separate file, so that we can actually regenerate it
  • Onlt generate a visit method for Node subtypes. Specifically, I would probably only generate a visit method for those Node subtypes which have a corresponding create method in the NodeFactory interface
  • Change the parameter type to use the corresponding interface type. E.g. visitIdentifier(node: ts.Identifier)
  • I think it would probably also be good to make the Visitor interface generic and then have an additional parameter of that generic T type, which we can pass around.
  • Possibly we should also have a generic type parameter for the return type, which in our case would probably be J then. But unsure about that part.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not. I manually imported all possible methods

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove method that are not used after we start working on lst. all those methods are created based on all possible kinds of nodes (see ts.SyntaxKind for more info)

@OlegDokuka OlegDokuka marked this pull request as ready for review September 24, 2024 10:36
@OlegDokuka OlegDokuka merged commit b01563c into main Sep 24, 2024
@OlegDokuka OlegDokuka deleted the main-parser-visitor branch September 24, 2024 10:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants