diff options
author | Bob Zeleznik <zzzman@gmail.com> | 2020-04-27 22:08:56 -0400 |
---|---|---|
committer | Bob Zeleznik <zzzman@gmail.com> | 2020-04-27 22:08:56 -0400 |
commit | 1f0d326a6c8735f67c6e37b19f4656e645e38c43 (patch) | |
tree | 65605e4183c7d79f1d193b9c7d6b32940d7ee8db /src/client/util/Scripting.ts | |
parent | 26e683056cddcbe8f90547c77519daa15c37518d (diff) | |
parent | 2f371a09f7305cbc44e9358af310078ce0cb4b3c (diff) |
Merge branch 'master' into richTextSchemaS
Diffstat (limited to 'src/client/util/Scripting.ts')
-rw-r--r-- | src/client/util/Scripting.ts | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts index cf04c44ca..12628273b 100644 --- a/src/client/util/Scripting.ts +++ b/src/client/util/Scripting.ts @@ -24,6 +24,8 @@ export interface ScriptError { export type ScriptResult = ScriptSucccess | ScriptError; +export type ScriptParam = { [name: string]: string }; + export interface CompiledScript { readonly compiled: true; readonly originalScript: string; @@ -37,6 +39,12 @@ export interface CompileError { } export type CompileResult = CompiledScript | CompileError; +export function isCompileError(toBeDetermined: CompileResult): toBeDetermined is CompileError { + if ((toBeDetermined as CompileError).errors) { + return true; + } + return false; +} export namespace Scripting { export function addGlobal(global: { name: string }): void; @@ -89,9 +97,9 @@ const _scriptingGlobals: { [name: string]: any } = {}; let scriptingGlobals: { [name: string]: any } = _scriptingGlobals; function Run(script: string | undefined, customParams: string[], diagnostics: any[], originalScript: string, options: ScriptOptions): CompileResult { - const errors = diagnostics.some(diag => diag.category === ts.DiagnosticCategory.Error); - if ((options.typecheck !== false && errors) || !script) { - return { compiled: false, errors: diagnostics }; + const errors = diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error); + if ((options.typecheck !== false && errors.length) || !script) { + return { compiled: false, errors }; } const paramNames = Object.keys(scriptingGlobals); @@ -201,7 +209,7 @@ export interface ScriptOptions { capturedVariables?: { [name: string]: Field }; // list of captured variables typecheck?: boolean; // should the compiler perform typechecking editable?: boolean; // can the script edit Docs - traverser?: TraverserParam; + traverser?: TraverserParam; transformer?: Transformer; // does the editor display a text label by each document that can be used as a captured document reference globals?: { [name: string]: any }; } |