It allow pipes to be used in nested functions. Before, pipes were added
to a variable before variable content was evaluated/compiled by
another function. This commit ensures that the commits are evaluted in
expected order.
The issue is solved by stopping precompiling functions. It makes code
less complex. It adds to compile time of the script file but nothing
noticable and something optimizable.
The problem was that the call trees we're not executed in expected
order. E.g. let's say we have functionA that outputs something like
"Hello {{ $name| pipe }}", and we have function B calling with "name:
dear {{ $firstName}}", and at last we have a script that's calling
function B with "firstName: undergroundwires". Before, expressions were
evaluated directly, meaning that function A would become:
"Hello Dear {{ $firstName}}", as you see the pipe in function A
is lost here after being applied to function B and not reaching
$firstTime input value. Parsing expressions in the end allows for pipes
etc. to not get lost.
The commit also does necessary name refactorings and folder refactorings
to reflect logical changes. `FunctionCompiler` is renamed to
`SharedFunctionsParser` as precompiling is removed and it just simply
parses now. `/FunctionCall/` is moved to `/Function/Call`.
Finally, it improves documentation and adds more tests.
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { FunctionData, ParameterDefinitionData, FunctionCallsData } from 'js-yaml-loader!@/*';
|
|
import { FunctionCallDataStub } from './FunctionCallDataStub';
|
|
|
|
export class FunctionDataStub implements FunctionData {
|
|
public static createWithCode() {
|
|
return new FunctionDataStub()
|
|
.withCode('stub-code')
|
|
.withRevertCode('stub-revert-code');
|
|
}
|
|
public static createWithCall(call?: FunctionCallsData) {
|
|
let instance = new FunctionDataStub();
|
|
if (call) {
|
|
instance = instance.withCall(call);
|
|
} else {
|
|
instance = instance.withMockCall();
|
|
}
|
|
return instance;
|
|
}
|
|
public static createWithoutCallOrCodes() {
|
|
return new FunctionDataStub();
|
|
}
|
|
|
|
public name = 'functionDataStub';
|
|
public code: string;
|
|
public revertCode: string;
|
|
public call?: FunctionCallsData;
|
|
public parameters?: readonly ParameterDefinitionData[];
|
|
|
|
private constructor() { /* use static factory methods to create an instance */ }
|
|
|
|
public withName(name: string) {
|
|
this.name = name;
|
|
return this;
|
|
}
|
|
public withParameters(...parameters: readonly ParameterDefinitionData[]) {
|
|
return this.withParametersObject(parameters);
|
|
}
|
|
public withParametersObject(parameters: readonly ParameterDefinitionData[]) {
|
|
this.parameters = parameters;
|
|
return this;
|
|
}
|
|
public withCode(code: string) {
|
|
this.code = code;
|
|
return this;
|
|
}
|
|
public withRevertCode(revertCode: string) {
|
|
this.revertCode = revertCode;
|
|
return this;
|
|
}
|
|
public withCall(call: FunctionCallsData) {
|
|
this.call = call;
|
|
return this;
|
|
}
|
|
public withMockCall() {
|
|
this.call = new FunctionCallDataStub();
|
|
return this;
|
|
}
|
|
}
|