spec/uglify/core.js
function riotjs(js) {
  var
    match,
    toes5,
    parts = [],   // parsed code
    pos

  // remove comments
  js = js.replace(JS_RMCOMMS, function (m, q) { return q ? m : ' ' })

  // $1: indentation,
  // $2: method name,
  // $3: parameters
  while (match = js.match(JS_ES6SIGN)) {

    // save remaining part now -- IE9 changes `rightContext` in `RegExp.test`
    parts.push(RegExp.leftContext)
    js  = RegExp.rightContext
    pos = skipBlock(js)           // find the closing bracket

    // convert ES6 method signature to ES5 function
    toes5 = !/^(?:if|while|for|switch|catch|function)$/.test(match[2])
    if (toes5)
      match[0] = match[1] + 'this.' + match[2] + ' = function' + match[3]

    parts.push(match[0], js.slice(0, pos))
    js = js.slice(pos)
    if (toes5 && !/^\s*.\s*bind\b/.test(js)) parts.push('.bind(this)')
  }

  return parts.length ? parts.join('') + js : js

  // Inner helper - find the position following the closing bracket for the current block
  function skipBlock(str) {
    var
      re = _regEx('([{}])|' + brackets.S_QBLOCKS, 'g'),
      level = 1,
      match

    while (level && (match = re.exec(str))) {
      if (match[1])
        match[1] === '{' ? ++level : --level
    }
    return level ? str.length : re.lastIndex
  }
}
function riotjs(js) {
  var
    match,
    toes5,
    parts = [],   // parsed code
    pos

  // remove comments
  js = js.replace(JS_RMCOMMS, function (m, q) { return q ? m : ' ' })

  // $1: indentation,
  // $2: method name,
  // $3: parameters
  while (match = js.match(JS_ES6SIGN)) {

    // save remaining part now -- IE9 changes `rightContext` in `RegExp.test`
    parts.push(RegExp.leftContext)
    js  = RegExp.rightContext
    pos = skipBlock(js)           // find the closing bracket

    // convert ES6 method signature to ES5 function
    toes5 = !/^(?:if|while|for|switch|catch|function)$/.test(match[2])
    if (toes5)
      match[0] = match[1] + 'this.' + match[2] + ' = function' + match[3]

    parts.push(match[0], js.slice(0, pos))
    js = js.slice(pos)
    if (toes5 && !/^\s*.\s*bind\b/.test(js)) parts.push('.bind(this)')
  }

  return parts.length ? parts.join('') + js : js

  // Inner helper - find the position following the closing bracket for the current block
  function skipBlock(str) {
    var
      re = _regEx('([{}])|' + brackets.S_QBLOCKS, 'g'),
      level = 1,
      match

    while (level && (match = re.exec(str))) {
      if (match[1])
        match[1] === '{' ? ++level : --level
    }
    return level ? str.length : re.lastIndex
  }
}
function riotjs ( js ) { var match , toes5 , parts = [ ] , // parsed code pos // remove comments js = js . replace ( JS_RMCOMMS , function ( m , q ) { return q ? m : ' ' } ) // $1: indentation, // $2: method name, // $3: parameters while ( match = js . match ( JS_ES6SIGN ) ) { // save remaining part now -- IE9 changes `rightContext` in `RegExp.test` parts . push ( RegExp . leftContext ) js = RegExp . rightContext pos = skipBlock ( js ) // find the closing bracket // convert ES6 method signature to ES5 function toes5 = ! / ^(?:if|while|for|switch|catch|function)$ / . test ( match [ 2 ] ) if ( toes5 ) match [ 0 ] = match [ 1 ] + 'this.' + match [ 2 ] + ' = function' + match [ 3 ] parts . push ( match [ 0 ] , js . slice ( 0 , pos ) ) js = js . slice ( pos ) if ( toes5 && ! / ^\s*.\s*bind\b / . test ( js ) ) parts . push ( '.bind(this)' ) } return parts . length ? parts . join ( '' ) + js : js // Inner helper - find the position following the closing bracket for the current block function skipBlock ( str ) { var re = _regEx ( '([{}])|' + brackets . S_QBLOCKS , 'g' ) , level = 1 , match while ( level && ( match = re . exec ( str ) ) ) { if ( match [ 1 ] ) match [ 1 ] === '{' ? ++ level : -- level } return level ? str . length : re . lastIndex } }
Default parser for JavaScript code
Default parser for JavaScript code