Refactor to enforce strictNullChecks
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.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { ISharedFunction, FunctionBodyType } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
||||
import { ISharedFunction } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
||||
import { ISharedFunctionCollection } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionCollection';
|
||||
import { SharedFunctionStub } from './SharedFunctionStub';
|
||||
import { createSharedFunctionStubWithCode } from './SharedFunctionStub';
|
||||
|
||||
export class SharedFunctionCollectionStub implements ISharedFunctionCollection {
|
||||
private readonly functions = new Map<string, ISharedFunction>();
|
||||
@@ -13,10 +13,11 @@ export class SharedFunctionCollectionStub implements ISharedFunctionCollection {
|
||||
}
|
||||
|
||||
public getFunctionByName(name: string): ISharedFunction {
|
||||
if (this.functions.has(name)) {
|
||||
return this.functions.get(name);
|
||||
const foundFunction = this.functions.get(name);
|
||||
if (foundFunction) {
|
||||
return foundFunction;
|
||||
}
|
||||
return new SharedFunctionStub(FunctionBodyType.Code)
|
||||
return createSharedFunctionStubWithCode()
|
||||
.withName(name)
|
||||
.withCode('code by SharedFunctionCollectionStub')
|
||||
.withRevertCode('revert-code by SharedFunctionCollectionStub');
|
||||
|
||||
Reference in New Issue
Block a user