diff --git a/lib/LessParser.js b/lib/LessParser.js index f901bea..60af9c0 100644 --- a/lib/LessParser.js +++ b/lib/LessParser.js @@ -92,7 +92,7 @@ module.exports = class LessParser extends Parser { // fix for #86. if rulesets are mixin params, they need to be converted to a brackets token if ((bracketsIndex < 0 || bracketsIndex > 3) && firstParenIndex > 0) { - const lastParenIndex = tokens.findIndex((t) => t[0] === ')'); + const lastParenIndex = tokens.reduce((last, t, i) => (t[0] === ')' ? i : last)); const contents = tokens.slice(firstParenIndex, lastParenIndex + firstParenIndex); const brackets = contents.map((t) => t[1]).join(''); diff --git a/test/parser/mixins.test.js b/test/parser/mixins.test.js index dd4b123..c218ddb 100644 --- a/test/parser/mixins.test.js +++ b/test/parser/mixins.test.js @@ -308,3 +308,20 @@ test('mixin parameters with functions (#122)', (t) => { t.is(first.name, 'mixin'); t.is(nodeToString(root), less); }); + +test('mixin parameters with multiple parens', (t) => { + const less = `.mixin({ + &__icon { + background-image: url('./icon.svg'); + width: calc(~"100% + 1px"); + } +}); +.two {}`; + + const root = parse(less); + const { first, last } = root; + + t.is(first.name, 'mixin'); + t.is(last.selector, '.two'); + t.is(nodeToString(root), less); +});