Add support for nested templates

Add support for expressions inside expressions.

Add support for templating where the output of one expression results in
another template part with expressions.

E.g., this did not work before, but compilation will now evaluate both
with expression with `$condition` and parameter substitution with
`$text`:

```
{{ with $condition }}
  echo '{{ $text }}'
{{ end }}
```

Add also more sanity checks (validation logic) when compiling
expressions to reveal problems quickly.
This commit is contained in:
undergroundwires
2022-10-11 20:42:38 +02:00
parent bf0c55fa60
commit 68a5d698a2
7 changed files with 552 additions and 85 deletions

View File

@@ -11,7 +11,7 @@ export class ExpressionStub implements IExpression {
public parameters: IReadOnlyFunctionParameterCollection = new FunctionParameterCollectionStub();
private result: string;
private result: string = undefined;
public withParameters(parameters: IReadOnlyFunctionParameterCollection) {
this.parameters = parameters;
@@ -35,9 +35,11 @@ export class ExpressionStub implements IExpression {
}
public evaluate(context: IExpressionEvaluationContext): string {
const { args } = context;
this.callHistory.push(context);
const result = this.result || `[expression-stub] args: ${args ? Object.keys(args).map((key) => `${key}: ${args[key]}`).join('", "') : 'none'}`;
return result;
if (this.result === undefined /* not empty string */) {
const { args } = context;
return `[expression-stub] args: ${args ? Object.keys(args).map((key) => `${key}: ${args[key]}`).join('", "') : 'none'}`;
}
return this.result;
}
}