Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[preset-env] Don't use async-to-generator when already using regenerator #9481

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,7 +1,3 @@
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var Example =
/*#__PURE__*/
function () {
Expand All @@ -11,33 +7,21 @@ function () {

var _proto = Example.prototype;

_proto.test1 =
/*#__PURE__*/
function () {
var _test = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return Promise.resolve(2);
_proto.test1 = function test1() {
return regeneratorRuntime.async(function test1$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return regeneratorRuntime.awrap(Promise.resolve(2));

case 2:
case "end":
return _context.stop();
}
case 2:
case "end":
return _context.stop();
}
}, _callee);
}));

function test1() {
return _test.apply(this, arguments);
}

return test1;
}();
}
});
};

_proto.test2 =
/*#__PURE__*/
Expand Down
@@ -1,26 +1,17 @@
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function test(fn) {
return (
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
var _args = arguments;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", fn.apply(void 0, _args));
return function _callee() {
var _args = arguments;
return regeneratorRuntime.async(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", fn.apply(void 0, _args));

case 1:
case "end":
return _context.stop();
}
case 1:
case "end":
return _context.stop();
}
}, _callee);
}))
);
}
});
};
}
15 changes: 15 additions & 0 deletions packages/babel-preset-env/data/overlapping-plugins.js
@@ -0,0 +1,15 @@
"use strict";

module.exports = new Map();

// async -> regenerator is better than async -> generator -> regenerator
ifIncluded("transform-regenerator")
.isUnnecessary("transform-async-to-generator");

function ifIncluded(name) {
const set = new Set();
module.exports.set(name, set);
return {
isUnnecessary(name) { set.add(name); return this; }
};
}
10 changes: 10 additions & 0 deletions packages/babel-preset-env/src/filter-items.js
Expand Up @@ -85,3 +85,13 @@ export default function(

return result;
}

export function removeUnnecessaryItems(
items: Set<string>,
overlapping: Map<string, Set<string>>,
) {
items.forEach(item => {
const names = overlapping.get(item);
if (names) names.forEach(name => items.delete(name));
});
}
4 changes: 3 additions & 1 deletion packages/babel-preset-env/src/index.js
Expand Up @@ -3,11 +3,12 @@
import { SemVer } from "semver";
import { logPluginOrPolyfill } from "./debug";
import getOptionSpecificExcludesFor from "./get-option-specific-excludes";
import filterItems from "./filter-items";
import filterItems, { removeUnnecessaryItems } from "./filter-items";
import moduleTransformations from "./module-transformations";
import normalizeOptions from "./normalize-options";
import pluginList from "../data/plugins.json";
import { proposalPlugins, pluginSyntaxMap } from "../data/shipped-proposals";
import overlappingPlugins from "../data/overlapping-plugins";

import addCoreJS2UsagePlugin from "./polyfills/corejs2/usage-plugin";
import addCoreJS3UsagePlugin from "./polyfills/corejs3/usage-plugin";
Expand Down Expand Up @@ -236,6 +237,7 @@ export default declare((api, opts) => {
getOptionSpecificExcludesFor({ loose }),
pluginSyntaxMap,
);
removeUnnecessaryItems(pluginNames, overlappingPlugins);

const polyfillPlugins = getPolyfillPlugins({
useBuiltIns,
Expand Down
@@ -1,28 +1,13 @@
import "regenerator-runtime/runtime";
import "core-js/modules/es6.promise";
import "core-js/modules/es6.object.to-string";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function a() {
return _a.apply(this, arguments);
}

function _a() {
_a = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
case "end":
return _context.stop();
}
return regeneratorRuntime.async(function a$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
case "end":
return _context.stop();
}
}, _callee);
}));
return _a.apply(this, arguments);
}
});
}
Expand Up @@ -2,27 +2,14 @@ import "core-js/modules/es.object.to-string";
import "core-js/modules/es.promise";
import "regenerator-runtime/runtime";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function a() {
return _a.apply(this, arguments);
}

function _a() {
_a = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
case "end":
return _context.stop();
}
return regeneratorRuntime.async(function a$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
case "end":
return _context.stop();
}
}, _callee);
}));
return _a.apply(this, arguments);
}
});
}
Expand Up @@ -30,7 +30,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -30,7 +30,6 @@ Using plugins:
transform-new-target { "android":"4" }
transform-regenerator { "android":"4" }
transform-exponentiation-operator { "android":"4" }
transform-async-to-generator { "android":"4" }
proposal-async-generator-functions { "android":"4" }
proposal-object-rest-spread { "android":"4" }
proposal-unicode-property-regex { "android":"4" }
Expand Down
Expand Up @@ -25,7 +25,6 @@ Using plugins:
transform-block-scoping { "electron":"0.36" }
transform-regenerator { "electron":"0.36" }
transform-exponentiation-operator { "electron":"0.36" }
transform-async-to-generator { "electron":"0.36" }
proposal-async-generator-functions { "electron":"0.36" }
proposal-object-rest-spread { "electron":"0.36" }
proposal-unicode-property-regex { "electron":"0.36" }
Expand Down
Expand Up @@ -30,7 +30,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions { "chrome":"55" }
proposal-object-rest-spread { "chrome":"55" }
proposal-unicode-property-regex { "chrome":"55" }
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -35,7 +35,6 @@ Using plugins:
transform-new-target { "edge":"13", "ie":"10", "ios":"9", "safari":"7" }
transform-regenerator { "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
transform-exponentiation-operator { "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
transform-async-to-generator { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
proposal-async-generator-functions { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
proposal-object-rest-spread { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
proposal-unicode-property-regex { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
Expand Down
Expand Up @@ -41,7 +41,6 @@ Using plugins:
transform-new-target { "ie":"10" }
transform-regenerator { "electron":"0.36", "ie":"10" }
transform-exponentiation-operator { "electron":"0.36", "ie":"10", "node":"6.1" }
transform-async-to-generator { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" }
proposal-async-generator-functions { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" }
proposal-object-rest-spread { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" }
proposal-unicode-property-regex { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" }
Expand Down
Expand Up @@ -32,7 +32,6 @@ Using plugins:
transform-new-target { "ie":"10" }
transform-regenerator { "ie":"10" }
transform-exponentiation-operator { "ie":"10", "node":"6.10" }
transform-async-to-generator { "chrome":"54", "ie":"10", "node":"6.10" }
proposal-async-generator-functions { "chrome":"54", "ie":"10", "node":"6.10" }
proposal-object-rest-spread { "chrome":"54", "ie":"10", "node":"6.10" }
proposal-unicode-property-regex { "chrome":"54", "ie":"10", "node":"6.10" }
Expand Down
Expand Up @@ -32,7 +32,6 @@ Using plugins:
transform-new-target { "ie":"10" }
transform-regenerator { "ie":"10" }
transform-exponentiation-operator { "ie":"10", "node":"6" }
transform-async-to-generator { "chrome":"54", "ie":"10", "node":"6" }
proposal-async-generator-functions { "chrome":"54", "ie":"10", "node":"6" }
proposal-object-rest-spread { "chrome":"54", "ie":"10", "node":"6" }
proposal-unicode-property-regex { "chrome":"54", "ie":"10", "node":"6" }
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -30,7 +30,6 @@ Using plugins:
transform-new-target { "android":"4" }
transform-regenerator { "android":"4" }
transform-exponentiation-operator { "android":"4" }
transform-async-to-generator { "android":"4" }
proposal-async-generator-functions { "android":"4" }
proposal-object-rest-spread { "android":"4" }
proposal-unicode-property-regex { "android":"4" }
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -25,7 +25,6 @@ Using plugins:
transform-block-scoping { "electron":"0.36" }
transform-regenerator { "electron":"0.36" }
transform-exponentiation-operator { "electron":"0.36" }
transform-async-to-generator { "electron":"0.36" }
proposal-async-generator-functions { "electron":"0.36" }
proposal-object-rest-spread { "electron":"0.36" }
proposal-unicode-property-regex { "electron":"0.36" }
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -30,7 +30,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions { "chrome":"55" }
proposal-object-rest-spread { "chrome":"55" }
proposal-unicode-property-regex { "chrome":"55" }
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -35,7 +35,6 @@ Using plugins:
transform-new-target { "edge":"13", "ie":"10", "ios":"9", "safari":"7" }
transform-regenerator { "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
transform-exponentiation-operator { "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
transform-async-to-generator { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
proposal-async-generator-functions { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
proposal-object-rest-spread { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
proposal-unicode-property-regex { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down
Expand Up @@ -28,7 +28,6 @@ Using plugins:
transform-new-target {}
transform-regenerator {}
transform-exponentiation-operator {}
transform-async-to-generator {}
proposal-async-generator-functions {}
proposal-object-rest-spread {}
proposal-unicode-property-regex {}
Expand Down