Automated Refactoring of Legacy JavaScript Code to ES6 Modules

Abstract The JavaScript language did not specify, until ECMAScript 6 (ES6), native features for streamlining encapsulation and modularity. Developer community filled the gap with a proliferation of design patterns and module formats, with impact on code reusability, portability and complexity of build configurations. This work studies the automated refactoring of legacy ES5 code to ES6 modules with fine-grained reuse of module contents through the named import/export language constructs. The focus is on reducing the coupling of refactored modules through destructuring exported module objects to fine-grained module features and enhancing module dependencies by leveraging the ES6 syntax. We employ static analysis to construct a model of a JavaScript project, the Module Dependence Graph (MDG), that represents modules and their dependencies. On the basis of MDG we specify the refactoring procedure for module migration to ES6. A prototype implementation has been empirically evaluated on 19 open source projects. Results highlight the relevance of the refactoring with a developer intent for fine-grained reuse. The analysis of refactored code shows an increase in the number of reusable elements per project and reduction in the coupling of refactored modules. The soundness of the refactoring is empirically validated through code inspection and execution of projects’ test suites.

[1]  Renata Pontin de Mattos Fortes,et al.  Accessibility and Software Engineering Processes: A Systematic Literature Review , 2021, J. Syst. Softw..

[2]  Claes Wohlin,et al.  Experimentation in software engineering: an introduction , 2000 .

[3]  Marouane Kessentini,et al.  30 Years of Software Refactoring Research: A Systematic Literature Review , 2020, ArXiv.

[4]  Anders Møller,et al.  Semi-automatic rename refactoring for JavaScript , 2013, OOPSLA.

[5]  Ivan Beschastnikh,et al.  Don't Call Us, We'll Call You: Characterizing Callbacks in Javascript , 2015, 2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM).

[6]  Alessandro F. Garcia,et al.  Refactoring effect on internal quality attributes: What haven't they told you yet? , 2020, Inf. Softw. Technol..

[7]  Simon Holm Jensen,et al.  Remedying the eval that men do , 2012, ISSTA 2012.

[8]  Jim Shore,et al.  Fail Fast , 2004, IEEE Softw..

[9]  Ivan Beschastnikh,et al.  Refactoring Asynchrony in JavaScript , 2017, 2017 IEEE International Conference on Software Maintenance and Evolution (ICSME).

[10]  Mehrdad Ashtiani,et al.  A fuzzy genetic automatic refactoring approach to improve software maintainability and flexibility , 2020, Soft Computing.

[11]  N. A. Diamantidis,et al.  Automated refactoring of client-side JavaScript code to ES6 modules , 2018, 2018 IEEE 25th International Conference on Software Analysis, Evolution and Reengineering (SANER).

[12]  Miryung Kim,et al.  JShrink: in-depth investigation into debloating modern Java applications , 2020, ESEC/SIGSOFT FSE.

[13]  Marco Tulio Valente,et al.  Identifying Classes in Legacy JavaScript Code , 2017, J. Softw. Evol. Process..

[14]  Robert L. Nord,et al.  Next generation automated software evolution refactoring at scale , 2020, ESEC/SIGSOFT FSE.

[15]  Tom Mens,et al.  A survey of software refactoring , 2004, IEEE Transactions on Software Engineering.

[16]  Marco Tulio Valente,et al.  Refactoring Graphs: Assessing Refactoring over Time , 2020, 2020 IEEE 27th International Conference on Software Analysis, Evolution and Reengineering (SANER).

[17]  Patricia Lago,et al.  An extensible approach for taming the challenges of JavaScript dead code elimination , 2018, 2018 IEEE 25th International Conference on Software Analysis, Evolution and Reengineering (SANER).

[18]  James Miller,et al.  Refactoring legacy AJAX applications to improve the efficiency of the data exchange component , 2013, J. Syst. Softw..

[19]  Stéphane Frénot,et al.  Toward automatic update from callbacks to promises , 2015, AWeS@EuroSys.

[20]  Mohammad Alshayeb,et al.  Automatic software refactoring: a systematic literature review , 2019, Software Quality Journal.

[21]  Jeffrey Boone Miller Don't call us , 1994, Nature.

[22]  Jeffrey Overbey,et al.  Systematic Testing of Refactoring Engines on Real Software Projects , 2013, ECOOP.

[23]  Yvonne Koch,et al.  Javascript The Good Parts , 2016 .

[24]  Anuradha Chug,et al.  A Systematic Literature Survey of Software Metrics, Code Smells and Refactoring Techniques , 2020, J. Inf. Process. Syst..

[25]  Nicholas C. Zakas Maintainable JavaScript , 2012 .

[26]  Axel Rauschmayer Speaking JavaScript , 2014 .

[27]  Marco Tulio Valente,et al.  Refactoring Legacy JavaScript Code to Use Classes: The Good, The Bad and The Ugly , 2017, ICSR.

[28]  Gabriele Bavota,et al.  An experimental investigation on the innate relationship between quality and refactoring , 2015, J. Syst. Softw..

[29]  Allen Wirfs-Brock,et al.  JavaScript: the first 20 years , 2020, Proc. ACM Program. Lang..

[30]  Frank Tip,et al.  Tool-supported refactoring for JavaScript , 2011, OOPSLA '11.

[31]  Marco Tulio Valente,et al.  Statically identifying class dependencies in legacy JavaScript systems: First results , 2017, 2017 IEEE 24th International Conference on Software Analysis, Evolution and Reengineering (SANER).

[32]  Alexandre Bergel,et al.  Slimming javascript applications: An approach for removing unused functions from javascript libraries , 2019, Inf. Softw. Technol..

[33]  Davood Mazinanian,et al.  Detecting Function Constructors in JavaScript , 2016, 2016 IEEE International Conference on Software Maintenance and Evolution (ICSME).

[34]  Mauricio A. Saca Refactoring improving the design of existing code , 2017, 2017 IEEE 37th Central America and Panama Convention (CONCAPAN XXXVII).

[35]  André L. M. Santos,et al.  Refactoring Test Smells: A Perspective from Open-Source Developers , 2020, SAST.

[36]  Yann-Gaël Guéhéneuc,et al.  Code Smells and Refactoring: A Tertiary Systematic Review of Challenges and Observations , 2020, J. Syst. Softw..

[37]  Alessandro F. Garcia,et al.  When Are Smells Indicators of Architectural Refactoring Opportunities: A Study of 50 Software Projects , 2020, ICPC.