source: trip-planner-front/node_modules/@babel/plugin-transform-runtime/lib/index.js@ ceaed42

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

initial commit

  • Property mode set to 100644
File size: 7.0 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _helperPluginUtils = require("@babel/helper-plugin-utils");
9
10var _helperModuleImports = require("@babel/helper-module-imports");
11
12var _core = require("@babel/core");
13
14var _helpers = require("./helpers");
15
16var _getRuntimePath = require("./get-runtime-path");
17
18var _babelPluginPolyfillCorejs = require("babel-plugin-polyfill-corejs2");
19
20var _babelPluginPolyfillCorejs2 = require("babel-plugin-polyfill-corejs3");
21
22var _babelPluginPolyfillRegenerator = require("babel-plugin-polyfill-regenerator");
23
24const pluginCorejs2 = _babelPluginPolyfillCorejs.default || _babelPluginPolyfillCorejs;
25const pluginCorejs3 = _babelPluginPolyfillCorejs2.default || _babelPluginPolyfillCorejs2;
26const pluginRegenerator = _babelPluginPolyfillRegenerator.default || _babelPluginPolyfillRegenerator;
27const pluginsCompat = "#__secret_key__@babel/runtime__compatibility";
28
29function supportsStaticESM(caller) {
30 return !!(caller != null && caller.supportsStaticESM);
31}
32
33var _default = (0, _helperPluginUtils.declare)((api, options, dirname) => {
34 api.assertVersion(7);
35 const {
36 corejs,
37 helpers: useRuntimeHelpers = true,
38 regenerator: useRuntimeRegenerator = true,
39 useESModules = false,
40 version: runtimeVersion = "7.0.0-beta.0",
41 absoluteRuntime = false
42 } = options;
43 let proposals = false;
44 let rawVersion;
45
46 if (typeof corejs === "object" && corejs !== null) {
47 rawVersion = corejs.version;
48 proposals = Boolean(corejs.proposals);
49 } else {
50 rawVersion = corejs;
51 }
52
53 const corejsVersion = rawVersion ? Number(rawVersion) : false;
54
55 if (![false, 2, 3].includes(corejsVersion)) {
56 throw new Error(`The \`core-js\` version must be false, 2 or 3, but got ${JSON.stringify(rawVersion)}.`);
57 }
58
59 if (proposals && (!corejsVersion || corejsVersion < 3)) {
60 throw new Error("The 'proposals' option is only supported when using 'corejs: 3'");
61 }
62
63 if (typeof useRuntimeRegenerator !== "boolean") {
64 throw new Error("The 'regenerator' option must be undefined, or a boolean.");
65 }
66
67 if (typeof useRuntimeHelpers !== "boolean") {
68 throw new Error("The 'helpers' option must be undefined, or a boolean.");
69 }
70
71 if (typeof useESModules !== "boolean" && useESModules !== "auto") {
72 throw new Error("The 'useESModules' option must be undefined, or a boolean, or 'auto'.");
73 }
74
75 if (typeof absoluteRuntime !== "boolean" && typeof absoluteRuntime !== "string") {
76 throw new Error("The 'absoluteRuntime' option must be undefined, a boolean, or a string.");
77 }
78
79 if (typeof runtimeVersion !== "string") {
80 throw new Error(`The 'version' option must be a version string.`);
81 }
82
83 const DUAL_MODE_RUNTIME = "7.13.0";
84 const supportsCJSDefault = (0, _helpers.hasMinVersion)(DUAL_MODE_RUNTIME, runtimeVersion);
85
86 function has(obj, key) {
87 return Object.prototype.hasOwnProperty.call(obj, key);
88 }
89
90 if (has(options, "useBuiltIns")) {
91 if (options.useBuiltIns) {
92 throw new Error("The 'useBuiltIns' option has been removed. The @babel/runtime " + "module now uses builtins by default.");
93 } else {
94 throw new Error("The 'useBuiltIns' option has been removed. Use the 'corejs'" + "option to polyfill with `core-js` via @babel/runtime.");
95 }
96 }
97
98 if (has(options, "polyfill")) {
99 if (options.polyfill === false) {
100 throw new Error("The 'polyfill' option has been removed. The @babel/runtime " + "module now skips polyfilling by default.");
101 } else {
102 throw new Error("The 'polyfill' option has been removed. Use the 'corejs'" + "option to polyfill with `core-js` via @babel/runtime.");
103 }
104 }
105
106 if (has(options, "moduleName")) {
107 throw new Error("The 'moduleName' option has been removed. @babel/transform-runtime " + "no longer supports arbitrary runtimes. If you were using this to " + "set an absolute path for Babel's standard runtimes, please use the " + "'absoluteRuntime' option.");
108 }
109
110 const esModules = useESModules === "auto" ? api.caller(supportsStaticESM) : useESModules;
111 const injectCoreJS2 = corejsVersion === 2;
112 const injectCoreJS3 = corejsVersion === 3;
113 const moduleName = injectCoreJS3 ? "@babel/runtime-corejs3" : injectCoreJS2 ? "@babel/runtime-corejs2" : "@babel/runtime";
114 const HEADER_HELPERS = ["interopRequireWildcard", "interopRequireDefault"];
115 const modulePath = (0, _getRuntimePath.default)(moduleName, dirname, absoluteRuntime);
116
117 function createCorejsPlgin(plugin, options, regeneratorPlugin) {
118 return (api, _, filename) => {
119 return Object.assign({}, plugin(api, options, filename), {
120 inherits: regeneratorPlugin
121 });
122 };
123 }
124
125 function createRegeneratorPlugin(options) {
126 if (!useRuntimeRegenerator) return undefined;
127 return (api, _, filename) => {
128 return pluginRegenerator(api, options, filename);
129 };
130 }
131
132 const corejsExt = absoluteRuntime ? ".js" : "";
133 return {
134 name: "transform-runtime",
135 inherits: injectCoreJS2 ? createCorejsPlgin(pluginCorejs2, {
136 method: "usage-pure",
137 [pluginsCompat]: {
138 runtimeVersion,
139 useBabelRuntime: modulePath,
140 ext: corejsExt
141 }
142 }, createRegeneratorPlugin({
143 method: "usage-pure",
144 [pluginsCompat]: {
145 useBabelRuntime: modulePath
146 }
147 })) : injectCoreJS3 ? createCorejsPlgin(pluginCorejs3, {
148 method: "usage-pure",
149 version: 3,
150 proposals,
151 [pluginsCompat]: {
152 useBabelRuntime: modulePath,
153 ext: corejsExt
154 }
155 }, createRegeneratorPlugin({
156 method: "usage-pure",
157 [pluginsCompat]: {
158 useBabelRuntime: modulePath
159 }
160 })) : createRegeneratorPlugin({
161 method: "usage-pure",
162 [pluginsCompat]: {
163 useBabelRuntime: modulePath
164 }
165 }),
166
167 pre(file) {
168 if (!useRuntimeHelpers) return;
169 file.set("helperGenerator", name => {
170 if (file.availableHelper && !file.availableHelper(name, runtimeVersion)) {
171 return;
172 }
173
174 const isInteropHelper = HEADER_HELPERS.indexOf(name) !== -1;
175 const blockHoist = isInteropHelper && !(0, _helperModuleImports.isModule)(file.path) ? 4 : undefined;
176 const helpersDir = esModules && file.path.node.sourceType === "module" ? "helpers/esm" : "helpers";
177 return addDefaultImport(`${modulePath}/${helpersDir}/${name}`, name, blockHoist, true);
178 });
179 const cache = new Map();
180
181 function addDefaultImport(source, nameHint, blockHoist, isHelper = false) {
182 const cacheKey = (0, _helperModuleImports.isModule)(file.path);
183 const key = `${source}:${nameHint}:${cacheKey || ""}`;
184 let cached = cache.get(key);
185
186 if (cached) {
187 cached = _core.types.cloneNode(cached);
188 } else {
189 cached = (0, _helperModuleImports.addDefault)(file.path, source, {
190 importedInterop: isHelper && supportsCJSDefault ? "compiled" : "uncompiled",
191 nameHint,
192 blockHoist
193 });
194 cache.set(key, cached);
195 }
196
197 return cached;
198 }
199 }
200
201 };
202});
203
204exports.default = _default;
Note: See TracBrowser for help on using the repository browser.