Merge pull request #12225 from webpack/bugfix/undefined-conditions

treat `undefined` equal to not existing in rules
This commit is contained in:
Tobias Koppers 2020-12-17 13:31:36 +01:00 committed by GitHub
commit ed4694dd9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 30 deletions

View File

@ -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.

View File

@ -96,9 +96,11 @@ class RuleSetCompiler {
} }
} else if (p in data) { } else if (p in data) {
const value = data[p]; const value = data[p];
if (value !== undefined) {
if (!condition.fn(value)) return false; if (!condition.fn(value)) return false;
continue; continue;
} }
}
if (!condition.matchWhenEmpty) { if (!condition.matchWhenEmpty) {
return false; return false;
} }

View File

@ -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"

View File

@ -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"]);
}); });

26
types.d.ts vendored
View File

@ -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[];
/** /**