From 80bd91400b6bc8167b1e42897872484b78284e6f Mon Sep 17 00:00:00 2001 From: "Anantachai Saothong (Manta)" Date: Sun, 31 Dec 2017 01:20:03 +0700 Subject: [PATCH] Fixed missing parenthesis in string interpolation --- edge/format.js | 7 +++++++ spec/interpolation/input.styl | 5 ++++- spec/interpolation/output.styl | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/edge/format.js b/edge/format.js index afb6d27..50c8577 100644 --- a/edge/format.js +++ b/edge/format.js @@ -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 && @@ -606,6 +612,7 @@ function format(content, options = {}) { inputNode.nodes[1] instanceof Stylus.nodes.Ident const currentHasParenthesis = parentIsArithmeticOperator || + parentIsStringInterpolation || parentIsNestedExpression || currentIsDivision if (currentHasParenthesis || currentHasUnitSuffix) { diff --git a/spec/interpolation/input.styl b/spec/interpolation/input.styl index a0214ba..c939a48 100644 --- a/spec/interpolation/input.styl +++ b/spec/interpolation/input.styl @@ -8,4 +8,7 @@ div:nth-child({row}) mySelectors='#foo,#bar,.class1' {mySelectors+'.class2'} - display none \ No newline at end of file + display none + +.class3 + height 'calc(%s - %s)' % (a b) \ No newline at end of file diff --git a/spec/interpolation/output.styl b/spec/interpolation/output.styl index c2e5e51..7f6c463 100644 --- a/spec/interpolation/output.styl +++ b/spec/interpolation/output.styl @@ -13,4 +13,8 @@ mySelectors = '#foo,#bar,.class1'; {mySelectors + '.class2'} { display: none; +} + +.class3 { + height: 'calc(%s - %s)' % (a b); } \ No newline at end of file