index.js
1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _helperDefinePolyfillProvider = _interopRequireDefault(require("@babel/helper-define-polyfill-provider"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const runtimeCompat = "#__secret_key__@babel/runtime__compatibility";
var _default = (0, _helperDefinePolyfillProvider.default)(({
debug,
targets,
babel
}, options) => {
if (!shallowEqual(targets, babel.targets())) {
throw new Error("This plugin does not use the targets option. Only preset-env's targets" + " or top-level targets need to be configured for this plugin to work." + " See https://github.com/babel/babel-polyfills/issues/36 for more" + " details.");
}
const {
[runtimeCompat]: {
useBabelRuntime
} = {
useBabelRuntime: ""
}
} = options;
const pureName = useBabelRuntime ? `${useBabelRuntime}/regenerator` : "regenerator-runtime";
return {
name: "regenerator",
polyfills: ["regenerator-runtime"],
usageGlobal(meta, utils) {
if (isRegenerator(meta)) {
debug("regenerator-runtime");
utils.injectGlobalImport("regenerator-runtime/runtime.js");
}
},
usagePure(meta, utils, path) {
if (isRegenerator(meta)) {
path.replaceWith(utils.injectDefaultImport(pureName, "regenerator-runtime"));
}
}
};
});
exports.default = _default;
const isRegenerator = meta => meta.kind === "global" && meta.name === "regeneratorRuntime";
function shallowEqual(obj1, obj2) {
return JSON.stringify(obj1) === JSON.stringify(obj2);
}