8000 Reorganized some of the parsing rule order · rusongyu/less.js@1e0cfe9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e0cfe9

Browse files
author
cloudhead
committed
Reorganized some of the parsing rule order
- Fix for "{" not parsing - Use some backtracking when necessary, it's prettier than crazy lookaheads.
1 parent aa13ee0 commit 1e0cfe9

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

lib/less/parser.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ less.Parser = function Parser(env) {
295295
primary: function () {
296296
var node, root = [];
297297

298-
while (node = $(this.mixin.definition) || $(this.ruleset) || $(this.rule) ||
298+
while (node = $(this.mixin.definition) || $(this.rule) || $(this.ruleset) ||
299299
$(this.mixin.call) || $(this.comment) ||
300300
$(/[\n\s]+/g) || $(this.directive)) {
301301
root.push(node);
@@ -677,9 +677,7 @@ less.Parser = function Parser(env) {
677677
// div, .class, body > p {...}
678678
//
679679
ruleset: function () {
680-
var selectors = [], s, rules, match;
681-
682-
if (peek(/[^{]+[@;}]/g)) return;
680+
var selectors = [], s, rules, match, memo = i;
683681

684682
if (match = peek(/([a-z.#: _-]+)[\s\n]*\{/g)) {
685683
i += match[0].length - 1;
@@ -692,14 +690,16 @@ less.Parser = function Parser(env) {
692690
if (s) $(this.comment);
693691
}
694692

695-
rules = $(this.block);
696-
697-
if (selectors.length > 0 && rules) {
693+
if (selectors.length > 0 && (rules = $(this.block))) {
698694
return new(tree.Ruleset)(selectors, rules);
695+
} else {
696+
// Backtrack
697+
i = memo;
699698
}
700699
},
701700
rule: function () {
702701
var value;
702+
var memo = i;
703703

704704
if (name = $(this.property) || $(this.variable)) {
705705
if ((name[0] != 8000 '@') && (match = peek(/([^@+\/*(;{}-]*);/g))) {
@@ -713,6 +713,8 @@ less.Parser = function Parser(env) {
713713

714714
if ($(this.end)) {
715715
return new(tree.Rule)(name, value);
716+
} else {
717+
i = memo;
716718
}
717719
}
718720
},

test/css/strings.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
quotes: "~" "~";
44
content: "#*%:&^,)!.(~*})";
55
empty: "";
6+
brackets: "{" "}";
67
}
78
#comments {
89
content: "/* hello */ // not-so-secret";

test/less/strings.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
quotes: "~" "~";
44
content: "#*%:&^,)!.(~*})";
55
empty: "";
6+
brackets: "{" "}";
67
}
78
#comments {
89
content: "/* hello */ // not-so-secret";
@@ -11,4 +12,4 @@
1112
quotes: "'" "'";
1213
content: '""#!&""';
1314
empty: '';
14-
}
15+
}

0 commit comments

Comments
 (0)
0