Skip to content

Commit 5e94a55

Browse files
ymichaelshellscape
authored andcommitted
less-parser: Handle edge case with single token mixins. (#80)
* 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} ``` * tests: Use to.be.undefined in assertion.
1 parent b13f0b1 commit 5e94a55

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/less-parser.js

+5
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ export default class LessParser extends Parser {
321321

322322
// dont process an end of rule if there's only one token and it's unknown (#64)
323323
if (end && this.tokens.length > 1) {
324+
// Handle the case where the there is only a single token in the end rule.
325+
if (start === this.pos) {
326+
this.pos += 1;
327+
}
328+
324329
const foundEndOfRule = this.ruleEnd({
325330
start,
326331
params,

test/parser/mixins.spec.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,19 @@ describe('Parser', () => {
3636

3737
expect(root.first.first.type).to.eql('rule');
3838
expect(root.first.first.selector).to.eql('.mixin-name');
39-
expect(root.first.params).to.be.an('undefined');
39+
expect(root.first.params).to.be.undefined;
4040
expect(root.first.first.empty).to.eql(true);
41-
expect(root.first.first.nodes).to.be.an('undefined');
41+
expect(root.first.first.nodes).to.be.undefined;
42+
});
43+
44+
it('mixin without body and without whitespace #2', () => {
45+
const root = parse('.base {.mixin-name}');
46+
47+
expect(root.first.first.type).to.eql('rule');
48+
expect(root.first.first.selector).to.eql('.mixin-name');
49+
expect(root.first.params).to.be.undefined;
50+
expect(root.first.first.empty).to.eql(true);
51+
expect(root.first.first.nodes).to.be.undefined;
4252
});
4353
});
4454

0 commit comments

Comments
 (0)