@@ -37,29 +37,14 @@ function processExports(exports, test, cached, parentKeyName) {
3737 exports [ keyName ] = processExports ( exports [ keyName ] , test , cached , name ) ;
3838 }
3939
40+ // Assign the new function in place.
41+ var wrapped = Promise . denodeify ( exports ) ;
42+
4043 // Find methods on the prototype, if there are any.
4144 if ( Object . keys ( exports . prototype ) . length ) {
4245 processExports ( exports . prototype , test , cached , name ) ;
4346 }
4447
45- // If a filter function exists, use this to determine if the function
46- // is asynchronous.
47- if ( test ) {
48- // Pass the function itself, its keyName, and the parent keyName.
49- if ( ! test ( exports , exports . name || parentKeyName , parentKeyName ) ) {
50- return exports ;
51- }
52- }
53-
54- // If the callback name exists as the last argument, consider it an
55- // asynchronous function. Brittle? Fragile? Effective.
56- else if ( callbacks . indexOf ( args ( exports ) . slice ( - 1 ) [ 0 ] ) === - 1 ) {
57- return exports ;
58- }
59-
60- // Assign the new function in place.
61- var wrapped = Promise . denodeify ( exports ) ;
62-
6348 // Attach the augmented prototype.
6449 wrapped . prototype = exports . prototype ;
6550
@@ -72,17 +57,35 @@ function processExports(exports, test, cached, parentKeyName) {
7257 Object . keys ( exports ) . map ( function ( keyName ) {
7358 // Convert to values.
7459 return [ keyName , exports [ keyName ] ] ;
75- } ) . forEach ( function ( keyVal ) {
60+ } ) . filter ( function ( keyVal ) {
7661 var keyName = keyVal [ 0 ] ;
7762 var value = keyVal [ 1 ] ;
7863
7964 // If an object is encountered, recursively traverse.
8065 if ( typeof value === "object" ) {
8166 processExports ( exports , test , cached , keyName + "." ) ;
8267 }
68+ // Filter to functions with callbacks only.
69+ else if ( typeof value === "function" ) {
70+ // If a filter function exists, use this to determine if the function
71+ // is asynchronous.
72+ if ( test ) {
73+ // Pass the function itself, its keyName, and the parent keyName.
74+ return test ( value , keyName , parentKeyName ) ;
75+ }
76+
77+ // If the callback name exists as the last argument, consider it an
78+ // asynchronous function. Brittle? Fragile? Effective.
79+ if ( callbacks . indexOf ( args ( value ) . slice ( - 1 ) [ 0 ] ) > - 1 ) {
80+ return true ;
81+ }
82+ }
83+ } ) . forEach ( function ( keyVal ) {
84+ var keyName = keyVal [ 0 ] ;
85+ var func = keyVal [ 1 ] ;
8386
8487 // Wrap this function and reassign.
85- exports [ keyName ] = processExports ( value , test , cached , parentKeyName ) ;
88+ exports [ keyName ] = processExports ( func , test , cached , parentKeyName ) ;
8689 } ) ;
8790
8891 return exports ;
0 commit comments