Prechádzať zdrojové kódy

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

Linus Groh 5 rokov pred
rodič
commit
015d65bc6f
1 zmenil súbory, kde vykonal 3 pridanie a 0 odobranie
  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);