From 5ea1bfe780a305c0600190084b36f1967c0b3857 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sat, 3 Feb 2018 17:08:12 -0500 Subject: [PATCH] Do not optimize away async/gen arrow functions (#7319) * Do not optimize away async/gen arrow functions * Node version 8 --- .../src/index.js | 5 ++++- .../fixtures/pipeline-operator/async-arrow/exec.js | 13 +++++++++++++ .../fixtures/pipeline-operator/async-arrow/input.js | 13 +++++++++++++ .../pipeline-operator/async-arrow/options.json | 3 +++ .../pipeline-operator/async-arrow/output.js | 12 ++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/exec.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/input.js create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/options.json create mode 100644 packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/output.js diff --git a/packages/babel-plugin-proposal-pipeline-operator/src/index.js b/packages/babel-plugin-proposal-pipeline-operator/src/index.js index 758211975b..e96bd2231a 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/src/index.js +++ b/packages/babel-plugin-proposal-pipeline-operator/src/index.js @@ -14,7 +14,10 @@ export default function() { if (operator !== "|>") return; let optimizeArrow = - t.isArrowFunctionExpression(right) && t.isExpression(right.body); + t.isArrowFunctionExpression(right) && + t.isExpression(right.body) && + !right.async && + !right.generator; let param; if (optimizeArrow) { diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/exec.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/exec.js new file mode 100644 index 0000000000..648a737a53 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/exec.js @@ -0,0 +1,13 @@ +function then(fn) { + return async (value) => { + return fn(await value); + }; +} + +var result = 1 + |> (async (x) => await x + 1) + |> then((x) => x + 1); + +result.then(val => { + assert.equal(val, 3); +}); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/input.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/input.js new file mode 100644 index 0000000000..648a737a53 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/input.js @@ -0,0 +1,13 @@ +function then(fn) { + return async (value) => { + return fn(await value); + }; +} + +var result = 1 + |> (async (x) => await x + 1) + |> then((x) => x + 1); + +result.then(val => { + assert.equal(val, 3); +}); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/options.json b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/options.json new file mode 100644 index 0000000000..2454c2169c --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/options.json @@ -0,0 +1,3 @@ +{ + "minNodeVersion": "8.0.0" +} diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/output.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/output.js new file mode 100644 index 0000000000..4fb6d4b2a8 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/pipeline-operator/async-arrow/output.js @@ -0,0 +1,12 @@ +var _ref, _; + +function then(fn) { + return async value => { + return fn((await value)); + }; +} + +var result = (_ref = (_ = 1, (async x => (await x) + 1)(_)), then(x => x + 1)(_ref)); +result.then(val => { + assert.equal(val, 3); +});