src/index.js
function tag (chrSource) {
      var program
      var replacements

      // Examine caller format
      if (typeof chrSource === 'object' && chrSource.type && chrSource.type === 'Program') {
        // called with already parsed source code
        // e.g. tag({ type: 'Program', body: [ ... ] })
        program = chrSource
        replacements = []

        // allow to specify replacements as second argument
        if (arguments[1] && typeof arguments[1] === 'object' && arguments[1] instanceof Array) {
          replacements = arguments[1]
        }
      } else if (typeof chrSource === 'object' && chrSource instanceof Array && typeof chrSource[0] === 'string') {
        // called as template tag
        // e.g. tag`a ==> b`
        // or   tag`a ==> ${ function() { console.log('Replacement test') } }`
        var combined = [
          chrSource[0]
        ]
        Array.prototype.slice.call(arguments, 1).forEach(function (repl, ix) {
          combined.push(repl)
          combined.push(chrSource[ix + 1])
        })
        chrSource = joinParts(combined)
        replacements = Array.prototype.slice.call(arguments, 1)
        program = parse(chrSource)
      } else if (typeof chrSource === 'string' && arguments[1] && arguments[1] instanceof Array) {
        // called with program and replacements array
        // e.g. tag(
        //        'a ==> ${ function() { console.log("Replacement test") } }',
        //        [ eval('( function() { console.log("Replacement test") } )') ]
        //      )
        // this is useful to ensure the scope of the given replacements
        program = parse(chrSource)
        replacements = arguments[1]
      } else if (typeof chrSource === 'string') {
        // called as normal function
        // e.g. tag('a ==> b')
        // or   tag('a ==> ', function() { console.log('Replacement test') })
        replacements = Array.prototype.filter.call(arguments, isFunction)
        chrSource = joinParts(Array.prototype.slice.call(arguments))
        program = parse(chrSource)
      }

      var rules = program.body
      rules.forEach(function (rule) {
        tag.Rules.Add(rule, replacements)
      })
    }
function tag (chrSource) {
      var program
      var replacements

      // Examine caller format
      if (typeof chrSource === 'object' && chrSource.type && chrSource.type === 'Program') {
        // called with already parsed source code
        // e.g. tag({ type: 'Program', body: [ ... ] })
        program = chrSource
        replacements = []

        // allow to specify replacements as second argument
        if (arguments[1] && typeof arguments[1] === 'object' && arguments[1] instanceof Array) {
          replacements = arguments[1]
        }
      } else if (typeof chrSource === 'object' && chrSource instanceof Array && typeof chrSource[0] === 'string') {
        // called as template tag
        // e.g. tag`a ==> b`
        // or   tag`a ==> ${ function() { console.log('Replacement test') } }`
        var combined = [
          chrSource[0]
        ]
        Array.prototype.slice.call(arguments, 1).forEach(function (repl, ix) {
          combined.push(repl)
          combined.push(chrSource[ix + 1])
        })
        chrSource = joinParts(combined)
        replacements = Array.prototype.slice.call(arguments, 1)
        program = parse(chrSource)
      } else if (typeof chrSource === 'string' && arguments[1] && arguments[1] instanceof Array) {
        // called with program and replacements array
        // e.g. tag(
        //        'a ==> ${ function() { console.log("Replacement test") } }',
        //        [ eval('( function() { console.log("Replacement test") } )') ]
        //      )
        // this is useful to ensure the scope of the given replacements
        program = parse(chrSource)
        replacements = arguments[1]
      } else if (typeof chrSource === 'string') {
        // called as normal function
        // e.g. tag('a ==> b')
        // or   tag('a ==> ', function() { console.log('Replacement test') })
        replacements = Array.prototype.filter.call(arguments, isFunction)
        chrSource = joinParts(Array.prototype.slice.call(arguments))
        program = parse(chrSource)
      }

      var rules = program.body
      rules.forEach(function (rule) {
        tag.Rules.Add(rule, replacements)
      })
    }
function tag ( chrSource ) { var program var replacements // Examine caller format if ( typeof chrSource === 'object' && chrSource . type && chrSource . type === 'Program' ) { // called with already parsed source code // e.g. tag({ type: 'Program', body: [ ... ] }) program = chrSource replacements = [ ] // allow to specify replacements as second argument if ( arguments [ 1 ] && typeof arguments [ 1 ] === 'object' && arguments [ 1 ] instanceof Array ) { replacements = arguments [ 1 ] } } else if ( typeof chrSource === 'object' && chrSource instanceof Array && typeof chrSource [ 0 ] === 'string' ) { // called as template tag // e.g. tag`a ==> b` // or   tag`a ==> ${ function() { console.log('Replacement test') } }` var combined = [ chrSource [ 0 ] ] Array . prototype . slice . call ( arguments , 1 ) . forEach ( function ( repl , ix ) { combined . push ( repl ) combined . push ( chrSource [ ix + 1 ] ) } ) chrSource = joinParts ( combined ) replacements = Array . prototype . slice . call ( arguments , 1 ) program = parse ( chrSource ) } else if ( typeof chrSource === 'string' && arguments [ 1 ] && arguments [ 1 ] instanceof Array ) { // called with program and replacements array // e.g. tag( //        'a ==> ${ function() { console.log("Replacement test") } }', //        [ eval('( function() { console.log("Replacement test") } )') ] //      ) // this is useful to ensure the scope of the given replacements program = parse ( chrSource ) replacements = arguments [ 1 ] } else if ( typeof chrSource === 'string' ) { // called as normal function // e.g. tag('a ==> b') // or   tag('a ==> ', function() { console.log('Replacement test') }) replacements = Array . prototype . filter . call ( arguments , isFunction ) chrSource = joinParts ( Array . prototype . slice . call ( arguments ) ) program = parse ( chrSource ) } var rules = program . body rules . forEach ( function ( rule ) { tag . Rules . Add ( rule , replacements ) } ) }
Adds a number of rules given.
Adds a number of rules given .