File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed
Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 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
5757normalized:
@@ -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 ) {
Original file line number Diff line number Diff line change @@ -268,4 +268,29 @@ describe("RuleSet", function() {
268268 ( match ( loader , 'style.css' ) ) . should . eql ( [ 'css' ] ) ;
269269 } , / N o l o a d e r s p e c i f i e d / )
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 : / \. c s s $ / ,
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 ( / E x p e c t e d c o n d i t i o n b u t g o t f a l s y v a l u e / . test ( err )
287+ && / t e s t / . test ( err )
288+ && / i n c l u d e / . test ( err )
289+ && / e x c l u d e / . test ( err )
290+ && / n o d e _ m o d u l e s / . test ( err )
291+ && / u n d e f i n e d / . test ( err ) ) {
292+ return true ;
293+ }
294+ } )
295+ } ) ;
271296} ) ;
You can’t perform that action at this time.
0 commit comments