Skip to content

Commit

Permalink
Enable debugging (#61)
Browse files Browse the repository at this point in the history
* Switch to single quotes

* Enable proper debugging and stack traces

* Use debuggable-eval to capture syntax errors
  • Loading branch information
mnaoumov authored Aug 6, 2023
1 parent f4e58b5 commit 33d040b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { App, Plugin, PluginSettingTab, Setting, TAbstractFile, FuzzySuggestModal, FuzzyMatch, Notice } from 'obsidian';
import * as obsidian from 'obsidian';
import compareVersions from 'compare-versions';
import debuggableEval from 'debuggable-eval';

interface CustomJSSettings {
jsFiles: string;
Expand Down Expand Up @@ -117,7 +118,7 @@ export default class CustomJS extends Plugin {
async evalFile(f: string): Promise<void> {
try {
const file = await this.app.vault.adapter.read(f);
const def = eval('(' + file + ')') as new () => unknown;
const def = debuggableEval(`(${file})`, f) as new () => unknown;
const cls = new def()
window.customJS[cls.constructor.name] = cls;
} catch (e) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"typescript": "^4.2.4"
},
"dependencies": {
"compare-versions": "^3.6.0"
"compare-versions": "^3.6.0",
"debuggable-eval": "^1.0.0"
}
}
}

0 comments on commit 33d040b

Please sign in to comment.