diff --git a/frontend/src/Editor/CodeEditor/utils.js b/frontend/src/Editor/CodeEditor/utils.js index f7baae2a49..877f46e772 100644 --- a/frontend/src/Editor/CodeEditor/utils.js +++ b/frontend/src/Editor/CodeEditor/utils.js @@ -4,7 +4,7 @@ import _, { isEmpty } from 'lodash'; import { useCurrentStateStore } from '@/_stores/currentStateStore'; import { any } from 'superstruct'; import { generateSchemaFromValidationDefinition, validate } from '../component-properties-validation'; -import { hasCircularDependency } from '@/_helpers/utils'; +import { hasCircularDependency, resolveReferences as olderResolverMethod } from '@/_helpers/utils'; import { validateMultilineCode } from '@/_helpers/utility'; const acorn = require('acorn'); diff --git a/frontend/src/_helpers/utils.js b/frontend/src/_helpers/utils.js index 19549fb11f..907c95c42e 100644 --- a/frontend/src/_helpers/utils.js +++ b/frontend/src/_helpers/utils.js @@ -164,7 +164,6 @@ export function resolveReferences( if (object === '{{{}}}') return ''; object = _.clone(object); - const currentState = useCurrentStateStore.getState(); const objectType = typeof object; let error; @@ -173,29 +172,31 @@ export function resolveReferences( switch (objectType) { case 'string': { if (object.includes('{{') && object.includes('}}') && object.includes('%%') && object.includes('%%')) { - object = resolveString(object, currentState, customObjects, reservedKeyword, withError, forPreviewBox); + object = resolveString(object, state, customObjects, reservedKeyword, withError, forPreviewBox); } if (object.startsWith('{{') && object.endsWith('}}')) { if ((object.match(/{{/g) || []).length === 1) { const code = object.replace('{{', '').replace('}}', ''); - const _reservedKeyword = ['app', 'window', 'this']; // Case-sensitive reserved keywords - const keywordRegex = new RegExp(`\\b(${_reservedKeyword.join('|')})\\b`, 'i'); + //Will be remove in next release - if (code.match(keywordRegex)) { - error = `${code} is a reserved keyword`; - return [{}, error]; + const { status, data } = validateMultilineCode(code); + + if (status === 'failed') { + const errMessage = `${data.message} - ${data.description}`; + + return [{}, errMessage]; } - return resolveCode(code, currentState, customObjects, withError, reservedKeyword, true); + return resolveCode(code, state, customObjects, withError, [], true); } else { const dynamicVariables = getDynamicVariables(object); for (const dynamicVariable of dynamicVariables) { const value = resolveString( dynamicVariable, - currentState, + state, customObjects, reservedKeyword, withError, @@ -215,7 +216,7 @@ export function resolveReferences( return [{}, error]; } - return resolveCode(code, currentState, customObjects, withError, reservedKeyword, false); + return resolveCode(code, state, customObjects, withError, reservedKeyword, false); } const dynamicVariables = getDynamicVariables(object);