Skip to content

Commit

Permalink
Fixed missing parenthesis in string interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsManta committed Dec 30, 2017
1 parent 054344e commit 80bd914
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,12 @@ function format(content, options = {}) {
inputNode.parent.op !== '[]' &&
inputNode.parent.op !== '[]='
)
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 @@ -606,6 +612,7 @@ function format(content, options = {}) {
inputNode.nodes[1] instanceof Stylus.nodes.Ident
const currentHasParenthesis =
parentIsArithmeticOperator ||
parentIsStringInterpolation ||
parentIsNestedExpression ||
currentIsDivision
if (currentHasParenthesis || currentHasUnitSuffix) {
Expand Down
5 changes: 4 additions & 1 deletion spec/interpolation/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ div:nth-child({row})

mySelectors='#foo,#bar,.class1'
{mySelectors+'.class2'}
display none
display none

.class3
height 'calc(%s - %s)' % (a b)
4 changes: 4 additions & 0 deletions spec/interpolation/output.styl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ mySelectors = '#foo,#bar,.class1';

{mySelectors + '.class2'} {
display: none;
}

.class3 {
height: 'calc(%s - %s)' % (a b);
}

0 comments on commit 80bd914

Please sign in to comment.