0

working on a project in which user writes some javascript code, i just need the syntax error if exists in user's code but don't want to execute the code..Is there any library exists or solution exists in c#?

4
  • 2
    Have you done a google search? Have you tried anything out? Unfortunately this isn't a question for Stack Overflow Commented Jun 27, 2016 at 9:55
  • Can this help you? Commented Jun 27, 2016 at 9:57
  • tried alot but could'nt find the exact solution. Commented Jun 27, 2016 at 9:57
  • Thanks codroipa,but this is executing the script i just want to get syntax error of code Commented Jun 27, 2016 at 9:59

1 Answer 1

1

You can use Jint. It can parse and execute JavaScript. We are interested in parsing, so we can do:

static void Main(string[] args)
{
    try
    {
        var validCode   = "alert('Hello World!');";
        var invalidCode = "alert['Hello World!');";
        var jsParser = new JavaScriptParser();
        var result = jsParser.Parse(validCode);
        result = jsParser.Parse(invalidCode); //Will throw...
    }
    catch (Exception ex)
    {
        //Invalid input!!
    }
}
Sign up to request clarification or add additional context in comments.

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.