From 4f594e3e5de160287d5d3e868dd3d3c09521e211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=AD=90=E6=BA=9F?= Date: Wed, 24 Apr 2024 20:32:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9EAssignmentPattern?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Plugin.js | 5 +++++ src/index.js | 1 + test/fixtures/assignment-pattern/actual.js | 3 +++ test/fixtures/assignment-pattern/expected.js | 4 ++++ 4 files changed, 13 insertions(+) create mode 100644 test/fixtures/assignment-pattern/actual.js create mode 100644 test/fixtures/assignment-pattern/expected.js diff --git a/src/Plugin.js b/src/Plugin.js index 77282ab..b0a3bd2 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -304,4 +304,9 @@ export default class Plugin { const expressionsProps = node.expressions.map((_, index) => index); this.buildExpressionHandler(node.expressions, expressionsProps, path, state); } + + AssignmentPattern(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ['right'], path, state); + } } diff --git a/src/index.js b/src/index.js index a3c8d5b..f0f9938 100644 --- a/src/index.js +++ b/src/index.js @@ -102,6 +102,7 @@ export default function ({ types }) { 'SwitchStatement', 'SwitchCase', 'SequenceExpression', + 'AssignmentPattern', ]; const ret = { diff --git a/test/fixtures/assignment-pattern/actual.js b/test/fixtures/assignment-pattern/actual.js new file mode 100644 index 0000000..6f2b082 --- /dev/null +++ b/test/fixtures/assignment-pattern/actual.js @@ -0,0 +1,3 @@ +import { Button } from 'antd'; + +const { a = Button } = {}; diff --git a/test/fixtures/assignment-pattern/expected.js b/test/fixtures/assignment-pattern/expected.js new file mode 100644 index 0000000..d10ce85 --- /dev/null +++ b/test/fixtures/assignment-pattern/expected.js @@ -0,0 +1,4 @@ +import _Button from "antd/lib/button"; +const { + a = _Button +} = {};