packages/solver/lib/util/removeUnnecessaryParens.js
function removeUnnecessaryParensInOperatorNode(node) {
  node.args.forEach((child, i) => {
    node.args[i] = removeUnnecessaryParensSearch(child);
  });

  // Sometimes, parens are around expressions that have been simplified
  // all they can be. If that expression is part of an addition or subtraction
  // operation, we can remove the parenthesis.
  // e.g. (x+4) + 12 -> x+4 + 12
  if (node.op === '+') {
    node.args.forEach((child, i) => {
      if (Node.Type.isParenthesis(child) &&
          !canCollectOrCombine(child.content)) {
        // remove the parens by replacing the child node (in its args list)
        // with its content
        node.args[i] = child.content;
      }
    });
  }
  // This is different from addition because when subtracting a group of terms
  //in parenthesis, we want to distribute the subtraction.
  // e.g. `(2 + x) - (1 + x)` => `2 + x - (1 + x)` not `2 + x - 1 + x`
  else if (node.op === '-') {
    if (Node.Type.isParenthesis(node.args[0]) &&
        !canCollectOrCombine(node.args[0].content)) {
      node.args[0] = node.args[0].content;
    }
  }

  return node;
}
function removeUnnecessaryParensInOperatorNode(node) {
  node.args.forEach((child, i) => {
    node.args[i] = removeUnnecessaryParensSearch(child);
  });

  // Sometimes, parens are around expressions that have been simplified
  // all they can be. If that expression is part of an addition or subtraction
  // operation, we can remove the parenthesis.
  // e.g. (x+4) + 12 -> x+4 + 12
  if (node.op === '+') {
    node.args.forEach((child, i) => {
      if (Node.Type.isParenthesis(child) &&
          !canCollectOrCombine(child.content)) {
        // remove the parens by replacing the child node (in its args list)
        // with its content
        node.args[i] = child.content;
      }
    });
  }
  // This is different from addition because when subtracting a group of terms
  //in parenthesis, we want to distribute the subtraction.
  // e.g. `(2 + x) - (1 + x)` => `2 + x - (1 + x)` not `2 + x - 1 + x`
  else if (node.op === '-') {
    if (Node.Type.isParenthesis(node.args[0]) &&
        !canCollectOrCombine(node.args[0].content)) {
      node.args[0] = node.args[0].content;
    }
  }

  return node;
}
function removeUnnecessaryParensInOperatorNode ( node ) { node . args . forEach ( ( child , i ) => { node . args [ i ] = removeUnnecessaryParensSearch ( child ) ; } ) ; // Sometimes, parens are around expressions that have been simplified // all they can be. If that expression is part of an addition or subtraction // operation, we can remove the parenthesis. // e.g. (x+4) + 12 -> x+4 + 12 if ( node . op === '+' ) { node . args . forEach ( ( child , i ) => { if ( Node . Type . isParenthesis ( child ) && ! canCollectOrCombine ( child . content ) ) { // remove the parens by replacing the child node (in its args list) // with its content node . args [ i ] = child . content ; } } ) ; } // This is different from addition because when subtracting a group of terms //in parenthesis, we want to distribute the subtraction. // e.g. `(2 + x) - (1 + x)` => `2 + x - (1 + x)` not `2 + x - 1 + x` else if ( node . op === '-' ) { if ( Node . Type . isParenthesis ( node . args [ 0 ] ) && ! canCollectOrCombine ( node . args [ 0 ] . content ) ) { node . args [ 0 ] = node . args [ 0 ] . content ; } } return node ; }
Removes unncessary parens for each operator in an operator node, and removes unncessary parens around operators that can't be simplified further. Returns a node.
Removes unncessary parens for each operator in an operator node and removes unncessary parens around operators that can t be simplified further . Returns a node .