Skip to content

Commit e471777

Browse files
committed
Minor quality of life fixes
- Better error passing on code editor error (set up for future improvements) - Add "sourceURL" for eval-ed code so it shows up in the dev tools debugger
1 parent 99ce7bc commit e471777

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

TODO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
- Context menu as last child of body, gets moved by right click
3333
- Render tables to images to save and share screenshots
3434
- Settings input with numeric input and buttons on either side
35+
- CSP to restrict `worker-src` (except that we don't want to block web
36+
workers, only service workers)
3537
- Clipboard integration
3638
- Cut
3739
- Fix "put" behavior to copy formulas around to selection

src/App.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@
211211
212212
let codeError = $state("");
213213
$effect(() => {
214-
evalDebounced(globals.formulaCode, (result) => {
215-
codeError = result ?? "";
214+
evalDebounced(globals.formulaCode, (err) => {
215+
codeError = "";
216+
if (err != null) {
217+
codeError = `Error: ${err.message}`;
218+
// TODO: Show stack trace or line nubmer of problematic code
219+
}
216220
});
217221
});
218222
@@ -398,7 +402,7 @@
398402
shadow="2px">{text}</Button
399403
>
400404
{/snippet}
401-
{#if innerHeight > visualBottom}
405+
{#if Math.abs(innerHeight - visualBottom) > 5}
402406
<div
403407
class="keyboardbar"
404408
style:top="calc({visualBottom}px - 2em - 2 * 0.25em - 2px)"

src/formula-functions.svelte.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ export function evalCode(code, ret = () => {}) {
3030
} catch {}
3131

3232
try {
33-
eval(code);
33+
eval(
34+
code +
35+
// Allows user code to show up in the devtools debugger as "user-code.js"
36+
"\n//# sourceURL=user-code.js",
37+
);
3438
return ret();
3539
} catch (e) {
36-
return ret(`Error: ${e.message}`);
40+
return ret(e);
3741
}
3842
}
3943
export const evalDebounced = debounce(evalCode, 500);

test/sheet-and-formula.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ test("Complex logical expressions in formulas", async () => {
193193

194194
test("Evaluating bad code", () => {
195195
evalCode();
196-
expect(evalCode(`asdf(`, (x) => x)).toBeTypeOf("string");
196+
expect(evalCode(`asdf(`, (x) => x)).toBeInstanceOf(Error);
197197
});
198198

199199
test("Miscellaneous standard library formula functions", async () => {

0 commit comments

Comments
 (0)