From 2923398158419e8acea88bd3642306a3e46da8d1 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 18 Oct 2022 17:34:48 +0100 Subject: [PATCH] Fix Issue 23426 - Example Run button shows wrong line numbers for errors --- js/run.js | 1 + js/run_examples.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/js/run.js b/js/run.js index f8f3f2011c..08bb3f630c 100644 --- a/js/run.js +++ b/js/run.js @@ -190,6 +190,7 @@ function wrapIntoMain(code) { var codeOut = "void main()\n{\n"; // writing to the stdout is probably often used codeOut += " import std.stdio: write, writeln, writef, writefln;\n "; + codeOut += "#line 1\n"; codeOut += code.split("\n").join("\n "); codeOut += "\n}"; return codeOut; diff --git a/js/run_examples.js b/js/run_examples.js index 3b90c3c6c6..063fea193a 100644 --- a/js/run_examples.js +++ b/js/run_examples.js @@ -22,6 +22,7 @@ function wrapIntoMain(code) { // dynamically wrap into main if needed if (code.indexOf("void main") >= 0) { codeOut = "import " + currentPackage + "; "; + codeOut += "#line 1\n"; codeOut += code; } else { @@ -29,6 +30,7 @@ function wrapIntoMain(code) { codeOut += " import " + currentPackage + ";\n"; // writing to the stdout is probably often used codeOut += (currentPackage == "std.file") ? " import std.stdio: writeln, writef, writefln;\n " : " import std.stdio: write, writeln, writef, writefln;\n "; + codeOut += "#line 1\n"; codeOut += code.split("\n").join("\n "); codeOut += "\n}"; }