Skip to content

Commit bc7914e

Browse files
feature(@nestjs/core) use generator instead of local variable
1 parent 2003c1e commit bc7914e

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

src/core/metadata-scanner.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,26 @@ export class MetadataScanner {
1212
prototype,
1313
callback: (name: string) => R,
1414
): R[] {
15-
return iterate(this.getAllFilteredMethodNames_(prototype))
15+
return iterate([...this.getAllFilteredMethodNames(prototype)])
1616
.map(callback)
1717
.filter(metadata => !isNil(metadata))
1818
.toArray();
1919
}
2020

21-
private getAllFilteredMethodNames_(prototype): string[] {
22-
let methods: string[] = [];
21+
*getAllFilteredMethodNames(prototype): IterableIterator<string> {
2322
do {
24-
iterate(Object.getOwnPropertyNames(prototype))
25-
.filter(prop => {
26-
const descriptor = Object.getOwnPropertyDescriptor(prototype, prop);
27-
if (descriptor.set || descriptor.get) {
28-
return false;
29-
}
30-
return !isConstructor(prop) && isFunction(prototype[prop]);
31-
})
32-
.forEach(method => {
33-
methods.push(method);
34-
});
35-
} while ((prototype = Reflect.getPrototypeOf(prototype)) && prototype != Object.prototype)
36-
return methods;
23+
yield* iterate(Object.getOwnPropertyNames(prototype))
24+
.filter(prop => {
25+
const descriptor = Object.getOwnPropertyDescriptor(prototype, prop);
26+
if (descriptor.set || descriptor.get) {
27+
return false;
28+
}
29+
return !isConstructor(prop) && isFunction(prototype[prop]);
30+
})
31+
.toArray()
32+
} while (
33+
(prototype = Reflect.getPrototypeOf(prototype)) &&
34+
prototype != Object.prototype
35+
);
3736
}
3837
}

0 commit comments

Comments
 (0)