diff --git a/src/Plugin.js b/src/Plugin.js index e72135d7..61cb7d81 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -116,13 +116,24 @@ export default class Plugin { const file = (path && path.hub && path.hub.file) || (state && state.file); const { types } = this; const pluginState = this.getPluginState(state); - if (!types.isIdentifier(node[prop])) return; - if ( - pluginState.specified[node[prop].name] && - path.scope.hasBinding(node[prop].name) && - path.scope.getBinding(node[prop].name).path.type === 'ImportSpecifier' - ) { + + const checkScope = targetNode => + pluginState.specified[targetNode.name] && // eslint-disable-line + path.scope.hasBinding(targetNode.name) && // eslint-disable-line + path.scope.getBinding(targetNode.name).path.type === 'ImportSpecifier'; // eslint-disable-line + + if (types.isIdentifier(node[prop]) && checkScope(node[prop])) { node[prop] = this.importMethod(pluginState.specified[node[prop].name], file, pluginState); // eslint-disable-line + } else if (types.isSequenceExpression(node[prop])) { + node[prop].expressions.forEach((expressionNode, index) => { + if (types.isIdentifier(expressionNode) && checkScope(expressionNode)) { + node[prop].expressions[index] = this.importMethod( + pluginState.specified[expressionNode.name], + file, + pluginState, + ); // eslint-disable-line + } + }); } } diff --git a/test/fixtures/variable-declarator/actual.js b/test/fixtures/variable-declarator/actual.js index cb15c56c..c3bb2dc3 100644 --- a/test/fixtures/variable-declarator/actual.js +++ b/test/fixtures/variable-declarator/actual.js @@ -1,3 +1,5 @@ -import { Button } from 'antd'; +import { Button, Modal } from 'antd'; const a = Button; + +const b = (a, Modal); diff --git a/test/fixtures/variable-declarator/expected.js b/test/fixtures/variable-declarator/expected.js index e543d4a9..14a1e7f2 100644 --- a/test/fixtures/variable-declarator/expected.js +++ b/test/fixtures/variable-declarator/expected.js @@ -1,7 +1,10 @@ "use strict"; +var _modal = _interopRequireDefault(require("antd/lib/modal")); + var _button = _interopRequireDefault(require("antd/lib/button")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -var a = _button.default; \ No newline at end of file +var a = _button.default; +var b = (a, _modal.default);