improve diagnostics upon AST validation failure (#4033)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 31 Jul 2020 14:50:16 +0000 (15:50 +0100)
committerGitHub <noreply@github.com>
Fri, 31 Jul 2020 14:50:16 +0000 (22:50 +0800)
lib/ast.js

index 093e192..2c27cbb 100644 (file)
@@ -123,7 +123,14 @@ var AST_Node = DEFNODE("Node", "start end", {
     validate_ast: function() {
         var marker = {};
         this.walk(new TreeWalker(function(node) {
-            if (node.validate_visited === marker) throw new Error("invalid node reuse: " + node);
+            if (node.validate_visited === marker) {
+                throw new Error(string_template("cannot reuse {type} from [{file}:{line},{col}]", {
+                    type: "AST_" + node.TYPE,
+                    file: node.start.file,
+                    line: node.start.line,
+                    col: node.start.col,
+                }));
+            }
             node.validate_visited = marker;
         }));
     },