Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jamischarles/5to6
A collection of codemods that allow you to transform your js code from ES5 to ES6.
https://github.com/jamischarles/5to6
Last synced: 3 months ago
JSON representation
A collection of codemods that allow you to transform your js code from ES5 to ES6.
- Host: GitHub
- URL: https://github.com/jamischarles/5to6
- Owner: jamischarles
- Created: 2015-11-11T06:39:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-23T02:54:25.000Z (about 9 years ago)
- Last Synced: 2024-08-02T07:18:24.280Z (7 months ago)
- Language: JavaScript
- Homepage: https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb
- Size: 0 Bytes
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-codemods - 5to6 - A collection of codemods that allow you to transform your js code from ES5 to ES6. (ESNext)
README
# 5to6
A collection of [codemods](https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb) that allow you to transform your
js code from ES5 to ES6.## What it does
Apply a transform to a file via [jscodeshift](https://github.com/facebook/jscodeshift):
`$ jscodeshift -t requireToImportTransform.js fileToTransform.js`**Before**
```js
var jamis = require('jquery');
var $ = require('jquery');
var $ = require("jquery");
require('something');var foo = bar;
// some comment
var jamis = 'bar',
_ = require('lodash'),
lodash = require('underscore'),
bar,
foo = 'bar',
$ = require('jquery');var routeTo = require('../routeHelper').routeTo;
var fetch = require('../someUtil').pluck;
```**After**
```js
import jamis from 'jquery';
import $ from 'jquery';
import $ from 'jquery';
import 'something';var foo = bar;
import _ from 'lodash';
import lodash from 'underscore';
import $ from 'jquery';// some comment
var jamis = 'bar', bar, foo = 'bar';import {routeTo} from '../routeHelper';
import {pluck as fetch} from '../someUtil';```
## Getting started
1. `$ npm install -g jscodeshift`
2. pick a transform you want from the `transforms` folder.
3. Save it locally on your machine.
4. Remove the `require('./utils/main')` statement and copy/paste the content of `utils/main.js`. (Lame, I know)
5. Run it via `$ jscodeshift -t yourLocallySavedTransformFile.js fileToTransform.js`.
6. Review changes via `$ git diff`. Keep what you want, throw it out if you don't. Magic!## Known issues
* Currently loses comments if directly before the `require()` statement.
* require() calls in single var statements get reordered, and moved before the single var after conversion to import.
* can't automagically figure out when you want to use `import * as varName`.## TODO:
- [ ] Fix single var issues
- [ ] Avoid losing info like comments when transforming require() statements.