Catch syntax errors. Also, don't let comment regex make weird behavior. Also, only let error() record, never let it throw.
This commit is contained in:
parent
8ba60b3e0d
commit
d54b36729b
@ -1,19 +1,10 @@
|
||||
@red: #fff;
|
||||
|
||||
#world {
|
||||
polygon-fill:#CCC;
|
||||
polygon-fill: @red;
|
||||
text-face-name: 'Arial', 'Verdana';
|
||||
}
|
||||
|
||||
#world[NAME='United States'] {
|
||||
polygon-fill:#F00;
|
||||
#countries {
|
||||
text-face-name: 'Arial', 'Verdana', 'Helvetica';
|
||||
}
|
||||
|
||||
#countries .countries .two {
|
||||
polygon-fill:#0FF;
|
||||
}
|
||||
|
||||
#countries, #world {
|
||||
polygon-fill:#F0F;
|
||||
polygon-opacity: 0.5;
|
||||
}
|
||||
|
||||
|
||||
#countries, #countries.foo.bar.baz {}
|
||||
|
@ -220,7 +220,8 @@ mess.Parser = function Parser(env) {
|
||||
chunks = (function(chunks) {
|
||||
var j = 0,
|
||||
skip = /[^"'`\{\}\/]+/g,
|
||||
comment = /\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)|\/\/.*/g,
|
||||
// comment = /\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)|\/\/.*/g,
|
||||
comment = /\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/.*/g,
|
||||
level = 0,
|
||||
match,
|
||||
chunk = chunks[0],
|
||||
@ -293,6 +294,10 @@ mess.Parser = function Parser(env) {
|
||||
|
||||
// return function(options, variables) {
|
||||
return function(env) {
|
||||
env.error = function(e) {
|
||||
if (!env.errors) env.errors = [];
|
||||
env.errors.push(e);
|
||||
};
|
||||
env.errors = [];
|
||||
env.frames = env.frames || [];
|
||||
|
||||
@ -446,7 +451,8 @@ mess.Parser = function Parser(env) {
|
||||
|
||||
if (input.charAt(i + 1) === '/') {
|
||||
return new tree.Comment($(/^\/\/.*/), true);
|
||||
} else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)/)) {
|
||||
} else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/)) {
|
||||
// } else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)/)) {
|
||||
return new tree.Comment(comment);
|
||||
}
|
||||
},
|
||||
|
@ -78,17 +78,6 @@ tree.Definition.prototype.toXML = function(env) {
|
||||
sym = sym[0];
|
||||
}
|
||||
|
||||
if (env.returnErrors) {
|
||||
env.error = function(e) {
|
||||
if (env.errors) {
|
||||
env.errors.push(e);
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var symname = sym.charAt(0).toUpperCase()
|
||||
+ sym.slice(1).replace(/\-./, function(str) {
|
||||
return str[1].toUpperCase();
|
||||
|
@ -5,14 +5,6 @@ var sys = require('sys');
|
||||
tree.Invalid = function (chunk, index) {
|
||||
this.chunk = chunk;
|
||||
this.index = index;
|
||||
this.message = "Invalid code: " + this.chunk;
|
||||
};
|
||||
tree.Invalid.prototype = {
|
||||
toCSS: function (env) {
|
||||
return env.error({
|
||||
message: "Invalid code: " + sys.inspect(this.chunk),
|
||||
index: this.index
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(require('mess/tree'));
|
||||
|
@ -147,6 +147,8 @@ tree.Ruleset.prototype = {
|
||||
rule.flatten(result, selectors, env);
|
||||
} else if (rule instanceof tree.Rule) {
|
||||
rules.push(rule);
|
||||
} else if (rule instanceof tree.Invalid) {
|
||||
env.errors.push(rule);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user