packages/babel-plugin-minify-simplify/src/if-statement.js
function removeUnnecessaryElse(path) {
    const { node } = path;
    const consequent = path.get("consequent");
    const alternate = path.get("alternate");

    if (
      consequent.node &&
      alternate.node &&
      (consequent.isReturnStatement() ||
        (consequent.isBlockStatement() &&
          t.isReturnStatement(
            consequent.node.body[consequent.node.body.length - 1]
          ))) &&
      // don't hoist declarations
      // TODO: validate declarations after fixing scope issues
      (alternate.isBlockStatement()
        ? !alternate
            .get("body")
            .some(
              stmt =>
                stmt.isVariableDeclaration({ kind: "let" }) ||
                stmt.isVariableDeclaration({ kind: "const" })
            )
        : true)
    ) {
      path.insertAfter(
        alternate.isBlockStatement()
          ? alternate.node.body.map(el => t.clone(el))
          : t.clone(alternate.node)
      );
      node.alternate = null;
      return REPLACED;
    }
  }
function removeUnnecessaryElse(path) {
    const { node } = path;
    const consequent = path.get("consequent");
    const alternate = path.get("alternate");

    if (
      consequent.node &&
      alternate.node &&
      (consequent.isReturnStatement() ||
        (consequent.isBlockStatement() &&
          t.isReturnStatement(
            consequent.node.body[consequent.node.body.length - 1]
          ))) &&
      // don't hoist declarations
      // TODO: validate declarations after fixing scope issues
      (alternate.isBlockStatement()
        ? !alternate
            .get("body")
            .some(
              stmt =>
                stmt.isVariableDeclaration({ kind: "let" }) ||
                stmt.isVariableDeclaration({ kind: "const" })
            )
        : true)
    ) {
      path.insertAfter(
        alternate.isBlockStatement()
          ? alternate.node.body.map(el => t.clone(el))
          : t.clone(alternate.node)
      );
      node.alternate = null;
      return REPLACED;
    }
  }
function removeUnnecessaryElse ( path ) { const { node } = path ; const consequent = path . get ( "consequent" ) ; const alternate = path . get ( "alternate" ) ; if ( consequent . node && alternate . node && ( consequent . isReturnStatement ( ) || ( consequent . isBlockStatement ( ) && t . isReturnStatement ( consequent . node . body [ consequent . node . body . length - 1 ] ) ) ) && // don't hoist declarations // TODO: validate declarations after fixing scope issues ( alternate . isBlockStatement ( ) ? ! alternate . get ( "body" ) . some ( stmt => stmt . isVariableDeclaration ( { kind : "let" } ) || stmt . isVariableDeclaration ( { kind : "const" } ) ) : true ) ) { path . insertAfter ( alternate . isBlockStatement ( ) ? alternate . node . body . map ( el => t . clone ( el ) ) : t . clone ( alternate . node ) ) ; node . alternate = null ; return REPLACED ; } }
Remove else for if-return
Remove else for if - return