This commit fixes compiler bug where it fails when optional values are compiled into absent values in nested calls. - Throw exception with more context for easier future debugging. - Add better validation of argument values for nested calls. - Refactor `FunctionCallCompiler` for better clarity and modularize it to make it more maintainable and testable. - Refactor related interface to not have `I` prefix, and function/variable names for better clarity. Context: Discovered this issue while attempting to call `RunInlineCodeAsTrustedInstaller` which in turn invokes `RunPowerShell` for issue #246. This led to the realization that despite parameters flagged as optional, the nested argument compilation didn't support them.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { ISharedFunction, FunctionBodyType } 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 withFunctions(...funcs: readonly ISharedFunction[]): this {
|
|
for (const func of funcs) {
|
|
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(FunctionBodyType.Code)
|
|
.withName(name)
|
|
.withCode('code by SharedFunctionCollectionStub')
|
|
.withRevertCode('revert-code by SharedFunctionCollectionStub');
|
|
}
|
|
|
|
public getRequiredParameterNames(functionName: string): string[] {
|
|
return this.getFunctionByName(functionName)
|
|
.parameters
|
|
.all
|
|
.filter((p) => !p.isOptional)
|
|
.map((p) => p.name);
|
|
}
|
|
}
|