diff --git a/Libraries/LibJS/Lexer.h b/Libraries/LibJS/Lexer.h index 24a4fe9d04..3efe290aa8 100644 --- a/Libraries/LibJS/Lexer.h +++ b/Libraries/LibJS/Lexer.h @@ -40,6 +40,8 @@ public: Token next(); + const StringView& source() const { return m_source; }; + private: void consume(); bool consume_exponent(); diff --git a/Libraries/LibJS/Parser.h b/Libraries/LibJS/Parser.h index 2672eca4d8..6b7a1554af 100644 --- a/Libraries/LibJS/Parser.h +++ b/Libraries/LibJS/Parser.h @@ -143,8 +143,12 @@ public: const Vector& errors() const { return m_parser_state.m_errors; } void print_errors() const { - for (auto& error : m_parser_state.m_errors) - fprintf(stderr, "SyntaxError: %s\n", error.to_string().characters()); + for (auto& error : m_parser_state.m_errors) { + auto hint = error.source_location_hint(m_parser_state.m_lexer.source()); + if (!hint.is_empty()) + warnln("{}", hint); + warnln("SyntaxError: {}", error.to_string()); + } } private: