diff options
author | bobzel <zzzman@gmail.com> | 2024-05-14 23:15:24 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-05-14 23:15:24 -0400 |
commit | 3534aaf88a3c30a474b3b5a5b7f04adfe6f15fac (patch) | |
tree | 47fb7a8671b209bd4d76e0f755a5b035c6936607 /src/client/util/ScriptingGlobals.ts | |
parent | 87bca251d87b5a95da06b2212400ce9427152193 (diff) | |
parent | 5cb7ad90e120123ca572e8ef5b1aa6ca41581134 (diff) |
Merge branch 'restoringEslint' into sarah-ai-visualization
Diffstat (limited to 'src/client/util/ScriptingGlobals.ts')
-rw-r--r-- | src/client/util/ScriptingGlobals.ts | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/client/util/ScriptingGlobals.ts b/src/client/util/ScriptingGlobals.ts index f151acd81..ac524394a 100644 --- a/src/client/util/ScriptingGlobals.ts +++ b/src/client/util/ScriptingGlobals.ts @@ -1,8 +1,18 @@ +import ts from 'typescript'; -import * as ts from "typescript"; export { ts }; +const _scriptingGlobals: { [name: string]: any } = {}; +const _scriptingDescriptions: { [name: string]: any } = {}; +const _scriptingParams: { [name: string]: any } = {}; +// eslint-disable-next-line import/no-mutable-exports +export let scriptingGlobals: { [name: string]: any } = _scriptingGlobals; export namespace ScriptingGlobals { + export function getGlobals() { return Object.keys(_scriptingGlobals); } // prettier-ignore + export function getGlobalObj() { return _scriptingGlobals; } // prettier-ignore + export function getDescriptions() { return _scriptingDescriptions; } // prettier-ignore + export function getParameters() { return _scriptingParams; } // prettier-ignore + export function add(global: { name: string }): void; export function add(name: string, global: any): void; export function add(global: { name: string }, decription?: string, params?: string): void; @@ -11,7 +21,7 @@ export namespace ScriptingGlobals { let obj: any; if (second !== undefined) { - if (typeof first === "string") { + if (typeof first === 'string') { n = first; obj = second; } else { @@ -22,18 +32,21 @@ export namespace ScriptingGlobals { _scriptingParams[n] = third; } } - } else if (first && typeof first.name === "string") { + } else if (first && typeof first.name === 'string') { n = first.name; obj = first; } else { - throw new Error("Must either register an object with a name, or give a name and an object"); + throw new Error('Must either register an object with a name, or give a name and an object'); } - if (n === undefined || n === "undefined") { + if (n === undefined || n === 'undefined') { return false; - } else if (_scriptingGlobals.hasOwnProperty(n)) { + } + // eslint-disable-next-line no-prototype-builtins + if (_scriptingGlobals.hasOwnProperty(n)) { throw new Error(`Global with name ${n} is already registered, choose another name`); } _scriptingGlobals[n] = obj; + return true; } export function makeMutableGlobalsCopy(globals?: { [name: string]: any }) { return { ..._scriptingGlobals, ...(globals || {}) }; @@ -57,25 +70,16 @@ export namespace ScriptingGlobals { return false; } - export function resetScriptingGlobals() { scriptingGlobals = _scriptingGlobals; } + export function resetScriptingGlobals() { + scriptingGlobals = _scriptingGlobals; + } // const types = Object.keys(ts.SyntaxKind).map(kind => ts.SyntaxKind[kind]); - export function printNodeType(node: any, indentation = "") { console.log(indentation + ts.SyntaxKind[node.kind]); } - - export function getGlobals() { return Object.keys(_scriptingGlobals); } - - export function getGlobalObj() { return _scriptingGlobals; } - - export function getDescriptions() { return _scriptingDescriptions; } - - export function getParameters() { return _scriptingParams; } + export function printNodeType(node: any, indentation = '') { + console.log(indentation + ts.SyntaxKind[node.kind]); + } } -export function scriptingGlobal(constructor: { new(...args: any[]): any }) { +export function scriptingGlobal(constructor: { new (...args: any[]): any }) { ScriptingGlobals.add(constructor); } - -const _scriptingGlobals: { [name: string]: any } = {}; -export let scriptingGlobals: { [name: string]: any } = _scriptingGlobals; -const _scriptingDescriptions: { [name: string]: any } = {}; -const _scriptingParams: { [name: string]: any } = {};
\ No newline at end of file |