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.
29 lines
905 B
TypeScript
29 lines
905 B
TypeScript
import { IExpression } from '@/application/Parser/Script/Compiler/Expressions/Expression/IExpression';
|
|
import { IExpressionParser } from '@/application/Parser/Script/Compiler/Expressions/Parser/IExpressionParser';
|
|
|
|
export class ExpressionParserStub implements IExpressionParser {
|
|
public callHistory = new Array<string>();
|
|
|
|
private results = new Map<string, readonly IExpression[]>();
|
|
|
|
public withResult(code: string, result: readonly IExpression[]) {
|
|
if (this.results.has(code)) {
|
|
throw new Error(
|
|
'Result for code is already registered.'
|
|
+ `\nCode: ${code}`
|
|
+ `\nResult: ${JSON.stringify(result)}`,
|
|
);
|
|
}
|
|
this.results.set(code, result);
|
|
return this;
|
|
}
|
|
|
|
public findExpressions(code: string): IExpression[] {
|
|
this.callHistory.push(code);
|
|
if (this.results.has(code)) {
|
|
return [...this.results.get(code)];
|
|
}
|
|
return [];
|
|
}
|
|
}
|