diff --git a/src/application/Common/CustomError.ts b/src/application/Common/CustomError.ts index 8a31884d..eff52bf6 100644 --- a/src/application/Common/CustomError.ts +++ b/src/application/Common/CustomError.ts @@ -1,4 +1,4 @@ -import { isFunction } from '@/TypeHelpers'; +import { isFunction, type ConstructorArguments } from '@/TypeHelpers'; /* Provides a unified and resilient way to extend errors across platforms. @@ -12,8 +12,8 @@ import { isFunction } from '@/TypeHelpers'; > https://web.archive.org/web/20230810014143/https://github.com/Microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work */ export abstract class CustomError extends Error { - constructor(message?: string, options?: ErrorOptions) { - super(message, options); + constructor(...args: ConstructorArguments) { + super(...args); fixPrototype(this, new.target.prototype); ensureStackTrace(this); diff --git a/src/application/Parser/CategoryParser.ts b/src/application/Parser/CategoryParser.ts index ccaff8e8..1eaa3fbc 100644 --- a/src/application/Parser/CategoryParser.ts +++ b/src/application/Parser/CategoryParser.ts @@ -3,10 +3,12 @@ import type { } from '@/application/collections/'; import { Script } from '@/domain/Script'; import { Category } from '@/domain/Category'; -import { NodeValidator } from '@/application/Parser/NodeValidation/NodeValidator'; -import { NodeType } from '@/application/Parser/NodeValidation/NodeType'; -import { parseDocs } from './DocumentationParser'; -import { parseScript } from './Script/ScriptParser'; +import { wrapErrorWithAdditionalContext, type ErrorWithContextWrapper } from '@/application/Parser/ContextualError'; +import type { ICategory } from '@/domain/ICategory'; +import { parseDocs, type DocsParser } from './DocumentationParser'; +import { parseScript, type ScriptParser } from './Script/ScriptParser'; +import { createNodeDataValidator, type NodeDataValidator, type NodeDataValidatorFactory } from './NodeValidation/NodeDataValidator'; +import { NodeDataType } from './NodeValidation/NodeDataType'; import type { ICategoryCollectionParseContext } from './Script/ICategoryCollectionParseContext'; let categoryIdCounter = 0; @@ -14,96 +16,108 @@ let categoryIdCounter = 0; export function parseCategory( category: CategoryData, context: ICategoryCollectionParseContext, - factory: CategoryFactoryType = CategoryFactory, + utilities: CategoryParserUtilities = DefaultCategoryParserUtilities, ): Category { return parseCategoryRecursively({ categoryData: category, context, - factory, + utilities, }); } -interface ICategoryParseContext { - readonly categoryData: CategoryData, - readonly context: ICategoryCollectionParseContext, - readonly factory: CategoryFactoryType, - readonly parentCategory?: CategoryData, +interface CategoryParseContext { + readonly categoryData: CategoryData; + readonly context: ICategoryCollectionParseContext; + readonly parentCategory?: CategoryData; + readonly utilities: CategoryParserUtilities; } -function parseCategoryRecursively(context: ICategoryParseContext): Category | never { - ensureValidCategory(context.categoryData, context.parentCategory); - const children: ICategoryChildren = { - subCategories: new Array(), - subScripts: new Array