Skip to content

Commit 09ff7fe

Browse files
smileccWhiteKiwi
andauthored
fix: Fix applyLazyDecorator return when metadataList is empty (#30)
* fix: Fix applyLazyDecorator return when metadataList is empty * fix: Fix Reflection fail caused by invalid target method * chore: rename methodNames to propertyKeys at applyLazyDecorator * Update src/auto-aspect-executor.ts --------- Co-authored-by: 장지훈 <[email protected]>
1 parent 193b58c commit 09ff7fe

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/auto-aspect-executor.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,32 @@ export class AutoAspectExecutor implements OnModuleInit {
4747
: instanceWrapper.metatype.prototype;
4848

4949
// Use scanFromPrototype for support nestjs 8
50-
const methodNames = this.metadataScanner.scanFromPrototype(
50+
const propertyKeys = this.metadataScanner.scanFromPrototype(
5151
target,
5252
instanceWrapper.isDependencyTreeStatic() ? Object.getPrototypeOf(target) : target,
5353
(name) => name,
5454
);
5555

5656
const metadataKey = this.reflector.get(ASPECT, lazyDecorator.constructor);
5757
// instance에 method names 를 순회하면서 lazyDecorator.wrap을 적용함
58-
for (const methodName of methodNames) {
58+
for (const propertyKey of propertyKeys) {
59+
// the target method is must be object or function
60+
// @see: https://github.com/rbuckton/reflect-metadata/blob/9562d6395cc3901eaafaf8a6ed8bc327111853d5/Reflect.ts#L938
61+
const targetProperty = target[propertyKey];
62+
if (!targetProperty || (typeof targetProperty !== "object" && typeof targetProperty !== "function")) {
63+
continue;
64+
}
65+
5966
const metadataList: AopMetadata[] = this.reflector.get<AopMetadata[]>(
6067
metadataKey,
61-
target[methodName],
68+
targetProperty,
6269
);
6370
if (!metadataList) {
64-
return;
71+
continue;
6572
}
6673

6774
for (const aopMetadata of metadataList) {
68-
this.wrapMethod({ lazyDecorator, aopMetadata, methodName, target });
75+
this.wrapMethod({ lazyDecorator, aopMetadata, methodName: propertyKey, target });
6976
}
7077
}
7178
}

0 commit comments

Comments
 (0)