WXL
4 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
node_modules/webpack/lib/library/AssignLibraryPlugin.js
@@ -9,7 +9,7 @@
const { UsageState } = require("../ExportsInfo");
const RuntimeGlobals = require("../RuntimeGlobals");
const Template = require("../Template");
const propertyAccess = require("../util/propertyAccess");
const { propertyAccess } = require("../util/property");
const { getEntryRuntime } = require("../util/runtime");
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
@@ -28,12 +28,13 @@
/** @typedef {import("../util/Hash")} Hash */
/**
 * Defines the shared type used by this module.
 * @template T
 * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
 */
const KEYWORD_REGEX =
   /^(await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/;
   /^(?:await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/;
const IDENTIFIER_REGEX =
   /^[\p{L}\p{Nl}$_][\p{L}\p{Nl}$\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*$/iu;
@@ -46,6 +47,7 @@
   !KEYWORD_REGEX.test(name) && IDENTIFIER_REGEX.test(name);
/**
 * Returns code to access the accessor while initializing.
 * @param {string[]} accessor variable plus properties
 * @param {number} existingLength items of accessor that are existing already
 * @param {boolean=} initLast if the last property should also be initialized to an object
@@ -99,6 +101,7 @@
/** @typedef {string[] | "global"} LibraryPrefix */
/**
 * Defines the assign library plugin options type used by this module.
 * @typedef {object} AssignLibraryPluginOptions
 * @property {LibraryType} type
 * @property {LibraryPrefix} prefix name prefix
@@ -110,17 +113,20 @@
/** @typedef {string | string[]} LibraryName */
/**
 * Defines the assign library plugin parsed type used by this module.
 * @typedef {object} AssignLibraryPluginParsed
 * @property {LibraryName} name
 * @property {LibraryExport=} export
 */
/**
 * Represents the assign library plugin runtime component.
 * @typedef {AssignLibraryPluginParsed} T
 * @extends {AbstractLibraryPlugin<AssignLibraryPluginParsed>}
 */
class AssignLibraryPlugin extends AbstractLibraryPlugin {
   /**
    * Creates an instance of AssignLibraryPlugin.
    * @param {AssignLibraryPluginOptions} options the plugin options
    */
   constructor(options) {
@@ -128,15 +134,20 @@
         pluginName: "AssignLibraryPlugin",
         type: options.type
      });
      /** @type {AssignLibraryPluginOptions["prefix"]} */
      this.prefix = options.prefix;
      /** @type {AssignLibraryPluginOptions["declare"]} */
      this.declare = options.declare;
      /** @type {AssignLibraryPluginOptions["unnamed"]} */
      this.unnamed = options.unnamed;
      /** @type {AssignLibraryPluginOptions["named"]} */
      this.named = options.named || "assign";
   }
   /**
    * Returns preprocess as needed by overriding.
    * @param {LibraryOptions} library normalized library option
    * @returns {T | false} preprocess as needed by overriding
    * @returns {T} preprocess as needed by overriding
    */
   parseOptions(library) {
      const { name } = library;
@@ -159,6 +170,7 @@
   }
   /**
    * Finish entry module.
    * @param {Module} module the exporting entry module
    * @param {string} entryName the name of the entrypoint
    * @param {LibraryContext<T>} libraryContext context
@@ -185,6 +197,7 @@
   }
   /**
    * Returns the prefix.
    * @param {Compilation} compilation the compilation
    * @returns {LibraryPrefix} the prefix
    */
@@ -195,6 +208,7 @@
   }
   /**
    * Get resolved full name.
    * @param {AssignLibraryPluginParsed} options the library options
    * @param {Chunk} chunk the chunk
    * @param {Compilation} compilation the compilation
@@ -216,6 +230,7 @@
   }
   /**
    * Returns source with library export.
    * @param {Source} source source
    * @param {RenderContext} renderContext render context
    * @param {LibraryContext<T>} libraryContext context
@@ -244,6 +259,7 @@
   }
   /**
    * Embed in runtime bailout.
    * @param {Module} module the exporting entry module
    * @param {RenderContext} renderContext render context
    * @param {LibraryContext<T>} libraryContext context
@@ -273,6 +289,7 @@
   }
   /**
    * Strict runtime bailout.
    * @param {RenderContext} renderContext render context
    * @param {LibraryContext<T>} libraryContext context
    * @returns {string | undefined} bailout reason
@@ -290,6 +307,7 @@
   }
   /**
    * Renders source with library export.
    * @param {Source} source source
    * @param {Module} module module
    * @param {StartupRenderContext} renderContext render context
@@ -402,6 +420,7 @@
   }
   /**
    * Processes the provided chunk.
    * @param {Chunk} chunk the chunk
    * @param {RuntimeRequirements} set runtime requirements
    * @param {LibraryContext<T>} libraryContext context
@@ -412,6 +431,7 @@
   }
   /**
    * Processes the provided chunk.
    * @param {Chunk} chunk the chunk
    * @param {Hash} hash hash
    * @param {ChunkHashContext} chunkHashContext chunk hash context