| | |
| | | /** @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 |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Stores the replacement variable name and the declaration metadata tracked |
| | | * for a compatibility rewrite. |
| | | * @typedef {object} CompatibilitySettings |
| | | * @property {string} name |
| | | * @property {CompatibilitySettingsDeclaration} declaration |
| | |
| | | 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} |
| | | */ |
| | |
| | | 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 |
| | | */ |
| | |
| | | }); |
| | | |
| | | /** |
| | | * Attaches the compatibility rewrites for a JavaScript parser |
| | | * instance. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @returns {void} |
| | | */ |
| | |
| | | range: /** @type {Range} */ (pattern.range) |
| | | } |
| | | }); |
| | | if (parser.scope.topLevelScope !== true) { |
| | | return true; |
| | | } |
| | | }); |
| | | parser.hooks.pattern |
| | | .for(RuntimeGlobals.exports) |