Skip to content

Commit 926a5a6

Browse files
committed
Fixes crash on trailing combinator.
1 parent e560399 commit 926a5a6

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.2.1
2+
3+
* Fixes a crash when the parser encountered a trailing combinator.
4+
15
# 1.2.0
26

37
* A more descriptive error is thrown when the parser expects to find a

src/__tests__/combinators.js

+6
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ test('multiple combinators with whitespaces', 'h1+ h2 >h3', (t, tree) => {
9797
t.equal(tree.nodes[0].nodes[1].value, '+', 'should have a combinator');
9898
t.equal(tree.nodes[0].nodes[3].value, '>', 'should have a combinator');
9999
});
100+
101+
test('trailing combinator & spaces', 'p + ', (t, tree) => {
102+
t.plan(2);
103+
t.equal(tree.nodes[0].nodes[0].value, 'p', 'should be a paragraph');
104+
t.equal(tree.nodes[0].nodes[1].value, '+', 'should have a combinator');
105+
});

src/parser.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ export default class Parser {
101101
},
102102
sourceIndex: this.currToken[4]
103103
});
104-
while ( this.position < this.tokens.length &&
105-
this.currToken[0] === 'space' ||
106-
this.currToken[0] === 'combinator') {
107-
if (this.nextToken[0] === 'combinator') {
104+
while ( this.position < this.tokens.length && this.currToken &&
105+
(this.currToken[0] === 'space' ||
106+
this.currToken[0] === 'combinator')) {
107+
if (this.nextToken && this.nextToken[0] === 'combinator') {
108108
combinator.spaces.before = this.currToken[1];
109109
combinator.source.start.line = this.nextToken[2];
110110
combinator.source.start.column = this.nextToken[3];

0 commit comments

Comments
 (0)