Advertisement
Guest User

Untitled

a guest
Feb 5th, 2021
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2.  
  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); } }
  4.  
  5. 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); }); }; }
  6.  
  7. let babel;
  8.  
  9. try {
  10.   babel = require("@babel/core");
  11. } catch (err) {
  12.   if (err.code === "MODULE_NOT_FOUND") {
  13.     err.message += "\n babel-loader@8 requires Babel 7.x (the package '@babel/core'). " + "If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.";
  14.   }
  15.  
  16.   throw err;
  17. } // Since we've got the reverse bridge package at @babel/core@6.x, give
  18. // people useful feedback if they try to use it alongside babel-loader.
  19.  
  20.  
  21. if (/^6\./.test(babel.version)) {
  22.   throw new Error("\n babel-loader@8 will not work with the '@babel/core@6' bridge package. " + "If you want to use Babel 6.x, install 'babel-loader@7'.");
  23. }
  24.  
  25. const {
  26.   version
  27. } = require("../package.json");
  28.  
  29. const cache = require("./cache");
  30.  
  31. const transform = require("./transform");
  32.  
  33. const injectCaller = require("./injectCaller");
  34.  
  35. const schema = require("./schema");
  36.  
  37. const {
  38.   isAbsolute
  39. } = require("path");
  40.  
  41. const loaderUtils = require("loader-utils");
  42.  
  43. const validateOptions = require("schema-utils");
  44.  
  45. function subscribe(subscriber, metadata, context) {
  46.   if (context[subscriber]) {
  47.     context[subscriber](metadata);
  48.   }
  49. }
  50.  
  51. module.exports = makeLoader();
  52. module.exports.custom = makeLoader;
  53.  
  54. function makeLoader(callback) {
  55.   const overrides = callback ? callback(babel) : undefined;
  56.   return function (source, inputSourceMap) {
  57.     // Make the loader async
  58.     const callback = this.async();
  59.     loader.call(this, source, inputSourceMap, overrides).then(args => callback(null, ...args), err => callback(err));
  60.   };
  61. }
  62.  
  63. function loader(_x, _x2, _x3) {
  64.   return _loader.apply(this, arguments);
  65. }
  66.  
  67. function _loader() {
  68.   _loader = _asyncToGenerator(function* (source, inputSourceMap, overrides) {
  69.     const filename = this.resourcePath;
  70.     let loaderOptions = loaderUtils.getOptions(this) || {};
  71.     validateOptions(schema, loaderOptions, {
  72.       name: "Babel loader"
  73.     });
  74.  
  75.     if (loaderOptions.customize != null) {
  76.       if (typeof loaderOptions.customize !== "string") {
  77.         throw new Error("Customized loaders must be implemented as standalone modules.");
  78.       }
  79.  
  80.       if (!isAbsolute(loaderOptions.customize)) {
  81.         throw new Error("Customized loaders must be passed as absolute paths, since " + "babel-loader has no way to know what they would be relative to.");
  82.       }
  83.  
  84.       if (overrides) {
  85.         throw new Error("babel-loader's 'customize' option is not available when already " + "using a customized babel-loader wrapper.");
  86.       }
  87.  
  88.       let override = require(loaderOptions.customize);
  89.  
  90.       if (override.__esModule) override = override.default;
  91.  
  92.       if (typeof override !== "function") {
  93.         throw new Error("Custom overrides must be functions.");
  94.       }
  95.  
  96.       overrides = override(babel);
  97.     }
  98.  
  99.     let customOptions;
  100.  
  101.     if (overrides && overrides.customOptions) {
  102.       const result = yield overrides.customOptions.call(this, loaderOptions, {
  103.         source,
  104.         map: inputSourceMap
  105.       });
  106.       customOptions = result.custom;
  107.       loaderOptions = result.loader;
  108.     } // Deprecation handling
  109.  
  110.  
  111.     if ("forceEnv" in loaderOptions) {
  112.       console.warn("The option `forceEnv` has been removed in favor of `envName` in Babel 7.");
  113.     }
  114.  
  115.     if (typeof loaderOptions.babelrc === "string") {
  116.       console.warn("The option `babelrc` should not be set to a string anymore in the babel-loader config. " + "Please update your configuration and set `babelrc` to true or false.\n" + "If you want to specify a specific babel config file to inherit config from " + "please use the `extends` option.\nFor more information about this options see " + "https://babeljs.io/docs/core-packages/#options");
  117.     } // Standardize on 'sourceMaps' as the key passed through to Webpack, so that
  118.     // users may safely use either one alongside our default use of
  119.     // 'this.sourceMap' below without getting error about conflicting aliases.
  120.  
  121.  
  122.     if (Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") && !Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps")) {
  123.       loaderOptions = Object.assign({}, loaderOptions, {
  124.         sourceMaps: loaderOptions.sourceMap
  125.       });
  126.       delete loaderOptions.sourceMap;
  127.     }
  128.  
  129.     const programmaticOptions = Object.assign({}, loaderOptions, {
  130.       filename,
  131.       inputSourceMap: inputSourceMap || undefined,
  132.       // Set the default sourcemap behavior based on Webpack's mapping flag,
  133.       // but allow users to override if they want.
  134.       sourceMaps: loaderOptions.sourceMaps === undefined ? this.sourceMap : loaderOptions.sourceMaps,
  135.       // Ensure that Webpack will get a full absolute path in the sourcemap
  136.       // so that it can properly map the module back to its internal cached
  137.       // modules.
  138.       sourceFileName: filename
  139.     }); // Remove loader related options
  140.  
  141.     delete programmaticOptions.customize;
  142.     delete programmaticOptions.cacheDirectory;
  143.     delete programmaticOptions.cacheIdentifier;
  144.     delete programmaticOptions.cacheCompression;
  145.     delete programmaticOptions.metadataSubscribers;
  146.  
  147.     if (!babel.loadPartialConfig) {
  148.       throw new Error(`babel-loader ^8.0.0-beta.3 requires @babel/core@7.0.0-beta.41, but ` + `you appear to be using "${babel.version}". Either update your ` + `@babel/core version, or pin you babel-loader version to 8.0.0-beta.2`);
  149.     }
  150.  
  151.     const config = babel.loadPartialConfig(injectCaller(programmaticOptions, this.target));
  152.  
  153.     if (config) {
  154.       let options = config.options;
  155.  
  156.       if (overrides && overrides.config) {
  157.         options = yield overrides.config.call(this, config, {
  158.           source,
  159.           map: inputSourceMap,
  160.           customOptions
  161.         });
  162.       }
  163.  
  164.       if (options.sourceMaps === "inline") {
  165.         // Babel has this weird behavior where if you set "inline", we
  166.         // inline the sourcemap, and set 'result.map = null'. This results
  167.         // in bad behavior from Babel since the maps get put into the code,
  168.         // which Webpack does not expect, and because the map we return to
  169.         // Webpack is null, which is also bad. To avoid that, we override the
  170.         // behavior here so "inline" just behaves like 'true'.
  171.         options.sourceMaps = true;
  172.       }
  173.  
  174.       const {
  175.         cacheDirectory = null,
  176.         cacheIdentifier = JSON.stringify({
  177.           options,
  178.           "@babel/core": transform.version,
  179.           "@babel/loader": version
  180.         }),
  181.         cacheCompression = true,
  182.         metadataSubscribers = []
  183.       } = loaderOptions;
  184.       let result;
  185.  
  186.       if (cacheDirectory) {
  187.         result = yield cache({
  188.           source,
  189.           options,
  190.           transform,
  191.           cacheDirectory,
  192.           cacheIdentifier,
  193.           cacheCompression
  194.         });
  195.       } else {
  196.         result = yield transform(source, options);
  197.       } // TODO: Babel should really provide the full list of config files that
  198.       // were used so that this can also handle files loaded with 'extends'.
  199.  
  200.  
  201.       if (typeof config.babelrc === "string") {
  202.         this.addDependency(config.babelrc);
  203.       }
  204.  
  205.       if (result) {
  206.         if (overrides && overrides.result) {
  207.           result = yield overrides.result.call(this, result, {
  208.             source,
  209.             map: inputSourceMap,
  210.             customOptions,
  211.             config,
  212.             options
  213.           });
  214.         }
  215.  
  216.         const {
  217.           code,
  218.           map,
  219.           metadata
  220.         } = result;
  221.         metadataSubscribers.forEach(subscriber => {
  222.           subscribe(subscriber, metadata, this);
  223.         });
  224.         return [code, map];
  225.       }
  226.     } // If the file was ignored, pass through the original content.
  227.  
  228.  
  229.     return [source, inputSourceMap];
  230.   });
  231.   return _loader.apply(this, arguments);
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement