1 | import defineProvider from '@babel/helper-define-polyfill-provider';
|
---|
2 |
|
---|
3 | const runtimeCompat = "#__secret_key__@babel/runtime__compatibility";
|
---|
4 | var index = defineProvider(({
|
---|
5 | debug,
|
---|
6 | targets,
|
---|
7 | babel
|
---|
8 | }, options) => {
|
---|
9 | if (!shallowEqual(targets, babel.targets())) {
|
---|
10 | 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.");
|
---|
11 | }
|
---|
12 | const {
|
---|
13 | [runtimeCompat]: {
|
---|
14 | moduleName = null,
|
---|
15 | useBabelRuntime = false
|
---|
16 | } = {}
|
---|
17 | } = options;
|
---|
18 | return {
|
---|
19 | name: "regenerator",
|
---|
20 | polyfills: ["regenerator-runtime"],
|
---|
21 | usageGlobal(meta, utils) {
|
---|
22 | if (isRegenerator(meta)) {
|
---|
23 | debug("regenerator-runtime");
|
---|
24 | utils.injectGlobalImport("regenerator-runtime/runtime.js");
|
---|
25 | }
|
---|
26 | },
|
---|
27 | usagePure(meta, utils, path) {
|
---|
28 | if (isRegenerator(meta)) {
|
---|
29 | let pureName = "regenerator-runtime";
|
---|
30 | if (useBabelRuntime) {
|
---|
31 | var _ref;
|
---|
32 | const runtimeName = (_ref = moduleName != null ? moduleName : path.hub.file.get("runtimeHelpersModuleName")) != null ? _ref : "@babel/runtime";
|
---|
33 | pureName = `${runtimeName}/regenerator`;
|
---|
34 | }
|
---|
35 | path.replaceWith(utils.injectDefaultImport(pureName, "regenerator-runtime"));
|
---|
36 | }
|
---|
37 | }
|
---|
38 | };
|
---|
39 | });
|
---|
40 | const isRegenerator = meta => meta.kind === "global" && meta.name === "regeneratorRuntime";
|
---|
41 | function shallowEqual(obj1, obj2) {
|
---|
42 | return JSON.stringify(obj1) === JSON.stringify(obj2);
|
---|
43 | }
|
---|
44 |
|
---|
45 | export default index;
|
---|
46 | //# sourceMappingURL=index.mjs.map
|
---|