aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/CompatibilityPlugin.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/webpack/lib/CompatibilityPlugin.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/webpack/lib/CompatibilityPlugin.js')
-rw-r--r--node_modules/webpack/lib/CompatibilityPlugin.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/node_modules/webpack/lib/CompatibilityPlugin.js b/node_modules/webpack/lib/CompatibilityPlugin.js
new file mode 100644
index 00000000..1544d6c8
--- /dev/null
+++ b/node_modules/webpack/lib/CompatibilityPlugin.js
@@ -0,0 +1,70 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const ConstDependency = require("./dependencies/ConstDependency");
+
+const NullFactory = require("./NullFactory");
+
+/** @typedef {import("./Compiler")} Compiler */
+
+class CompatibilityPlugin {
+ /**
+ * Apply the plugin
+ * @param {Compiler} compiler Webpack Compiler
+ * @returns {void}
+ */
+ apply(compiler) {
+ compiler.hooks.compilation.tap(
+ "CompatibilityPlugin",
+ (compilation, { normalModuleFactory }) => {
+ compilation.dependencyFactories.set(ConstDependency, new NullFactory());
+ compilation.dependencyTemplates.set(
+ ConstDependency,
+ new ConstDependency.Template()
+ );
+
+ normalModuleFactory.hooks.parser
+ .for("javascript/auto")
+ .tap("CompatibilityPlugin", (parser, parserOptions) => {
+ if (
+ parserOptions.browserify !== undefined &&
+ !parserOptions.browserify
+ )
+ return;
+
+ parser.hooks.call
+ .for("require")
+ .tap("CompatibilityPlugin", expr => {
+ // support for browserify style require delegator: "require(o, !0)"
+ if (expr.arguments.length !== 2) return;
+ const second = parser.evaluateExpression(expr.arguments[1]);
+ if (!second.isBoolean()) return;
+ if (second.asBool() !== true) return;
+ const dep = new ConstDependency("require", expr.callee.range);
+ dep.loc = expr.loc;
+ if (parser.state.current.dependencies.length > 1) {
+ const last =
+ parser.state.current.dependencies[
+ parser.state.current.dependencies.length - 1
+ ];
+ if (
+ last.critical &&
+ last.options &&
+ last.options.request === "." &&
+ last.userRequest === "." &&
+ last.options.recursive
+ )
+ parser.state.current.dependencies.pop();
+ }
+ parser.state.current.addDependency(dep);
+ return true;
+ });
+ });
+ }
+ );
+ }
+}
+module.exports = CompatibilityPlugin;