<commit_before>var _ = require('underscore')
  , ast = require('../ast/ast-adapter')

module.exports = {
  match: match
  , convert: convert
}

function match(body) {
  return ast.is.amd('define', body)
}

function convert(body, module) {
  module.deps = deps(body)
  module.ast = redefine(module.name, body)
}

function deps (body) {
  var expression = ast.get.expressionArgs(body)
  return _(expression[0].elements).map(function(e) { return e.value })
}

function redefine(name, expressionStatement) {
  var expression = ast.get.expressionArgs(expressionStatement)
    , deps =  expression[0].elements
    , fun  =  expression[1] || expression[0]

  // variable = config.is.complexName(name)
  //            ? config.normalize.module(name)
  //            : "var " + name

  // variable += " = " + ast.generate()

  return convertExpression(fun, deps)

  function convertExpression(block, deps) {
    if(ast.is.object(block))
      return block

    if(ast.is.independentExpression(block) && deps && deps.length === 0)
      return resolveInlineDeps(block)

    return ast.create.iife(resolveElements(deps), block)

    function resolveInlineDeps(body) {
      var body = block.body.body
        , len = body.length
      return body[0].argument
    }
  }<commit_msg>better checking define args<commit_after>var _ = require('underscore')
  , ast = require('../ast/ast-adapter')

module.exports = {
  match: match
  , convert: convert
}

function match(body) {
  return ast.is.amd('define', body)
}

function convert(body, module) {
  module.deps = deps(body)
  module.ast = redefine(module.name, body)
}

function deps (body) {
  var expression = ast.get.expressionArgs(body)
  return _(expression[0].elements).map(function(e) { return e.value })
}

function redefine(name, expressionStatement) {
  var expression = ast.get.expressionArgs(expressionStatement)
    , name
    , deps
    , fun

  if(expression.length === 3) {
    name = expression[0].value
    deps = expression[0].elements
    fun  = expression[1] || expression[0]
  } else if(expression.length === 2) {
    deps = expression[0].elements
    fun  = expression[1] || expression[0]
  } else if(expression.length === 1) {
    fun = expression[0]
  }

  // variable = config.is.complexName(name)
  //            ? config.normalize.module(name)
  //            : "var " + name

  // variable += " = " + ast.generate()

  return convertExpression(fun, deps)

  function convertExpression(block, deps) {
    if(ast.is.object(block))
      return block

    if(ast.is.independentExpression(block) && deps && deps.length === 0)
      return resolveInlineDeps(block)

    return ast.create.iife(resolveElements(deps), block)

    function resolveInlineDeps(body) {
      var body = block.body.body
        , len = body.length
      return body[0].argument
    }
  }
{'fraction_non_alphanumeric': 0.14058073654390935, 'fraction_numerical': 0.007082152974504249, 'mean_word_length': 3.1789940828402368, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4483003', 'n_tokens_mistral': 917, 'n_tokens_neox': 894, 'n_words': 177}