diff --git a/transforms/__testfixtures__/class/class-prune-react4.input.js b/transforms/__testfixtures__/class/class-prune-react4.input.js new file mode 100644 index 00000000..2f68eb10 --- /dev/null +++ b/transforms/__testfixtures__/class/class-prune-react4.input.js @@ -0,0 +1,19 @@ +'use strict'; + +import React, {PropTypes} from 'React'; + +const SomeMixin = { + componentDidMount() { + console.log('did mount'); + }, +}; + +export default React.createClass({ + mixins: [SomeMixin], + propTypes: { + foo: PropTypes.string, + }, + render: function() { + return
; + }, +}); diff --git a/transforms/__testfixtures__/class/class-prune-react4.output.js b/transforms/__testfixtures__/class/class-prune-react4.output.js new file mode 100644 index 00000000..8bb26a9c --- /dev/null +++ b/transforms/__testfixtures__/class/class-prune-react4.output.js @@ -0,0 +1,24 @@ +'use strict'; + +import React, {PropTypes} from 'React'; + +import createReactClass from 'create-react-class'; + +const SomeMixin = { + componentDidMount() { + console.log('did mount'); + }, +}; + +export default createReactClass({ + displayName: 'class-prune-react4.input', + mixins: [SomeMixin], + + propTypes: { + foo: PropTypes.string, + }, + + render: function() { + return
; + }, +}); diff --git a/transforms/__tests__/class-test.js b/transforms/__tests__/class-test.js index 78297200..9a80ce1e 100644 --- a/transforms/__tests__/class-test.js +++ b/transforms/__tests__/class-test.js @@ -56,6 +56,7 @@ defineTest(__dirname, 'class', { defineTest(__dirname, 'class', null, 'class/class-prune-react'); defineTest(__dirname, 'class', null, 'class/class-prune-react2'); defineTest(__dirname, 'class', null, 'class/class-prune-react3'); +defineTest(__dirname, 'class', null, 'class/class-prune-react4'); defineTest(__dirname, 'class', { 'create-class-module-name': 'createReactClass__deprecated', 'create-class-variable-name': 'createReactClass__deprecated', diff --git a/transforms/class.js b/transforms/class.js index 53ca458d..e61c7348 100644 --- a/transforms/class.js +++ b/transforms/class.js @@ -1258,7 +1258,10 @@ module.exports = (file, api, options) => { shouldReinsertComment = bodyNode.indexOf(importDeclarationNode) === 0; removePath = path; } else { - j(path).find(j.ImportDefaultSpecifier).remove(); + const paths = j(path).find(j.ImportDefaultSpecifier); + if (paths.length) { + removePath = j(path).find(j.ImportDefaultSpecifier).paths()[0]; + } } }