5to6 / 5to6-codemod

A collection of codemods that allow you to transform your js code from ES5 to ES6.
https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb
302 stars 36 forks source link

changed cjs, export transforms and added import-cleanup #42

Closed gmathieu closed 7 years ago

gmathieu commented 7 years ago

Sorry, the right thing to do would have been to create multiple PRs for this change but I figured I'd share the love since I just used this update to convert our entire codebase.

Enhanced cjs

Added support for renamed decomposition.

Before

var { x: y, z: a } = require(‘foo’)

After

import { x as y, z as a } from ‘foo’

Enhanced exports

Added export aggregation. Until now, the following conversion happened module.export.foo = foo -> export const foo = foo. This broke no-redeclare and no-user-before-define for our codebase.

Before

module.export.foo = foo
module.export.bar = bar
module.export.baz = baz

After

export { foo, bar, baz }

Introduced import-cleanup script

This script was introduced to deal with no-duplicate-imports which eslint didn't care about enforcing for requires. In the future, this script could be enhanced to handle sorting.

Before

import * as foo from 'bar'
import React from 'react';
import { PropTypes } from 'react';
import { createClass } from 'react';

After

import * as foo from 'bar'
import { default as React, PropTypes, createClass } from 'react'
gmathieu commented 7 years ago

Anyone have any feedback on this?

xjamundx commented 7 years ago

👍🏼 On Thu, Apr 6, 2017 at 5:39 PM Guillaume Mathieu notifications@github.com wrote:

Anyone have any feedback on this?

— You are receiving this because your review was requested.

Reply to this email directly, view it on GitHub https://github.com/5to6/5to6-codemod/pull/42#issuecomment-292378194, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPBf-GQFcv1KxJM_FNxh7tTWmKGdwW2ks5rtYWlgaJpZM4M15ST .