From 58397f356f6a4359d5aefe6a5dcd618abd23cd77 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 23 Nov 2021 23:02:19 +0200 Subject: [PATCH] js: Add command line flag for disabling source line hints --- Base/usr/share/man/man1/js.md | 1 + Userland/Utilities/js.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Base/usr/share/man/man1/js.md b/Base/usr/share/man/man1/js.md index 0d797df1b98..023b766c0ff 100644 --- a/Base/usr/share/man/man1/js.md +++ b/Base/usr/share/man/man1/js.md @@ -29,6 +29,7 @@ Run `help()` in REPL mode to see its available built-in functions. * `-l`, `--print-last-result`: Print the result of the last statement executed. * `-g`, `--gc-on-every-allocation`: Run garbage collection on every allocation. * `-c`, `--disable-ansi-colors`: Disable ANSI colors +* `-h`, `--disable-source-location-hints`: Disable source location hints * `-s`, `--no-syntax-highlight`: Disable live syntax highlighting in the REPL ## Examples diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index fc6b275910e..e433be05aca 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -105,6 +105,7 @@ static bool s_opt_bytecode = false; static bool s_as_module = false; static bool s_print_last_result = false; static bool s_strip_ansi = false; +static bool s_disable_source_location_hints = false; static RefPtr s_editor; static String s_history_path = String::formatted("{}/.js-history", Core::StandardPaths::home_directory()); static int s_repl_line_level = 0; @@ -868,9 +869,11 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView source, Strin if (parser.has_errors()) { auto error = parser.errors()[0]; - auto hint = error.source_location_hint(source); - if (!hint.is_empty()) - js_outln("{}", hint); + if (!s_disable_source_location_hints) { + auto hint = error.source_location_hint(source); + if (!hint.is_empty()) + js_outln("{}", hint); + } vm->throw_exception(interpreter.global_object(), error.to_string()); } else { if (JS::Bytecode::g_dump_bytecode || s_run_bytecode) { @@ -1171,6 +1174,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(s_as_module, "Treat as module", "as-module", 'm'); args_parser.add_option(s_print_last_result, "Print last result", "print-last-result", 'l'); args_parser.add_option(s_strip_ansi, "Disable ANSI colors", "disable-ansi-colors", 'c'); + args_parser.add_option(s_disable_source_location_hints, "Disable source location hints", "disable-source-location-hints", 'h'); args_parser.add_option(gc_on_every_allocation, "GC on every allocation", "gc-on-every-allocation", 'g'); #ifdef JS_TRACK_ZOMBIE_CELLS bool zombify_dead_cells = false;