Files
privacy.sexy/tests/unit/shared/Stubs/SingleCallCompilerStrategyStub.ts
undergroundwires 53222fd83c Fix compiler bug with nested optional arguments
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.
2023-09-16 16:11:41 +02:00

46 lines
1.8 KiB
TypeScript

import { CompiledCode } from '@/application/Parser/Script/Compiler/Function/Call/Compiler/CompiledCode';
import { FunctionCallCompilationContext } from '@/application/Parser/Script/Compiler/Function/Call/Compiler/FunctionCallCompilationContext';
import { SingleCallCompilerStrategy } from '@/application/Parser/Script/Compiler/Function/Call/Compiler/SingleCall/SingleCallCompilerStrategy';
import { FunctionCall } from '@/application/Parser/Script/Compiler/Function/Call/FunctionCall';
import { ISharedFunction } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
import { CompiledCodeStub } from './CompiledCodeStub';
export class SingleCallCompilerStrategyStub
extends StubWithObservableMethodCalls<SingleCallCompilerStrategy>
implements SingleCallCompilerStrategy {
private canCompileResult = true;
private compiledFunctionResult: CompiledCode[] = [new CompiledCodeStub()];
public canCompile(func: ISharedFunction): boolean {
this.registerMethodCall({
methodName: 'canCompile',
args: [func],
});
return this.canCompileResult;
}
public compileFunction(
calledFunction: ISharedFunction,
callToFunction: FunctionCall,
context: FunctionCallCompilationContext,
): CompiledCode[] {
this.registerMethodCall({
methodName: 'compileFunction',
args: [calledFunction, callToFunction, context],
});
return this.compiledFunctionResult;
}
public withCanCompileResult(canCompileResult: boolean): this {
this.canCompileResult = canCompileResult;
return this;
}
public withCompiledFunctionResult(compiledFunctionResult: CompiledCode[]): this {
this.compiledFunctionResult = compiledFunctionResult;
return this;
}
}