diff --git a/lib/less/parser.js b/lib/less/parser.js index 70d2256ba..43a0b58c8 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -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; @@ -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: // \ @@ -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); diff --git a/test/less/errors/import-subfolder2.txt b/test/less/errors/import-subfolder2.txt index 7d514efc8..b5b1a69ba 100644 --- a/test/less/errors/import-subfolder2.txt +++ b/test/less/errors/import-subfolder2.txt @@ -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 diff --git a/test/less/errors/parse-error-curly-bracket.less b/test/less/errors/parse-error-curly-bracket.less index a2950a11c..f78ceb701 100644 --- a/test/less/errors/parse-error-curly-bracket.less +++ b/test/less/errors/parse-error-curly-bracket.less @@ -1 +1,4 @@ -}} \ No newline at end of file +body { + background-color: #fff; + } +} diff --git a/test/less/errors/parse-error-curly-bracket.txt b/test/less/errors/parse-error-curly-bracket.txt index 7d514efc8..b5b1a69ba 100644 --- a/test/less/errors/parse-error-curly-bracket.txt +++ b/test/less/errors/parse-error-curly-bracket.txt @@ -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 diff --git a/test/less/errors/parse-error-extra-parens.txt b/test/less/errors/parse-error-extra-parens.txt index cd70195ca..5c1aaef2a 100644 --- a/test/less/errors/parse-error-extra-parens.txt +++ b/test/less/errors/parse-error-extra-parens.txt @@ -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 { diff --git a/test/less/errors/parse-error-missing-parens.txt b/test/less/errors/parse-error-missing-parens.txt index d11127ca8..a7a67067a 100644 --- a/test/less/errors/parse-error-missing-parens.txt +++ b/test/less/errors/parse-error-missing-parens.txt @@ -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 {