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

Question: how to check javascript code syntax (or expression syntax)? #203

Open
lafar6502 opened this issue Feb 1, 2020 · 2 comments
Open
Labels

Comments

@lafar6502
Copy link

lafar6502 commented Feb 1, 2020

What is the best way to check if block of code is syntactically correct javascript? or if an expression is correct? Without providing all variables etc, just syntax check.

And as a bonus: when parsing, is it possible to identify names of variables that the code is referring to?

And another question: is it possible to provide values of unresolved variables via some callback function from C# (variableName => value)?

BTW i really like the performance of Nil.JS, it's insanely fast compared to even simple expression evaluators in .Net

@nilproject
Copy link
Owner

I think, the best way is using of Script.Parse with passing value for messageCallback (but be careful, some messages contains grammar mistakes due my mediocre knowledge of English language, corrections are welcome).

Yes, it's possible. Script.Parse returns root of AST of script. You can get all variables, all functions, everything. Also, all variables contains link to VariableDescriptor, which contains links to all instances of every variable.

Yes. You can make you own implementation of NiL.JS.Core.Context and override some methods. See NiL.JS.Core.WithContext for example

@deandob
Copy link

deandob commented Feb 23, 2020

An alternative if you are using a JavaScript editor like codemirror is that there are plugins that will check syntax and highlight these in the editor. It works well if this is how you are using Nil.JS

Also callout to nilproject for a reliable and fast JavaScript engine, its an important part of our solution and works well.

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

No branches or pull requests

3 participants