KEMBAR78
Avoiding JavaScript Pitfalls Through Tree Hugging | PDF
Avoiding JavaScript Pitfalls
 Through Tree Hugging



        Zef Hemel (@zef)
JavaScript Developer
http://c9.io
we’re building
#1 JavaScript IDE
~400,000
Iterating using undeclared variable
Warning: you are in an anonymous inner function with its
 own “this” pointer -- ya sure this is what you mean?
Did you mean “length”?
How?
Unleash the
awesome power of...
tatic
X   tatic
program analysis
What
can you do with it?
code outlines
code completion (intellisense)
       code navigation

              ...
Parse




Analyze
Code   Parser   AST
Abstract Syntax Tree

                                Op




a * 10        Parser     “*”    Var   Num




                                “a”   “10”
Zeon                   Narcissus



              UglifyJS


language.js
                         Esprima
performance (speed/memory)



     AST datastructure



      traversal tools
i fi c
                        ec
                       p
   performance (speed/memory)

                     s
         i pt
        r
        AST datastructure


     S c
  v a    traversal tools

Ja
treehugger.js
“The JQuery of AST analysis.”
Standard AST Datastructure
Standard Traversals
        +
Pattern Matching
Op




a * 10   “*”   Var   Num




               “a”   “10”
Op



                   Op("*", Var("a"),
“*”   Var   Num            Num("10"))


      “a”   “10”
Op

                         ATerm
                   Op("*", Var("a"),
“*”   Var   Num             Num("10"))


      “a”   “10”
Constructors   Var(_)


Lists          [_, _]


Strings        "hello"


Placeholders   x
http://github.com/ajaxorg/treehugger
http://github.com/ajaxorg/treehugger




   http://c9.io   @zef    @cloud9ide

Avoiding JavaScript Pitfalls Through Tree Hugging