Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 &&
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;