Skip to content

Commit

Permalink
fix(classes): skip empty metadataList before looping
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jan 4, 2021
1 parent 449da22 commit 88ecf9c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/classes/src/lib/classes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createInitialMapping } from '@automapper/core';
import { createInitialMapping, isDefined } from '@automapper/core';
import type {
Dictionary,
Mapping,
Expand Down Expand Up @@ -150,19 +150,22 @@ function exploreMetadata(
...models: Constructible[]
) {
// Loop through each models passed in
models.forEach((model) => {
for (const model of models) {
// if metadataStorage hasn't had metadata of the model
if (!metadataStorage.has(model)) {
// get the metadata from Reflection then populate metadataStorage and instanceStorage
const metadataList = Reflect.getMetadata('automap:properties', model);
// skip if no metadata
if (!isDefined(metadataList)) continue;
// loop through metadata list
for (const [propertyKey, { typeFn, depth }] of metadataList) {
metadataStorage.addMetadata(model, [propertyKey, typeFn]);
if (depth != null) {
instanceStorage.setDepth(model, propertyKey, depth);
}
}
}
});
}
}

function prePropertiesLoop(
Expand Down

0 comments on commit 88ecf9c

Please sign in to comment.