diff --git a/packages/workflow/src/Expression.ts b/packages/workflow/src/Expression.ts index 8817bb7da9..f1e6c18a0f 100644 --- a/packages/workflow/src/Expression.ts +++ b/packages/workflow/src/Expression.ts @@ -314,11 +314,15 @@ export class Expression { } extendSyntax(bracketedExpression: string): string { - if (!hasExpressionExtension(bracketedExpression) || hasNativeMethod(bracketedExpression)) - return bracketedExpression; - const chunks = splitExpression(bracketedExpression); + const codeChunks = chunks + .filter((c) => c.type === 'code') + .map((c) => c.text.replace(/("|').*?("|')/, '').trim()); + + if (!codeChunks.some(hasExpressionExtension) || hasNativeMethod(bracketedExpression)) + return bracketedExpression; + const extendedChunks = chunks.map((chunk): ExpressionChunk => { if (chunk.type === 'code') { const output = extendTransform(chunk.text); diff --git a/packages/workflow/src/Extensions/ExpressionExtension.ts b/packages/workflow/src/Extensions/ExpressionExtension.ts index 59ab1cc9d2..378012d830 100644 --- a/packages/workflow/src/Extensions/ExpressionExtension.ts +++ b/packages/workflow/src/Extensions/ExpressionExtension.ts @@ -41,14 +41,17 @@ const EXPRESSION_EXTENSION_METHODS = Array.from( ...Object.keys(arrayExtensions.functions), ...Object.keys(objectExtensions.functions), ...Object.keys(genericExtensions), - '$if', ]), ); +const EXPRESSION_EXTENSION_REGEX = new RegExp( + `(\\$if|\\.(${EXPRESSION_EXTENSION_METHODS.join('|')}))\\s*\\(`, +); + const isExpressionExtension = (str: string) => EXPRESSION_EXTENSION_METHODS.some((m) => m === str); export const hasExpressionExtension = (str: string): boolean => - EXPRESSION_EXTENSION_METHODS.some((m) => str.includes(m)); + EXPRESSION_EXTENSION_REGEX.test(str); export const hasNativeMethod = (method: string): boolean => { if (hasExpressionExtension(method)) {