better errorWithNode that's consolidated across paths and files

This commit is contained in:
Sebastian McKenzie 2015-06-13 02:19:44 +01:00
parent 763892aa79
commit f5b921cda9
2 changed files with 3 additions and 5 deletions

View File

@ -415,11 +415,12 @@ export default class File {
errorWithNode(node, msg, Error = SyntaxError) {
var err;
if (node.loc) {
if (node && node.loc) {
var loc = node.loc.start;
err = new Error(`Line ${loc.line}: ${msg}`);
err.loc = loc;
} else {
// todo: find errors with nodes inside to at least point to something
err = new Error("There's been an error on a dynamic node. This is almost certainly an internal error. Please report it.");
}
return err;

View File

@ -81,10 +81,7 @@ export default class NodePath {
*/
errorWithNode(msg, Error = SyntaxError) {
var loc = this.node.loc.start;
var err = new Error(`Line ${loc.line}: ${msg}`);
err.loc = loc;
return err;
return this.hub.file.errorWithNode(this.node, msg, Error);
}
/**