Skip to content

Commit 9392246

Browse files
authored
fix: mixin parameters with functions. fixes #122 (#125)
* fix: mixin parameters with functions. fixes #122 * test: change new test name
1 parent 3016597 commit 9392246

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

lib/LessParser.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ module.exports = class LessParser extends Parser {
8282
}
8383

8484
unknownWord(tokens) {
85+
// NOTE: keep commented for examining unknown structures
86+
// console.log('unknown', tokens);
87+
// console.log(this.root.first);
88+
8589
const [first] = tokens;
8690

8791
// TODO: move this into a util function/file
@@ -92,7 +96,7 @@ module.exports = class LessParser extends Parser {
9296
let important = '';
9397

9498
// fix for #86. if rulesets are mixin params, they need to be converted to a brackets token
95-
if (bracketsIndex < 0 && firstParenIndex > 0) {
99+
if ((bracketsIndex < 0 || bracketsIndex > 3) && firstParenIndex > 0) {
96100
const lastParenIndex = tokens.findIndex((t) => t[0] === ')');
97101

98102
const contents = tokens.slice(firstParenIndex, lastParenIndex + firstParenIndex);
@@ -125,28 +129,14 @@ module.exports = class LessParser extends Parser {
125129
this.lastNode.mixin = true;
126130
this.lastNode.raws.identifier = identifier;
127131

128-
// const importantIndex = tokens.findIndex((t) => importantPattern.test(t[1]));
129-
130132
if (important) {
131133
this.lastNode.important = true;
132134
this.lastNode.raws.important = important;
133135
}
134136

135-
// if (importantIndex > 0) {
136-
// nodes.splice(importantIndex, 1);
137-
// [this.lastNode.raws.important] = this.lastNode.params.match(importantPattern);
138-
139-
// this.lastNode.params = this.lastNode.params.replace(importantPattern, '');
140-
141-
// const [spaces] = this.lastNode.params.match(/\s+$/) || [''];
142-
// this.lastNode.raws.between = spaces;
143-
// this.lastNode.params = this.lastNode.params.trim();
144-
// }
145-
146137
return;
147138
}
148-
// NOTE: keep commented for examining unknown structures
149-
// console.log('unknown', tokens);
139+
150140
super.unknownWord(tokens);
151141
}
152142
};

test/parser/mixins.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,19 @@ test('important in parameters (#102)', (t) => {
268268
t.falsy(first.important);
269269
t.is(nodeToString(root), less);
270270
});
271+
272+
test('mixin parameters with functions (#122)', (t) => {
273+
const less = `.mixin({
274+
0% {
275+
transform: rotate(0deg);
276+
}
277+
100% {
278+
transform: rotate(360deg);
279+
}
280+
});`;
281+
const root = parse(less);
282+
const { first } = root;
283+
284+
t.is(first.name, 'mixin');
285+
t.is(nodeToString(root), less);
286+
});

0 commit comments

Comments
 (0)