Skip to content

Commit c77d9fe

Browse files
committed
feat: add espree and types
use this .d.ts workaround until eslint/js#529 fixed
1 parent 9131478 commit c77d9fe

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"electron-util": "0.17.2",
4343
"electron-window-state": "5.0.3",
4444
"errio": "1.2.2",
45+
"espree": "^9.5.2",
4546
"exponential-backoff": "^3.1.1",
4647
"fs-extra": "11.1.1",
4748
"git-sync-js": "^1.0.5",

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/services/wiki/plugin/zxPlugin.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ITiddlyWiki } from '@tiddlygit/tiddlywiki';
2+
import * as espree from 'espree';
23
import _ from 'lodash';
34
import vm, { Context } from 'vm';
45

@@ -33,6 +34,10 @@ export function executeScriptInTWContext(scriptContent: string, context: ITWVMCo
3334
return context.executionResults;
3435
}
3536

37+
export function getVariablesFromScript(scriptContent: string): string[] {
38+
espree.parse(scriptContent, { sourceType: 'module' });
39+
}
40+
3641
export interface ITWVMContext {
3742
context: Context;
3843
executionResults: string[];

src/type.d.ts

+39
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,45 @@ declare module '@tiddlygit/tiddlywiki' {
99
export * from 'tiddlywiki';
1010
}
1111

12+
declare module 'espree' {
13+
// https://github.com/eslint/espree#options
14+
export interface Options {
15+
comment?: boolean;
16+
ecmaFeatures?: {
17+
globalReturn?: boolean;
18+
impliedStrict?: boolean;
19+
jsx?: boolean;
20+
};
21+
ecmaVersion?:
22+
| 3
23+
| 5
24+
| 6
25+
| 7
26+
| 8
27+
| 9
28+
| 10
29+
| 11
30+
| 12
31+
| 2015
32+
| 2016
33+
| 2017
34+
| 2018
35+
| 2019
36+
| 2020
37+
| 2021
38+
| 2022
39+
| 'latest';
40+
loc?: boolean;
41+
range?: boolean;
42+
sourceType?: 'script' | 'module';
43+
tokens?: boolean;
44+
}
45+
// https://github.com/eslint/espree#options
46+
export function parse(code: string, options?: Options): any;
47+
// https://github.com/eslint/espree#tokenize
48+
export function tokenize(code: string, options?: Options): any;
49+
}
50+
1251
declare module 'threads-plugin' {
1352
const value: any;
1453
export default value;

0 commit comments

Comments
 (0)