index.js
function acornExtractComments (input, opts) {
  if (typeof input !== 'string') {
    throw new TypeError('acorn-extract-comments expect `input` to be a string')
  }
  if (!input.length) return []

  opts = extend({
    ast: false,
    line: false,
    block: false,
    preserve: false,
    locations: false,
    ecmaVersion: 6
  }, opts)

  var comments = opts.onComment = []
  var ast = acorn.parse(stripShebang(input), opts)

  if (!comments.length) return []

  comments = filter(comments, function (comment) {
    var line = (opts.line && comment.type === 'Line') || false
    var block = (opts.block && comment.type === 'Block') || false
    var ignore = false
    if (typeof opts.preserve === 'boolean') {
      ignore = opts.preserve && defaultIsIgnore(comment.value)
    }
    if (typeof opts.preserve === 'function') {
      var preserve = opts.preserve(comment.value)
      ignore = typeof preserve === 'boolean' ? preserve : ignore
    }

    if (!ignore && line) return true
    if (!ignore && block) return true
    return false
  })

  comments.ast = opts.ast && ast || undefined
  return comments
}
function acornExtractComments (input, opts) {
  if (typeof input !== 'string') {
    throw new TypeError('acorn-extract-comments expect `input` to be a string')
  }
  if (!input.length) return []

  opts = extend({
    ast: false,
    line: false,
    block: false,
    preserve: false,
    locations: false,
    ecmaVersion: 6
  }, opts)

  var comments = opts.onComment = []
  var ast = acorn.parse(stripShebang(input), opts)

  if (!comments.length) return []

  comments = filter(comments, function (comment) {
    var line = (opts.line && comment.type === 'Line') || false
    var block = (opts.block && comment.type === 'Block') || false
    var ignore = false
    if (typeof opts.preserve === 'boolean') {
      ignore = opts.preserve && defaultIsIgnore(comment.value)
    }
    if (typeof opts.preserve === 'function') {
      var preserve = opts.preserve(comment.value)
      ignore = typeof preserve === 'boolean' ? preserve : ignore
    }

    if (!ignore && line) return true
    if (!ignore && block) return true
    return false
  })

  comments.ast = opts.ast && ast || undefined
  return comments
}
function acornExtractComments ( input , opts ) { if ( typeof input !== 'string' ) { throw new TypeError ( 'acorn-extract-comments expect `input` to be a string' ) } if ( ! input . length ) return [ ] opts = extend ( { ast : false , line : false , block : false , preserve : false , locations : false , ecmaVersion : 6 } , opts ) var comments = opts . onComment = [ ] var ast = acorn . parse ( stripShebang ( input ) , opts ) if ( ! comments . length ) return [ ] comments = filter ( comments , function ( comment ) { var line = ( opts . line && comment . type === 'Line' ) || false var block = ( opts . block && comment . type === 'Block' ) || false var ignore = false if ( typeof opts . preserve === 'boolean' ) { ignore = opts . preserve && defaultIsIgnore ( comment . value ) } if ( typeof opts . preserve === 'function' ) { var preserve = opts . preserve ( comment . value ) ignore = typeof preserve === 'boolean' ? preserve : ignore } if ( ! ignore && line ) return true if ( ! ignore && block ) return true return false } ) comments . ast = opts . ast && ast || undefined return comments }
> Core logic to extract comments

@param  {String} `<input>` string from which to get comments
@param  {Object} `[opts]` optional options, passed to `acorn`
@return {Array} can have `.ast` property if `opts.ast: true`
@api private
> Core logic to extract comments