Automatic Module Extraction in JavaScript Applications by Leveraging Code Clone Analysis

MPhil Thesis Defence


Title: "Automatic Module Extraction in JavaScript Applications by
Leveraging Code Clone Analysis"

By

Mr. Wai Ting CHEUNG


Abstract

In software development, modular programming is a technique that separates the 
functionality of a program into small components, modules, each accomplishing 
different tasks and having less interaction with each other. Using modules in 
software development enables the same functionality to be reused in other 
systems, hence reducing the amount of duplicate code. While many traditional 
programming languages such as Python and Perl support the use of module system, 
JavaScript does not have a language-level module system. The JavaScript 
community recommends the module pattern using function-local namespaces to 
simulate modules. However, the single global namespace in JavaScript makes it 
hard to avoid name conflicts between modules. The introduction of the next 
version of ECMAScript, known as ECMAScript Harmony, brings native support of 
module system in JavaScript. In our previous work, we conducted an empirical 
study of code clones in JavaScript applications. We found that the amount of 
consistent clones is significant and most of them are easily refactorable. This 
finding suggests the need of module systems for JavaScript applications.

In this paper, we propose an approach to extract modules in JavaScript 
applications automatically by leveraging code clone analysis. We first identify 
reusable functions from JavaScript applications and dispatch them into groups. 
We then leverage clone detection and removal techniques to merge code clones in 
each group. After that, we apply transformation rules based on the ECMAScript 
Harmony specification to rewrite each group of functions with the module 
syntax. We then apply topic modeling to identify the optimal name of each 
module. We evaluated our approach on 29 JavaScript web pages and 27 JavaScript 
standalone projects in terms of the software quality and developers' 
acceptability. We found that our approach helps to improve the 
understandability of the extracted modules by at most 20% and complexity by at 
most 35%, and developers have higher acceptability in the modules extracted by 
the proposed approach.


Date:			Thursday, 15 August 2013

Time:			3:00pm – 5:00pm

Venue:			Room 3416
 			Lifts 17/18

Committee Members:	Dr. Sunghun Kim (Supervisor)
 			Prof. Shing-Chi Cheung (Chairperson)
 			Dr. Charles Zhang


**** ALL are Welcome ****