diff --git a/edge/format.js b/edge/format.js index 70e2720..1f701f2 100644 --- a/edge/format.js +++ b/edge/format.js @@ -528,6 +528,11 @@ function format(content, options = {}) { outputBuffer.append('{') } + const parentIsArithmeticOperator = inputNode.parent instanceof Stylus.nodes.UnaryOp || inputNode.parent instanceof Stylus.nodes.BinOp && inputNode.parent.left === inputNode + if (parentIsArithmeticOperator) { + outputBuffer.append(openParen) + } + const currentIsPartOfPropertyNames = !!findParentNode(inputNode, node => node instanceof Stylus.nodes.Property && node.segments.includes(inputNode)) const currentIsPartOfKeyframes = !!findParentNode(inputNode, node => node instanceof Stylus.nodes.Keyframes && node.segments.includes(inputNode)) @@ -558,6 +563,10 @@ function format(content, options = {}) { outputBuffer.append('}') } + if (parentIsArithmeticOperator) { + outputBuffer.append(closeParen) + } + if (insideExpression === false) { if (options.insertSemicolons) { outputBuffer.append(';') @@ -601,9 +610,8 @@ function format(content, options = {}) { outputBuffer.append(travel(inputNode, inputNode.val, indentLevel, true)) } else { - const insideUnaryOp = inputNode.parent instanceof Stylus.nodes.Expression && (inputNode.parent.parent instanceof Stylus.nodes.UnaryOp || inputNode.parent.parent instanceof Stylus.nodes.BinOp) const escapeDivider = inputNode.op === '/' - if (insideUnaryOp || escapeDivider) { + if (escapeDivider) { outputBuffer.append(openParen) } @@ -613,7 +621,7 @@ function format(content, options = {}) { outputBuffer.append(' ' + travel(inputNode, inputNode.right, indentLevel, true)) } - if (insideUnaryOp || escapeDivider) { + if (escapeDivider) { outputBuffer.append(closeParen) } } diff --git a/spec/operator/input.styl b/spec/operator/input.styl index 3fe0603..a4a91d0 100644 --- a/spec/operator/input.styl +++ b/spec/operator/input.styl @@ -1,11 +1,14 @@ body display !0 visibility not true is false - left -5px - margin 1+2px + margin-top -5px + margin-bottom -(6px) + margin-left value + margin-right -(value) + padding 1+2px list = 1 2 3 color 1 in list - padding list[-1] + item = list[-1] range = 1...5 math = 1+2- 3*(4/5) %6**7 color = color is defined ? unit(num,'px') : white diff --git a/spec/operator/output.styl b/spec/operator/output.styl index 4202756..9f8fe99 100644 --- a/spec/operator/output.styl +++ b/spec/operator/output.styl @@ -1,11 +1,14 @@ body { display: !0; visibility: !true == false; - left: -5px; - margin: 1 + 2px; + margin-top: -5px; + margin-bottom: -(6px); + margin-left: value; + margin-right: -(value); + padding: 1 + 2px; list = 1 2 3; color: 1 in list; - padding: list[-1]; + item = list[-1]; range = 1...5; math = 1 + 2 - 3 * (4 / 5) % 6 ** 7; color = color is defined ? unit(num, 'px') : white;