Skip to content

Commit f18feef

Browse files
Dale-Blackclaude
andcommitted
Fix playground output capture: copy fixed worker.js from src/playground/
The docs/src/playground/ was copied from the old docs-old/ which predated the output capture fix (commit b0e6dfe). Now copies the correct worker.js that overrides jl_println AFTER codegen defines it and calls $main() after. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9f911e8 commit f18feef

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

docs/src/playground/worker.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,21 @@ function compileAndRun(source) {
5151
diagnostics = result.diagnostics || [];
5252

5353
// Step 2: Execute the compiled JS and capture output
54-
// Prepend runtime overrides so jl_println captures output
54+
// The codegen output includes jl_println (console.log) + $main() call.
55+
// Strip the $main() call, override jl_println to capture, then call $main().
56+
var jsBody = js.replace(/\$main\(\);?\s*$/, ''); // Remove trailing $main() call
5557
var execCode =
5658
'var _jl_output = [];\n' +
57-
'function jl_println() {\n' +
59+
jsBody + '\n' +
60+
'jl_println = function() {\n' +
5861
' var a = []; for (var i = 0; i < arguments.length; i++) {\n' +
5962
' var v = arguments[i]; a.push(v === null ? "nothing" : v === undefined ? "missing" : String(v));\n' +
60-
' }\n _jl_output.push(a.join("") + "\\n");\n}\n' +
61-
'function jl_print() {\n' +
63+
' }\n _jl_output.push(a.join("") + "\\n");\n};\n' +
64+
'jl_print = function() {\n' +
6265
' var a = []; for (var i = 0; i < arguments.length; i++) {\n' +
6366
' var v = arguments[i]; a.push(v === null ? "nothing" : v === undefined ? "missing" : String(v));\n' +
64-
' }\n _jl_output.push(a.join(""));\n}\n' +
65-
js + '\n' +
67+
' }\n _jl_output.push(a.join(""));\n};\n' +
68+
'if (typeof $main === "function") { var _r = $main(); if (_r !== null && _r !== undefined) _jl_output.push(String(_r) + "\\n"); }\n' +
6669
'_jl_output.join("")';
6770

6871
try {

0 commit comments

Comments
 (0)