WXL
3 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js
@@ -6,13 +6,14 @@
"use strict";
const Dependency = require("../Dependency");
const InitFragment = require("../InitFragment");
const Template = require("../Template");
const {
   getDependencyUsedByExportsCondition
} = require("../optimize/InnerGraph");
const { getTrimmedIdsAndRange } = require("../util/chainedImports");
const makeSerializable = require("../util/makeSerializable");
const propertyAccess = require("../util/propertyAccess");
const { propertyAccess } = require("../util/property");
const traverseDestructuringAssignmentProperties = require("../util/traverseDestructuringAssignmentProperties");
const HarmonyImportDependency = require("./HarmonyImportDependency");
const { ImportPhaseUtils } = require("./ImportPhase");
@@ -39,12 +40,15 @@
/** @typedef {HarmonyImportDependency.Ids} Ids */
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
const idsSymbol = Symbol("HarmonyImportSpecifierDependency.ids");
const idsSymbol = /** @type {symbol} */ (
   Symbol("HarmonyImportSpecifierDependency.ids")
);
const { ExportPresenceModes } = HarmonyImportDependency;
class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
   /**
    * Creates an instance of HarmonyImportSpecifierDependency.
    * @param {string} request request
    * @param {number} sourceOrder source order
    * @param {Ids} ids ids
@@ -72,10 +76,15 @@
      this.range = range;
      this.idRanges = idRanges;
      this.exportPresenceMode = exportPresenceMode;
      /** @type {undefined | boolean} */
      this.namespaceObjectAsContext = false;
      /** @type {undefined | boolean} */
      this.call = undefined;
      /** @type {undefined | boolean} */
      this.directImport = undefined;
      /** @type {undefined | boolean | string} */
      this.shorthand = undefined;
      /** @type {undefined | boolean} */
      this.asiSafe = undefined;
      /** @type {UsedByExports | undefined} */
      this.usedByExports = undefined;
@@ -84,16 +93,28 @@
   }
   // TODO webpack 6 remove
   /**
    * Returns id.
    * @deprecated
    */
   get id() {
      throw new Error("id was renamed to ids and type changed to string[]");
   }
   // TODO webpack 6 remove
   /**
    * Returns id.
    * @deprecated
    */
   getId() {
      throw new Error("id was renamed to ids and type changed to string[]");
   }
   // TODO webpack 6 remove
   /**
    * Updates id.
    * @deprecated
    */
   setId() {
      throw new Error("id was renamed to ids and type changed to string[]");
   }
@@ -103,6 +124,7 @@
   }
   /**
    * Returns the imported ids.
    * @param {ModuleGraph} moduleGraph the module graph
    * @returns {Ids} the imported ids
    */
@@ -114,6 +136,7 @@
   }
   /**
    * Updates ids using the provided module graph.
    * @param {ModuleGraph} moduleGraph the module graph
    * @param {Ids} ids the imported ids
    * @returns {void}
@@ -123,6 +146,7 @@
   }
   /**
    * Returns function to determine if the connection is active.
    * @param {ModuleGraph} moduleGraph module graph
    * @returns {null | false | GetConditionFn} function to determine if the connection is active
    */
@@ -135,6 +159,7 @@
   }
   /**
    * Gets module evaluation side effects state.
    * @param {ModuleGraph} moduleGraph the module graph
    * @returns {ConnectionState} how this dependency connects the module to referencing modules
    */
@@ -192,6 +217,7 @@
   }
   /**
    * Get referenced exports in destructuring.
    * @param {Ids=} ids ids
    * @returns {RawReferencedExports} referenced exports
    */
@@ -214,6 +240,7 @@
   }
   /**
    * Get effective export presence level.
    * @param {ModuleGraph} moduleGraph module graph
    * @returns {ExportPresenceMode} effective mode
    */
@@ -233,7 +260,7 @@
   }
   /**
    * Returns warnings
    * Returns warnings.
    * @param {ModuleGraph} moduleGraph module graph
    * @returns {WebpackError[] | null | undefined} warnings
    */
@@ -246,7 +273,7 @@
   }
   /**
    * Returns errors
    * Returns errors.
    * @param {ModuleGraph} moduleGraph module graph
    * @returns {WebpackError[] | null | undefined} errors
    */
@@ -259,6 +286,7 @@
   }
   /**
    * Returns errors.
    * @param {ModuleGraph} moduleGraph module graph
    * @returns {WebpackError[] | undefined} errors
    */
@@ -280,6 +308,7 @@
   }
   /**
    * Serializes this instance into the provided serializer context.
    * @param {ObjectSerializerContext} context context
    */
   serialize(context) {
@@ -300,6 +329,7 @@
   }
   /**
    * Restores this instance from the provided deserializer context.
    * @param {ObjectDeserializerContext} context context
    */
   deserialize(context) {
@@ -329,6 +359,7 @@
   HarmonyImportDependency.Template
) {
   /**
    * Applies the plugin by registering its hooks on the compiler.
    * @param {Dependency} dependency the dependency for which the template should be applied
    * @param {ReplaceSource} source the current replace source which can be modified
    * @param {DependencyTemplateContext} templateContext the context object
@@ -336,10 +367,22 @@
    */
   apply(dependency, source, templateContext) {
      const dep = /** @type {HarmonyImportSpecifierDependency} */ (dependency);
      const { moduleGraph, runtime } = templateContext;
      const { moduleGraph, runtime, initFragments } = templateContext;
      const connection = moduleGraph.getConnection(dep);
      // Skip rendering depending when dependency is conditional
      if (connection && !connection.isTargetActive(runtime)) return;
      // Only render declaration for import specifier when the dependency is conditional
      if (connection && !connection.isTargetActive(runtime)) {
         initFragments.push(
            new InitFragment(
               `/* unused harmony import specifier */ var ${dep.name};\n`,
               InitFragment.STAGE_HARMONY_IMPORTS,
               0,
               `unused import specifier ${dep.name}`
            )
         );
         return;
      }
      const ids = dep.getIds(moduleGraph);
      const {
@@ -421,6 +464,7 @@
   }
   /**
    * Returns generated code.
    * @param {HarmonyImportSpecifierDependency} dep dependency
    * @param {ReplaceSource} source source
    * @param {DependencyTemplateContext} templateContext context
@@ -431,6 +475,7 @@
      const { moduleGraph, module, runtime, concatenationScope } =
         templateContext;
      const connection = moduleGraph.getConnection(dep);
      /** @type {string} */
      let exportExpr;
      if (
         connection &&