mirror of https://github.com/webpack/webpack.git
				
				
				
			Merge pull request #12225 from webpack/bugfix/undefined-conditions
treat `undefined` equal to not existing in rules
This commit is contained in:
		
						commit
						ed4694dd9b
					
				|  | @ -240,7 +240,7 @@ export type RuleSetCondition = | |||
| 			 */ | ||||
| 			or?: RuleSetConditions; | ||||
| 	  } | ||||
| 	| ((value: string | undefined) => boolean) | ||||
| 	| ((value: string) => boolean) | ||||
| 	| RuleSetConditions; | ||||
| /** | ||||
|  * A list of rule conditions. | ||||
|  | @ -272,7 +272,7 @@ export type RuleSetConditionAbsolute = | |||
| 			 */ | ||||
| 			or?: RuleSetConditionsAbsolute; | ||||
| 	  } | ||||
| 	| ((value: string | undefined) => boolean) | ||||
| 	| ((value: string) => boolean) | ||||
| 	| RuleSetConditionsAbsolute; | ||||
| /** | ||||
|  * A list of rule conditions matching an absolute path. | ||||
|  |  | |||
|  | @ -96,9 +96,11 @@ class RuleSetCompiler { | |||
| 					} | ||||
| 				} else if (p in data) { | ||||
| 					const value = data[p]; | ||||
| 					if (value !== undefined) { | ||||
| 						if (!condition.fn(value)) return false; | ||||
| 						continue; | ||||
| 					} | ||||
| 				} | ||||
| 				if (!condition.matchWhenEmpty) { | ||||
| 					return false; | ||||
| 				} | ||||
|  |  | |||
|  | @ -2663,7 +2663,7 @@ | |||
|         }, | ||||
|         { | ||||
|           "instanceof": "Function", | ||||
|           "tsType": "((value: string | undefined) => boolean)" | ||||
|           "tsType": "((value: string) => boolean)" | ||||
|         }, | ||||
|         { | ||||
|           "$ref": "#/definitions/RuleSetConditions" | ||||
|  | @ -2716,7 +2716,7 @@ | |||
|         }, | ||||
|         { | ||||
|           "instanceof": "Function", | ||||
|           "tsType": "((value: string | undefined) => boolean)" | ||||
|           "tsType": "((value: string) => boolean)" | ||||
|         }, | ||||
|         { | ||||
|           "$ref": "#/definitions/RuleSetConditionsAbsolute" | ||||
|  |  | |||
|  | @ -1,15 +1,10 @@ | |||
| it("should match rule with resource query", function () { | ||||
| 	var a1 = require("./a"); | ||||
| 	expect(a1).toEqual([ | ||||
| 		"a" | ||||
| 	]); | ||||
| 	expect(a1).toEqual(["a"]); | ||||
| 	var a2 = require("./a?loader"); | ||||
| 	expect(a2).toEqual([ | ||||
| 		"a", | ||||
| 		"?query" | ||||
| 	]); | ||||
| 	expect(a2).toEqual(["a", "?query"]); | ||||
| 	var a3 = require("./a?other"); | ||||
| 	expect(a3).toEqual([ | ||||
| 		"a" | ||||
| 	]); | ||||
| 	expect(a3).toEqual(["a"]); | ||||
| 	var a4 = require('data:application/node,module.exports = ["a"];'); | ||||
| 	expect(a4).toEqual(["a"]); | ||||
| }); | ||||
|  |  | |||
|  | @ -7735,7 +7735,7 @@ type RuleSetCondition = | |||
| 			 */ | ||||
| 			or?: RuleSetCondition[]; | ||||
| 	  } | ||||
| 	| ((value?: string) => boolean) | ||||
| 	| ((value: string) => boolean) | ||||
| 	| RuleSetCondition[]; | ||||
| type RuleSetConditionAbsolute = | ||||
| 	| string | ||||
|  | @ -7754,7 +7754,7 @@ type RuleSetConditionAbsolute = | |||
| 			 */ | ||||
| 			or?: RuleSetConditionAbsolute[]; | ||||
| 	  } | ||||
| 	| ((value?: string) => boolean) | ||||
| 	| ((value: string) => boolean) | ||||
| 	| RuleSetConditionAbsolute[]; | ||||
| 
 | ||||
| /** | ||||
|  | @ -7781,7 +7781,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetCondition[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetCondition[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -7804,7 +7804,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetCondition[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetCondition[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -7837,7 +7837,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetConditionAbsolute[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetConditionAbsolute[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -7865,7 +7865,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetConditionAbsolute[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetConditionAbsolute[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -7888,7 +7888,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetConditionAbsolute[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetConditionAbsolute[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -7916,7 +7916,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetCondition[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetCondition[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -7954,7 +7954,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetConditionAbsolute[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetConditionAbsolute[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -7982,7 +7982,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetConditionAbsolute[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetConditionAbsolute[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -8005,7 +8005,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetCondition[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetCondition[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -8028,7 +8028,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetCondition[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetCondition[]; | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -8061,7 +8061,7 @@ declare interface RuleSetRule { | |||
| 				 */ | ||||
| 				or?: RuleSetConditionAbsolute[]; | ||||
| 		  } | ||||
| 		| ((value?: string) => boolean) | ||||
| 		| ((value: string) => boolean) | ||||
| 		| RuleSetConditionAbsolute[]; | ||||
| 
 | ||||
| 	/** | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue