Skip to content

Commit

Permalink
Fix Issue 23426 - Example Run button shows wrong line numbers for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrel authored and dlang-bot committed Oct 18, 2022
1 parent d6fa144 commit 2923398
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions js/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions js/run_examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ 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 {
var codeOut = "void main()\n{\n";
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}";
}
Expand Down

0 comments on commit 2923398

Please sign in to comment.