| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var path = require("path"); | 
					
						
							| 
									
										
										
										
											2014-06-06 01:52:45 +08:00
										 |  |  | var ConstDependency = require("./dependencies/ConstDependency"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-16 21:18:49 +08:00
										 |  |  | var NullFactory = require("./NullFactory"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | function CompatibilityPlugin() {} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | module.exports = CompatibilityPlugin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CompatibilityPlugin.prototype.apply = function(compiler) { | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 	compiler.plugin("compilation", function(compilation) { | 
					
						
							| 
									
										
										
										
											2014-06-16 21:18:49 +08:00
										 |  |  | 		compilation.dependencyFactories.set(ConstDependency, new NullFactory()); | 
					
						
							|  |  |  | 		compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template()); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-06-06 01:52:45 +08:00
										 |  |  | 	compiler.parser.plugin("call require", function(expr) { | 
					
						
							|  |  |  | 		// support for browserify style require delegator: "require(o, !0)"
 | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 		if(expr.arguments.length !== 2) return; | 
					
						
							| 
									
										
										
										
											2014-06-06 01:52:45 +08:00
										 |  |  | 		var second = this.evaluateExpression(expr.arguments[1]); | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 		if(!second.isBoolean()) return; | 
					
						
							|  |  |  | 		if(second.asBool() !== true) return; | 
					
						
							| 
									
										
										
										
											2014-06-06 01:52:45 +08:00
										 |  |  | 		var dep = new ConstDependency("require", expr.callee.range); | 
					
						
							|  |  |  | 		dep.loc = expr.loc; | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 		if(this.state.current.dependencies.length > 1) { | 
					
						
							| 
									
										
										
										
											2014-06-06 01:52:45 +08:00
										 |  |  | 			var last = this.state.current.dependencies[this.state.current.dependencies.length - 1]; | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 			if(last.critical && last.request === "." && last.userRequest === "." && last.recursive) | 
					
						
							| 
									
										
										
										
											2014-06-06 01:52:45 +08:00
										 |  |  | 				this.state.current.dependencies.pop(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this.state.current.addDependency(dep); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-03-06 21:59:11 +08:00
										 |  |  | }; |