Fix failing of functions without revert code

Add missing empty/undefined handling to fix a bug where defining new
functions without `revertCode:` fails.
This commit is contained in:
undergroundwires
2021-12-21 06:01:16 +01:00
parent 5a2c263af3
commit 87de017afd
5 changed files with 61 additions and 9 deletions

View File

@@ -10,11 +10,14 @@ export class ExpressionsCompiler implements IExpressionsCompiler {
public constructor(
private readonly extractor: IExpressionParser = new CompositeExpressionParser()) { }
public compileExpressions(
code: string,
code: string | undefined,
args: IReadOnlyFunctionCallArgumentCollection): string {
if (!args) {
throw new Error('undefined args, send empty collection instead');
}
if (!code) {
return code;
}
const expressions = this.extractor.findExpressions(code);
ensureParamsUsedInCodeHasArgsProvided(expressions, args);
const context = new ExpressionEvaluationContext(args);

View File

@@ -2,6 +2,6 @@ import { IReadOnlyFunctionCallArgumentCollection } from '../Function/Call/Argume
export interface IExpressionsCompiler {
compileExpressions(
code: string,
code: string | undefined,
args: IReadOnlyFunctionCallArgumentCollection): string;
}

View File

@@ -15,6 +15,9 @@ export abstract class RegexParser implements IExpressionParser {
protected abstract buildExpression(match: RegExpMatchArray): IPrimitiveExpression;
private* findRegexExpressions(code: string): Iterable<IExpression> {
if (!code) {
throw new Error('undefined code');
}
const matches = Array.from(code.matchAll(this.regex));
for (const match of matches) {
const startPos = match.index;