WXL
4 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
node_modules/webpack/lib/RuntimeTemplate.js
@@ -19,7 +19,7 @@
const { equals } = require("./util/ArrayHelpers");
const compileBooleanMatcher = require("./util/compileBooleanMatcher");
const memoize = require("./util/memoize");
const propertyAccess = require("./util/propertyAccess");
const { propertyAccess } = require("./util/property");
const { forEachRuntime, subtractRuntime } = require("./util/runtime");
const getHarmonyImportDependency = memoize(() =>
@@ -45,6 +45,7 @@
/** @typedef {import("./NormalModuleFactory").ModuleDependency} ModuleDependency */
/**
 * No module id error message.
 * @param {Module} module the module
 * @param {ChunkGraph} chunkGraph the chunk graph
 * @returns {string} error message
@@ -71,6 +72,7 @@
).join("")}`;
/**
 * Gets global object.
 * @param {string | undefined} definition global object definition
 * @returns {string | undefined} save to use global object
 */
@@ -84,7 +86,7 @@
      // iife
      // call expression
      // expression in parentheses
      /^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
      /^(?:[_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
   ) {
      return trimmed;
   }
@@ -94,6 +96,7 @@
class RuntimeTemplate {
   /**
    * Creates an instance of RuntimeTemplate.
    * @param {Compilation} compilation the compilation
    * @param {OutputOptions} outputOptions the compilation output options
    * @param {RequestShortener} requestShortener the request shortener
@@ -125,6 +128,10 @@
   supportsConst() {
      return this.outputOptions.environment.const;
   }
   supportsMethodShorthand() {
      return this.outputOptions.environment.methodShorthand;
   }
   supportsArrowFunction() {
@@ -168,6 +175,7 @@
   }
   /**
    * Renders node prefix for core module.
    * @param {string} mod a module
    * @returns {string} a module with `node:` prefix when supported, otherwise an original name
    */
@@ -178,6 +186,7 @@
   }
   /**
    * Renders return const when it is supported, otherwise var.
    * @returns {"const" | "var"} return `const` when it is supported, otherwise `var`
    */
   renderConst() {
@@ -185,6 +194,7 @@
   }
   /**
    * Returning function.
    * @param {string} returnValue return value
    * @param {string} args arguments
    * @returns {string} returning function
@@ -196,6 +206,7 @@
   }
   /**
    * Returns basic function.
    * @param {string} args arguments
    * @param {string | string[]} body body
    * @returns {string} basic function
@@ -207,6 +218,7 @@
   }
   /**
    * Returns result expression.
    * @param {(string | { expr: string })[]} args args
    * @returns {string} result expression
    */
@@ -256,6 +268,7 @@
   }
   /**
    * Returns result expression.
    * @param {(string | { expr: string })[]} args args (len >= 2)
    * @returns {string} result expression
    * @private
@@ -273,6 +286,7 @@
   }
   /**
    * Expression function.
    * @param {string} expression expression
    * @param {string} args arguments
    * @returns {string} expression function code
@@ -284,6 +298,7 @@
   }
   /**
    * Returns empty function code.
    * @returns {string} empty function code
    */
   emptyFunction() {
@@ -291,6 +306,7 @@
   }
   /**
    * Returns destructure array code.
    * @param {string[]} items items
    * @param {string} value value
    * @returns {string} destructure array code
@@ -304,6 +320,7 @@
   }
   /**
    * Destructure object.
    * @param {string[]} items items
    * @param {string} value value
    * @returns {string} destructure object code
@@ -319,6 +336,7 @@
   }
   /**
    * Returns iIFE code.
    * @param {string} args arguments
    * @param {string} body body
    * @returns {string} IIFE code
@@ -328,6 +346,7 @@
   }
   /**
    * Returns for each code.
    * @param {string} variable variable
    * @param {string} array array
    * @param {string | string[]} body body
@@ -342,7 +361,7 @@
   }
   /**
    * Add a comment
    * Returns comment.
    * @param {object} options Information content of the comment
    * @param {string=} options.request request string used originally
    * @param {(string | null)=} options.chunkName name of the chunk referenced
@@ -352,6 +371,7 @@
    * @returns {string} comment
    */
   comment({ request, chunkName, chunkReason, message, exportName }) {
      /** @type {string} */
      let content;
      if (this.outputOptions.pathinfo) {
         content = [message, request, chunkName, chunkReason]
@@ -372,6 +392,7 @@
   }
   /**
    * Throw missing module error block.
    * @param {object} options generation options
    * @param {string=} options.request request string used originally
    * @returns {string} generated error block
@@ -384,6 +405,7 @@
   }
   /**
    * Throw missing module error function.
    * @param {object} options generation options
    * @param {string=} options.request request string used originally
    * @returns {string} generated error function
@@ -395,6 +417,7 @@
   }
   /**
    * Returns generated error IIFE.
    * @param {object} options generation options
    * @param {string=} options.request request string used originally
    * @returns {string} generated error IIFE
@@ -404,6 +427,7 @@
   }
   /**
    * Missing module statement.
    * @param {object} options generation options
    * @param {string=} options.request request string used originally
    * @returns {string} generated error statement
@@ -413,6 +437,7 @@
   }
   /**
    * Missing module promise.
    * @param {object} options generation options
    * @param {string=} options.request request string used originally
    * @returns {string} generated error code
@@ -424,6 +449,7 @@
   }
   /**
    * Returns the code.
    * @param {object} options options object
    * @param {ChunkGraph} options.chunkGraph the chunk graph
    * @param {Module} options.module the module
@@ -460,6 +486,7 @@
   }
   /**
    * Returns the expression.
    * @param {object} options options object
    * @param {Module} options.module the module
    * @param {ChunkGraph} options.chunkGraph the chunk graph
@@ -489,6 +516,7 @@
   }
   /**
    * Returns the expression.
    * @param {object} options options object
    * @param {Module | null} options.module the module
    * @param {ChunkGraph} options.chunkGraph the chunk graph
@@ -532,6 +560,7 @@
   }
   /**
    * Returns the expression.
    * @param {object} options options object
    * @param {Module | null} options.module the module
    * @param {ChunkGraph} options.chunkGraph the chunk graph
@@ -551,6 +580,7 @@
   }
   /**
    * Returns the expression.
    * @param {object} options options object
    * @param {Module} options.module the module
    * @param {ChunkGraph} options.chunkGraph the chunk graph
@@ -620,6 +650,7 @@
   }
   /**
    * Module namespace promise.
    * @param {object} options options object
    * @param {ChunkGraph} options.chunkGraph the chunk graph
    * @param {AsyncDependenciesBlock=} options.block the current dependencies block
@@ -674,6 +705,7 @@
         runtimeRequirements
      });
      /** @type {string} */
      let appending;
      let idExpr = JSON.stringify(chunkGraph.getModuleId(module));
      const comment = this.comment({
@@ -707,7 +739,10 @@
      if (isModuleDeferred) {
         runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
         const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
         let mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
         if (mode) mode = `${mode} | 16`;
         const asyncDeps = Array.from(
            getOutgoingAsyncModules(chunkGraph.moduleGraph, module),
            (m) => chunkGraph.getModuleId(m)
@@ -808,6 +843,7 @@
   }
   /**
    * Runtime condition expression.
    * @param {object} options options object
    * @param {ChunkGraph} options.chunkGraph the chunk graph
    * @param {RuntimeSpec=} options.runtime runtime for which this code will be generated
@@ -845,17 +881,18 @@
   }
   /**
    * Returns the import statement and the compat statement.
    * @param {object} options options object
    * @param {boolean=} options.update whether a new variable should be created or the existing one updated
    * @param {Module} options.module the module
    * @param {Module} options.originModule module in which the statement is emitted
    * @param {ModuleGraph} options.moduleGraph the module graph
    * @param {ChunkGraph} options.chunkGraph the chunk graph
    * @param {string} options.request the request that should be printed as comment
    * @param {string} options.importVar name of the import variable
    * @param {Module} options.originModule module in which the statement is emitted
    * @param {boolean=} options.weak true, if this is a weak dependency
    * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
    * @param {ModuleDependency} options.dependency module dependency
    * @param {string} options.importVar name of the import variable
    * @param {string=} options.request the request that should be printed as comment
    * @param {boolean=} options.weak true, if this is a weak dependency
    * @param {ModuleDependency=} options.dependency module dependency
    * @returns {[string, string]} the import statement and the compat statement
    */
   importStatement({
@@ -914,6 +951,8 @@
         (originModule.buildMeta).strictHarmonyModule
      );
      runtimeRequirements.add(RuntimeGlobals.require);
      /** @type {string} */
      let importContent;
      const isModuleDeferred =
@@ -948,6 +987,7 @@
   }
   /**
    * Export from import.
    * @template GenerateContext
    * @param {object} options options
    * @param {ModuleGraph} options.moduleGraph the module graph
@@ -956,8 +996,8 @@
    * @param {string} options.request the request
    * @param {string | string[]} options.exportName the export name
    * @param {Module} options.originModule the origin module
    * @param {boolean|undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted
    * @param {boolean} options.isCall true, if expression will be called
    * @param {boolean | undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted
    * @param {boolean | undefined} options.isCall true, if expression will be called
    * @param {boolean | null} options.callContext when false, call context will not be preserved
    * @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated
    * @param {string} options.importVar the identifier name of the import variable
@@ -1143,6 +1183,7 @@
   }
   /**
    * Returns expression.
    * @param {object} options options
    * @param {AsyncDependenciesBlock | undefined} options.block the async block
    * @param {string} options.message the message
@@ -1194,6 +1235,7 @@
         }
         /**
          * Returns require chunk id code.
          * @param {Chunk} chunk chunk
          * @returns {string} require chunk id code
          */
@@ -1209,6 +1251,7 @@
   }
   /**
    * Async module factory.
    * @param {object} options options
    * @param {AsyncDependenciesBlock} options.block the async block
    * @param {ChunkGraph} options.chunkGraph the chunk graph
@@ -1241,6 +1284,7 @@
   }
   /**
    * Sync module factory.
    * @param {object} options options
    * @param {Dependency} options.dependency the dependency
    * @param {ChunkGraph} options.chunkGraph the chunk graph
@@ -1262,6 +1306,7 @@
   }
   /**
    * Define es module flag statement.
    * @param {object} options options
    * @param {string} options.exportsArgument the name of the exports object
    * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements