Combining Form and Function: Static Types for JQuery Programs
Benjamin S. Lerner, Liam Elberty, Jincheng Li, and Shriram Krishnamurthi
  author = {Benjamin S. Lerner and Liam Elberty and Jincheng Li
            and Shriram Krishnamurthi},
  title = {Combining Form and Function: Static Types for
           JQuery Programs},
  booktitle = {European Conference on Object-Oriented Programming 
  year = {2013},
  month = jul

The jQuery library defines a powerful query language for web applications’ scripts to interact with Web page content. This language is exposed as jQuery’s API, which is implemented to fail silently so that incorrect queries will not cause the program to halt. Since the correctness of a query depends on the structure of a page, discrepancies between the page’s actual structure and what the query expects will also result in failure, but with no error traces to indicate where the mismatch occurred. This work proposes a novel type system to statically detect jQuery errors. The type system extends Typed JavaScript with local structure about the page and with multiplicities about the structure of containers. Together, these two extensions allow us to track precisely which nodes are active in a jQuery object, with minimal programmer annotation effort. We evaluate this work by applying it to sample real-world jQuery programs.