Skip to content

Instantly share code, notes, and snippets.

@mofas
Last active March 26, 2016 12:37
Show Gist options
  • Save mofas/d4c3714462f5d7cd7ea1 to your computer and use it in GitHub Desktop.
Save mofas/d4c3714462f5d7cd7ea1 to your computer and use it in GitHub Desktop.
CodeMod: Insert import react-addons-pure-render-mixin after import react
import React from 'react';
import Immutable from 'immutable';
import classnames from 'classnames';
export default function transformer(file, api) {
const j = api.jscodeshift;
const pureRenderMixinImport = j.importDeclaration(
[j.importDefaultSpecifier(
j.identifier("PureRenderMixin")
)],
j.literal("react-addons-pure-render-mixin")
);
return j(file.source)
.find(j.ImportDeclaration, {
type: "ImportDeclaration",
source: {
type: "Literal",
value: "react"
}
})
.forEach(p => {
j(p).insertAfter(pureRenderMixinImport);
}).toSource()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment