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.
21 lines
916 B
TypeScript
21 lines
916 B
TypeScript
import { ISharedFunction } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
|
import { ISharedFunctionCollection } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionCollection';
|
|
import { SharedFunctionStub } from './SharedFunctionStub';
|
|
|
|
export class SharedFunctionCollectionStub implements ISharedFunctionCollection {
|
|
private readonly functions = new Map<string, ISharedFunction>();
|
|
public withFunction(func: ISharedFunction) {
|
|
this.functions.set(func.name, func);
|
|
return this;
|
|
}
|
|
public getFunctionByName(name: string): ISharedFunction {
|
|
if (this.functions.has(name)) {
|
|
return this.functions.get(name);
|
|
}
|
|
return new SharedFunctionStub()
|
|
.withName(name)
|
|
.withCode('code by SharedFunctionCollectionStub')
|
|
.withRevertCode('revert-code by SharedFunctionCollectionStub');
|
|
}
|
|
}
|