Skip to content

Commit 6dd2863

Browse files
feat(ruleSet): show context when exclude holds undefined
1 parent 80bd894 commit 6dd2863

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lib/RuleSet.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<condition>: { and: [<condition>] }
5252
<condition>: { or: [<condition>] }
5353
<condition>: { not: [<condition>] }
54-
<condition>: { test: <condition>, include: <condition>, exclude: <codition> }
54+
<condition>: { test: <condition>, include: <condition>, exclude: <condition> }
5555
5656
5757
normalized:
@@ -109,11 +109,20 @@ RuleSet.normalizeRule = function(rule) {
109109

110110
if(rule.test || rule.include || rule.exclude) {
111111
checkResourceSource("test + include + exclude");
112-
newRule.resource = RuleSet.normalizeCondition({
112+
var condition = {
113113
test: rule.test,
114114
include: rule.include,
115115
exclude: rule.exclude
116-
});
116+
};
117+
try {
118+
newRule.resource = RuleSet.normalizeCondition(condition);
119+
} catch (error) {
120+
var conditionAsText = JSON.stringify(condition, function(key, value) {
121+
return (value === undefined) ? "undefined" : value;
122+
}, 2)
123+
var message = error.message + " in " + conditionAsText;
124+
throw new Error(message);
125+
}
117126
}
118127

119128
if(rule.resource) {

test/RuleSet.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,29 @@ describe("RuleSet", function() {
268268
(match(loader, 'style.css')).should.eql(['css']);
269269
}, /No loader specified/)
270270
});
271+
it('should throw with context if exclude array holds an undefined item', function() {
272+
should.throws(function() {
273+
var loader = new RuleSet([{
274+
test: /\.css$/,
275+
loader: 'css',
276+
include: [
277+
'src',
278+
],
279+
exclude: [
280+
'node_modules',
281+
undefined,
282+
],
283+
}]);
284+
(match(loader, 'style.css')).should.eql(['css']);
285+
}, function(err) {
286+
if (/Expected condition but got falsy value/.test(err)
287+
&& /test/.test(err)
288+
&& /include/.test(err)
289+
&& /exclude/.test(err)
290+
&& /node_modules/.test(err)
291+
&& /undefined/.test(err)) {
292+
return true;
293+
}
294+
})
295+
});
271296
});

0 commit comments

Comments
 (0)