<commit_before>// @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: $FlowFixMe) {
  const { node } = path

  if (!t.isBooleanLiteral(node.test)) return

  function visitIfNode(leafNode) {
    if (!t.isBooleanLiteral(leafNode.test)) return
    const { test, consequent, alternate } = node

    if (test.value) {
      path.replaceWithMultiple(consequent.body)
      return
    }
    node.consequent.body = []
    if (t.isIfStatement(alternate)) {
      visitIfNode(alternate)
    } else if (t.isBlockStatement(alternate)) {
      path.replaceWithMultiple(alternate.body)
    }
  }

  if (t.isIfStatement(node)) {
    visitIfNode(node)
  } else {
    path.replaceWith(node.test.value ? node.consequent : node.alternate)
  }
}

export default {
  visitor: {
    IfStatement: {
      exit: processBooleanConditional,
    },
    ConditionalExpression: {
      exit: processBooleanConditional,
    },
  },
}<commit_msg>:bug: Remove dead nodes on enter not exit<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: $FlowFixMe) {
  const { node } = path

  if (!t.isBooleanLiteral(node.test)) return

  function visitIfNode(leafNode) {
    if (!t.isBooleanLiteral(leafNode.test)) return
    const { test, consequent, alternate } = node

    if (test.value) {
      path.replaceWithMultiple(consequent.body)
      return
    }
    node.consequent.body = []
    if (t.isIfStatement(alternate)) {
      visitIfNode(alternate)
    } else if (t.isBlockStatement(alternate)) {
      path.replaceWithMultiple(alternate.body)
    }
  }

  if (t.isIfStatement(node)) {
    visitIfNode(node)
  } else {
    path.replaceWith(node.test.value ? node.consequent : node.alternate)
  }
}

export default {
  visitor: {
    IfStatement: processBooleanConditional,
    ConditionalExpression: processBooleanConditional,
  },
}
{'fraction_non_alphanumeric': 0.13486590038314175, 'fraction_numerical': 0.0, 'mean_word_length': 3.5017241379310344, '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': '4112213', 'n_tokens_mistral': 815, 'n_tokens_neox': 791, 'n_words': 175}