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

Validating JS Syntax #86

Open
oroojlooy opened this issue Jun 22, 2023 · 1 comment
Open

Validating JS Syntax #86

oroojlooy opened this issue Jun 22, 2023 · 1 comment

Comments

@oroojlooy
Copy link

I have bunch of JavaScript functions, all loaded in memory inside a python code, and I need to validate their syntax without writing them down in .js files.
I was looking for a python package that could perform this task for me, and found this package. I tried to use javascript package for my goal, but was not sure if there is any way that I could only check syntax with that in python.

P.S.: JSHint/prettier work OK if I write each function in a file and then call something like os.system("jshint --verbose sample.js"), but writing the js functions in file is expensive and takes a lot of time. So, looking for a method/package that can do the same without writing the codes in file.

@extremeheat
Copy link
Owner

extremeheat commented Jun 23, 2023

What you're looking for is a JavaScript AST parser library.

From a quick search, https://pypi.org/project/esprima/ is a native Python package on pip that can do the parsing.

If you want to use something from the JS side (that maybe more up to date/maintained), you can checkout the TypeScript AST parser, or use Babel's parser, with JSPyBridge usage demonstrated here:

https://github.com/MineDojo/Voyager/blob/01fb04666a8f3ba47dec74fb4cfd46e0125fe5a0/voyager/agents/action.py#L208-L213

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