Skip to content

Commit 86d44cb

Browse files
committed
Small fixes
1 parent fccb8ce commit 86d44cb

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

packages/assemblerjs/src/features/assembler/lib/cycle-detector.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Identifier } from '@/shared/common';
2-
import { formatIdentifier } from './injectable-manager';
32

43
export interface CycleDetectionResult {
54
cycle: string[];
@@ -11,8 +10,8 @@ export interface CycleDetectionResult {
1110
*/
1211
abstract class AbstractCycleDetector {
1312
abstract detect(
14-
injectables: Map<Identifier, any>,
15-
formatFn: (id: Identifier) => string
13+
injectables: Map<Identifier<any>, any>,
14+
formatFn: (id: Identifier<any>) => string
1615
): CycleDetectionResult[];
1716
}
1817

@@ -30,17 +29,17 @@ class NoOpCycleDetector extends AbstractCycleDetector {
3029
*/
3130
class ActiveCycleDetector extends AbstractCycleDetector {
3231
detect(
33-
injectables: Map<Identifier, any>,
34-
formatFn: (id: Identifier) => string
32+
injectables: Map<Identifier<any>, any>,
33+
formatFn: (id: Identifier<any>) => string
3534
): CycleDetectionResult[] {
3635
const cycles: CycleDetectionResult[] = [];
37-
const visited = new Set<Identifier>();
36+
const visited = new Set<Identifier<any>>();
3837

3938
for (const [identifier] of injectables) {
4039
if (visited.has(identifier)) continue;
4140

42-
const path: Identifier[] = [];
43-
const inPath = new Set<Identifier>();
41+
const path: Identifier<any>[] = [];
42+
const inPath = new Set<Identifier<any>>();
4443

4544
if (this.hasCycleDFS(identifier, path, inPath, visited, injectables)) {
4645
// Cycle found - extract the cycle path
@@ -62,11 +61,11 @@ class ActiveCycleDetector extends AbstractCycleDetector {
6261
* DFS helper to detect cycles
6362
*/
6463
private hasCycleDFS(
65-
current: Identifier,
66-
path: Identifier[],
67-
inPath: Set<Identifier>,
68-
visited: Set<Identifier>,
69-
injectables: Map<Identifier, any>
64+
current: Identifier<any>,
65+
path: Identifier<any>[],
66+
inPath: Set<Identifier<any>>,
67+
visited: Set<Identifier<any>>,
68+
injectables: Map<Identifier<any>, any>
7069
): boolean {
7170
if (inPath.has(current)) {
7271
path.push(current);

packages/assemblerjs/src/features/assembler/lib/injectable-manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class InjectableManager {
200200
)! as Injectable<T>;
201201

202202
// Track resolution start
203-
this.resolvingStack.add(injectable.identifier);
203+
this.resolvingStack.add(injectable.identifier as Identifier<any>);
204204

205205
try {
206206
if (injectable.isSingleton) {
@@ -210,7 +210,7 @@ export class InjectableManager {
210210
}
211211
} finally {
212212
// Always cleanup after resolution (success or error)
213-
this.resolvingStack.delete(injectable.identifier);
213+
this.resolvingStack.delete(injectable.identifier as Identifier<any>);
214214
}
215215
}
216216

@@ -253,7 +253,7 @@ export class InjectableManager {
253253
/**
254254
* Get the injectables map for cycle detection and other analysis
255255
*/
256-
public getInjectables(): Map<Identifier, any> {
256+
public getInjectables(): Map<Identifier<any>, any> {
257257
return this.injectables;
258258
}
259259
}

packages/assemblerjs/src/features/injectable/lib/dependencies.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Concrete } from '@assemblerjs/core';
2+
import type { Identifier } from '@/shared/common';
23
import { getParamTypes } from '@/shared/common';
34
import { getDecoratedParametersIndexes } from '@/shared/decorators';
45
import { AbstractInjectable } from '@/features/injectable';
@@ -12,7 +13,10 @@ const dependenciesCache = new WeakMap<Function, any[]>();
1213
* Helper function to determine the decorator type for a given parameter index.
1314
* Now uses dynamic decorator registration instead of hardcoded names.
1415
*/
15-
const getDecoratorType = (indexes: ReturnType<typeof getDecoratedParametersIndexes>, index: number): string | null => {
16+
const getDecoratorType = (indexes: ReturnType<typeof getDecoratedParametersIndexes> | never[], index: number): string | null => {
17+
if (!indexes || typeof indexes !== 'object' || Array.isArray(indexes)) {
18+
return null;
19+
}
1620
for (const [decoratorName, decoratorIndexes] of Object.entries(indexes)) {
1721
if (decoratorIndexes.includes(index)) {
1822
return decoratorName;
@@ -35,8 +39,8 @@ export const resolveInjectableParameters = <T>(
3539
const parameters: any[] = [];
3640

3741
// Parameters passed in constructor.
38-
const paramTypes = getParamTypes(injectable.concrete);
39-
const indexes = getDecoratedParametersIndexes(injectable.concrete);
42+
const paramTypes = injectable.concrete ? getParamTypes(injectable.concrete) : [];
43+
const indexes = injectable.concrete ? getDecoratedParametersIndexes(injectable.concrete) : [];
4044

4145
// Build parameters to pass to instance.
4246
for (let i = 0; i < paramTypes.length; i++) {
@@ -45,7 +49,7 @@ export const resolveInjectableParameters = <T>(
4549
if (decoratorType) {
4650
// Use the appropriate resolver for decorated parameters
4751
const resolver = ParameterResolverFactory.getResolver(decoratorType);
48-
parameters.push(resolver.resolve(i, injectable, injectable.concrete, configuration));
52+
parameters.push(resolver.resolve(i, injectable, injectable.concrete as Concrete<T>, configuration));
4953
} else {
5054
const paramType = paramTypes[i];
5155

@@ -74,7 +78,7 @@ export const resolveInjectableParameters = <T>(
7478
__paramCount: paramTypes.length,
7579
__expectedType: paramType
7680
},
77-
injectable.identifier
81+
injectable.identifier as Identifier<any>
7882
)
7983
);
8084
}

0 commit comments

Comments
 (0)