This commit applies `strictNullChecks` to the entire codebase to improve maintainability and type safety. Key changes include: - Remove some explicit null-checks where unnecessary. - Add necessary null-checks. - Refactor static factory functions for a more functional approach. - Improve some test names and contexts for better debugging. - Add unit tests for any additional logic introduced. - Refactor `createPositionFromRegexFullMatch` to its own function as the logic is reused. - Prefer `find` prefix on functions that may return `undefined` and `get` prefix for those that always return a value.
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { IFunctionCallArgument } from './IFunctionCallArgument';
|
|
import { IFunctionCallArgumentCollection } from './IFunctionCallArgumentCollection';
|
|
|
|
export class FunctionCallArgumentCollection implements IFunctionCallArgumentCollection {
|
|
private readonly arguments = new Map<string, IFunctionCallArgument>();
|
|
|
|
public addArgument(argument: IFunctionCallArgument): void {
|
|
if (this.hasArgument(argument.parameterName)) {
|
|
throw new Error(`argument value for parameter ${argument.parameterName} is already provided`);
|
|
}
|
|
this.arguments.set(argument.parameterName, argument);
|
|
}
|
|
|
|
public getAllParameterNames(): string[] {
|
|
return Array.from(this.arguments.keys());
|
|
}
|
|
|
|
public hasArgument(parameterName: string): boolean {
|
|
if (!parameterName) {
|
|
throw new Error('missing parameter name');
|
|
}
|
|
return this.arguments.has(parameterName);
|
|
}
|
|
|
|
public getArgument(parameterName: string): IFunctionCallArgument {
|
|
if (!parameterName) {
|
|
throw new Error('missing parameter name');
|
|
}
|
|
const arg = this.arguments.get(parameterName);
|
|
if (!arg) {
|
|
throw new Error(`parameter does not exist: ${parameterName}`);
|
|
}
|
|
return arg;
|
|
}
|
|
}
|