From a60c12ddef3db4123dffb2c91b446d20633f523a Mon Sep 17 00:00:00 2001 From: geireann Date: Sun, 13 Oct 2024 16:24:17 -0400 Subject: fixes to scripting to generate errors to allow schema view to enter strings that conflict with function names. --- src/client/util/Scripting.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/client/util/Scripting.ts') diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts index b1db0bf39..5d78c2fab 100644 --- a/src/client/util/Scripting.ts +++ b/src/client/util/Scripting.ts @@ -48,7 +48,7 @@ export function isCompileError(toBeDetermined: CompileResult): toBeDetermined is // eslint-disable-next-line no-use-before-define function Run(script: string | undefined, customParams: string[], diagnostics: ts.Diagnostic[], originalScript: string, options: ScriptOptions): CompileResult { - const errors = diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error); + const errors = diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error).filter(diag => diag.code !== 2304 && diag.code !== 2339); if ((options.typecheck !== false && errors.length) || !script) { return { compiled: false, errors }; } @@ -188,6 +188,7 @@ export function CompileScript(script: string, options: ScriptOptions = {}): Comp }, ''); const found = ScriptField.GetScriptFieldCache(script + ':' + signature); // if already compiled, found is the result; cache set below if (found) return found as CompiledScript; + options.typecheck = true; const { requiredType = '', addReturn = false, params = {}, capturedVariables = {}, typecheck = true } = options; if (options.params && !options.params.this) options.params.this = Doc.name; if (options.globals) { @@ -221,13 +222,10 @@ export function CompileScript(script: string, options: ScriptOptions = {}): Comp if ('this' in params || 'this' in capturedVariables) { paramNames.push('this'); } - for (const key in params) { - if (key !== 'this') { - paramNames.push(key); - } - } + paramNames.push(...Object.keys(params).filter(p => p!== 'this' && !Object.keys(capturedVariables).includes(p))); + const paramList = paramNames.map(key => { - const val = params[key]; + const val = typeof params[key] === "string" && params[key].length && !"\"'`".includes(params[key][0]) ? `"${params[key]}"` : params[key]; return `${key}: ${val}`; }); for (const key in capturedVariables) { -- cgit v1.2.3-70-g09d2