Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Finding Variable References in Code Snippet

$
0
0
Hi,

I ended up finding out that Jint includes a parser that can do what I was looking for. Here is an example of how I used it:
List<string> itemRefs = new List<string>();
        JavaScriptParser jpParser = new JavaScriptParser();

        Program parsedJS = jpParser.Parse(formulaToEval, new ParserOptions { Comment = true, Source = formulaToEval, Tokens = true, Tolerant = true });

        foreach (Token jsToken in parsedJS.Tokens)
        {
            string tokenVal = jsToken.Value.ToString();

            if (jsToken.Type != Tokens.Identifier )
                continue;



            itemRefs.Add(tokenVal );
        }

        return itemRefs;

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>