index.js
function func(declarations, functions, functionMatcher, parseArgs) {
  if (!declarations) return;
  if (false !== parseArgs) parseArgs = true;

  declarations.forEach(function(decl){
    if ('comment' == decl.type) return;
    var generatedFuncs = [], result, generatedFunc;

    while (decl.value.match(functionMatcher)) {
      decl.value = decl.value.replace(functionMatcher, function(_, name, args){
        if (parseArgs) {
          args = args.split(/\s*,\s*/).map(strip);
        } else {
          args = [strip(args)];
        }
        // Ensure result is string
        result = '' + functions[name].apply(decl, args);

        // Prevent fall into infinite loop like this:
        //
        // {
        //   url: function(path) {
        //     return 'url(' + '/some/prefix' + path + ')'
        //   }
        // }
        //
        generatedFunc = {from: name, to: name + getRandomString()};
        result = result.replace(functionMatcherBuilder(name), generatedFunc.to + '($2)');
        generatedFuncs.push(generatedFunc);
        return result;
      });
    }

    generatedFuncs.forEach(function(func) {
      decl.value = decl.value.replace(func.to, func.from);
    })
  });
}
function func(declarations, functions, functionMatcher, parseArgs) {
  if (!declarations) return;
  if (false !== parseArgs) parseArgs = true;

  declarations.forEach(function(decl){
    if ('comment' == decl.type) return;
    var generatedFuncs = [], result, generatedFunc;

    while (decl.value.match(functionMatcher)) {
      decl.value = decl.value.replace(functionMatcher, function(_, name, args){
        if (parseArgs) {
          args = args.split(/\s*,\s*/).map(strip);
        } else {
          args = [strip(args)];
        }
        // Ensure result is string
        result = '' + functions[name].apply(decl, args);

        // Prevent fall into infinite loop like this:
        //
        // {
        //   url: function(path) {
        //     return 'url(' + '/some/prefix' + path + ')'
        //   }
        // }
        //
        generatedFunc = {from: name, to: name + getRandomString()};
        result = result.replace(functionMatcherBuilder(name), generatedFunc.to + '($2)');
        generatedFuncs.push(generatedFunc);
        return result;
      });
    }

    generatedFuncs.forEach(function(func) {
      decl.value = decl.value.replace(func.to, func.from);
    })
  });
}
function func ( declarations , functions , functionMatcher , parseArgs ) { if ( ! declarations ) return ; if ( false !== parseArgs ) parseArgs = true ; declarations . forEach ( function ( decl ) { if ( 'comment' == decl . type ) return ; var generatedFuncs = [ ] , result , generatedFunc ; while ( decl . value . match ( functionMatcher ) ) { decl . value = decl . value . replace ( functionMatcher , function ( _ , name , args ) { if ( parseArgs ) { args = args . split ( / \s*,\s* / ) . map ( strip ) ; } else { args = [ strip ( args ) ] ; } // Ensure result is string result = '' + functions [ name ] . apply ( decl , args ) ; // Prevent fall into infinite loop like this: // // { //   url: function(path) { //     return 'url(' + '/some/prefix' + path + ')' //   } // } // generatedFunc = { from : name , to : name + getRandomString ( ) } ; result = result . replace ( functionMatcherBuilder ( name ) , generatedFunc . to + '($2)' ) ; generatedFuncs . push ( generatedFunc ) ; return result ; } ) ; } generatedFuncs . forEach ( function ( func ) { decl . value = decl . value . replace ( func . to , func . from ) ; } ) } ) ; }
Visit declarations and apply functions.

@param {Array} declarations
@param {Object} functions
@param {RegExp} functionMatcher
@param {Boolean} [parseArgs]
@api private
Visit declarations and apply functions .