<commit_before>// @flow

// Empty out bodies of falsy parts of if/else statements
// to avoid requiring modules that aren't needed aka
// if (process.env.NODE_ENV === 'production') module.exports = require('./prod-version') else module.exports = require('./dev-version')
// OR
// module.exports = process.env.NODE_ENV === 'production' ? require('./prod-version') : require('./dev-version')

export default {
  visitor: {
    IfStatement: {
      exit(path) {
        const { node } = path
        const { test, consequent } = node

        if (test && test.type === 'BooleanLiteral') {
          if (test.value) {
            if (node.alternate) {
              node.alternate = null
            }
          } else {
            consequent.body = []
          }
        }
      },
    },
  },
}<commit_msg>:new: Support ternary in dead code removal plugin<commit_after>// @flow

import * as t from '@babel/types'

// Empty out bodies of falsy parts of if/else statements
// to avoid requiring modules that aren't needed aka
// if (process.env.NODE_ENV === 'production') module.exports = require('./prod-version') else module.exports = require('./dev-version')
// OR
// module.exports = process.env.NODE_ENV === 'production' ? require('./prod-version') : require('./dev-version')

function processBooleanConditional(path) {
  const { node } = path
  const { test, consequent, alternate } = node

  if (test && test.type === 'BooleanLiteral') {
    if (test.value) {
      if (alternate) {
        if (t.isBlockStatement(alternate)) {
          node.alternate = null
        } else {
          node.alternate = t.numericLiteral(0)
        }
      }
    } else {
      consequent.body = []
    }
  }
}

export default {
  visitor: {
    IfStatement: {
      exit: processBooleanConditional,
    },
    ConditionalExpression: {
      exit: processBooleanConditional,
    },
  },
}
{'fraction_non_alphanumeric': 0.14498933901918976, 'fraction_numerical': 0.0005330490405117271, 'mean_word_length': 2.3637992831541217, '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': '1791079', 'n_tokens_mistral': 547, 'n_tokens_neox': 535, 'n_words': 138}