source: trip-planner-front/node_modules/babel-plugin-polyfill-corejs2/lib/index.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.6 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports.default = void 0;
5
6var _corejs2BuiltIns = _interopRequireDefault(require("@babel/compat-data/corejs2-built-ins"));
7
8var _builtInDefinitions = require("./built-in-definitions");
9
10var _addPlatformSpecificPolyfills = _interopRequireDefault(require("./add-platform-specific-polyfills"));
11
12var _helpers = require("./helpers");
13
14var _helperDefinePolyfillProvider = _interopRequireDefault(require("@babel/helper-define-polyfill-provider"));
15
16var babel = _interopRequireWildcard(require("@babel/core"));
17
18function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
19
20function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
22function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
24const {
25 types: t
26} = babel.default || babel;
27const presetEnvCompat = "#__secret_key__@babel/preset-env__compatibility";
28const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; // $FlowIgnore
29
30const has = Function.call.bind(Object.hasOwnProperty);
31
32var _default = (0, _helperDefinePolyfillProvider.default)(function (api, {
33 [presetEnvCompat]: {
34 entryInjectRegenerator
35 } = {},
36 [runtimeCompat]: {
37 useBabelRuntime,
38 runtimeVersion,
39 ext = ".js"
40 } = {}
41}) {
42 const resolve = api.createMetaResolver({
43 global: _builtInDefinitions.BuiltIns,
44 static: _builtInDefinitions.StaticProperties,
45 instance: _builtInDefinitions.InstanceProperties
46 });
47 const {
48 debug,
49 shouldInjectPolyfill,
50 method
51 } = api;
52 const polyfills = (0, _addPlatformSpecificPolyfills.default)(api.targets, method, _corejs2BuiltIns.default);
53 const coreJSBase = useBabelRuntime ? `${useBabelRuntime}/core-js` : method === "usage-pure" ? "core-js/library/fn" : "core-js/modules";
54
55 function inject(name, utils) {
56 if (typeof name === "string") {
57 // Some polyfills aren't always available, for example
58 // web.dom.iterable when targeting node
59 if (has(polyfills, name) && shouldInjectPolyfill(name)) {
60 debug(name);
61 utils.injectGlobalImport(`${coreJSBase}/${name}.js`);
62 }
63
64 return;
65 }
66
67 name.forEach(name => inject(name, utils));
68 }
69
70 function maybeInjectPure(desc, hint, utils) {
71 const {
72 pure,
73 meta,
74 name
75 } = desc;
76 if (!pure || !shouldInjectPolyfill(name)) return;
77
78 if (runtimeVersion && meta && meta.minRuntimeVersion && !(0, _helpers.hasMinVersion)(meta && meta.minRuntimeVersion, runtimeVersion)) {
79 return;
80 }
81
82 return utils.injectDefaultImport(`${coreJSBase}/${pure}${ext}`, hint);
83 }
84
85 return {
86 name: "corejs2",
87 polyfills,
88
89 entryGlobal(meta, utils, path) {
90 if (meta.kind === "import" && meta.source === "core-js") {
91 debug(null);
92 inject(Object.keys(polyfills), utils);
93
94 if (entryInjectRegenerator) {
95 utils.injectGlobalImport("regenerator-runtime/runtime.js");
96 }
97
98 path.remove();
99 }
100 },
101
102 usageGlobal(meta, utils) {
103 const resolved = resolve(meta);
104 if (!resolved) return;
105 let deps = resolved.desc.global;
106
107 if (resolved.kind !== "global" && meta.object && meta.placement === "prototype") {
108 const low = meta.object.toLowerCase();
109 deps = deps.filter(m => m.includes(low));
110 }
111
112 inject(deps, utils);
113 },
114
115 usagePure(meta, utils, path) {
116 if (meta.kind === "in") {
117 if (meta.key === "Symbol.iterator") {
118 path.replaceWith(t.callExpression(utils.injectDefaultImport(`${coreJSBase}/is-iterable${ext}`, "isIterable"), [path.node.right]));
119 }
120
121 return;
122 }
123
124 if (path.parentPath.isUnaryExpression({
125 operator: "delete"
126 })) return;
127
128 if (meta.kind === "property") {
129 // We can't compile destructuring.
130 if (!path.isMemberExpression()) return;
131 if (!path.isReferenced()) return;
132
133 if (meta.key === "Symbol.iterator" && shouldInjectPolyfill("es6.symbol") && path.parentPath.isCallExpression({
134 callee: path.node
135 }) && path.parent.arguments.length === 0) {
136 path.parentPath.replaceWith(t.callExpression(utils.injectDefaultImport(`${coreJSBase}/get-iterator${ext}`, "getIterator"), [path.node.object]));
137 path.skip();
138 return;
139 }
140 }
141
142 const resolved = resolve(meta);
143 if (!resolved) return;
144 const id = maybeInjectPure(resolved.desc, resolved.name, utils);
145 if (id) path.replaceWith(id);
146 },
147
148 visitor: method === "usage-global" && {
149 // yield*
150 YieldExpression(path) {
151 if (path.node.delegate) {
152 inject("web.dom.iterable", api.getUtils(path));
153 }
154 },
155
156 // for-of, [a, b] = c
157 "ForOfStatement|ArrayPattern"(path) {
158 _builtInDefinitions.CommonIterators.forEach(name => inject(name, api.getUtils(path)));
159 }
160
161 }
162 };
163});
164
165exports.default = _default;
Note: See TracBrowser for help on using the repository browser.