@@ -216,7 +216,9 @@ function map<
216216 // Do not run before map when in Map Array mode
217217 if ( ! isMapArray ) {
218218 const beforeMap = mapBeforeAction ?? mappingBeforeAction ;
219- beforeMap ?.( sourceObj , destination ) ;
219+ if ( beforeMap ) {
220+ beforeMap ( sourceObj , destination ) ;
221+ }
220222 }
221223
222224 // map
@@ -358,7 +360,9 @@ Original error: ${originalError}`;
358360 // Do not map for when in Map Array mode
359361 if ( ! isMapArray ) {
360362 const afterMap = mapAfterAction ?? mappingAfterAction ;
361- afterMap ?.( sourceObj , destination ) ;
363+ if ( afterMap ) {
364+ afterMap ( sourceObj , destination ) ;
365+ }
362366 }
363367
364368 // Check unmapped properties
@@ -394,15 +398,19 @@ export function mapArray<
394398 const { beforeMap, afterMap, extraArguments } = options ?? { } ;
395399
396400 // run beforeMap for the whole map operation
397- beforeMap ?.( sourceArray , [ ] ) ;
401+ if ( beforeMap ) {
402+ beforeMap ( sourceArray , destinationArray ) ;
403+ }
398404
399405 // loop through each item and run map() for each
400406 for ( let i = 0 , len = sourceArray . length ; i < len ; i ++ ) {
401- const mapping = mapper . getMapping ( source , destination ) ;
402407 destinationArray . push (
403408 mapReturn (
404409 sourceArray [ i ] ,
405- mapping as Mapping < TSource , TDestination > ,
410+ mapper . getMapping ( source , destination ) as Mapping <
411+ TSource ,
412+ TDestination
413+ > ,
406414 { extraArguments } ,
407415 mapper ,
408416 errorHandler ,
@@ -412,7 +420,9 @@ export function mapArray<
412420 }
413421
414422 // run afterMap for the whole map operation
415- afterMap ?.( sourceArray , destinationArray ) ;
423+ if ( afterMap ) {
424+ afterMap ( sourceArray , destinationArray ) ;
425+ }
416426
417427 return destinationArray ;
418428}
0 commit comments