JSClassFinder

Description

Detecting class-like structures in JavaScript

Details

Source
GitHub
License
MIT
Stars
65
Forks
2
Created
July 31, 2015
Updated
Jan. 13, 2024

README excerpt

# JSClassFinder
A tool to detect class-like structures in legacy JavaScript code (i.e., prior to ECMAScript 6).

<p><strong>Example of Class detected by JSClassFinder</strong></p>

```javascript
function Circle (radius) { //  class
   this.radius= radius; // attribute
   this.getArea= function () { // method
     return (3.14 * this.radius * this.radius);
   }
 }
 
 var myCircle = new Circle (10); // Circle instance
 
 function Circle2D (x, y) { // class Circle2D
   this.x = x;
   this.y= y;
 }

// Circle2D is a subclass of Circle
Circle2D.prototype = new Circle(10);

// Circle2D extends Circle with new methods
Circle2D.prototype.getX = function () {
  return (x);
}
Circle2D.prototype.getY = function () {
  return (y);
}
 ```

<p><strong>Example of Class Diagram Generated by JSClassFinder (for algorithm.js)</strong></p>

![alt text](https://github.com/aserg-ufmg/JSClassFinder/blob/master/UMLdiagramAlgorithms.png "Class diagram")


<p><strong>Data about Class Emulation in 60 JavaScript systems</strong></p>

![alt text](https://github.com/aserg-ufmg/JSClassFinder/blob/master/dataset.png "Dataset")


<p><strong>Installation</strong></p>
<p>JSClassFinder is implemented in <a href="http://pharo.org/" title="Pharo">Pharo</a> (a Smalltalk-like language) <br />
You can download a ready-to-use Pharo image <a href="https://drive.google.com/file/d/0B-ZbjmvQs5bXamZEbzN6LTluUTg/view?usp=sharing" title="Ready-to-use Pharo image">here</a>, or use the instructions below to install JSClassFinder inside your own Pharo image:<br />
1 &#8211; Open Monticello browser<br />
2 &#8211; Add a new repository (+Repository) of type HTTP<br />
3 &#8211; Fill in the required information as below<br />
&nbsp;<code>MCHttpRepository<br />
&nbsp;&nbsp;&nbsp;&nbsp;location: 'http://smalltalkhub.com/mc/LeonardoHumberto/JSClasses/main'<br />
&nbsp;&nbsp;&nbsp;&nbsp;user: ''<br />
&nbsp;&nbsp;&nbsp;&nbsp;password: '' </code><br />
4 &#8211; Choose the newest release</p>
<p><strong>Input</strong></p>
<p>JSClassFinder expects the AST of a JS source code, in JSON format, as input.<br />
To generate the AST we use <a href="http://esprima.org/" title="Esprima">Esprima</a>.<br />
Use the instructions below to use Esprima under <a href="http://nodejs.org/" title="Node.js">Node.js</a>:<br />
1- install Node.js<br />
2- load Esprima package : &#8220;npm install esprima&#8221;<br />
3- Ok, you are ready to execute Esprima commands. </p>
<p>The file <a href="http://java.llp.dcc.ufmg.br/mediawiki/images/0/09/Analysejs.zip" title="script">analyse.js</a> is one example of script that can be used to generate JSON files.</p>

<p><strong>More Info</strong></p>
 Leonardo Humberto Silva, Marco Tulio Valente, Alexandre Bergel, Nicolas Anquetil, Anne Etien. Identifying Classes in Legacy JavaScript Code. Journal of Software: Evolution and Process, vol. 29, n. 8, pages 1-20, 2017. 
 <a href="http://www.dcc.ufmg.br/~mtov/pub/2017-jsep.pdf">Paper</a>
 <br /><br />
 Leonardo Humberto Silva, Miguel Ramos, Marco Tulio Valente, Nicolas Anquetil, Alexandre Bergel. Does Javascript Software Embrace Classes? In <em>22nd International Conference on Software Analysis, Evolution and Reengineering (SANER) </em>, pages 1-10, 2015. 
 <a href="http://www.dcc.ufmg.br/~mtov/pub/2015_saner.pdf">Paper</a>, <a href="https://speakerdeck.com/aserg_ufmg/does-javascript-software-embrace-classes-saner-2015">Slides</a><br />

<p></p>
<p><strong>Download</strong></p>
<p><a href="https://drive.google.com/file/d/0B-ZbjmvQs5bXMnNHMjFMRFhCU2c/view?usp=sharing" title="Ready-to-use Pharo image">Ready-to-use Pharo image with JSClassFinder installed</a><br />
<a href="http://smalltalkhub.com/#!/~LeonardoHumberto/JSClasses" title="JSClassFinder Packages">JSClassFinder packages on SmalltalkHub</a><br />
<a href="http://aserg.labsoft.dcc.ufmg.br/qualitas.js/qualitas.js.rar" title="Dataset">Dataset for SANER paper</a></p>
← Back to results