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;
}
| ((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.

View File

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

View File

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

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

26
types.d.ts vendored
View File

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