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;
 | 
								or?: RuleSetConditions;
 | 
				
			||||||
	  }
 | 
						  }
 | 
				
			||||||
	| ((value: string | undefined) => boolean)
 | 
						| ((value: string) => boolean)
 | 
				
			||||||
	| RuleSetConditions;
 | 
						| RuleSetConditions;
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * A list of rule conditions.
 | 
					 * A list of rule conditions.
 | 
				
			||||||
| 
						 | 
					@ -272,7 +272,7 @@ export type RuleSetConditionAbsolute =
 | 
				
			||||||
			 */
 | 
								 */
 | 
				
			||||||
			or?: RuleSetConditionsAbsolute;
 | 
								or?: RuleSetConditionsAbsolute;
 | 
				
			||||||
	  }
 | 
						  }
 | 
				
			||||||
	| ((value: string | undefined) => boolean)
 | 
						| ((value: string) => boolean)
 | 
				
			||||||
	| RuleSetConditionsAbsolute;
 | 
						| RuleSetConditionsAbsolute;
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * A list of rule conditions matching an absolute path.
 | 
					 * A list of rule conditions matching an absolute path.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,8 +96,10 @@ class RuleSetCompiler {
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				} else if (p in data) {
 | 
									} else if (p in data) {
 | 
				
			||||||
					const value = data[p];
 | 
										const value = data[p];
 | 
				
			||||||
					if (!condition.fn(value)) return false;
 | 
										if (value !== undefined) {
 | 
				
			||||||
					continue;
 | 
											if (!condition.fn(value)) return false;
 | 
				
			||||||
 | 
											continue;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (!condition.matchWhenEmpty) {
 | 
									if (!condition.matchWhenEmpty) {
 | 
				
			||||||
					return false;
 | 
										return false;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2663,7 +2663,7 @@
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          "instanceof": "Function",
 | 
					          "instanceof": "Function",
 | 
				
			||||||
          "tsType": "((value: string | undefined) => boolean)"
 | 
					          "tsType": "((value: string) => boolean)"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          "$ref": "#/definitions/RuleSetConditions"
 | 
					          "$ref": "#/definitions/RuleSetConditions"
 | 
				
			||||||
| 
						 | 
					@ -2716,7 +2716,7 @@
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          "instanceof": "Function",
 | 
					          "instanceof": "Function",
 | 
				
			||||||
          "tsType": "((value: string | undefined) => boolean)"
 | 
					          "tsType": "((value: string) => boolean)"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          "$ref": "#/definitions/RuleSetConditionsAbsolute"
 | 
					          "$ref": "#/definitions/RuleSetConditionsAbsolute"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,15 +1,10 @@
 | 
				
			||||||
it("should match rule with resource query", function() {
 | 
					it("should match rule with resource query", function () {
 | 
				
			||||||
	var a1 = require("./a");
 | 
						var a1 = require("./a");
 | 
				
			||||||
	expect(a1).toEqual([
 | 
						expect(a1).toEqual(["a"]);
 | 
				
			||||||
		"a"
 | 
					 | 
				
			||||||
	]);
 | 
					 | 
				
			||||||
	var a2 = require("./a?loader");
 | 
						var a2 = require("./a?loader");
 | 
				
			||||||
	expect(a2).toEqual([
 | 
						expect(a2).toEqual(["a", "?query"]);
 | 
				
			||||||
		"a",
 | 
					 | 
				
			||||||
		"?query"
 | 
					 | 
				
			||||||
	]);
 | 
					 | 
				
			||||||
	var a3 = require("./a?other");
 | 
						var a3 = require("./a?other");
 | 
				
			||||||
	expect(a3).toEqual([
 | 
						expect(a3).toEqual(["a"]);
 | 
				
			||||||
		"a"
 | 
						var a4 = require('data:application/node,module.exports = ["a"];');
 | 
				
			||||||
	]);
 | 
						expect(a4).toEqual(["a"]);
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7735,7 +7735,7 @@ type RuleSetCondition =
 | 
				
			||||||
			 */
 | 
								 */
 | 
				
			||||||
			or?: RuleSetCondition[];
 | 
								or?: RuleSetCondition[];
 | 
				
			||||||
	  }
 | 
						  }
 | 
				
			||||||
	| ((value?: string) => boolean)
 | 
						| ((value: string) => boolean)
 | 
				
			||||||
	| RuleSetCondition[];
 | 
						| RuleSetCondition[];
 | 
				
			||||||
type RuleSetConditionAbsolute =
 | 
					type RuleSetConditionAbsolute =
 | 
				
			||||||
	| string
 | 
						| string
 | 
				
			||||||
| 
						 | 
					@ -7754,7 +7754,7 @@ type RuleSetConditionAbsolute =
 | 
				
			||||||
			 */
 | 
								 */
 | 
				
			||||||
			or?: RuleSetConditionAbsolute[];
 | 
								or?: RuleSetConditionAbsolute[];
 | 
				
			||||||
	  }
 | 
						  }
 | 
				
			||||||
	| ((value?: string) => boolean)
 | 
						| ((value: string) => boolean)
 | 
				
			||||||
	| RuleSetConditionAbsolute[];
 | 
						| RuleSetConditionAbsolute[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -7781,7 +7781,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetCondition[];
 | 
									or?: RuleSetCondition[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetCondition[];
 | 
							| RuleSetCondition[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -7804,7 +7804,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetCondition[];
 | 
									or?: RuleSetCondition[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetCondition[];
 | 
							| RuleSetCondition[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -7837,7 +7837,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetConditionAbsolute[];
 | 
									or?: RuleSetConditionAbsolute[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetConditionAbsolute[];
 | 
							| RuleSetConditionAbsolute[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -7865,7 +7865,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetConditionAbsolute[];
 | 
									or?: RuleSetConditionAbsolute[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetConditionAbsolute[];
 | 
							| RuleSetConditionAbsolute[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -7888,7 +7888,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetConditionAbsolute[];
 | 
									or?: RuleSetConditionAbsolute[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetConditionAbsolute[];
 | 
							| RuleSetConditionAbsolute[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -7916,7 +7916,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetCondition[];
 | 
									or?: RuleSetCondition[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetCondition[];
 | 
							| RuleSetCondition[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -7954,7 +7954,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetConditionAbsolute[];
 | 
									or?: RuleSetConditionAbsolute[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetConditionAbsolute[];
 | 
							| RuleSetConditionAbsolute[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -7982,7 +7982,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetConditionAbsolute[];
 | 
									or?: RuleSetConditionAbsolute[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetConditionAbsolute[];
 | 
							| RuleSetConditionAbsolute[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -8005,7 +8005,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetCondition[];
 | 
									or?: RuleSetCondition[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetCondition[];
 | 
							| RuleSetCondition[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -8028,7 +8028,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetCondition[];
 | 
									or?: RuleSetCondition[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetCondition[];
 | 
							| RuleSetCondition[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					@ -8061,7 +8061,7 @@ declare interface RuleSetRule {
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				or?: RuleSetConditionAbsolute[];
 | 
									or?: RuleSetConditionAbsolute[];
 | 
				
			||||||
		  }
 | 
							  }
 | 
				
			||||||
		| ((value?: string) => boolean)
 | 
							| ((value: string) => boolean)
 | 
				
			||||||
		| RuleSetConditionAbsolute[];
 | 
							| RuleSetConditionAbsolute[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue