diff --git a/declarations/WebpackOptions.d.ts b/declarations/WebpackOptions.d.ts index d2cac1d46..e2c5dab7e 100644 --- a/declarations/WebpackOptions.d.ts +++ b/declarations/WebpackOptions.d.ts @@ -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. diff --git a/lib/rules/RuleSetCompiler.js b/lib/rules/RuleSetCompiler.js index 34dc1ac1f..81241d2cd 100644 --- a/lib/rules/RuleSetCompiler.js +++ b/lib/rules/RuleSetCompiler.js @@ -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; diff --git a/schemas/WebpackOptions.json b/schemas/WebpackOptions.json index 8b5fff49a..4bdbb164b 100644 --- a/schemas/WebpackOptions.json +++ b/schemas/WebpackOptions.json @@ -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" diff --git a/test/configCases/rule-set/query/index.js b/test/configCases/rule-set/query/index.js index 7114b9778..ea461d53b 100644 --- a/test/configCases/rule-set/query/index.js +++ b/test/configCases/rule-set/query/index.js @@ -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"]); }); diff --git a/types.d.ts b/types.d.ts index 6fad48796..756256ca9 100644 --- a/types.d.ts +++ b/types.d.ts @@ -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[]; /**