Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ function uid() {

function safeEval(code, inputs, __setEcho__) {
const create = (code) => {
const resultVar = `__recho_v_${uid()}`;
// Ensure the current echo function is bound for the executing cell.
const body = `__setEcho__(echo); const __foo__ = ${code}; const v = __foo__(${inputs.join(",")}); __setEcho__(null); return v;`;
const body = `__setEcho__(echo); const __foo__ = ${code}; const ${resultVar} = __foo__(${inputs.join(",")}); __setEcho__(null); return ${resultVar};`;
const fn = new Function("__setEcho__", ...inputs, body);
return (...args) => fn(__setEcho__, ...args);
};
Expand Down
1 change: 1 addition & 0 deletions test/js/index-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export {echoInRecursiveFunction} from "./echo-in-recursive-function.js";
export {echoInBracket} from "./echo-in-bracket.js";
export {echoAsParams} from "./echo-as-params.js";
export {echoKey} from "./echo-key.js";
export {vCollision} from "./v-collision.js";
1 change: 1 addition & 0 deletions test/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export {echoInBlock} from "./echo-in-block.js";
export {echoInAsyncCallback} from "./echo-in-async-callback.js";
export {echoInBracket} from "./echo-in-bracket.js";
export {echoAsParams} from "./echo-as-params.js";
export {vCollision} from "./v-collision.js";
4 changes: 4 additions & 0 deletions test/js/v-collision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const vCollision = `const v = 123;

echo(v);
`;
4 changes: 4 additions & 0 deletions test/output/vCollision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const v = 123;

//➜ 123
echo(v);
Loading