Skip to content

Instantly share code, notes, and snippets.

@mofas
Last active March 25, 2016 16:48
Show Gist options
  • Save mofas/200c0020224b082ab807 to your computer and use it in GitHub Desktop.
Save mofas/200c0020224b082ab807 to your computer and use it in GitHub Desktop.
Codemod: Replace react/addons to react
import React from 'react/addons';
import Immutable from 'immutable';
import classnames from 'classnames';
export default function transformer(file, api) {
const j = api.jscodeshift;
const {expression, statement, statements} = j.template;
var root = j(file.source);
return root
.find(j.ImportDeclaration, {
type: "ImportDeclaration",
source: {
type: "Literal",
value: "react/addons"
}
})
.replaceWith(p => {
return (
j.importDeclaration(
[j.importDefaultSpecifier(
j.identifier("React")
)],
j.literal("react")
)
);
}).toSource()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment