@@ -224,21 +224,33 @@ RuleSet.normalizeUse = function normalizeUse(use) {
224224 return [ RuleSet . normalizeUseItem ( use ) ] ;
225225} ;
226226
227+ RuleSet . normalizeUseItemFunction = function normalizeUseItemFunction ( use , data ) {
228+ var result = use ( data ) ;
229+ if ( typeof result === "string" ) {
230+ return RuleSet . normalizeUseItem ( result ) ;
231+ }
232+ return result ;
233+ }
234+
235+ RuleSet . normalizeUseItemString = function normalizeUseItemString ( useItemString ) {
236+ var idx = useItemString . indexOf ( "?" ) ;
237+ if ( idx >= 0 ) {
238+ return {
239+ loader : useItemString . substr ( 0 , idx ) ,
240+ options : useItemString . substr ( idx + 1 )
241+ } ;
242+ }
243+ return {
244+ loader : useItemString
245+ } ;
246+ }
247+
227248RuleSet . normalizeUseItem = function normalizeUseItem ( item ) {
228249 if ( typeof item === "function" )
229250 return item ;
230251
231252 if ( typeof item === "string" ) {
232- var idx = item . indexOf ( "?" ) ;
233- if ( idx >= 0 ) {
234- return {
235- loader : item . substr ( 0 , idx ) ,
236- options : item . substr ( idx + 1 )
237- } ;
238- }
239- return {
240- loader : item
241- } ;
253+ return RuleSet . normalizeUseItemString ( item ) ;
242254 }
243255
244256 var newItem = { } ;
@@ -384,7 +396,7 @@ RuleSet.prototype._run = function _run(data, rule, result) {
384396 rule . use . forEach ( function ( use ) {
385397 result . push ( {
386398 type : "use" ,
387- value : typeof use === "function" ? use ( data ) : use ,
399+ value : typeof use === "function" ? RuleSet . normalizeUseItemFunction ( use , data ) : use ,
388400 enforce : rule . enforce
389401 } ) ;
390402 } ) ;
0 commit comments