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

Refactor code parser to ast from regex #43

Merged

Conversation

roypeled
Copy link
Collaborator

@roypeled roypeled commented Jul 4, 2024

The regex parsing engine was not handling compiled code correctly, it would extract malformed tokens when self invoked functions and compiled imported modules were introduced in the code ((0, imported)(arg)).

I used babel's parser to parse the code string and traversed the AST to extract functions and method names.

Several other changes had to be made, since the Regex parser did not rely on valid code, it could handle parts of complete code to extract information.
This is no longer valid, so I had to change the way ObjectPropertyCodeRetriever works:
It used to get object and property, and extract the code for that property. Since the only usage was when iterating over an object's fields, and only the functions were necessary, I changed it to return a functional mock class with all the required properties.
I changed the tests to match this scenario.

…rk well in all cases, implemented JS parser and AST traversing to better handle code
@LironHazan
Copy link
Collaborator

@roypeled Thanks that's a great contribution and the way to go IMO, we had an older thread about the need of having a parser.

Copy link
Collaborator

@LironHazan LironHazan left a comment

Choose a reason for hiding this comment

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

LGTM

@roypeled
Copy link
Collaborator Author

roypeled commented Jul 7, 2024

Hey @cspotcode, just wanted to get your input before we merge and publish a new version with the babel parser!

@roypeled roypeled merged commit bc819e4 into TypeStrong:master Jul 11, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

3 participants