Add optionality for parameters
This commit allows for parameters that does not require any arguments to be provided in function calls. It changes collection syntax where parameters are list of objects instead of primitive strings. A parameter has now 'name' and 'optional' properties. 'name' is required and used in same way as older strings as parameter definitions. 'Optional' property is optional, 'false' is the default behavior if undefined. It also adds additional validation to restrict parameter names to alphanumeric strings to have a clear syntax in expressions.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { ISharedFunction } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
||||
import { IReadOnlyFunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/IFunctionParameterCollection';
|
||||
import { FunctionParameterCollectionStub } from './FunctionParameterCollectionStub';
|
||||
|
||||
export class SharedFunctionStub implements ISharedFunction {
|
||||
public name = 'shared-function-stub-name';
|
||||
public parameters?: readonly string[] = [
|
||||
'shared-function-stub-parameter',
|
||||
];
|
||||
public parameters: IReadOnlyFunctionParameterCollection = new FunctionParameterCollectionStub()
|
||||
.withParameterName('shared-function-stub-parameter-name');
|
||||
public code = 'shared-function-stub-code';
|
||||
public revertCode = 'shared-function-stub-revert-code';
|
||||
|
||||
@@ -20,8 +21,15 @@ export class SharedFunctionStub implements ISharedFunction {
|
||||
this.revertCode = revertCode;
|
||||
return this;
|
||||
}
|
||||
public withParameters(...params: string[]) {
|
||||
this.parameters = params;
|
||||
public withParameters(parameters: IReadOnlyFunctionParameterCollection) {
|
||||
this.parameters = parameters;
|
||||
return this;
|
||||
}
|
||||
public withParameterNames(...parameterNames: readonly string[]) {
|
||||
let collection = new FunctionParameterCollectionStub();
|
||||
for (const name of parameterNames) {
|
||||
collection = collection.withParameterName(name);
|
||||
}
|
||||
return this.withParameters(collection);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user