<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)) {
      if (leafNode !== node) {
        path.replaceWith(leafNode)
      }
      return
    }
    const { test, consequent, alternate } = leafNode

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

  if (t.isIfStatement(node)) {
    visitIfNode(node)
  } else {
    path.replaceWith(node.test.value ? node.consequent : node.alternate)<commit_msg>:new: Remove node completely if boolean literal is false<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)) {
      if (leafNode !== node) {
        path.replaceWith(leafNode)
      }
      return
    }
    const { test, consequent, alternate } = leafNode

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

  if (t.isIfStatement(node)) {
    visitIfNode(node)
  } else {
    path.replaceWith(node.test.value ? node.consequent : node.alternate)
{'fraction_non_alphanumeric': 0.13537271448663854, 'fraction_numerical': 0.0, 'mean_word_length': 3.1776798825256973, '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': '6438849', 'n_tokens_mistral': 889, 'n_tokens_neox': 861, 'n_words': 185}