From e97b1d2c2b293a8d9b4a47c5b7279ec14cb99a5c Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Fri, 21 Mar 2025 17:35:14 +0200 Subject: [PATCH] UI: Fixed init js-func component --- ui-ngx/src/app/shared/components/js-func.component.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/shared/components/js-func.component.ts b/ui-ngx/src/app/shared/components/js-func.component.ts index 5568e6779d..4026b54984 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.ts +++ b/ui-ngx/src/app/shared/components/js-func.component.ts @@ -336,7 +336,7 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal } private updatedScriptLanguage() { - this.jsEditor.session.setMode(`ace/mode/${ScriptLanguage.TBEL === this.scriptLanguage ? 'tbel' : 'javascript'}`); + this.jsEditor?.session?.setMode(`ace/mode/${ScriptLanguage.TBEL === this.scriptLanguage ? 'tbel' : 'javascript'}`); } validateOnSubmit(): Observable { @@ -582,7 +582,7 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal private updateHighlightRules(): void { // @ts-ignore - if (!!this.jsEditor.session.$mode) { + if (!!this.jsEditor?.session?.$mode) { // @ts-ignore const newMode = new this.jsEditor.session.$mode.constructor(); newMode.$highlightRules = new newMode.HighlightRules(); @@ -598,7 +598,7 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal if (this.scriptLanguage === ScriptLanguage.TBEL) { newMode.$highlightRules.$rules.start = [...tbelUtilsFuncHighlightRules, ...newMode.$highlightRules.$rules.start]; } - const identifierRule = newMode.$highlightRules.$rules.no_regex.find(rule => rule.token?.includes('identifier')); + const identifierRule = newMode.$highlightRules.$rules.no_regex.find(rule => Array.isArray(rule.token) && rule.token.includes('identifier')); if (identifierRule && identifierRule.next === 'no_regex') { identifierRule.next = 'start'; } @@ -609,7 +609,7 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal private updateJsWorkerGlobals() { // @ts-ignore - if (!!this.jsEditor.session.$worker) { + if (!!this.jsEditor?.session?.$worker) { const jsWorkerOptions = { undef: !this.disableUndefinedCheck, unused: true, @@ -638,6 +638,9 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal } updateCompleters() { + if (!this.jsEditor) { + return; + } let modulesCompleterObservable: Observable; if (this.withModules) { modulesCompleterObservable = loadModulesCompleter(this.http, this.modules);