From ca096c56aa1196e00ecca06af952d9a3d480d999 Mon Sep 17 00:00:00 2001 From: Zen <843968788@qq.com> Date: Tue, 7 Apr 2020 23:10:21 +0800 Subject: [PATCH] =?UTF-8?q?fix=20Incorrect=20destructuring=20compilation?= =?UTF-8?q?=20of=20`for=20(let=20[[x]=20=3D=20[1=E2=80=A6=20(#11360)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/babel-plugin-transform-destructuring/src/index.js | 2 +- .../test/fixtures/destructuring/for-let-nest/input.js | 2 ++ .../test/fixtures/destructuring/for-let-nest/output.js | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/for-let-nest/input.js create mode 100644 packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/for-let-nest/output.js diff --git a/packages/babel-plugin-transform-destructuring/src/index.js b/packages/babel-plugin-transform-destructuring/src/index.js index 714e5f5afb..cc60ebd458 100644 --- a/packages/babel-plugin-transform-destructuring/src/index.js +++ b/packages/babel-plugin-transform-destructuring/src/index.js @@ -166,7 +166,7 @@ export default declare((api, options) => { let patternId; let node; - if (this.kind === "const") { + if (this.kind === "const" || this.kind === "let") { patternId = this.scope.generateUidIdentifier(tempId.name); node = this.buildVariableDeclaration(patternId, tempConditional); } else { diff --git a/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/for-let-nest/input.js b/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/for-let-nest/input.js new file mode 100644 index 0000000000..4c54b1e75d --- /dev/null +++ b/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/for-let-nest/input.js @@ -0,0 +1,2 @@ +for (let [[x] = [1]] = []; ; ) { +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/for-let-nest/output.js b/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/for-let-nest/output.js new file mode 100644 index 0000000000..9c0f8685ef --- /dev/null +++ b/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/for-let-nest/output.js @@ -0,0 +1 @@ +for (var _ref = [], _ref$ = _ref[0], _ref$2 = _ref$ === void 0 ? [1] : _ref$, _ref$3 = babelHelpers.slicedToArray(_ref$2, 1), x = _ref$3[0];;) {} \ No newline at end of file