Coder Social home page Coder Social logo

js-analyze's Introduction

JS-Analyze

Javascript code analyzer project for Khan Academy

Install

npm install
bower install
grunt

after running those you can open up build/index.html and try it out. REFRESH the page for different trials!!

Why Esprima?

So when I first read the problem I looked at both Acorn, and Esprima. I thought Acorn was a much better choice: It's faster, and smaller. I did not like Acorn's documentation however, and considering how short the parse strings will be the performance increase will hardly make a difference. Esprima has a wider contributor base than Acorn so I expect it to get faster over time anyway ( among more features and less bugs ). Also Esprima has good browser support.

How it works

Create an analyzer object ( Coffee Script )

analyzer = new Analyzer

Add whatever you would like to the whitelist or blacklist. Here are some examples:

# Must have an if statement
analyzer.whitelist.add '{ "if":{} }'
# Must have an if statement, and must NOT have a while loop
analyzer.whitelist.add '{ "if":{} }'
analyzer.blacklist.add '{ "while":{} }'
# Must have triple nested if statements, and a while loop containing a for loop
# Also must NOT have any if statements containing while loops
analyzer.whitelist.add '{ "if":{"if":{"if":{}}} }'
analyzer.whitelist.add '{ "while":{"for":{}} }'
analyzer.blacklist.add '{ "if":{"while":{}} }'

Once you have your lists set up, check them against an esprima AST

editor = ace.edit "editor"
ast = esprima.parse editor.getValue()
# Make sure the AST is valid...
analyzer.verify ast

Please see the unit tests for more examples.

Limitations

Currently you cannot look for statements like "two if statements one after another", this is because I don't prune them from the AST leads

js-analyze's People

Contributors

newbrict avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.