Skip to content

Commit e936611

Browse files
authored
fixes #64: invalid less should throw CSSSyntaxError (#66)
1 parent adb2389 commit e936611

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/less-parser.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export default class LessParser extends Parser {
143143
let bracket = null;
144144
const brackets = [];
145145
const start = this.pos;
146-
146+
147147
// we need pass "()" as spaces
148148
// However we can override method Parser.loop, but it seems less maintainable
149149
if (this.tokens[start][0] === 'brackets') {
@@ -213,7 +213,8 @@ export default class LessParser extends Parser {
213213
this.unclosedBracket(bracket);
214214
}
215215

216-
if (end) {
216+
// dont process an end of rule if there's only one token and it's unknown (#64)
217+
if (end && this.tokens.length > 1) {
217218
const foundEndOfRule = this.processEndOfRule({
218219
start,
219220
params,

test/postcss.spec.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// chai uses expressions for validation
22
/* eslint no-unused-expressions: 0 */
33

4+
import CssSyntaxError from 'postcss/lib/css-syntax-error';
45
import {expect} from 'chai';
56
import lessSyntax from '../lib/less-syntax';
67
import postcss from 'postcss';
78

89
describe('#postcss', () => {
9-
it('can process LESS syntax', (done) => {
10+
it('should process LESS syntax', (done) => {
1011
const lessText = 'a { b {} }';
1112

1213
postcss()
@@ -19,8 +20,8 @@ describe('#postcss', () => {
1920
done();
2021
}).catch(done);
2122
});
22-
23-
it('can parse LESS mixins as at rules', (done) => {
23+
24+
it('should parse LESS mixins as at rules', (done) => {
2425
const lessText = '.foo (@bar; @baz...) { border: @{baz}; }';
2526

2627
postcss()
@@ -33,4 +34,15 @@ describe('#postcss', () => {
3334
done();
3435
}).catch(done);
3536
});
36-
});
37+
38+
it('should not parse invalid LESS (#64)', (done) => {
39+
const lessText = '.foo';
40+
41+
postcss()
42+
.process(lessText, {syntax: lessSyntax})
43+
.catch((err) => {
44+
expect(err).to.be.an.instanceof(CssSyntaxError);
45+
done();
46+
});
47+
});
48+
});

0 commit comments

Comments
 (0)