Skip to content

Commit 402dc5d

Browse files
Andreas Högströmshellscape
Andreas Högström
authored andcommitted
fix: correctly calculate last parens in ruleset as mixin param (#132)
1 parent 714ce13 commit 402dc5d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/LessParser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = class LessParser extends Parser {
9292

9393
// fix for #86. if rulesets are mixin params, they need to be converted to a brackets token
9494
if ((bracketsIndex < 0 || bracketsIndex > 3) && firstParenIndex > 0) {
95-
const lastParenIndex = tokens.findIndex((t) => t[0] === ')');
95+
const lastParenIndex = tokens.reduce((last, t, i) => (t[0] === ')' ? i : last));
9696

9797
const contents = tokens.slice(firstParenIndex, lastParenIndex + firstParenIndex);
9898
const brackets = contents.map((t) => t[1]).join('');

test/parser/mixins.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,20 @@ test('mixin parameters with functions (#122)', (t) => {
308308
t.is(first.name, 'mixin');
309309
t.is(nodeToString(root), less);
310310
});
311+
312+
test('mixin parameters with multiple parens', (t) => {
313+
const less = `.mixin({
314+
&__icon {
315+
background-image: url('./icon.svg');
316+
width: calc(~"100% + 1px");
317+
}
318+
});
319+
.two {}`;
320+
321+
const root = parse(less);
322+
const { first, last } = root;
323+
324+
t.is(first.name, 'mixin');
325+
t.is(last.selector, '.two');
326+
t.is(nodeToString(root), less);
327+
});

0 commit comments

Comments
 (0)