From 06dace1cdb4408a8320004e45dc178bcb51792b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 16 Jan 2020 18:15:31 -0500 Subject: [PATCH] fix: for-of transform should skip for-await-of (#11023) --- packages/babel-plugin-transform-for-of/src/index.js | 5 ++++- .../test/fixtures/for-of-as-array/for-await-of/input.js | 1 + .../test/fixtures/for-of-as-array/for-await-of/output.js | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-await-of/input.js create mode 100644 packages/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-await-of/output.js diff --git a/packages/babel-plugin-transform-for-of/src/index.js b/packages/babel-plugin-transform-for-of/src/index.js index cd4c6e17bcd5..85d6034f3ffd 100644 --- a/packages/babel-plugin-transform-for-of/src/index.js +++ b/packages/babel-plugin-transform-for-of/src/index.js @@ -19,7 +19,10 @@ export default declare((api, options) => { visitor: { ForOfStatement(path) { const { scope } = path; - const { left, right, body } = path.node; + const { left, right, body, await: isAwait } = path.node; + if (isAwait) { + return; + } const i = scope.generateUidIdentifier("i"); let array = scope.maybeGenerateMemoised(right, true); diff --git a/packages/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-await-of/input.js b/packages/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-await-of/input.js new file mode 100644 index 000000000000..623d204b34cb --- /dev/null +++ b/packages/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-await-of/input.js @@ -0,0 +1 @@ +async () => { for await (let foo of []); }; diff --git a/packages/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-await-of/output.js b/packages/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-await-of/output.js new file mode 100644 index 000000000000..03379d55586f --- /dev/null +++ b/packages/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-await-of/output.js @@ -0,0 +1,3 @@ +async () => { + for await (let foo of []); +};