@@ -10,7 +10,6 @@ export default function dereference(container, dataSources, config = {deleteKeys
10
10
}
11
11
12
12
const dataKey = key . replace ( SRC_ATTR_PATTERN , '' ) ;
13
- const traceType = parent . type ;
14
13
15
14
let srcRef = config . toSrc ? config . toSrc ( parent [ key ] ) : parent [ key ] ;
16
15
@@ -19,7 +18,7 @@ export default function dereference(container, dataSources, config = {deleteKeys
19
18
srcRef = [ srcRef ] ;
20
19
}
21
20
22
- let data = srcRef . map ( ref => {
21
+ let dereferencedData = srcRef . map ( ref => {
23
22
if ( config . deleteKeys && ! ( ref in dataSources ) ) {
24
23
delete parent [ dataKey ] ;
25
24
}
@@ -28,18 +27,29 @@ export default function dereference(container, dataSources, config = {deleteKeys
28
27
29
28
// remove extra data wrapping
30
29
if ( srcRef . length === 1 ) {
31
- data = data [ 0 ] ;
30
+ dereferencedData = dereferencedData [ 0 ] ;
32
31
}
33
32
34
- if ( ! Array . isArray ( data ) ) {
33
+ if ( ! Array . isArray ( dereferencedData ) ) {
35
34
return ;
36
35
}
37
36
38
- parent [ dataKey ] = maybeTransposeData ( data , srcPath , traceType ) ;
37
+ if ( Array . isArray ( container ) ) {
38
+ // Case where we were originally given data to dereference
39
+ const traceType = parent . type ;
40
+ parent [ dataKey ] = maybeTransposeData ( dereferencedData , srcPath , traceType ) ;
41
+ } else {
42
+ // This means we're dereferencing layout
43
+ parent [ dataKey ] = dereferencedData ;
44
+ }
39
45
} ;
40
46
41
- walkObject ( container , replacer , {
42
- walkArraysMatchingKeys : [ 'data' , 'transforms' ] ,
43
- pathType : 'nestedProperty' ,
44
- } ) ;
47
+ if ( Array . isArray ( container ) ) {
48
+ walkObject ( container , replacer , {
49
+ walkArraysMatchingKeys : [ 'data' , 'transforms' ] ,
50
+ pathType : 'nestedProperty' ,
51
+ } ) ;
52
+ } else {
53
+ walkObject ( container , replacer , { pathType : 'nestedProperty' } ) ;
54
+ }
45
55
}
0 commit comments