mirror of https://github.com/webpack/webpack.git
				
				
				
			Merge pull request #3360 from webpack/bugfix/loader-options-remaining-request
fixes a bug in which complex options are not passed through chain
This commit is contained in:
		
						commit
						f4adee3e9d
					
				|  | @ -118,6 +118,17 @@ function NormalModuleFactory(context, resolvers, options) { | |||
| 				var loaders = results[0]; | ||||
| 				resource = results[1]; | ||||
| 
 | ||||
| 				// translate option idents
 | ||||
| 				try { | ||||
| 					loaders.forEach(function(item) { | ||||
| 						if(typeof item.options === "string" && /^\?/.test(item.options)) { | ||||
| 							item.options = _this.ruleSet.findOptionsByIdent(item.options.substr(1)); | ||||
| 						} | ||||
| 					}) | ||||
| 				} catch(e) { | ||||
| 					return callback(e); | ||||
| 				} | ||||
| 
 | ||||
| 				if(resource === false) | ||||
| 					return callback(null, | ||||
| 						new RawModule("/* (ignored) */", | ||||
|  |  | |||
|  | @ -71,24 +71,25 @@ normalized: | |||
| */ | ||||
| 
 | ||||
| function RuleSet(rules) { | ||||
| 	this.rules = RuleSet.normalizeRules(rules); | ||||
| 	this.references = {}; | ||||
| 	this.rules = RuleSet.normalizeRules(rules, this.references); | ||||
| } | ||||
| 
 | ||||
| module.exports = RuleSet; | ||||
| 
 | ||||
| RuleSet.normalizeRules = function(rules) { | ||||
| RuleSet.normalizeRules = function(rules, refs) { | ||||
| 	if(Array.isArray(rules)) { | ||||
| 		return rules.map(function(rule) { | ||||
| 			return RuleSet.normalizeRule(rule); | ||||
| 			return RuleSet.normalizeRule(rule, refs); | ||||
| 		}); | ||||
| 	} else if(rules) { | ||||
| 		return [RuleSet.normalizeRule(rules)] | ||||
| 		return [RuleSet.normalizeRule(rules, refs)] | ||||
| 	} else { | ||||
| 		return []; | ||||
| 	} | ||||
| }; | ||||
| 
 | ||||
| RuleSet.normalizeRule = function(rule) { | ||||
| RuleSet.normalizeRule = function(rule, refs) { | ||||
| 	if(typeof rule === "string") | ||||
| 		return { | ||||
| 			use: [{ | ||||
|  | @ -171,10 +172,10 @@ RuleSet.normalizeRule = function(rule) { | |||
| 	} | ||||
| 
 | ||||
| 	if(rule.rules) | ||||
| 		newRule.rules = RuleSet.normalizeRules(rule.rules); | ||||
| 		newRule.rules = RuleSet.normalizeRules(rule.rules, refs); | ||||
| 
 | ||||
| 	if(rule.oneOf) | ||||
| 		newRule.oneOf = RuleSet.normalizeRules(rule.oneOf); | ||||
| 		newRule.oneOf = RuleSet.normalizeRules(rule.oneOf, refs); | ||||
| 
 | ||||
| 	var keys = Object.keys(rule).filter(function(key) { | ||||
| 		return ["resource", "resourceQuery", "test", "include", "exclude", "issuer", "loader", "options", "query", "loaders", "use", "rules", "oneOf"].indexOf(key) < 0; | ||||
|  | @ -195,6 +196,14 @@ RuleSet.normalizeRule = function(rule) { | |||
| 		resourceSource = newSource; | ||||
| 	} | ||||
| 
 | ||||
| 	if(Array.isArray(newRule.use)) { | ||||
| 		newRule.use.forEach(function(item) { | ||||
| 			if(typeof item.options === "object" && item.options && item.options.ident) { | ||||
| 				refs["$" + item.options.ident] = item.options; | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	return newRule; | ||||
| }; | ||||
| 
 | ||||
|  | @ -398,3 +407,9 @@ RuleSet.prototype._run = function _run(data, rule, result) { | |||
| 
 | ||||
| 	return true; | ||||
| }; | ||||
| 
 | ||||
| RuleSet.prototype.findOptionsByIdent = function findOptionsByIdent(ident) { | ||||
| 	var options = this.references["$" + ident]; | ||||
| 	if(!options) throw new Error("Can't find options with ident '" + ident + "'"); | ||||
| 	return options; | ||||
| }; | ||||
|  |  | |||
|  | @ -0,0 +1,3 @@ | |||
| it("should correctly pass complex query object with remaining request", function() { | ||||
| 	require("./a").should.be.eql("ok"); | ||||
| }); | ||||
|  | @ -0,0 +1,3 @@ | |||
| module.exports.pitch = function(remainingRequest) { | ||||
| 	return "module.exports = require(" + JSON.stringify("!!" + remainingRequest) + ");"; | ||||
| }; | ||||
|  | @ -0,0 +1,3 @@ | |||
| module.exports = function(source) { | ||||
| 	return "module.exports = " + JSON.stringify(this.query.f()); | ||||
| }; | ||||
|  | @ -0,0 +1,21 @@ | |||
| module.exports = { | ||||
| 	module: { | ||||
| 		rules: [ | ||||
| 			{ | ||||
| 				test: /a\.js$/, | ||||
| 				use: [ | ||||
| 					"./loader1", | ||||
| 					{ | ||||
| 						loader: "./loader2", | ||||
| 						options: { | ||||
| 							ident: "loader2", | ||||
| 							f: function() { | ||||
| 								return "ok"; | ||||
| 							} | ||||
| 						} | ||||
| 					} | ||||
| 				] | ||||
| 			} | ||||
| 		] | ||||
| 	} | ||||
| } | ||||
		Loading…
	
		Reference in New Issue