将遗留JavaScript代码自动转换为ES6模块
Automated Refactoring of Legacy JavaScript Code to ES6 Modules
AI总结:
本文研究了将遗留ES5代码自动转换为ES6模块,通过命名导入/导出语言构造实现细粒度重用,减少模块耦合并增强模块依赖。
摘要:
JavaScript语言直到ECMAScript 6 (ES6)才规定了流化封装和模块化的原生特性。开发社区通过大量设计模式和模块格式填补了这一空白,影响了代码重用性、可移植性和构建配置的复杂性。本文研究了通过命名导入/导出语言构造实现遗留ES5代码到ES6模块的自动重构,重点是通过解构导出模块对象减少重构模块的耦合,并通过ES6语法增强模块依赖。我们采用静态分析构建JavaScript项目的模型,即模块依赖图(MDG),以表示模块及其依赖。基于MDG,我们指定了模块迁移至ES6的重构过程。一个原型实现已在19个开源项目上进行了实证评估。结果突显了重构的相关性,与开发者意图的细粒度重用相关。重构代码的分析显示每个项目可重用元素数量增加,重构模块的耦合度降低。通过代码检查和执行项目测试套件,重构的正确性得到了实证验证。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。