diff --git a/src/Plugin.js b/src/Plugin.js index 56939495..883608c8 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -139,7 +139,15 @@ export default class AntdPlugin { this.buildExpressionHandler(node, ['test'], path, opts); this.buildExpressionHandler(node.test, ['left', 'right'], path, opts); } - + + ExpressionStatement(path, {opts}){ + const { node } = path; + const { types } = this; + if(types.isAssignmentExpression(node.expression)){ + this.buildExpressionHandler(node.expression, ['right'], path, opts); + } + } + ExportDefaultDeclaration(path, { opts }) { const { node } = path; this.buildExpressionHandler(node, ['declaration'], path, opts); diff --git a/src/index.js b/src/index.js index 336ad2e7..07ba28b5 100644 --- a/src/index.js +++ b/src/index.js @@ -57,6 +57,9 @@ export default function ({ types }) { IfStatement() { applyInstance('IfStatement', arguments, this); }, + ExpressionStatement(){ + applyInstance('ExpressionStatement', arguments, this); + }, ExportDefaultDeclaration() { applyInstance('ExportDefaultDeclaration', arguments, this); }, diff --git a/test/fixtures/expression-statement/actual.js b/test/fixtures/expression-statement/actual.js new file mode 100644 index 00000000..b1ce1c98 --- /dev/null +++ b/test/fixtures/expression-statement/actual.js @@ -0,0 +1,3 @@ +import {Toast} from 'antd-mobile'; +window.Toast = Toast; +Toast.success('test'); \ No newline at end of file diff --git a/test/fixtures/expression-statement/expected.js b/test/fixtures/expression-statement/expected.js new file mode 100644 index 00000000..12a03c58 --- /dev/null +++ b/test/fixtures/expression-statement/expected.js @@ -0,0 +1,6 @@ +'use strict'; + +var _antdMobile = require('antd-mobile'); + +window.Toast = _antdMobile.Toast; +_antdMobile.Toast.success('test'); \ No newline at end of file