<NME> NodeSourcePlugin.js
<BEF> /*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
var AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
var ParserHelpers = require("../ParserHelpers");
var nodeLibsBrowser = require("node-libs-browser");

function NodeSourcePlugin(options) {
	this.options = options;
}
module.exports = NodeSourcePlugin;
NodeSourcePlugin.prototype.apply = function(compiler) {
	var options = this.options;

	function getPathToModule(module, type) {
		if(type === true || (type === undefined && nodeLibsBrowser[module])) {
			if(!nodeLibsBrowser[module]) throw new Error("No browser version for node.js core module '" + module + "' available");
			return nodeLibsBrowser[module];
		} else if(type === "mock") {
			return require.resolve("node-libs-browser/mock/" + module);
		} else if(type === "empty") {
			return require.resolve("node-libs-browser/mock/empty");
		} else return module;
	}

	function addExpression(parser, name, module, type, suffix) {
		suffix = suffix || "";
		parser.plugin("expression " + name, function() {
			if(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;
			var mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));
			return ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);
		});
	}

	compiler.plugin("compilation", function(compilation, params) {
		params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {

			if(parserOptions.node === false)
				return;

			var localOptions = options;
			if(parserOptions.node)
				localOptions = Object.assign({}, localOptions, parserOptions.node);

			if(localOptions.global) {
				parser.plugin("expression global", function() {
					var retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));
					return ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);
				});
			}
			if(localOptions.process) {
				var processType = localOptions.process;
				addExpression(parser, "process", "process", processType);
			}
			if(localOptions.console) {
				var consoleType = localOptions.console;
				addExpression(parser, "console", "console", consoleType);
			}
			var bufferType = localOptions.Buffer;
			if(bufferType) {
				addExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");
			}
			if(localOptions.setImmediate) {
				var setImmediateType = localOptions.setImmediate;
				addExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");
				addExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");
			}
		});
	});
	compiler.plugin("after-resolvers", function(compiler) {
		Object.keys(nodeLibsBrowser).forEach(function(lib) {
			if(options[lib] !== false) {
				compiler.resolvers.normal.apply(
					new AliasPlugin("described-resolve", {
						name: lib,
						onlyModule: true,
						alias: getPathToModule(lib, options[lib])
					}, "resolve")
				);
			}
		});
	});
};

<MSG> ES6 refactor of NodeSourcePlugin

<DFF> @@ -2,83 +2,85 @@
 	MIT License http://www.opensource.org/licenses/mit-license.php
 	Author Tobias Koppers @sokra
 */
-var AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
-var ParserHelpers = require("../ParserHelpers");
-var nodeLibsBrowser = require("node-libs-browser");
+"use strict";
+const AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
+const ParserHelpers = require("../ParserHelpers");
+const nodeLibsBrowser = require("node-libs-browser");
 
-function NodeSourcePlugin(options) {
-	this.options = options;
-}
-module.exports = NodeSourcePlugin;
-NodeSourcePlugin.prototype.apply = function(compiler) {
-	var options = this.options;
-
-	function getPathToModule(module, type) {
-		if(type === true || (type === undefined && nodeLibsBrowser[module])) {
-			if(!nodeLibsBrowser[module]) throw new Error("No browser version for node.js core module '" + module + "' available");
-			return nodeLibsBrowser[module];
-		} else if(type === "mock") {
-			return require.resolve("node-libs-browser/mock/" + module);
-		} else if(type === "empty") {
-			return require.resolve("node-libs-browser/mock/empty");
-		} else return module;
+module.exports = class NodeSourcePlugin {
+	constructor(options) {
+		this.options = options;
 	}
+	apply(compiler) {
+		let options = this.options;
 
-	function addExpression(parser, name, module, type, suffix) {
-		suffix = suffix || "";
-		parser.plugin("expression " + name, function() {
-			if(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;
-			var mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));
-			return ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);
-		});
-	}
+		function getPathToModule(module, type) {
+			if(type === true || (type === undefined && nodeLibsBrowser[module])) {
+				if(!nodeLibsBrowser[module]) throw new Error(`No browser version for node.js core module ${module} available`);
+				return nodeLibsBrowser[module];
+			} else if(type === "mock") {
+				return require.resolve(`node-libs-browser/mock/${module}`);
+			} else if(type === "empty") {
+				return require.resolve("node-libs-browser/mock/empty");
+			} else return module;
+		}
 
-	compiler.plugin("compilation", function(compilation, params) {
-		params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
+		function addExpression(parser, name, module, type, suffix) {
+			suffix = suffix || "";
+			parser.plugin(`expression ${name}`, function() {
+				if(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;
+				let mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));
+				return ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);
+			});
+		}
 
-			if(parserOptions.node === false)
-				return;
+		compiler.plugin("compilation", function(compilation, params) {
+			params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
 
-			var localOptions = options;
-			if(parserOptions.node)
-				localOptions = Object.assign({}, localOptions, parserOptions.node);
+				if(parserOptions.node === false)
+					return;
 
-			if(localOptions.global) {
-				parser.plugin("expression global", function() {
-					var retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));
-					return ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);
-				});
-			}
-			if(localOptions.process) {
-				var processType = localOptions.process;
-				addExpression(parser, "process", "process", processType);
-			}
-			if(localOptions.console) {
-				var consoleType = localOptions.console;
-				addExpression(parser, "console", "console", consoleType);
-			}
-			var bufferType = localOptions.Buffer;
-			if(bufferType) {
-				addExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");
-			}
-			if(localOptions.setImmediate) {
-				var setImmediateType = localOptions.setImmediate;
-				addExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");
-				addExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");
-			}
+				let localOptions = options;
+				if(parserOptions.node)
+					localOptions = Object.assign({}, localOptions, parserOptions.node);
+
+				if(localOptions.global) {
+					parser.plugin("expression global", function() {
+						let retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));
+						return ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);
+					});
+				}
+				if(localOptions.process) {
+					let processType = localOptions.process;
+					addExpression(parser, "process", "process", processType);
+				}
+				if(localOptions.console) {
+					let consoleType = localOptions.console;
+					addExpression(parser, "console", "console", consoleType);
+				}
+				let bufferType = localOptions.Buffer;
+				if(bufferType) {
+					addExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");
+				}
+				if(localOptions.setImmediate) {
+					let setImmediateType = localOptions.setImmediate;
+					addExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");
+					addExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");
+				}
+			});
 		});
-	});
-	compiler.plugin("after-resolvers", function(compiler) {
-		Object.keys(nodeLibsBrowser).forEach(function(lib) {
-			if(options[lib] !== false) {
-				compiler.resolvers.normal.apply(
-					new AliasPlugin("described-resolve", {
-						name: lib,
-						onlyModule: true,
-						alias: getPathToModule(lib, options[lib])
-					}, "resolve")
-				);
-			}
+		compiler.plugin("after-resolvers", (compiler) => {
+			Object.keys(nodeLibsBrowser).forEach((lib) => {
+				if(options[lib] !== false) {
+					compiler.resolvers.normal.apply(
+						new AliasPlugin("described-resolve", {
+							name: lib,
+							onlyModule: true,
+							alias: getPathToModule(lib, options[lib])
+						}, "resolve")
+					);
+				}
+			});
 		});
-	});
+	}
 };

{'commit': 'diff --git a/lib/node/NodeSourcePlugin.js b/lib/node/NodeSourcePlugin.js\nindex ca27c4e93..35dfb537e 100644\n--- a/lib/node/NodeSourcePlugin.js\n+++ b/lib/node/NodeSourcePlugin.js\n@@ -2,83 +2,85 @@\n \tMIT License http://www.opensource.org/licenses/mit-license.php\n \tAuthor Tobias Koppers @sokra\n */\n-var AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");\n-var ParserHelpers = require("../ParserHelpers");\n-var nodeLibsBrowser = require("node-libs-browser");\n+"use strict";\n+const AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");\n+const ParserHelpers = require("../ParserHelpers");\n+const nodeLibsBrowser = require("node-libs-browser");\n \n-function NodeSourcePlugin(options) {\n-\tthis.options = options;\n-}\n-module.exports = NodeSourcePlugin;\n-NodeSourcePlugin.prototype.apply = function(compiler) {\n-\tvar options = this.options;\n-\n-\tfunction getPathToModule(module, type) {\n-\t\tif(type === true || (type === undefined && nodeLibsBrowser[module])) {\n-\t\t\tif(!nodeLibsBrowser[module]) throw new Error("No browser version for node.js core module \'" + module + "\' available");\n-\t\t\treturn nodeLibsBrowser[module];\n-\t\t} else if(type === "mock") {\n-\t\t\treturn require.resolve("node-libs-browser/mock/" + module);\n-\t\t} else if(type === "empty") {\n-\t\t\treturn require.resolve("node-libs-browser/mock/empty");\n-\t\t} else return module;\n+module.exports = class NodeSourcePlugin {\n+\tconstructor(options) {\n+\t\tthis.options = options;\n \t}\n+\tapply(compiler) {\n+\t\tlet options = this.options;\n \n-\tfunction addExpression(parser, name, module, type, suffix) {\n-\t\tsuffix = suffix || "";\n-\t\tparser.plugin("expression " + name, function() {\n-\t\t\tif(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;\n-\t\t\tvar mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));\n-\t\t\treturn ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);\n-\t\t});\n-\t}\n+\t\tfunction getPathToModule(module, type) {\n+\t\t\tif(type === true || (type === undefined && nodeLibsBrowser[module])) {\n+\t\t\t\tif(!nodeLibsBrowser[module]) throw new Error(`No browser version for node.js core module ${module} available`);\n+\t\t\t\treturn nodeLibsBrowser[module];\n+\t\t\t} else if(type === "mock") {\n+\t\t\t\treturn require.resolve(`node-libs-browser/mock/${module}`);\n+\t\t\t} else if(type === "empty") {\n+\t\t\t\treturn require.resolve("node-libs-browser/mock/empty");\n+\t\t\t} else return module;\n+\t\t}\n \n-\tcompiler.plugin("compilation", function(compilation, params) {\n-\t\tparams.normalModuleFactory.plugin("parser", function(parser, parserOptions) {\n+\t\tfunction addExpression(parser, name, module, type, suffix) {\n+\t\t\tsuffix = suffix || "";\n+\t\t\tparser.plugin(`expression ${name}`, function() {\n+\t\t\t\tif(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;\n+\t\t\t\tlet mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));\n+\t\t\t\treturn ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);\n+\t\t\t});\n+\t\t}\n \n-\t\t\tif(parserOptions.node === false)\n-\t\t\t\treturn;\n+\t\tcompiler.plugin("compilation", function(compilation, params) {\n+\t\t\tparams.normalModuleFactory.plugin("parser", function(parser, parserOptions) {\n \n-\t\t\tvar localOptions = options;\n-\t\t\tif(parserOptions.node)\n-\t\t\t\tlocalOptions = Object.assign({}, localOptions, parserOptions.node);\n+\t\t\t\tif(parserOptions.node === false)\n+\t\t\t\t\treturn;\n \n-\t\t\tif(localOptions.global) {\n-\t\t\t\tparser.plugin("expression global", function() {\n-\t\t\t\t\tvar retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));\n-\t\t\t\t\treturn ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);\n-\t\t\t\t});\n-\t\t\t}\n-\t\t\tif(localOptions.process) {\n-\t\t\t\tvar processType = localOptions.process;\n-\t\t\t\taddExpression(parser, "process", "process", processType);\n-\t\t\t}\n-\t\t\tif(localOptions.console) {\n-\t\t\t\tvar consoleType = localOptions.console;\n-\t\t\t\taddExpression(parser, "console", "console", consoleType);\n-\t\t\t}\n-\t\t\tvar bufferType = localOptions.Buffer;\n-\t\t\tif(bufferType) {\n-\t\t\t\taddExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");\n-\t\t\t}\n-\t\t\tif(localOptions.setImmediate) {\n-\t\t\t\tvar setImmediateType = localOptions.setImmediate;\n-\t\t\t\taddExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");\n-\t\t\t\taddExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");\n-\t\t\t}\n+\t\t\t\tlet localOptions = options;\n+\t\t\t\tif(parserOptions.node)\n+\t\t\t\t\tlocalOptions = Object.assign({}, localOptions, parserOptions.node);\n+\n+\t\t\t\tif(localOptions.global) {\n+\t\t\t\t\tparser.plugin("expression global", function() {\n+\t\t\t\t\t\tlet retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));\n+\t\t\t\t\t\treturn ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);\n+\t\t\t\t\t});\n+\t\t\t\t}\n+\t\t\t\tif(localOptions.process) {\n+\t\t\t\t\tlet processType = localOptions.process;\n+\t\t\t\t\taddExpression(parser, "process", "process", processType);\n+\t\t\t\t}\n+\t\t\t\tif(localOptions.console) {\n+\t\t\t\t\tlet consoleType = localOptions.console;\n+\t\t\t\t\taddExpression(parser, "console", "console", consoleType);\n+\t\t\t\t}\n+\t\t\t\tlet bufferType = localOptions.Buffer;\n+\t\t\t\tif(bufferType) {\n+\t\t\t\t\taddExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");\n+\t\t\t\t}\n+\t\t\t\tif(localOptions.setImmediate) {\n+\t\t\t\t\tlet setImmediateType = localOptions.setImmediate;\n+\t\t\t\t\taddExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");\n+\t\t\t\t\taddExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");\n+\t\t\t\t}\n+\t\t\t});\n \t\t});\n-\t});\n-\tcompiler.plugin("after-resolvers", function(compiler) {\n-\t\tObject.keys(nodeLibsBrowser).forEach(function(lib) {\n-\t\t\tif(options[lib] !== false) {\n-\t\t\t\tcompiler.resolvers.normal.apply(\n-\t\t\t\t\tnew AliasPlugin("described-resolve", {\n-\t\t\t\t\t\tname: lib,\n-\t\t\t\t\t\tonlyModule: true,\n-\t\t\t\t\t\talias: getPathToModule(lib, options[lib])\n-\t\t\t\t\t}, "resolve")\n-\t\t\t\t);\n-\t\t\t}\n+\t\tcompiler.plugin("after-resolvers", (compiler) => {\n+\t\t\tObject.keys(nodeLibsBrowser).forEach((lib) => {\n+\t\t\t\tif(options[lib] !== false) {\n+\t\t\t\t\tcompiler.resolvers.normal.apply(\n+\t\t\t\t\t\tnew AliasPlugin("described-resolve", {\n+\t\t\t\t\t\t\tname: lib,\n+\t\t\t\t\t\t\tonlyModule: true,\n+\t\t\t\t\t\t\talias: getPathToModule(lib, options[lib])\n+\t\t\t\t\t\t}, "resolve")\n+\t\t\t\t\t);\n+\t\t\t\t}\n+\t\t\t});\n \t\t});\n-\t});\n+\t}\n };\n', 'commit_subject': 'ES6 refactor of NodeSourcePlugin', 'repo_name': 'webpack/webpack', 'committer': {'name': 'Orlando Wenzinger', 'email': '7b384d93fafcc7f245ae6aeb4930972e1e9b4aa8@bluewin.ch', 'time_sec': '1494096086', 'tz_offset': '120', 'date': {'seconds': '1494096086'}}, 'commit_tree': '2df5677abc157ef9774db1b21dceaf23354051b7', 'commit_message': 'ES6 refactor of NodeSourcePlugin\n', 'language_name': 'TypeScript', 'license': 'mit', 'hunks': '@@ -2,83 +2,85 @@\n \tMIT License http://www.opensource.org/licenses/mit-license.php\n \tAuthor Tobias Koppers @sokra\n */\n-var AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");\n-var ParserHelpers = require("../ParserHelpers");\n-var nodeLibsBrowser = require("node-libs-browser");\n+"use strict";\n+const AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");\n+const ParserHelpers = require("../ParserHelpers");\n+const nodeLibsBrowser = require("node-libs-browser");\n \n-function NodeSourcePlugin(options) {\n-\tthis.options = options;\n-}\n-module.exports = NodeSourcePlugin;\n-NodeSourcePlugin.prototype.apply = function(compiler) {\n-\tvar options = this.options;\n-\n-\tfunction getPathToModule(module, type) {\n-\t\tif(type === true || (type === undefined && nodeLibsBrowser[module])) {\n-\t\t\tif(!nodeLibsBrowser[module]) throw new Error("No browser version for node.js core module \'" + module + "\' available");\n-\t\t\treturn nodeLibsBrowser[module];\n-\t\t} else if(type === "mock") {\n-\t\t\treturn require.resolve("node-libs-browser/mock/" + module);\n-\t\t} else if(type === "empty") {\n-\t\t\treturn require.resolve("node-libs-browser/mock/empty");\n-\t\t} else return module;\n+module.exports = class NodeSourcePlugin {\n+\tconstructor(options) {\n+\t\tthis.options = options;\n \t}\n+\tapply(compiler) {\n+\t\tlet options = this.options;\n \n-\tfunction addExpression(parser, name, module, type, suffix) {\n-\t\tsuffix = suffix || "";\n-\t\tparser.plugin("expression " + name, function() {\n-\t\t\tif(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;\n-\t\t\tvar mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));\n-\t\t\treturn ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);\n-\t\t});\n-\t}\n+\t\tfunction getPathToModule(module, type) {\n+\t\t\tif(type === true || (type === undefined && nodeLibsBrowser[module])) {\n+\t\t\t\tif(!nodeLibsBrowser[module]) throw new Error(`No browser version for node.js core module ${module} available`);\n+\t\t\t\treturn nodeLibsBrowser[module];\n+\t\t\t} else if(type === "mock") {\n+\t\t\t\treturn require.resolve(`node-libs-browser/mock/${module}`);\n+\t\t\t} else if(type === "empty") {\n+\t\t\t\treturn require.resolve("node-libs-browser/mock/empty");\n+\t\t\t} else return module;\n+\t\t}\n \n-\tcompiler.plugin("compilation", function(compilation, params) {\n-\t\tparams.normalModuleFactory.plugin("parser", function(parser, parserOptions) {\n+\t\tfunction addExpression(parser, name, module, type, suffix) {\n+\t\t\tsuffix = suffix || "";\n+\t\t\tparser.plugin(`expression ${name}`, function() {\n+\t\t\t\tif(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;\n+\t\t\t\tlet mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));\n+\t\t\t\treturn ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);\n+\t\t\t});\n+\t\t}\n \n-\t\t\tif(parserOptions.node === false)\n-\t\t\t\treturn;\n+\t\tcompiler.plugin("compilation", function(compilation, params) {\n+\t\t\tparams.normalModuleFactory.plugin("parser", function(parser, parserOptions) {\n \n-\t\t\tvar localOptions = options;\n-\t\t\tif(parserOptions.node)\n-\t\t\t\tlocalOptions = Object.assign({}, localOptions, parserOptions.node);\n+\t\t\t\tif(parserOptions.node === false)\n+\t\t\t\t\treturn;\n \n-\t\t\tif(localOptions.global) {\n-\t\t\t\tparser.plugin("expression global", function() {\n-\t\t\t\t\tvar retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));\n-\t\t\t\t\treturn ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);\n-\t\t\t\t});\n-\t\t\t}\n-\t\t\tif(localOptions.process) {\n-\t\t\t\tvar processType = localOptions.process;\n-\t\t\t\taddExpression(parser, "process", "process", processType);\n-\t\t\t}\n-\t\t\tif(localOptions.console) {\n-\t\t\t\tvar consoleType = localOptions.console;\n-\t\t\t\taddExpression(parser, "console", "console", consoleType);\n-\t\t\t}\n-\t\t\tvar bufferType = localOptions.Buffer;\n-\t\t\tif(bufferType) {\n-\t\t\t\taddExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");\n-\t\t\t}\n-\t\t\tif(localOptions.setImmediate) {\n-\t\t\t\tvar setImmediateType = localOptions.setImmediate;\n-\t\t\t\taddExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");\n-\t\t\t\taddExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");\n-\t\t\t}\n+\t\t\t\tlet localOptions = options;\n+\t\t\t\tif(parserOptions.node)\n+\t\t\t\t\tlocalOptions = Object.assign({}, localOptions, parserOptions.node);\n+\n+\t\t\t\tif(localOptions.global) {\n+\t\t\t\t\tparser.plugin("expression global", function() {\n+\t\t\t\t\t\tlet retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));\n+\t\t\t\t\t\treturn ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);\n+\t\t\t\t\t});\n+\t\t\t\t}\n+\t\t\t\tif(localOptions.process) {\n+\t\t\t\t\tlet processType = localOptions.process;\n+\t\t\t\t\taddExpression(parser, "process", "process", processType);\n+\t\t\t\t}\n+\t\t\t\tif(localOptions.console) {\n+\t\t\t\t\tlet consoleType = localOptions.console;\n+\t\t\t\t\taddExpression(parser, "console", "console", consoleType);\n+\t\t\t\t}\n+\t\t\t\tlet bufferType = localOptions.Buffer;\n+\t\t\t\tif(bufferType) {\n+\t\t\t\t\taddExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");\n+\t\t\t\t}\n+\t\t\t\tif(localOptions.setImmediate) {\n+\t\t\t\t\tlet setImmediateType = localOptions.setImmediate;\n+\t\t\t\t\taddExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");\n+\t\t\t\t\taddExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");\n+\t\t\t\t}\n+\t\t\t});\n \t\t});\n-\t});\n-\tcompiler.plugin("after-resolvers", function(compiler) {\n-\t\tObject.keys(nodeLibsBrowser).forEach(function(lib) {\n-\t\t\tif(options[lib] !== false) {\n-\t\t\t\tcompiler.resolvers.normal.apply(\n-\t\t\t\t\tnew AliasPlugin("described-resolve", {\n-\t\t\t\t\t\tname: lib,\n-\t\t\t\t\t\tonlyModule: true,\n-\t\t\t\t\t\talias: getPathToModule(lib, options[lib])\n-\t\t\t\t\t}, "resolve")\n-\t\t\t\t);\n-\t\t\t}\n+\t\tcompiler.plugin("after-resolvers", (compiler) => {\n+\t\t\tObject.keys(nodeLibsBrowser).forEach((lib) => {\n+\t\t\t\tif(options[lib] !== false) {\n+\t\t\t\t\tcompiler.resolvers.normal.apply(\n+\t\t\t\t\t\tnew AliasPlugin("described-resolve", {\n+\t\t\t\t\t\t\tname: lib,\n+\t\t\t\t\t\t\tonlyModule: true,\n+\t\t\t\t\t\t\talias: getPathToModule(lib, options[lib])\n+\t\t\t\t\t\t}, "resolve")\n+\t\t\t\t\t);\n+\t\t\t\t}\n+\t\t\t});\n \t\t});\n-\t});\n+\t}\n };\n', 'addition_count': 72, 'deletion_count': 70, 'src_file': 'a/lib/node/NodeSourcePlugin.js', 'tgt_file': 'b/lib/node/NodeSourcePlugin.js', 'file_extension': '.js', 'before_file': '/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra\n*/\nvar AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");\nvar ParserHelpers = require("../ParserHelpers");\nvar nodeLibsBrowser = require("node-libs-browser");\n\nfunction NodeSourcePlugin(options) {\n\tthis.options = options;\n}\nmodule.exports = NodeSourcePlugin;\nNodeSourcePlugin.prototype.apply = function(compiler) {\n\tvar options = this.options;\n\n\tfunction getPathToModule(module, type) {\n\t\tif(type === true || (type === undefined && nodeLibsBrowser[module])) {\n\t\t\tif(!nodeLibsBrowser[module]) throw new Error("No browser version for node.js core module \'" + module + "\' available");\n\t\t\treturn nodeLibsBrowser[module];\n\t\t} else if(type === "mock") {\n\t\t\treturn require.resolve("node-libs-browser/mock/" + module);\n\t\t} else if(type === "empty") {\n\t\t\treturn require.resolve("node-libs-browser/mock/empty");\n\t\t} else return module;\n\t}\n\n\tfunction addExpression(parser, name, module, type, suffix) {\n\t\tsuffix = suffix || "";\n\t\tparser.plugin("expression " + name, function() {\n\t\t\tif(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;\n\t\t\tvar mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));\n\t\t\treturn ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);\n\t\t});\n\t}\n\n\tcompiler.plugin("compilation", function(compilation, params) {\n\t\tparams.normalModuleFactory.plugin("parser", function(parser, parserOptions) {\n\n\t\t\tif(parserOptions.node === false)\n\t\t\t\treturn;\n\n\t\t\tvar localOptions = options;\n\t\t\tif(parserOptions.node)\n\t\t\t\tlocalOptions = Object.assign({}, localOptions, parserOptions.node);\n\n\t\t\tif(localOptions.global) {\n\t\t\t\tparser.plugin("expression global", function() {\n\t\t\t\t\tvar retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));\n\t\t\t\t\treturn ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);\n\t\t\t\t});\n\t\t\t}\n\t\t\tif(localOptions.process) {\n\t\t\t\tvar processType = localOptions.process;\n\t\t\t\taddExpression(parser, "process", "process", processType);\n\t\t\t}\n\t\t\tif(localOptions.console) {\n\t\t\t\tvar consoleType = localOptions.console;\n\t\t\t\taddExpression(parser, "console", "console", consoleType);\n\t\t\t}\n\t\t\tvar bufferType = localOptions.Buffer;\n\t\t\tif(bufferType) {\n\t\t\t\taddExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");\n\t\t\t}\n\t\t\tif(localOptions.setImmediate) {\n\t\t\t\tvar setImmediateType = localOptions.setImmediate;\n\t\t\t\taddExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");\n\t\t\t\taddExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");\n\t\t\t}\n\t\t});\n\t});\n\tcompiler.plugin("after-resolvers", function(compiler) {\n\t\tObject.keys(nodeLibsBrowser).forEach(function(lib) {\n\t\t\tif(options[lib] !== false) {\n\t\t\t\tcompiler.resolvers.normal.apply(\n\t\t\t\t\tnew AliasPlugin("described-resolve", {\n\t\t\t\t\t\tname: lib,\n\t\t\t\t\t\tonlyModule: true,\n\t\t\t\t\t\talias: getPathToModule(lib, options[lib])\n\t\t\t\t\t}, "resolve")\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t});\n};\n', 'message': 'ES6 refactor of NodeSourcePlugin\n', 'author_name': 'Orlando Wenzinger', 'lang': 'js'}