some coffeescript errors can be detected only with compile
This commit is contained in:
parent
6e8989095c
commit
796fb32cc2
2 changed files with 24 additions and 20 deletions
|
|
@ -45,35 +45,39 @@ function assertLocation(e, sl, sc, el, ec) {
|
|||
assert.equal(e.location.last_column, ec);
|
||||
}
|
||||
|
||||
function parse(str) {
|
||||
try {
|
||||
coffee.parse(str).compile();
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
"test parse valid coffee script": function() {
|
||||
coffee.parse("square = (x) -> x * x");
|
||||
},
|
||||
|
||||
"test parse invalid coffee script": function() {
|
||||
try {
|
||||
coffee.parse("a = 12 f");
|
||||
} catch (e) {
|
||||
assert.equal(e.message, "Unexpected 'IDENTIFIER'");
|
||||
assertLocation(e, 0, 4, 0, 5);
|
||||
}
|
||||
var e = parse("a = 12 f");
|
||||
assert.equal(e.message, "Unexpected 'IDENTIFIER'");
|
||||
assertLocation(e, 0, 4, 0, 5);
|
||||
},
|
||||
|
||||
"test parse missing bracket": function() {
|
||||
try {
|
||||
coffee.parse("a = 12 f {\n\n");
|
||||
} catch (e) {
|
||||
assert.equal(e.message, "missing }");
|
||||
assertLocation(e, 0, 10, 0, 10);
|
||||
}
|
||||
var e = parse("a = 12 f {\n\n");
|
||||
assert.equal(e.message, "missing }");
|
||||
assertLocation(e, 0, 10, 0, 10);
|
||||
},
|
||||
"test unexpected indent": function() {
|
||||
try {
|
||||
coffee.parse("a\n a\n");
|
||||
} catch (e) {
|
||||
assert.equal(e.message, "Unexpected 'INDENT'");
|
||||
assertLocation(e, 0, 0, 0, 0);
|
||||
}
|
||||
var e = parse("a\n a\n");
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ window.addEventListener = function() {};
|
|||
|
||||
var Worker = exports.Worker = function(sender) {
|
||||
Mirror.call(this, sender);
|
||||
this.setTimeout(200);
|
||||
this.setTimeout(250);
|
||||
};
|
||||
|
||||
oop.inherits(Worker, Mirror);
|
||||
|
|
@ -51,7 +51,7 @@ oop.inherits(Worker, Mirror);
|
|||
var value = this.doc.getValue();
|
||||
|
||||
try {
|
||||
coffee.parse(value);
|
||||
coffee.parse(value).compile();
|
||||
} catch(e) {
|
||||
var loc = e.location;
|
||||
if (loc) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue