From 29528b6e8440cf60ced15e126e9fe38421e2e22b Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 12 Nov 2018 23:08:44 -0500 Subject: [PATCH 1/2] fix: mixin parameters with functions. fixes #122 --- lib/LessParser.js | 22 ++++++---------------- test/parser/mixins.test.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/LessParser.js b/lib/LessParser.js index 95dc110..599901f 100644 --- a/lib/LessParser.js +++ b/lib/LessParser.js @@ -82,6 +82,10 @@ module.exports = class LessParser extends Parser { } unknownWord(tokens) { + // NOTE: keep commented for examining unknown structures + // console.log('unknown', tokens); + // console.log(this.root.first); + const [first] = tokens; // TODO: move this into a util function/file @@ -92,7 +96,7 @@ module.exports = class LessParser extends Parser { let important = ''; // fix for #86. if rulesets are mixin params, they need to be converted to a brackets token - if (bracketsIndex < 0 && firstParenIndex > 0) { + if ((bracketsIndex < 0 || bracketsIndex > 3) && firstParenIndex > 0) { const lastParenIndex = tokens.findIndex((t) => t[0] === ')'); const contents = tokens.slice(firstParenIndex, lastParenIndex + firstParenIndex); @@ -125,28 +129,14 @@ module.exports = class LessParser extends Parser { this.lastNode.mixin = true; this.lastNode.raws.identifier = identifier; - // const importantIndex = tokens.findIndex((t) => importantPattern.test(t[1])); - if (important) { this.lastNode.important = true; this.lastNode.raws.important = important; } - // if (importantIndex > 0) { - // nodes.splice(importantIndex, 1); - // [this.lastNode.raws.important] = this.lastNode.params.match(importantPattern); - - // this.lastNode.params = this.lastNode.params.replace(importantPattern, ''); - - // const [spaces] = this.lastNode.params.match(/\s+$/) || ['']; - // this.lastNode.raws.between = spaces; - // this.lastNode.params = this.lastNode.params.trim(); - // } - return; } - // NOTE: keep commented for examining unknown structures - // console.log('unknown', tokens); + super.unknownWord(tokens); } }; diff --git a/test/parser/mixins.test.js b/test/parser/mixins.test.js index 87efdd0..ba10ce7 100644 --- a/test/parser/mixins.test.js +++ b/test/parser/mixins.test.js @@ -268,3 +268,19 @@ test('important in parameters (#102)', (t) => { t.falsy(first.important); t.is(nodeToString(root), less); }); + +test('mixin parameters keyframes (#122)', (t) => { + const less = `.mixin({ + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +});`; + const root = parse(less); + const { first } = root; + + t.is(first.name, 'mixin'); + t.is(nodeToString(root), less); +}); From 5a2bc2bf268cf2cd5c48758c10cd592b2c29ef04 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 12 Nov 2018 23:13:13 -0500 Subject: [PATCH 2/2] test: change new test name --- test/parser/mixins.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parser/mixins.test.js b/test/parser/mixins.test.js index ba10ce7..5a1f625 100644 --- a/test/parser/mixins.test.js +++ b/test/parser/mixins.test.js @@ -269,7 +269,7 @@ test('important in parameters (#102)', (t) => { t.is(nodeToString(root), less); }); -test('mixin parameters keyframes (#122)', (t) => { +test('mixin parameters with functions (#122)', (t) => { const less = `.mixin({ 0% { transform: rotate(0deg);