From 54a94bc0520826233909ff42eb68b87f88b925b1 Mon Sep 17 00:00:00 2001 From: Licic Date: Thu, 5 Jan 2023 10:56:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9ESequenceExpression?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20(#625)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Plugin.js | 7 +++++++ src/index.js | 1 + test/fixtures/sequence-expression/actual.js | 5 +++++ test/fixtures/sequence-expression/expected.js | 9 +++++++++ 4 files changed, 22 insertions(+) create mode 100644 test/fixtures/sequence-expression/actual.js create mode 100644 test/fixtures/sequence-expression/expected.js diff --git a/src/Plugin.js b/src/Plugin.js index a1860815..8afe921a 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -294,4 +294,11 @@ export default class Plugin { const { node } = path; this.buildExpressionHandler(node, ['superClass'], path, state); } + + SequenceExpression(path, state) { + const { node } = path; + + const expressionsProps = node.expressions.map((_, index) => index); + this.buildExpressionHandler(node.expressions, expressionsProps, path, state); + } } diff --git a/src/index.js b/src/index.js index f6de1a58..a3c8d5b7 100644 --- a/src/index.js +++ b/src/index.js @@ -101,6 +101,7 @@ export default function ({ types }) { 'ClassDeclaration', 'SwitchStatement', 'SwitchCase', + 'SequenceExpression', ]; const ret = { diff --git a/test/fixtures/sequence-expression/actual.js b/test/fixtures/sequence-expression/actual.js new file mode 100644 index 00000000..de321aa9 --- /dev/null +++ b/test/fixtures/sequence-expression/actual.js @@ -0,0 +1,5 @@ +import { Button } from 'antd'; + +(true, Button); + +true ? (true, Button) : (false, Button); diff --git a/test/fixtures/sequence-expression/expected.js b/test/fixtures/sequence-expression/expected.js new file mode 100644 index 00000000..ff610a3e --- /dev/null +++ b/test/fixtures/sequence-expression/expected.js @@ -0,0 +1,9 @@ +"use strict"; + +var _button = _interopRequireDefault(require("antd/lib/button")); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +true, _button.default; + +true ? (true, _button.default) : (false, _button.default); \ No newline at end of file