Skip to content

Commit

Permalink
Fixed removing parentheses around negation in an expression list
Browse files Browse the repository at this point in the history
  • Loading branch information
Anantachai Saothong (Manta) committed Sep 24, 2018
1 parent c2ae1ad commit c7c0f8b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
13 changes: 8 additions & 5 deletions edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,11 @@ function format(content, options = {}) {
inputNode.parent.op !== '[]' &&
inputNode.parent.op !== '[]='
)
const parentIsStringInterpolation = (
const parentIsStringInterpolation =
inputNode.parent instanceof Stylus.nodes.BinOp &&
inputNode.parent.op === '%' &&
inputNode.parent.right === inputNode &&
inputNode.nodes.length > 1
)
const parentIsNestedExpression =
inputNode.nodes.length === 1 &&
inputNode.parent instanceof Stylus.nodes.Expression &&
Expand All @@ -646,16 +645,19 @@ function format(content, options = {}) {
inputNode.parent.parent instanceof Stylus.nodes.Object ||
inputNode.parent.parent instanceof Stylus.nodes.BinOp && inputNode.parent.parent.op === '[]'
) === false
const currentIsEmpty = (
const currentIsEmpty =
inputNode.nodes.length === 0 &&
inputNode.parent instanceof Stylus.nodes.Expression &&
!(inputNode.parent instanceof Stylus.nodes.Arguments) && // Note that `Arguments` type inherits `Expression` type
inputNode.parent.nodes.length === 1
)
const currentIsDivision =
inputNode.nodes.length === 1 &&
inputNode.nodes[0] instanceof Stylus.nodes.BinOp &&
inputNode.nodes[0].op === '/'
const currentIsNegation =
inputNode.nodes.length === 1 &&
inputNode.nodes[0] instanceof Stylus.nodes.UnaryOp &&
inputNode.nodes[0].op === '-'
const currentHasUnitSuffix =
inputNode.nodes.length === 2 &&
inputNode.nodes[0] instanceof Stylus.nodes.BinOp &&
Expand All @@ -665,7 +667,8 @@ function format(content, options = {}) {
parentIsStringInterpolation ||
parentIsNestedExpression ||
currentIsEmpty ||
currentIsDivision
currentIsDivision ||
currentIsNegation
if (currentHasParenthesis || currentHasUnitSuffix) {
outputBuffer.append(openParen)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.class2
top -x
left - x
right -(x)
right -(x)
padding 1px (- x)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
top: -x;
left: - x;
right: -(x);
padding: 1px (- x);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.class2
top -x
left - x
right -(x)
right -(x)
padding 1px (- x)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
top: -x;
left: -(x);
right: -(x);
padding: 1px (-(x));
}

0 comments on commit c7c0f8b

Please sign in to comment.