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.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { ISharedFunction } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
|
import { ISharedFunctionCollection } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionCollection';
|
|
import { createSharedFunctionStubWithCode } 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 {
|
|
const foundFunction = this.functions.get(name);
|
|
if (foundFunction) {
|
|
return foundFunction;
|
|
}
|
|
return createSharedFunctionStubWithCode()
|
|
.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);
|
|
}
|
|
}
|