Skip to content

Commit 0cab179

Browse files
docs(core): add comment to the replacer function
1 parent db9f95b commit 0cab179

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/core/injector/module-token-factory.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ export class ModuleTokenFactory {
1010
scope: Type<any>[],
1111
dynamicModuleMetadata?: Partial<DynamicModule> | undefined,
1212
): string {
13-
const reflectedScope = this.reflectScope(metatype);
14-
const isSingleScoped = reflectedScope === true;
13+
const moduleScope = this.reflectScope(metatype);
14+
const isSingleScoped = moduleScope === true;
1515
const opaqueToken = {
1616
module: this.getModuleName(metatype),
1717
dynamic: this.getDynamicMetadataToken(dynamicModuleMetadata),
18-
scope: isSingleScoped ? this.getScopeStack(scope) : reflectedScope,
18+
scope: isSingleScoped ? this.getScopeStack(scope) : moduleScope,
1919
};
2020
return hash(opaqueToken);
2121
}
2222

2323
public getDynamicMetadataToken(
2424
dynamicModuleMetadata: Partial<DynamicModule> | undefined,
2525
): string {
26-
// Uses safeStringify instead of JSON.stringify
27-
// to support circular dynamic modules
28-
return dynamicModuleMetadata ? stringify(dynamicModuleMetadata, this.replacer) : '';
26+
// Uses safeStringify instead of JSON.stringify to support circular dynamic modules
27+
// The replacer function is also required in order to obtain real class names
28+
// instead of the unified "Function" key
29+
return dynamicModuleMetadata
30+
? stringify(dynamicModuleMetadata, this.replacer)
31+
: '';
2932
}
3033

3134
public getModuleName(metatype: Type<any>): string {
@@ -54,8 +57,7 @@ export class ModuleTokenFactory {
5457
private replacer(key: string, value: any) {
5558
if (typeof value === 'function') {
5659
return value.name;
57-
} else {
58-
return value;
5960
}
61+
return value;
6062
}
6163
}

packages/core/scanner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export class DependenciesScanner {
194194
(a: any[], b: any[]) => a.concat(b),
195195
initialValue,
196196
) as any[];
197+
197198
const combinedInjectables = [
198199
...controllerInjectables,
199200
...flattenMethodsInjectables,

0 commit comments

Comments
 (0)