Skip to content

Commit

Permalink
fix eslint (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
nap-liu committed Nov 24, 2020
1 parent 3a93f5a commit 3ac277e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
23 changes: 17 additions & 6 deletions src/Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/variable-declarator/actual.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Button } from 'antd';
import { Button, Modal } from 'antd';

const a = Button;

const b = (a, Modal);
5 changes: 4 additions & 1 deletion test/fixtures/variable-declarator/expected.js
Original file line number Diff line number Diff line change
@@ -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;
var a = _button.default;
var b = (a, _modal.default);

0 comments on commit 3ac277e

Please sign in to comment.