6

Not sure if the title explains it correctly.

Anyways, I'm building a .NET WPF application which should go through the JavaScript and identify issues such as

  1. If the variables defined are being nullified at the end
  2. If try/catch/finally blocks are being used.
  3. Function calls

I went through the questions over here which were all revolving around c/c++. Now I regret bunking my compilers classes.

I wanted to know how to verify points 1-3 in C#. Any library out there which does this?

5
  • Is there a question inside your posting? Commented Jan 16, 2013 at 10:14
  • 1
    Edited the question. Eg. I want to check in C#, if a variable defined in a JS function is being nullified or not. Commented Jan 16, 2013 at 10:20
  • 2
    I would suggest that you take a look at V8, the JavaScript engine of Google. There is a similar SO question (and answer) on how to use V8 from within C#/.NET. With this engine, you could compile your script and let it run, possibly seeing compiler warnings/errors. Commented Jan 16, 2013 at 10:35
  • BTW: Why do you consider "function calls" as being issues? I think function calls are a pretty good thing, actually! Commented Jan 16, 2013 at 10:38
  • Thanks for the link. I don't think it'll throw any warnings for the issues 1 and 2. And, by 3 I meant to write External Library Function calls. Commented Jan 16, 2013 at 10:53

2 Answers 2

5

What you're looking for is an abstract syntax tree parser for Javascript written in C#.

There are a few choices I know of:

Microsoft's Ajax Minifier library comes with its own AST parser (used to minify / optimize Javascript files). You can find the source code for that on GitHub.

Esprima.net is another option. It's a port of the popular Javascript library Esprima.

The good thing about Esprima is it outputs the AST in a common format (defined by Mozilla here) that's used across a few parsers, making it really easy to port utilities for walking the tree, etc. since they all use the same underlying data structure.

Sign up to request clarification or add additional context in comments.

Comments

3

Check out IronJS I know they have a pretty good JavaScript library for .Net

IronJS

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.