Skip to content

Commit 0377bb9

Browse files
committed
jal-semicolon-fix: reversed parsing of semicolon after mixin without body fix
1 parent 86158c8 commit 0377bb9

File tree

4 files changed

+14
-92
lines changed

4 files changed

+14
-92
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.15.0
2+
* reversed parsing of semicolon after mixin without body fix
3+
14
## 0.14.0
25
* fixed parsing of semicolon after mixin without body
36

lib/less-parser.js

+2-54
Original file line numberDiff line numberDiff line change
@@ -225,57 +225,5 @@ export default class LessParser extends Parser {
225225
this.unknownWord(start);
226226
}
227227

228-
/* eslint-enable max-statements */
229-
230-
loop () {
231-
while (this.pos < this.tokens.length) {
232-
const token = this.tokens[this.pos];
233-
234-
switch (token[0]) {
235-
case 'word':
236-
case ':':
237-
this.word();
238-
break;
239-
240-
case '}':
241-
this.end(token);
242-
break;
243-
244-
case 'comment':
245-
this.comment(token);
246-
break;
247-
248-
case 'at-word':
249-
this.atrule(token);
250-
break;
251-
252-
case '{':
253-
this.emptyRule(token);
254-
break;
255-
256-
case ';':
257-
{
258-
const lastNode = this.current && this.current.last;
259-
260-
// mark semicolon, but don't save it
261-
if (lastNode && lastNode.ruleWithoutBody) {
262-
lastNode.raws.semicolon = true;
263-
} else {
264-
this.spaces += token[1];
265-
}
266-
267-
break;
268-
}
269-
default:
270-
this.spaces += token[1];
271-
break;
272-
}
273-
274-
this.pos += 1;
275-
}
276-
277-
this.endFile();
278-
}
279-
280-
/* eslint-enable complexity */
281-
}
228+
/* eslint-enable max-statements, complexity */
229+
}

test/postcss.spec.js

+6-19
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,16 @@ describe('#postcss', () => {
1919
done();
2020
}).catch(done);
2121
});
22+
23+
it('can parse LESS mixins as at rules', (done) => {
24+
const lessText = '.foo (@bar; @baz...) { border: @{baz}; }';
2225

23-
it('can parse LESS mixins without body', (done) => {
24-
const lessText = `.test4 {
25-
.mixin();
26-
background: red;
27-
}`;
28-
2926
postcss()
3027
.process(lessText, {syntax: lessSyntax})
3128
.then((result) => {
32-
const [rule, declaration] = result.root.first.nodes;
33-
34-
expect(rule.raws).to.deep.equal({
35-
before: '\n ',
36-
between: '',
37-
after: '',
38-
semicolon: true
39-
});
40-
41-
expect(declaration.raws).to.deep.equal({
42-
before: '\n ',
43-
between: ': '
44-
});
29+
expect(result).to.be.not.null;
30+
expect(result.css).to.equal(lessText);
31+
expect(result.content).to.equal(lessText);
4532

4633
done();
4734
}).catch(done);

test/stringify.spec.js

+3-19
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('#stringify()', () => {
6060
syntax: postcssLess,
6161
stringifier: stringify
6262
}).then((result) => {
63-
expect(result.content).to.eql('.selector:extend(.f, .g) {&:extend(.a)}');
63+
expect(result.content).to.eql(less);
6464
done();
6565
}).catch((error) => {
6666
done(error);
@@ -103,33 +103,17 @@ describe('#stringify()', () => {
103103
width: @width;
104104
}
105105
}
106-
106+
107107
.rotation(@deg:5deg){
108108
.transform(rotate(@deg));
109109
}
110110
`;
111-
112-
function prepareOutput (str) {
113-
return str.replace(/\s{2,}/g, ' ');
114-
}
115111

116112
postcss().process(less, {
117113
syntax: postcssLess,
118114
stringifier: stringify
119115
}).then((result) => {
120-
expect(prepareOutput(result.content)).to.eql(prepareOutput(`
121-
.container {
122-
.mixin-1()
123-
.mixin-2
124-
.mixin-3 (@width: 100px) {
125-
width: @width;
126-
}
127-
}
128-
129-
.rotation(@deg:5deg){
130-
.transform(rotate(@deg))
131-
}
132-
`));
116+
expect(result.content).to.eql(less);
133117
done();
134118
}).catch((error) => {
135119
done(error);

0 commit comments

Comments
 (0)