1
1
import nodeSerializer from './node-serializer' ;
2
2
import getAllChecks from './get-all-checks' ;
3
3
import findBy from './find-by' ;
4
+ import mergeErrors from './merge-errors' ;
4
5
5
6
/**
6
7
* Adds the owning frame's CSS selector onto each instance of DqElement
@@ -75,13 +76,20 @@ function normalizeResult(result) {
75
76
*/
76
77
function mergeResults ( frameResults , options ) {
77
78
const mergedResult = [ ] ;
79
+ let mergedErrors = { } ;
78
80
frameResults . forEach ( frameResult => {
79
81
const results = normalizeResult ( frameResult ) ;
80
82
if ( ! results || ! results . length ) {
81
83
return ;
82
84
}
83
85
84
86
const frameSpec = getFrameSpec ( frameResult ) ;
87
+ if ( results [ results . length - 1 ] . errorsObj ) {
88
+ const error = results . pop ( ) ;
89
+ delete error . errorsObj ;
90
+ mergedErrors = mergeErrors ( mergedErrors , error , frameSpec ) ;
91
+ }
92
+
85
93
results . forEach ( ruleResult => {
86
94
if ( ruleResult . nodes && frameSpec ) {
87
95
pushFrame ( ruleResult . nodes , options , frameSpec ) ;
@@ -106,7 +114,11 @@ function mergeResults(frameResults, options) {
106
114
} ) ;
107
115
}
108
116
} ) ;
109
- return mergedResult ;
117
+
118
+ if ( Object . keys ( mergedErrors ) . length === 0 ) {
119
+ return mergedResult ;
120
+ }
121
+ return [ ...mergedResult , { ...mergedErrors , errorsObj : true } ] ;
110
122
}
111
123
112
124
function nodeIndexSort ( nodeIndexesA = [ ] , nodeIndexesB = [ ] ) {
0 commit comments