monocart-coverage-reports 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/converter/branches.js +56 -26
- package/package.json +1 -1
|
@@ -108,33 +108,58 @@ const addBranch = (group, node, locationMap, functionInfo) => {
|
|
|
108
108
|
return branchInfo;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
const addNoneBranch = (group) => {
|
|
112
|
+
group.locations.push({
|
|
113
|
+
none: true,
|
|
114
|
+
count: 0
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
111
118
|
// =======================================================================================
|
|
112
119
|
|
|
120
|
+
const hasFunctionBlock = (functionInfo) => {
|
|
121
|
+
const { range } = functionInfo;
|
|
122
|
+
if (range) {
|
|
123
|
+
const { blockMap } = range;
|
|
124
|
+
if (blockMap) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
};
|
|
130
|
+
|
|
113
131
|
const addNodeCount = (node, parents, functionInfo) => {
|
|
114
132
|
|
|
115
133
|
const { start, end } = node;
|
|
116
|
-
const { count, range } = functionInfo;
|
|
117
134
|
|
|
118
|
-
if (
|
|
135
|
+
if (hasFunctionBlock(functionInfo)) {
|
|
136
|
+
const { range } = functionInfo;
|
|
119
137
|
const { blockMap, blockRanges } = range;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const blockItem = findInRanges(start, end, blockRanges);
|
|
130
|
-
if (blockItem) {
|
|
131
|
-
node._state = {
|
|
132
|
-
count: blockItem.count
|
|
133
|
-
};
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
138
|
+
const block = blockMap.get(start);
|
|
139
|
+
if (block) {
|
|
140
|
+
node._state = {
|
|
141
|
+
count: block.count
|
|
142
|
+
};
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
136
145
|
|
|
146
|
+
const blockItem = findInRanges(start, end, blockRanges);
|
|
147
|
+
if (blockItem) {
|
|
148
|
+
node._state = {
|
|
149
|
+
count: blockItem.count
|
|
150
|
+
};
|
|
151
|
+
return;
|
|
137
152
|
}
|
|
153
|
+
|
|
154
|
+
// continue find in reverseParents
|
|
155
|
+
|
|
156
|
+
} else {
|
|
157
|
+
|
|
158
|
+
// default to 1 if no function block
|
|
159
|
+
node._state = {
|
|
160
|
+
count: 1
|
|
161
|
+
};
|
|
162
|
+
return;
|
|
138
163
|
}
|
|
139
164
|
|
|
140
165
|
const reverseParents = [].concat(parents).reverse();
|
|
@@ -149,7 +174,7 @@ const addNodeCount = (node, parents, functionInfo) => {
|
|
|
149
174
|
|
|
150
175
|
// function count
|
|
151
176
|
node._state = {
|
|
152
|
-
count: count
|
|
177
|
+
count: functionInfo.count
|
|
153
178
|
};
|
|
154
179
|
|
|
155
180
|
};
|
|
@@ -198,10 +223,7 @@ const createBranches = (ast, functionInfo, branchMap) => {
|
|
|
198
223
|
addBranch(group, alternate, locationMap, functionInfo);
|
|
199
224
|
} else {
|
|
200
225
|
// add none branch
|
|
201
|
-
group
|
|
202
|
-
none: true,
|
|
203
|
-
count: 0
|
|
204
|
-
});
|
|
226
|
+
addNoneBranch(group);
|
|
205
227
|
// no need update group end, there is no end
|
|
206
228
|
}
|
|
207
229
|
},
|
|
@@ -306,7 +328,7 @@ const LogicalExpression = (group, parentCount, noBlockList, blockCount) => {
|
|
|
306
328
|
|
|
307
329
|
// const start = group.loc.start;
|
|
308
330
|
// if (start > 7874 && start < 7922) {
|
|
309
|
-
// console.log(group.type, parentCount, 'locations', group.locations
|
|
331
|
+
// console.log(group.type, parentCount, 'locations', group.locations);
|
|
310
332
|
// }
|
|
311
333
|
|
|
312
334
|
};
|
|
@@ -351,6 +373,14 @@ const updateBranchCount = (group) => {
|
|
|
351
373
|
const parentCount = getBranchParentCount(reverseParents, functionCount);
|
|
352
374
|
// console.log(functionInfo.start, 'function count', functionCount, 'parent count', parentCount);
|
|
353
375
|
|
|
376
|
+
if (!hasFunctionBlock(functionInfo)) {
|
|
377
|
+
// default to parent if no function range
|
|
378
|
+
locations.forEach((item) => {
|
|
379
|
+
item.count = parentCount;
|
|
380
|
+
});
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
354
384
|
// calculate branches count
|
|
355
385
|
// > 1
|
|
356
386
|
|
|
@@ -360,9 +390,9 @@ const updateBranchCount = (group) => {
|
|
|
360
390
|
if (item.block) {
|
|
361
391
|
item.count = item.block.count;
|
|
362
392
|
blockCount += item.count;
|
|
363
|
-
|
|
364
|
-
noBlockList.push(item);
|
|
393
|
+
return;
|
|
365
394
|
}
|
|
395
|
+
noBlockList.push(item);
|
|
366
396
|
});
|
|
367
397
|
|
|
368
398
|
const handlers = {
|