WXL
4 天以前 2cc85c64f1c64a2dbaeae276a3e2ca8420de76b7
node_modules/webpack/lib/CompatibilityPlugin.js
@@ -21,6 +21,8 @@
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
/**
 * Captures the source range of a renamed compatibility binding so it can be
 * rewritten exactly once.
 * @typedef {object} CompatibilitySettingsDeclaration
 * @property {boolean} updated
 * @property {DependencyLocation} loc
@@ -28,6 +30,8 @@
 */
/**
 * Stores the replacement variable name and the declaration metadata tracked
 * for a compatibility rewrite.
 * @typedef {object} CompatibilitySettings
 * @property {string} name
 * @property {CompatibilitySettingsDeclaration} declaration
@@ -36,9 +40,14 @@
const nestedWebpackIdentifierTag = Symbol("nested webpack identifier");
const PLUGIN_NAME = "CompatibilityPlugin";
/**
 * Adds parser-time compatibility rewrites for legacy runtime patterns that
 * webpack still needs to recognize in user and generated code.
 */
class CompatibilityPlugin {
   /**
    * Apply the plugin
    * Installs parser hooks that preserve compatibility with legacy patterns
    * such as nested `__webpack_require__` bindings and hashbang handling.
    * @param {Compiler} compiler the compiler instance
    * @returns {void}
    */
@@ -64,6 +73,9 @@
                  parser.hooks.call.for("require").tap(
                     PLUGIN_NAME,
                     /**
                      * Rewrites browserify-style delegated `require` calls into a
                      * plain webpack require reference and removes the synthetic
                      * context dependency created for the delegator pattern.
                      * @param {CallExpression} expr call expression
                      * @returns {boolean | void} true when need to handle
                      */
@@ -103,6 +115,8 @@
               });
            /**
             * Attaches the compatibility rewrites for a JavaScript parser
             * instance.
             * @param {JavascriptParser} parser the parser
             * @returns {void}
             */
@@ -147,6 +161,9 @@
                           range: /** @type {Range} */ (pattern.range)
                        }
                     });
                     if (parser.scope.topLevelScope !== true) {
                        return true;
                     }
                  });
               parser.hooks.pattern
                  .for(RuntimeGlobals.exports)