Skip to content

Commit

Permalink
Add guard for visitor functions preventing from cryptic errors due to…
Browse files Browse the repository at this point in the history
… incomplete visitors
  • Loading branch information
Mingun committed Jan 17, 2018
1 parent 4037a86 commit f29e1ea
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/compiler/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
let visitor = {
build(functions) {
function visit(node) {
return functions[node.type].apply(null, arguments);
if (!node) {
throw new Error("`Visitor function called with no or `null` node");
}

let func = functions[node.type];
if (!func) {
throw new Error("Visitor function for node type '" + node.type + " not defined");
}

return func.apply(null, arguments);
}

function visitNop() {
Expand Down

0 comments on commit f29e1ea

Please sign in to comment.