[Pkg-javascript-commits] [less.js] 55/285: improve some of the error messages when not using the chunker.
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:23:37 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.0.0
in repository less.js.
commit 73c34ac24f4c0dccc683c5e93e5f13cd4454e4ab
Author: Luke Page <luke.a.page at gmail.com>
Date: Sun Jun 22 10:43:05 2014 +0100
improve some of the error messages when not using the chunker.
---
lib/less/index.js | 2 +-
lib/less/parser.js | 66 +++++++++++++++++-------
test/less/errors/detached-ruleset-2.txt | 2 +-
test/less/errors/detached-ruleset-4.txt | 5 +-
test/less/errors/detached-ruleset-6.txt | 2 +-
test/less/errors/import-no-semi.txt | 2 +-
test/less/errors/import-subfolder2.txt | 2 +-
test/less/errors/parse-error-curly-bracket.txt | 2 +-
test/less/errors/parse-error-extra-parens.txt | 2 +-
test/less/errors/parse-error-missing-bracket.txt | 4 +-
test/less/errors/parse-error-missing-parens.txt | 2 +-
test/less/errors/property-asterisk-only-name.txt | 2 +-
test/less/errors/property-ie5-hack.txt | 3 +-
13 files changed, 61 insertions(+), 35 deletions(-)
diff --git a/lib/less/index.js b/lib/less/index.js
index 879a64d..5d4a0bd 100644
--- a/lib/less/index.js
+++ b/lib/less/index.js
@@ -54,7 +54,7 @@ less.formatError = function(ctx, options) {
var errorTxt = ctx.line + ' ';
if (extract[1]) {
errorTxt += extract[1].slice(0, ctx.column) +
- stylize(stylize(stylize(extract[1][ctx.column], 'bold') +
+ stylize(stylize(stylize(extract[1].substr(ctx.column, 1), 'bold') +
extract[1].slice(ctx.column + 1), 'red'), 'inverse');
}
error.push(errorTxt);
diff --git a/lib/less/parser.js b/lib/less/parser.js
index 7341edd..bdc0a1f 100644
--- a/lib/less/parser.js
+++ b/lib/less/parser.js
@@ -41,6 +41,7 @@ var Parser = function Parser(env) {
j, // current chunk
saveStack = [], // holds state for backtracking
furthest, // furthest index the parser has gone to
+ furthestPossibleErrorMessage,// if this is furthest we got to, this is the probably cause
chunks, // chunkified input
current, // current chunk
currentPos, // index of current chunk, in `input`
@@ -129,9 +130,23 @@ var Parser = function Parser(env) {
}
};
- function save() { currentPos = i; saveStack.push( { current: current, i: i, j: j }); }
- function restore() { var state = saveStack.pop(); current = state.current; currentPos = i = state.i; j = state.j; }
- function forget() { saveStack.pop(); }
+ function save() {
+ currentPos = i;
+ saveStack.push( { current: current, i: i, j: j });
+ }
+ function restore(possibleErrorMessage) {
+ if (i > furthest) {
+ furthest = i;
+ furthestPossibleErrorMessage = possibleErrorMessage;
+ }
+ var state = saveStack.pop();
+ current = state.current;
+ currentPos = i = state.i;
+ j = state.j;
+ }
+ function forget() {
+ saveStack.pop();
+ }
function sync() {
if (i > currentPos) {
@@ -519,14 +534,21 @@ var Parser = function Parser(env) {
// We split it up into two parts (the part which parsed,
// and the part which didn't), so we can color them differently.
if (i < input.length - 1) {
- i = Math.max(i, furthest);
var message = "Unrecognised input";
+ if (i < furthest) {
+ message = furthestPossibleErrorMessage || message;
+ i = furthest;
+ }
- if (input[i] === '}') {
- message = "Missing opening '{'";
- } else if (input[i] === ')') {
- message = "Missing opening '('";
+ if (!furthestPossibleErrorMessage) {
+ if (input[i] === '}') {
+ message += ". Possibly missing opening '{'";
+ } else if (input[i] === ')') {
+ message += ". Possibly missing opening '('";
+ } else if (i >= input.length - 1) {
+ message += ". Possibly missing something";
+ }
}
var loc = getLocation(i, input);
@@ -1185,8 +1207,7 @@ var Parser = function Parser(env) {
// .mixincall(@a: {rule: set;});
// so we have to be nice and restore
if (!$char(')')) {
- furthest = i;
- restore();
+ restore("Missing closing ')'");
return;
}
@@ -1275,7 +1296,7 @@ var Parser = function Parser(env) {
e = new(tree.Paren)(v);
forget();
} else {
- restore();
+ restore("Missing closing ')'");
}
} else {
forget();
@@ -1434,8 +1455,6 @@ var Parser = function Parser(env) {
}
return ruleset;
} else {
- // Backtrack
- furthest = i;
restore();
}
},
@@ -1473,7 +1492,6 @@ var Parser = function Parser(env) {
forget();
return new (tree.Rule)(name, value, important, merge, startOfRule, env.currentFileInfo);
} else {
- furthest = i;
restore();
if (value && !tryAnonymous) {
return this.rule(true);
@@ -1518,9 +1536,11 @@ var Parser = function Parser(env) {
features = features && new(tree.Value)(features);
return new(tree.Import)(path, features, options, index, env.currentFileInfo);
}
+ restore("bad media features or missing ';'");
+ return;
}
- restore();
+ restore("malformed import");
},
importOptions: function() {
@@ -1560,6 +1580,7 @@ var Parser = function Parser(env) {
mediaFeature: function () {
var entities = this.entities, nodes = [], e, p;
+ save();
do {
e = entities.keyword() || entities.variable();
if (e) {
@@ -1573,12 +1594,17 @@ var Parser = function Parser(env) {
} else if (e) {
nodes.push(new(tree.Paren)(e));
} else {
+ restore("badly formed media feature definition");
return null;
}
- } else { return null; }
+ } else {
+ restore("Missing closing ')'");
+ return null;
+ }
}
} while (e);
+ forget();
if (nodes.length > 0) {
return new(tree.Expression)(nodes);
}
@@ -1720,7 +1746,7 @@ var Parser = function Parser(env) {
env.dumpLineNumbers ? getDebugInfo(index, input, env) : null);
}
- restore();
+ restore("directive options not recognised");
},
//
@@ -1933,9 +1959,9 @@ var Parser = function Parser(env) {
}
for (k = 0; k < name.length; k++) {
s = name[k];
- name[k] = (s.charAt(0) !== '@')
- ? new(tree.Keyword)(s)
- : new(tree.Variable)('@' + s.slice(2, -1),
+ name[k] = (s.charAt(0) !== '@') ?
+ new(tree.Keyword)(s) :
+ new(tree.Variable)('@' + s.slice(2, -1),
index[k], env.currentFileInfo);
}
return name;
diff --git a/test/less/errors/detached-ruleset-2.txt b/test/less/errors/detached-ruleset-2.txt
index f18e093..32344a8 100644
--- a/test/less/errors/detached-ruleset-2.txt
+++ b/test/less/errors/detached-ruleset-2.txt
@@ -1,4 +1,4 @@
-ParseError: Unrecognised input in {path}detached-ruleset-2.less on line 5, column 3:
+ParseError: Unrecognised input. Possibly missing opening '(' in {path}detached-ruleset-2.less on line 5, column 9:
4 .a {
5 a: @a();
6 }
diff --git a/test/less/errors/detached-ruleset-4.txt b/test/less/errors/detached-ruleset-4.txt
index d6d6526..905222e 100644
--- a/test/less/errors/detached-ruleset-4.txt
+++ b/test/less/errors/detached-ruleset-4.txt
@@ -1,3 +1,4 @@
-ParseError: Unrecognised input in {path}detached-ruleset-4.less on line 1, column 18:
-1 .mixin-definition(@a: {
+ParseError: Unrecognised input in {path}detached-ruleset-4.less on line 3, column 4:
2 b: 1;
+3 }) {
+4 @a();
diff --git a/test/less/errors/detached-ruleset-6.txt b/test/less/errors/detached-ruleset-6.txt
index 0784044..7f6b0ae 100644
--- a/test/less/errors/detached-ruleset-6.txt
+++ b/test/less/errors/detached-ruleset-6.txt
@@ -1,4 +1,4 @@
-ParseError: Unrecognised input in {path}detached-ruleset-6.less on line 2, column 3:
+ParseError: Unrecognised input in {path}detached-ruleset-6.less on line 2, column 6:
1 .a {
2 b: {
3 color: red;
diff --git a/test/less/errors/import-no-semi.txt b/test/less/errors/import-no-semi.txt
index 8b3f795..d373cf4 100644
--- a/test/less/errors/import-no-semi.txt
+++ b/test/less/errors/import-no-semi.txt
@@ -1,2 +1,2 @@
-ParseError: Unrecognised input in {path}import-no-semi.less on line 1, column 1:
+ParseError: bad media features or missing ';' in {path}import-no-semi.less on line 1, column 41:
1 @import "this-statement-is-invalid.less"
diff --git a/test/less/errors/import-subfolder2.txt b/test/less/errors/import-subfolder2.txt
index bb77163..59cf5bd 100644
--- a/test/less/errors/import-subfolder2.txt
+++ b/test/less/errors/import-subfolder2.txt
@@ -1,4 +1,4 @@
-ParseError: Missing opening '{' in {path}parse-error-curly-bracket.less on line 4, column 1:
+ParseError: Unrecognised input. Possibly 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.txt b/test/less/errors/parse-error-curly-bracket.txt
index bb77163..59cf5bd 100644
--- a/test/less/errors/parse-error-curly-bracket.txt
+++ b/test/less/errors/parse-error-curly-bracket.txt
@@ -1,4 +1,4 @@
-ParseError: Missing opening '{' in {path}parse-error-curly-bracket.less on line 4, column 1:
+ParseError: Unrecognised input. Possibly 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 4eccf1b..9e79065 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 1, column 24:
+ParseError: Unrecognised input. Possibly 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-bracket.txt b/test/less/errors/parse-error-missing-bracket.txt
index a516a0a..307bbd4 100644
--- a/test/less/errors/parse-error-missing-bracket.txt
+++ b/test/less/errors/parse-error-missing-bracket.txt
@@ -1,3 +1,3 @@
-ParseError: Missing closing '}' in {path}parse-error-missing-bracket.less on line 1, column 6:
-1 body {
+ParseError: Unrecognised input. Possibly missing something in {path}parse-error-missing-bracket.less on line 3, column 1:
2 background-color: #fff;
+3
diff --git a/test/less/errors/parse-error-missing-parens.txt b/test/less/errors/parse-error-missing-parens.txt
index f92da45..b5998fe 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 1, column 8:
+ParseError: Missing closing ')' in {path}parse-error-missing-parens.less on line 1, column 26:
1 @media (missing: bracket {
2 body {
diff --git a/test/less/errors/property-asterisk-only-name.txt b/test/less/errors/property-asterisk-only-name.txt
index 6adc6c6..b81d757 100644
--- a/test/less/errors/property-asterisk-only-name.txt
+++ b/test/less/errors/property-asterisk-only-name.txt
@@ -1,4 +1,4 @@
-ParseError: Unrecognised input in {path}property-asterisk-only-name.less on line 2, column 5:
+ParseError: Unrecognised input in {path}property-asterisk-only-name.less on line 2, column 7:
1 a {
2 * : 1;
3 }
diff --git a/test/less/errors/property-ie5-hack.txt b/test/less/errors/property-ie5-hack.txt
index e42ef90..434943f 100644
--- a/test/less/errors/property-ie5-hack.txt
+++ b/test/less/errors/property-ie5-hack.txt
@@ -1,4 +1,3 @@
-ParseError: Unrecognised input in {path}property-ie5-hack.less on line 2, column 3:
-1 .test {
+ParseError: Unrecognised input. Possibly missing opening '{' in {path}property-ie5-hack.less on line 3, column 1:
2 display/*/: block; /*sorry for IE5*/
3 }
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list