Skip to content

Commit

Permalink
Minor fixes. #1615
Browse files Browse the repository at this point in the history
  • Loading branch information
fredburger committed Oct 30, 2013
1 parent 52dc714 commit 56c3338
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions lib/less/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ less.Parser = function Parser(env) {
k, ko, cc, cc2, matched;

function fail(msg, index) {
index = index || k;
error = new(LessError)({
index: index || k,
type: 'Parse',
Expand Down Expand Up @@ -409,8 +408,7 @@ less.Parser = function Parser(env) {
continue;
case 92: // \
if (k < len - 1) { k++; continue; }
fail("unescaped '\\'");
break;
return fail("unescaped `\\`");
case 34:
case 39:
case 96: // ", ' and `
Expand All @@ -422,17 +420,13 @@ less.Parser = function Parser(env) {
if (cc2 == cc) { matched = 1; break; }
if (cc2 == 92) { // \
if (k == len - 1) {
fail("unescaped '\\'");
break;
return fail("unescaped `\\`");
}
k++;
}
}
if (matched) { continue; }
if (!error) {
fail("unmatched '" + String.fromCharCode(cc) + "'", ko);
}
break;
return fail("unmatched `" + String.fromCharCode(cc) + "`", ko);
case 47: // /, check for comment
if (parenLevel || (k == len - 1)) { continue; }
cc2 = input.charCodeAt(k + 1);
Expand All @@ -452,50 +446,41 @@ less.Parser = function Parser(env) {
if (input.charCodeAt(k + 1) == 47) { break; }
}
if (k == len - 1) {
fail("missing closing `*/`", ko);
return fail("missing closing `*/`", ko);
}
}
continue;
case 42: // *, check for unmatched */
if ((k < len - 1) && (input.charCodeAt(k + 1) == 47)) {
fail("unmatched `/*`");
break;
return fail("unmatched `/*`");
}
continue;
default:
continue;
}

// only reaches here on error
break;
}

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

emitChunk(true);
return chunks;
})(str);

current = chunks[0];

if (error) {
return callback(new(LessError)(error, env));
}

current = chunks[0];

// Start with the primary rule.
// The whole syntax tree is held under a Ruleset node,
// with the `root` property set to true, so no `{}` are
Expand Down

0 comments on commit 56c3338

Please sign in to comment.