feat(core): Add Tournament as the new default expression evaluator (#6964)

Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: Omar Ajoue <krynble@gmail.com>
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Val
2023-09-21 13:57:45 +01:00
committed by GitHub
parent 67b985fe89
commit bf74f09d69
12 changed files with 434 additions and 223 deletions

View File

@@ -1,5 +1,5 @@
import * as tmpl from '@n8n_io/riot-tmpl';
import { DateTime, Duration, Interval } from 'luxon';
import * as tmpl from '@n8n_io/riot-tmpl';
import type {
IDataObject,
@@ -22,6 +22,7 @@ import type { Workflow } from './Workflow';
import { extend, extendOptional } from './Extensions';
import { extendedFunctions } from './Extensions/ExtendedFunctions';
import { extendSyntax } from './Extensions/ExpressionExtension';
import { evaluateExpression, setErrorHandler } from './ExpressionEvaluatorProxy';
const IS_FRONTEND_IN_DEV_MODE =
typeof process === 'object' &&
@@ -40,13 +41,10 @@ export const isExpressionError = (error: unknown): error is ExpressionError =>
export const isTypeError = (error: unknown): error is TypeError =>
error instanceof TypeError || (error instanceof Error && error.name === 'TypeError');
// Set it to use double curly brackets instead of single ones
tmpl.brackets.set('{{ }}');
// Make sure that error get forwarded
tmpl.tmpl.errorHandler = (error: Error) => {
setErrorHandler((error: Error) => {
if (isExpressionError(error)) throw error;
};
});
// eslint-disable-next-line @typescript-eslint/naming-convention
const AsyncFunction = (async () => {}).constructor as FunctionConstructor;
@@ -339,7 +337,7 @@ export class Expression {
[Function, AsyncFunction].forEach(({ prototype }) =>
Object.defineProperty(prototype, 'constructor', { value: fnConstructors.mock }),
);
return tmpl.tmpl(expression, data);
return evaluateExpression(expression, data);
} catch (error) {
if (isExpressionError(error)) throw error;