[Paper Review] JSClassFinder: A Tool to Detect Class-like Structures in JavaScript
JSClassFinder is a reengineering tool that detects class-like structures in JavaScript code using static analysis of the Abstract Syntax Tree (AST), enabling the creation of object-oriented models with UML diagrams, distribution maps, and standard metrics. It supports visualization and metric computation for legacy JavaScript systems lacking native class syntax, facilitating software analysis and future migration to ECMAScript 6.
With the increasing usage of JavaScript in web applications, there is a great demand to write JavaScript code that is reliable and maintainable. To achieve these goals, classes can be emulated in the current JavaScript standard version. In this paper, we propose a reengineering tool to identify such class-like structures and to create an object-oriented model based on JavaScript source code. The tool has a parser that loads the AST (Abstract Syntax Tree) of a JavaScript application to model its structure. It is also integrated with the Moose platform to provide powerful visualization, e.g., UML diagram and Distribution Maps, and well-known metric values for software analysis. We also provide some examples with real JavaScript applications to evaluate the tool.
Motivation & Objective
- To address the lack of tools that identify class-like structures in JavaScript, which is widely used but lacks native class syntax in ES5.
- To support software analysis of JavaScript systems by modeling object-oriented entities such as classes, methods, and attributes.
- To provide visual and metric-based insights into the structural organization of JavaScript applications through integration with the Moose platform.
- To enable reverse engineering of prototype-based inheritance patterns into formal class models for better maintainability.
- To support future migration to ECMAScript 6 by identifying patterns that align with the new class syntax.
Proposed method
- Parsing JavaScript source code into an AST using Esprima, then converting it into a JSON-formatted AST for analysis.
- Detecting class-like structures by identifying constructor functions that define properties and methods, and inferring prototype-based inheritance relationships.
- Constructing an object-oriented model from the AST by grouping attributes and methods under class-like entities based on naming and structural patterns.
- Integrating the resulting model with the Moose platform to enable UML class diagrams, distribution maps, and tree view visualizations.
- Computing standard software metrics such as number of classes (NOC), methods (NOM), attributes (NOA), and depth of inheritance tree (DIT).
- Supporting user interaction via a Pharo-based interface to load, visualize, and navigate the model with customizable visual and metric filters.
Experimental results
Research questions
- RQ1How can class-like structures be automatically detected in JavaScript code that lacks native class syntax in ES5?
- RQ2To what extent can prototype-based inheritance patterns be reverse-engineered into formal class models?
- RQ3How effective is the tool in identifying and visualizing object-oriented structures in real-world JavaScript applications?
- RQ4What metrics and visualizations can enhance the understanding of the structural organization of JavaScript systems?
- RQ5How can the tool support the migration of legacy JavaScript code to ECMAScript 6’s native class syntax?
Key findings
- JSClassFinder successfully identifies class-like structures in JavaScript by analyzing ASTs and inferring class definitions from constructor functions and prototype chains.
- The tool generates accurate UML class diagrams and distribution maps that reflect the structural organization of real-world JavaScript applications such as PDF.js and jQuery.
- It computes standard software metrics including NOC, NOM, NOA, and DIT, providing quantitative insights into code complexity and design.
- The integration with the Moose platform enables advanced visualization and analysis, supporting navigation and exploration of the object-oriented model.
- The tool identifies limitations in detecting classes created via third-party libraries like ClazzJS and singleton objects, highlighting areas for future enhancement.
- The tool is publicly available and supports future extension for ECMAScript 6 class syntax, aiding in legacy code modernization.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.