From cd2a130bd95aa2ab3269fee9e2fdf957b44345e7 Mon Sep 17 00:00:00 2001 From: Michael Yong Date: Wed, 14 Jun 2017 15:45:01 -0700 Subject: [PATCH 1/2] less-parser: Handle edge case with single token mixins. The parser didn't account for mixins that were used in the following manner: ``` .foo {.my-mixin} ``` --- lib/less-parser.js | 5 +++++ test/parser/mixins.spec.js | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/less-parser.js b/lib/less-parser.js index 105613b..7b64943 100755 --- a/lib/less-parser.js +++ b/lib/less-parser.js @@ -321,6 +321,11 @@ export default class LessParser extends Parser { // dont process an end of rule if there's only one token and it's unknown (#64) if (end && this.tokens.length > 1) { + // Handle the case where the there is only a single token in the end rule. + if (start === this.pos) { + this.pos += 1; + } + const foundEndOfRule = this.ruleEnd({ start, params, diff --git a/test/parser/mixins.spec.js b/test/parser/mixins.spec.js index b8a7d15..e1bf95c 100644 --- a/test/parser/mixins.spec.js +++ b/test/parser/mixins.spec.js @@ -40,6 +40,16 @@ describe('Parser', () => { expect(root.first.first.empty).to.eql(true); expect(root.first.first.nodes).to.be.an('undefined'); }); + + it('mixin without body and without whitespace #2', () => { + const root = parse('.base {.mixin-name}'); + + expect(root.first.first.type).to.eql('rule'); + expect(root.first.first.selector).to.eql('.mixin-name'); + expect(root.first.params).to.be.an('undefined'); + expect(root.first.first.empty).to.eql(true); + expect(root.first.first.nodes).to.be.an('undefined'); + }); }); describe('Nested mixin', () => { From e544159b4a3d92a18e7041c9d44f72509533696f Mon Sep 17 00:00:00 2001 From: Michael Yong Date: Thu, 15 Jun 2017 19:42:32 -0700 Subject: [PATCH 2/2] tests: Use to.be.undefined in assertion. --- test/parser/mixins.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parser/mixins.spec.js b/test/parser/mixins.spec.js index e1bf95c..1987681 100644 --- a/test/parser/mixins.spec.js +++ b/test/parser/mixins.spec.js @@ -36,9 +36,9 @@ describe('Parser', () => { expect(root.first.first.type).to.eql('rule'); expect(root.first.first.selector).to.eql('.mixin-name'); - expect(root.first.params).to.be.an('undefined'); + expect(root.first.params).to.be.undefined; expect(root.first.first.empty).to.eql(true); - expect(root.first.first.nodes).to.be.an('undefined'); + expect(root.first.first.nodes).to.be.undefined; }); it('mixin without body and without whitespace #2', () => { @@ -46,9 +46,9 @@ describe('Parser', () => { expect(root.first.first.type).to.eql('rule'); expect(root.first.first.selector).to.eql('.mixin-name'); - expect(root.first.params).to.be.an('undefined'); + expect(root.first.params).to.be.undefined; expect(root.first.first.empty).to.eql(true); - expect(root.first.first.nodes).to.be.an('undefined'); + expect(root.first.first.nodes).to.be.undefined; }); });