From 4e98889b6049d9a248ae2f58a3eb970a16d37b65 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 3 Sep 2023 10:03:05 +0400 Subject: [PATCH] Fix script function to string. Closes #5352 --- src/dom_components/model/Component.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dom_components/model/Component.ts b/src/dom_components/model/Component.ts index eab0b0f0b..5c72aa8d9 100644 --- a/src/dom_components/model/Component.ts +++ b/src/dom_components/model/Component.ts @@ -1767,16 +1767,16 @@ export default class Component extends StyleableModel { } else { // Deprecated // Need to convert script functions to strings - if (typeof scr == 'function') { - var scrStr = scr.toString().trim(); - scrStr = scrStr.replace(/^function[\s\w]*\(\)\s?\{/, '').replace(/\}$/, ''); + if (isFunction(scr)) { + let scrStr = scr.toString().trim(); + scrStr = scrStr.slice(scrStr.indexOf('{') + 1, scrStr.lastIndexOf('}')); scr = scrStr.trim(); } - var config = this.em.getConfig(); - var tagVarStart = escapeRegExp(config.tagVarStart || '{[ '); - var tagVarEnd = escapeRegExp(config.tagVarEnd || ' ]}'); - var reg = new RegExp(`${tagVarStart}([\\w\\d-]*)${tagVarEnd}`, 'g'); + const config = this.em.getConfig(); + const tagVarStart = escapeRegExp(config.tagVarStart || '{[ '); + const tagVarEnd = escapeRegExp(config.tagVarEnd || ' ]}'); + const reg = new RegExp(`${tagVarStart}([\\w\\d-]*)${tagVarEnd}`, 'g'); scr = scr.replace(reg, (match, v) => { // If at least one match is found I have to track this change for a // better optimization inside JS generator