How to use the lua-types.isUnaryExpression function in lua-types

To help you get started, we’ve selected a few lua-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ark120202 / babel-lua / packages / lua-generator / src / node / parentheses.js View on Github external
function Binary(node, parent) {
  if (t.isCallExpression(parent) || (t.isIndexExpression(parent) && parent.identifier === node)) {
    return false;
  }
  if (t.isUnaryExpression(parent)) return true;

  if (t.isBinary(parent)) {
    const parentOp = parent.operator;
    // Unary was tested above
    const parentPos = PRECEDENCE[parentOp];

    let nodeOp = node.operator;
    // Prepend 'U' to differ unary operators
    if (t.isUnaryExpression(node)) nodeOp = `U${nodeOp}`;
    const nodePos = PRECEDENCE[nodeOp];

    if (
      (parentPos === nodePos &&
        // babylon parses x + y + z as x + (y + z)
        // luarparse parses x + y + z as x + (y + z), yet x .. y .. z as (x .. y) .. z
        parent[parent.operator === '..' ? 'left' : 'right'] === node &&
github ark120202 / babel-lua / packages / lua-generator / src / node / parentheses.js View on Github external
function Binary(node, parent) {
  if (t.isCallExpression(parent) || (t.isIndexExpression(parent) && parent.identifier === node)) {
    return false;
  }
  if (t.isUnaryExpression(parent)) return true;

  if (t.isBinary(parent)) {
    const parentOp = parent.operator;
    // Unary was tested above
    const parentPos = PRECEDENCE[parentOp];

    let nodeOp = node.operator;
    // Prepend 'U' to differ unary operators
    if (t.isUnaryExpression(node)) nodeOp = `U${nodeOp}`;
    const nodePos = PRECEDENCE[nodeOp];

    if (
      (parentPos === nodePos &&
        // babylon parses x + y + z as x + (y + z)
        // luarparse parses x + y + z as x + (y + z), yet x .. y .. z as (x .. y) .. z
        parent[parent.operator === '..' ? 'left' : 'right'] === node &&
        // Logical expressions with the same precedence don't need parens.
        !t.isLogicalExpression(parent)) ||
      parentPos > nodePos
    ) {
      return true;
    }
  }

  return false;