@shelter/babel-plugin-codemod-script-to-module
v0.0.4
Published
A babel codemod to transform a script to a module with equivalent behaviour
Downloads
4
Readme
babel-plugin-codemod-script-to-module
A babel codemod to transform an ECMAScript script to a ECMAScript module while preserving behaviour. This is useful for integrating legacy code with your module bundler.
Usage
This is designed to be used alongside babel-codemod.
yarn add -D @shelter/babel-plugin-codemod-script-to-module babel-codemod
codemod --plugin @shelter/babel-plugin-codemod-script-to-module --source-type script path/to/file.js
After you have finished using the codemod, you can remove the related packages:
yarn remove @shelter/babel-plugin-codemod-script-to-module babel-codemod
Testing
Most testing is done by using the fixtures in the __fixtures__
directory. Their purpose is two-fold. Firstly, we check that input.js
compiles to output.js
. Secondly, these files contain assertions, and we check that the assertions pass in both the input when interpreted as a script and the output when interpreted as a module. These assertions help ensure that behaviour is preserved during transformation.