浏览代码

js: Show a "source location hint" for syntax errors :^)

Linus Groh 5 年之前
父节点
当前提交
015d65bc6f
共有 1 个文件被更改,包括 3 次插入0 次删除
  1. 3 0
      Userland/js.cpp

+ 3 - 0
Userland/js.cpp

@@ -287,6 +287,9 @@ bool parse_and_run(JS::Interpreter& interpreter, const StringView& source)
 
     if (parser.has_errors()) {
         auto error = parser.errors()[0];
+        auto hint = error.source_location_hint(source);
+        if (!hint.is_empty())
+            printf("%s\n", hint.characters());
         interpreter.throw_exception<JS::SyntaxError>(error.to_string());
     } else {
         interpreter.run(*program);