diff --git a/src/__tests__/classes.js b/src/__tests__/classes.js index 9cc2a0b..34222c4 100644 --- a/src/__tests__/classes.js +++ b/src/__tests__/classes.js @@ -20,3 +20,9 @@ test('qualified class', 'button.btn-primary', (t, tree) => { t.equal(tree.selectors[0].rules[0].type, 'tag'); t.equal(tree.selectors[0].rules[1].type, 'class'); }); + +test('escaped numbers in class name', '.\\31\\ 0', (t, tree, d) => { + t.plan(2); + t.equal(tree.selectors[0].rules[0].type, 'class'); + t.equal(tree.selectors[0].rules[0].value, '\\31\\ 0'); +}); diff --git a/src/parser.js b/src/parser.js index 9a31e81..1f281a2 100644 --- a/src/parser.js +++ b/src/parser.js @@ -234,6 +234,18 @@ export default class Parser { return this.namespace(); } let word = this.tokens[this.position][1]; + while (this.tokens[this.position + 1] && this.tokens[this.position + 1][0] === 'word') { + this.position ++; + let current = this.tokens[this.position][1]; + word += current; + if (current.lastIndexOf('\\') === current.length - 1) { + let next = this.tokens[this.position + 1]; + if (next[0] === 'space') { + word += next[1]; + this.position ++; + } + } + } let hasClass = indexesOf(word, '.'); let hasId = indexesOf(word, '#'); if (hasId.length > 1) {