Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved missing ( and { error detection. #1841

Merged
merged 3 commits into from
Feb 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions lib/less/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ less.Parser = function Parser(env) {
// Split the input into chunks.
chunks = (function (input) {
var len = input.length, level = 0, parenLevel = 0,
lastOpening, lastClosing, lastMultiComment, lastMultiCommentEndBrace,
lastOpening, lastOpeningParen, lastMultiComment, lastMultiCommentEndBrace,
chunks = [], emitFrom = 0,
parserCurrentIndex, currentChunkStartIndex, cc, cc2, matched;

Expand Down Expand Up @@ -403,16 +403,25 @@ less.Parser = function Parser(env) {

switch (cc) {
case 40: // (
parenLevel++; continue;
parenLevel++;
lastOpeningParen = parserCurrentIndex;
continue;
case 41: // )
parenLevel--; continue;
if (--parenLevel < 0) {
return fail("missing opening `(`");
}
continue;
case 59: // ;
if (!parenLevel) { emitChunk(); }
continue;
case 123: // {
level++; lastOpening = parserCurrentIndex; continue;
level++;
lastOpening = parserCurrentIndex;
continue;
case 125: // }
level--; lastClosing = parserCurrentIndex;
if (--level < 0) {
return fail("missing opening `{`");
}
if (!level) { emitChunk(); }
continue;
case 92: // \
Expand Down Expand Up @@ -468,16 +477,13 @@ less.Parser = function Parser(env) {
}

if (level !== 0) {
if (level > 0) {
if ((lastMultiComment > lastOpening) && (lastMultiCommentEndBrace > lastMultiComment)) {
return fail("missing closing `}` or `*/`", lastOpening);
} else {
return fail("missing closing `}`", lastOpening);
}
if ((lastMultiComment > lastOpening) && (lastMultiCommentEndBrace > lastMultiComment)) {
return fail("missing closing `}` or `*/`", lastOpening);
} else {
return fail("missing closing `}`", lastOpening);
}
return fail("missing opening `{`", lastClosing);
} else if (parenLevel !== 0) {
return fail((parenLevel > 0) ? "missing closing `)`" : "missing opening `(`");
return fail("missing closing `)`", lastOpeningParen);
}

emitChunk(true);
Expand Down
6 changes: 4 additions & 2 deletions test/less/errors/import-subfolder2.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ParseError: missing opening `{` in {path}parse-error-curly-bracket.less on line 1, column 2:
1 }}
ParseError: missing opening `{` in {path}parse-error-curly-bracket.less on line 4, column 1:
3 }
4 }
5
5 changes: 4 additions & 1 deletion test/less/errors/parse-error-curly-bracket.less
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
}}
body {
background-color: #fff;
}
}
6 changes: 4 additions & 2 deletions test/less/errors/parse-error-curly-bracket.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ParseError: missing opening `{` in {path}parse-error-curly-bracket.less on line 1, column 2:
1 }}
ParseError: missing opening `{` in {path}parse-error-curly-bracket.less on line 4, column 1:
3 }
4 }
5
6 changes: 3 additions & 3 deletions test/less/errors/parse-error-extra-parens.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ParseError: missing opening `(` in {path}parse-error-extra-parens.less on line 6, column 1:
5 }
6
ParseError: missing opening `(` in {path}parse-error-extra-parens.less on line 1, column 24:
1 @media (extra: bracket)) {
2 body {
6 changes: 3 additions & 3 deletions test/less/errors/parse-error-missing-parens.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ParseError: missing closing `)` in {path}parse-error-missing-parens.less on line 6, column 1:
5 }
6
ParseError: missing closing `)` in {path}parse-error-missing-parens.less on line 1, column 8:
1 @media (missing: bracket {
2 body {