some coffeescript errors can be detected only with compile

This commit is contained in:
nightwing 2013-04-20 18:27:06 +04:00
commit 796fb32cc2
2 changed files with 24 additions and 20 deletions

View file

@ -45,35 +45,39 @@ function assertLocation(e, sl, sc, el, ec) {
assert.equal(e.location.last_column, ec); assert.equal(e.location.last_column, ec);
} }
function parse(str) {
try {
coffee.parse(str).compile();
} catch (e) {
return e;
}
}
module.exports = { module.exports = {
"test parse valid coffee script": function() { "test parse valid coffee script": function() {
coffee.parse("square = (x) -> x * x"); coffee.parse("square = (x) -> x * x");
}, },
"test parse invalid coffee script": function() { "test parse invalid coffee script": function() {
try { var e = parse("a = 12 f");
coffee.parse("a = 12 f"); assert.equal(e.message, "Unexpected 'IDENTIFIER'");
} catch (e) { assertLocation(e, 0, 4, 0, 5);
assert.equal(e.message, "Unexpected 'IDENTIFIER'");
assertLocation(e, 0, 4, 0, 5);
}
}, },
"test parse missing bracket": function() { "test parse missing bracket": function() {
try { var e = parse("a = 12 f {\n\n");
coffee.parse("a = 12 f {\n\n"); assert.equal(e.message, "missing }");
} catch (e) { assertLocation(e, 0, 10, 0, 10);
assert.equal(e.message, "missing }");
assertLocation(e, 0, 10, 0, 10);
}
}, },
"test unexpected indent": function() { "test unexpected indent": function() {
try { var e = parse("a\n a\n");
coffee.parse("a\n a\n"); assert.equal(e.message, "Unexpected 'INDENT'");
} catch (e) { assertLocation(e, 0, 0, 0, 0);
assert.equal(e.message, "Unexpected 'INDENT'"); },
assertLocation(e, 0, 0, 0, 0); "test invalid destructuring": function() {
} var e = parse("\n{b: 5} = {}");
assert.equal(e.message, '"5" cannot be assigned');
assertLocation(e, 1, 4, 1, 4);
} }
}; };

View file

@ -40,7 +40,7 @@ window.addEventListener = function() {};
var Worker = exports.Worker = function(sender) { var Worker = exports.Worker = function(sender) {
Mirror.call(this, sender); Mirror.call(this, sender);
this.setTimeout(200); this.setTimeout(250);
}; };
oop.inherits(Worker, Mirror); oop.inherits(Worker, Mirror);
@ -51,7 +51,7 @@ oop.inherits(Worker, Mirror);
var value = this.doc.getValue(); var value = this.doc.getValue();
try { try {
coffee.parse(value); coffee.parse(value).compile();
} catch(e) { } catch(e) {
var loc = e.location; var loc = e.location;
if (loc) { if (loc) {