Skip to content

Commit

Permalink
refactor: simplify eval selection
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed May 18, 2024
1 parent 5e66a11 commit d6e1ce0
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions apps/playground/src/monaco/eval-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,11 @@ export function registerEvalSelection(
) {
if (ranges.some((range) => range.isEmpty())) return;

const expressions = ranges
.map((range) => {
const value = editor.getModel()!.getValueInRange(range);
return `eval(${JSON.stringify(value)})`;
})
.join(',');
// New lines are added so line comments don't mess up the rest of the code
const code = `[\n${expressions}\n]`;
const expressions = ranges.map((range) => {
const value = editor.getModel()!.getValueInRange(range);
return `eval(${JSON.stringify(value)})`;
});
const code = `[${expressions.join(',')}]`;
const values = (await evalCode(code)) as unknown[];

const edits = ranges.map((range, index) => ({
Expand Down

0 comments on commit d6e1ce0

Please sign in to comment.