Skip to content

Commit

Permalink
feat: add espree and types
Browse files Browse the repository at this point in the history
use this .d.ts workaround until eslint/js#529 fixed
  • Loading branch information
linonetwo committed Jun 8, 2023
1 parent 9131478 commit 1f22d49
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"electron-util": "0.17.2",
"electron-window-state": "5.0.3",
"errio": "1.2.2",
"espree": "^9.5.2",
"exponential-backoff": "^3.1.1",
"fs-extra": "11.1.1",
"git-sync-js": "^1.0.5",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/services/wiki/plugin/zxPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ITiddlyWiki } from '@tiddlygit/tiddlywiki';
import * as espree from 'espree';
import _ from 'lodash';
import vm, { Context } from 'vm';

Expand Down Expand Up @@ -33,6 +34,10 @@ export function executeScriptInTWContext(scriptContent: string, context: ITWVMCo
return context.executionResults;
}

export function getVariablesFromScript(scriptContent: string): string[] {
espree.parse(scriptContent, { sourceType: 'module' });
}

export interface ITWVMContext {
context: Context;
executionResults: string[];
Expand Down
39 changes: 39 additions & 0 deletions src/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,45 @@ declare module '@tiddlygit/tiddlywiki' {
export * from 'tiddlywiki';
}

declare module 'espree' {
// https://github.com/eslint/espree#options
export interface Options {
comment?: boolean;
ecmaFeatures?: {
globalReturn?: boolean;
impliedStrict?: boolean;
jsx?: boolean;
};
ecmaVersion?:
| 3
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 2015
| 2016
| 2017
| 2018
| 2019
| 2020
| 2021
| 2022
| 'latest';
loc?: boolean;
range?: boolean;
sourceType?: 'script' | 'module';
tokens?: boolean;
}
// https://github.com/eslint/espree#options
export function parse(code: string, options?: Options): any;
// https://github.com/eslint/espree#tokenize
export function tokenize(code: string, options?: Options): any;
}

declare module 'threads-plugin' {
const value: any;
export default value;
Expand Down

0 comments on commit 1f22d49

Please sign in to comment.