monocart-coverage-reports 2.3.3 → 2.4.0
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/README.md +50 -20
- package/lib/converter/ast-visitor.js +646 -0
- package/lib/converter/ast.js +116 -137
- package/lib/converter/collect-source-maps.js +1 -1
- package/lib/converter/converter.js +337 -226
- package/lib/converter/find-original-range.js +471 -411
- package/lib/converter/ignore.js +33 -22
- package/lib/converter/info-branch.js +13 -2
- package/lib/converter/info-function.js +29 -6
- package/lib/converter/info-statement.js +43 -0
- package/lib/default/options.js +1 -1
- package/lib/generate.js +2 -2
- package/lib/index.d.ts +24 -13
- package/lib/istanbul/istanbul.js +1 -1
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js +38 -37
- package/lib/platform/share.js +39 -4
- package/lib/utils/util.js +8 -2
- package/lib/v8/v8-summary.js +5 -1
- package/lib/v8/v8.js +4 -1
- package/package.json +3 -3
- package/lib/converter/branches.js +0 -429
- package/lib/converter/find-in-ranges.js +0 -39
- package/lib/converter/info-line.js +0 -23
package/lib/platform/share.js
CHANGED
|
@@ -248,6 +248,41 @@ const Util = {
|
|
|
248
248
|
return false;
|
|
249
249
|
},
|
|
250
250
|
|
|
251
|
+
findInRanges: (startPos, endPos, rangeList, startKey = 'start', endKey = 'end') => {
|
|
252
|
+
if (!Util.isList(rangeList)) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const quickFindRange = (position, ranges) => {
|
|
257
|
+
let start = 0;
|
|
258
|
+
let end = ranges.length - 1;
|
|
259
|
+
while (end - start > 1) {
|
|
260
|
+
const i = Math.floor((start + end) * 0.5);
|
|
261
|
+
const item = ranges[i];
|
|
262
|
+
if (position < item[startKey]) {
|
|
263
|
+
end = i;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (position > item[endKey]) {
|
|
267
|
+
start = i;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
return ranges[i];
|
|
271
|
+
}
|
|
272
|
+
// last two items, less is start
|
|
273
|
+
const endItem = ranges[end];
|
|
274
|
+
if (position < endItem[startKey]) {
|
|
275
|
+
return ranges[start];
|
|
276
|
+
}
|
|
277
|
+
return ranges[end];
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const range = quickFindRange(startPos, rangeList);
|
|
281
|
+
if (startPos >= range[startKey] && endPos <= range[endKey]) {
|
|
282
|
+
return range;
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
|
|
251
286
|
getRangeLines: (sLoc, eLoc) => {
|
|
252
287
|
|
|
253
288
|
const lines = [];
|
|
@@ -273,7 +308,7 @@ const Util = {
|
|
|
273
308
|
lines.push({
|
|
274
309
|
line: sLoc.line,
|
|
275
310
|
entire,
|
|
276
|
-
|
|
311
|
+
pieces: {
|
|
277
312
|
start: sLoc.column,
|
|
278
313
|
end: sLoc.length
|
|
279
314
|
}
|
|
@@ -289,7 +324,7 @@ const Util = {
|
|
|
289
324
|
lines.push({
|
|
290
325
|
line: sLoc.line,
|
|
291
326
|
entire,
|
|
292
|
-
|
|
327
|
+
pieces: {
|
|
293
328
|
start: sLoc.column,
|
|
294
329
|
end: eLoc.column
|
|
295
330
|
}
|
|
@@ -307,7 +342,7 @@ const Util = {
|
|
|
307
342
|
lines.push({
|
|
308
343
|
line: eLoc.line,
|
|
309
344
|
entire,
|
|
310
|
-
|
|
345
|
+
pieces: {
|
|
311
346
|
start: eLoc.indent,
|
|
312
347
|
end: eLoc.column
|
|
313
348
|
}
|
|
@@ -332,7 +367,7 @@ const Util = {
|
|
|
332
367
|
lines.push({
|
|
333
368
|
line: i,
|
|
334
369
|
entire: true
|
|
335
|
-
// no
|
|
370
|
+
// no pieces for entire line
|
|
336
371
|
});
|
|
337
372
|
}
|
|
338
373
|
}
|
package/lib/utils/util.js
CHANGED
|
@@ -12,10 +12,12 @@ const { deflateSync } = require('lz-utils');
|
|
|
12
12
|
const { acornWalk } = require('../packages/monocart-coverage-vendor.js');
|
|
13
13
|
|
|
14
14
|
const Util = {
|
|
15
|
+
... Share,
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
EC,
|
|
18
|
+
CG,
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
root: process.cwd(),
|
|
19
21
|
|
|
20
22
|
relativePath: function(p, root) {
|
|
21
23
|
p = `${p}`;
|
|
@@ -416,6 +418,10 @@ const Util = {
|
|
|
416
418
|
debug: 30
|
|
417
419
|
},
|
|
418
420
|
|
|
421
|
+
isDebug: () => {
|
|
422
|
+
return Util.loggingType === 'debug';
|
|
423
|
+
},
|
|
424
|
+
|
|
419
425
|
initLoggingLevel: (level) => {
|
|
420
426
|
|
|
421
427
|
const types = {
|
package/lib/v8/v8-summary.js
CHANGED
|
@@ -75,7 +75,7 @@ const getV8Summary = (v8list, watermarks) => {
|
|
|
75
75
|
total: 0,
|
|
76
76
|
covered: 0
|
|
77
77
|
},
|
|
78
|
-
|
|
78
|
+
statements: {
|
|
79
79
|
total: 0,
|
|
80
80
|
covered: 0
|
|
81
81
|
},
|
|
@@ -83,6 +83,10 @@ const getV8Summary = (v8list, watermarks) => {
|
|
|
83
83
|
total: 0,
|
|
84
84
|
covered: 0
|
|
85
85
|
},
|
|
86
|
+
functions: {
|
|
87
|
+
total: 0,
|
|
88
|
+
covered: 0
|
|
89
|
+
},
|
|
86
90
|
lines: {
|
|
87
91
|
total: 0,
|
|
88
92
|
covered: 0,
|
package/lib/v8/v8.js
CHANGED
|
@@ -79,6 +79,8 @@ const initV8ListAndSourcemap = async (v8list, options) => {
|
|
|
79
79
|
scriptOffset,
|
|
80
80
|
// Manually Resolve the Sourcemap
|
|
81
81
|
sourceMap: item.sourceMap,
|
|
82
|
+
// fake source with `lineLengths`
|
|
83
|
+
fake: item.fake,
|
|
82
84
|
// empty coverage
|
|
83
85
|
empty: item.empty,
|
|
84
86
|
// match source if using empty coverage
|
|
@@ -319,8 +321,9 @@ const saveV8Report = async (v8list, options) => {
|
|
|
319
321
|
|
|
320
322
|
const defaultWatermarks = {
|
|
321
323
|
bytes: [50, 80],
|
|
322
|
-
|
|
324
|
+
statements: [50, 80],
|
|
323
325
|
branches: [50, 80],
|
|
326
|
+
functions: [50, 80],
|
|
324
327
|
lines: [50, 80]
|
|
325
328
|
};
|
|
326
329
|
const watermarks = Util.resolveWatermarks(defaultWatermarks, options.watermarks);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "monocart-coverage-reports",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Monocart coverage reports",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
"turbogrid": "^3.0.13"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"commander": "^
|
|
68
|
+
"commander": "^12.0.0",
|
|
69
69
|
"eslint": "^8.56.0",
|
|
70
70
|
"eslint-config-plus": "^1.0.6",
|
|
71
71
|
"eslint-plugin-html": "^7.1.0",
|
|
72
|
-
"eslint-plugin-vue": "^9.
|
|
72
|
+
"eslint-plugin-vue": "^9.21.1",
|
|
73
73
|
"stylelint": "^15.11.0",
|
|
74
74
|
"stylelint-config-plus": "^1.0.4"
|
|
75
75
|
}
|
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
const Util = require('../utils/util.js');
|
|
2
|
-
const findInRanges = require('./find-in-ranges.js');
|
|
3
|
-
|
|
4
|
-
const findBranchBlock = (start, end, functionInfo) => {
|
|
5
|
-
const { range } = functionInfo;
|
|
6
|
-
if (range) {
|
|
7
|
-
const { blockMap, blockRanges } = range;
|
|
8
|
-
if (blockMap) {
|
|
9
|
-
// exact matched a block
|
|
10
|
-
const block = blockMap.get(start);
|
|
11
|
-
if (block) {
|
|
12
|
-
return block;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// support for tf2 || a || 1;
|
|
16
|
-
// "a" is in "|| a"
|
|
17
|
-
const blockItem = findInRanges(start, end, blockRanges);
|
|
18
|
-
if (blockItem) {
|
|
19
|
-
return blockItem;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// =======================================================================================
|
|
27
|
-
|
|
28
|
-
const createBranchGroup = (type, branchStart, parents, branchMap, functionInfo) => {
|
|
29
|
-
// clone and reverse parents
|
|
30
|
-
const reverseParents = [].concat(parents).reverse();
|
|
31
|
-
const group = {
|
|
32
|
-
type,
|
|
33
|
-
|
|
34
|
-
start: branchStart,
|
|
35
|
-
// could be updated if multiple locations
|
|
36
|
-
end: branchStart,
|
|
37
|
-
|
|
38
|
-
locations: [],
|
|
39
|
-
reverseParents,
|
|
40
|
-
functionInfo
|
|
41
|
-
};
|
|
42
|
-
branchMap.set(branchStart, group);
|
|
43
|
-
return group;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const addBranch = (group, node, locationMap, functionInfo) => {
|
|
47
|
-
const { start, end } = node;
|
|
48
|
-
|
|
49
|
-
const branchStart = group.start;
|
|
50
|
-
|
|
51
|
-
// the block is not exact correct, if there is a block wrapped
|
|
52
|
-
// [x8]{ var a = b || [x4]c }, b is no block, but it can be found in x8 block
|
|
53
|
-
const block = findBranchBlock(start, end, functionInfo);
|
|
54
|
-
|
|
55
|
-
const branchInfo = {
|
|
56
|
-
// for get previous group for LogicalExpression
|
|
57
|
-
branchStart,
|
|
58
|
-
start,
|
|
59
|
-
end,
|
|
60
|
-
// cache block
|
|
61
|
-
block,
|
|
62
|
-
// branch count default to 0
|
|
63
|
-
count: 0
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
group.locations.push(branchInfo);
|
|
67
|
-
|
|
68
|
-
// update group end
|
|
69
|
-
group.end = end;
|
|
70
|
-
|
|
71
|
-
locationMap.set(start, branchInfo);
|
|
72
|
-
|
|
73
|
-
return branchInfo;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const addNoneBranch = (group) => {
|
|
77
|
-
group.locations.push({
|
|
78
|
-
none: true,
|
|
79
|
-
count: 0
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// =======================================================================================
|
|
84
|
-
|
|
85
|
-
const hasFunctionBlock = (functionInfo) => {
|
|
86
|
-
const { range } = functionInfo;
|
|
87
|
-
if (range) {
|
|
88
|
-
const { blockMap } = range;
|
|
89
|
-
if (blockMap) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return false;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const addNodeCount = (node, parents, functionInfo) => {
|
|
97
|
-
|
|
98
|
-
const { start, end } = node;
|
|
99
|
-
|
|
100
|
-
if (hasFunctionBlock(functionInfo)) {
|
|
101
|
-
const { range } = functionInfo;
|
|
102
|
-
const { blockMap, blockRanges } = range;
|
|
103
|
-
const block = blockMap.get(start);
|
|
104
|
-
if (block) {
|
|
105
|
-
node._state = {
|
|
106
|
-
count: block.count
|
|
107
|
-
};
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const blockItem = findInRanges(start, end, blockRanges);
|
|
112
|
-
if (blockItem) {
|
|
113
|
-
node._state = {
|
|
114
|
-
count: blockItem.count
|
|
115
|
-
};
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// continue find in reverseParents
|
|
120
|
-
|
|
121
|
-
} else {
|
|
122
|
-
|
|
123
|
-
// default to 1 if no function block
|
|
124
|
-
node._state = {
|
|
125
|
-
count: 1
|
|
126
|
-
};
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const reverseParents = [].concat(parents).reverse();
|
|
131
|
-
for (const parent of reverseParents) {
|
|
132
|
-
if (parent._state) {
|
|
133
|
-
node._state = {
|
|
134
|
-
count: parent._state.count
|
|
135
|
-
};
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// function count
|
|
141
|
-
node._state = {
|
|
142
|
-
count: functionInfo.count
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// =======================================================================================
|
|
148
|
-
|
|
149
|
-
const addAssignmentPattern = (params, parents, functionInfo, branchMap, locationMap) => {
|
|
150
|
-
if (!Util.isList(params)) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
params.forEach((param) => {
|
|
155
|
-
if (param.type !== 'AssignmentPattern') {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const start = param.start;
|
|
159
|
-
const group = createBranchGroup('AssignmentPattern', start, parents, branchMap, functionInfo);
|
|
160
|
-
addBranch(group, param, locationMap, functionInfo);
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const createBranches = (functionInfo, branchMap, body, params, functionParents = []) => {
|
|
165
|
-
|
|
166
|
-
// locationMap for chain LogicalExpression locations
|
|
167
|
-
const locationMap = new Map();
|
|
168
|
-
|
|
169
|
-
// function's arguments
|
|
170
|
-
addAssignmentPattern(params, functionParents, functionInfo, branchMap, locationMap);
|
|
171
|
-
|
|
172
|
-
Util.visitAst(body, {
|
|
173
|
-
|
|
174
|
-
Function() {
|
|
175
|
-
return 'break';
|
|
176
|
-
},
|
|
177
|
-
|
|
178
|
-
Statement: (node, parents) => {
|
|
179
|
-
addNodeCount(node, parents, functionInfo);
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
// cond-expr Ternary
|
|
183
|
-
// var b = a ? 'consequent' : 'alternate';
|
|
184
|
-
ConditionalExpression: (node, parents) => {
|
|
185
|
-
addNodeCount(node, parents, functionInfo);
|
|
186
|
-
const { consequent, alternate } = node;
|
|
187
|
-
const start = consequent.start;
|
|
188
|
-
const group = createBranchGroup('ConditionalExpression', start, parents, branchMap, functionInfo);
|
|
189
|
-
addBranch(group, consequent, locationMap, functionInfo);
|
|
190
|
-
addBranch(group, alternate, locationMap, functionInfo);
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
// if
|
|
194
|
-
// An IF statement always has exactly two branches:
|
|
195
|
-
// one where the condition is FALSE and one where the condition is TRUE
|
|
196
|
-
IfStatement: (node, parents) => {
|
|
197
|
-
addNodeCount(node, parents, functionInfo);
|
|
198
|
-
const { consequent, alternate } = node;
|
|
199
|
-
const start = consequent.start;
|
|
200
|
-
const group = createBranchGroup('IfStatement', start, parents, branchMap, functionInfo);
|
|
201
|
-
addBranch(group, consequent, locationMap, functionInfo);
|
|
202
|
-
|
|
203
|
-
// console.log('if type', consequent.type);
|
|
204
|
-
|
|
205
|
-
if (alternate) {
|
|
206
|
-
addBranch(group, alternate, locationMap, functionInfo);
|
|
207
|
-
} else {
|
|
208
|
-
// add none branch
|
|
209
|
-
addNoneBranch(group);
|
|
210
|
-
// no need update group end, there is no end
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
// binary-expr
|
|
215
|
-
// var b = a || b || c;
|
|
216
|
-
// do not use BinaryExpression
|
|
217
|
-
LogicalExpression: (node, parents) => {
|
|
218
|
-
addNodeCount(node, parents, functionInfo);
|
|
219
|
-
|
|
220
|
-
const { left, right } = node;
|
|
221
|
-
const start = left.start;
|
|
222
|
-
|
|
223
|
-
// console.log(left.start, right.start);
|
|
224
|
-
|
|
225
|
-
let group;
|
|
226
|
-
// link to same branch start if LogicalExpression
|
|
227
|
-
const prevLocation = locationMap.get(start);
|
|
228
|
-
if (prevLocation) {
|
|
229
|
-
// console.log('link branch ==================', type);
|
|
230
|
-
group = branchMap.get(prevLocation.branchStart);
|
|
231
|
-
} else {
|
|
232
|
-
group = createBranchGroup('LogicalExpression', start, parents, branchMap, functionInfo);
|
|
233
|
-
addBranch(group, left, locationMap, functionInfo);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
addBranch(group, right, locationMap, functionInfo);
|
|
237
|
-
|
|
238
|
-
// console.log(group.locations.map((it) => it.start));
|
|
239
|
-
|
|
240
|
-
// sort branch locations
|
|
241
|
-
// a || b || c
|
|
242
|
-
// first, left a and right c
|
|
243
|
-
// then, left a and right b
|
|
244
|
-
if (prevLocation) {
|
|
245
|
-
const { locations } = group;
|
|
246
|
-
locations.sort((a, b) => {
|
|
247
|
-
return a.start - b.start;
|
|
248
|
-
});
|
|
249
|
-
// update group end after sorted
|
|
250
|
-
group.end = locations[locations.length - 1].end;
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
|
|
254
|
-
// switch
|
|
255
|
-
SwitchStatement: (node, parents) => {
|
|
256
|
-
addNodeCount(node, parents, functionInfo);
|
|
257
|
-
const start = node.start;
|
|
258
|
-
const group = createBranchGroup('SwitchStatement', start, parents, branchMap, functionInfo);
|
|
259
|
-
const cases = node.cases;
|
|
260
|
-
cases.forEach((switchCase) => {
|
|
261
|
-
// console.log('switchCase', switchCase.start);
|
|
262
|
-
addBranch(group, switchCase, locationMap, functionInfo);
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
// =======================================================================================
|
|
272
|
-
|
|
273
|
-
// const a = tf1 ? 'true' : 'false';
|
|
274
|
-
const ConditionalExpression = (group, parentCount, noBlockList, blockCount) => {
|
|
275
|
-
if (!noBlockList.length) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
let count = parentCount - blockCount;
|
|
279
|
-
noBlockList.forEach((item) => {
|
|
280
|
-
item.count = count;
|
|
281
|
-
count = 0;
|
|
282
|
-
});
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
const IfStatement = (group, parentCount, noBlockList, blockCount) => {
|
|
286
|
-
if (!noBlockList.length) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
// console.log(parentCount, 'uncovered list', noBlockList.length, group.start);
|
|
290
|
-
let count = parentCount - blockCount;
|
|
291
|
-
noBlockList.forEach((item) => {
|
|
292
|
-
item.count = count;
|
|
293
|
-
count = 0;
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
// const b = tf2 || tf1 || a;
|
|
299
|
-
const LogicalExpression = (group, parentCount, noBlockList, blockCount) => {
|
|
300
|
-
if (!noBlockList.length) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
const count = parentCount - blockCount;
|
|
304
|
-
noBlockList.forEach((item) => {
|
|
305
|
-
item.count = count;
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
// const start = group.start;
|
|
309
|
-
// if (start > 7874 && start < 7922) {
|
|
310
|
-
// console.log(group.type, parentCount, 'locations', group.locations);
|
|
311
|
-
// }
|
|
312
|
-
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
const SwitchStatement = (group, parentCount, noBlockList, blockCount) => {
|
|
316
|
-
if (!noBlockList.length) {
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
const count = parentCount - blockCount;
|
|
320
|
-
noBlockList.forEach((item) => {
|
|
321
|
-
item.count = count;
|
|
322
|
-
});
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
// =======================================================================================
|
|
326
|
-
|
|
327
|
-
const getBranchParentCount = (reverseParents, functionCount) => {
|
|
328
|
-
// parent count
|
|
329
|
-
for (const parent of reverseParents) {
|
|
330
|
-
if (parent._state) {
|
|
331
|
-
return parent._state.count;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// root function count
|
|
336
|
-
return functionCount;
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
const updateBranchCount = (group) => {
|
|
340
|
-
|
|
341
|
-
const {
|
|
342
|
-
type, locations, reverseParents, functionInfo
|
|
343
|
-
} = group;
|
|
344
|
-
|
|
345
|
-
const functionCount = functionInfo.count;
|
|
346
|
-
|
|
347
|
-
// default is 0, no need continue
|
|
348
|
-
if (functionCount === 0) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const parentCount = getBranchParentCount(reverseParents, functionCount);
|
|
353
|
-
// console.log(functionInfo.start, 'function count', functionCount, 'parent count', parentCount);
|
|
354
|
-
|
|
355
|
-
if (!hasFunctionBlock(functionInfo)) {
|
|
356
|
-
// default to parent if no function range
|
|
357
|
-
locations.forEach((item) => {
|
|
358
|
-
item.count = parentCount;
|
|
359
|
-
});
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// calculate branches count
|
|
364
|
-
// > 1
|
|
365
|
-
|
|
366
|
-
const noBlockList = [];
|
|
367
|
-
let blockCount = 0;
|
|
368
|
-
locations.forEach((item) => {
|
|
369
|
-
if (item.block) {
|
|
370
|
-
item.count = item.block.count;
|
|
371
|
-
blockCount += item.count;
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
noBlockList.push(item);
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
const handlers = {
|
|
378
|
-
ConditionalExpression,
|
|
379
|
-
IfStatement,
|
|
380
|
-
LogicalExpression,
|
|
381
|
-
SwitchStatement
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
const handler = handlers[type];
|
|
385
|
-
if (handler) {
|
|
386
|
-
handler(group, parentCount, noBlockList, blockCount);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
const collectBranches = (branchMap) => {
|
|
392
|
-
|
|
393
|
-
// calculate count for all branches
|
|
394
|
-
branchMap.forEach((group) => {
|
|
395
|
-
updateBranchCount(group);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
// init branches
|
|
399
|
-
const branches = [];
|
|
400
|
-
branchMap.forEach((group) => {
|
|
401
|
-
|
|
402
|
-
// add start/end for none with group start/end
|
|
403
|
-
group.locations.forEach((item) => {
|
|
404
|
-
if (item.none) {
|
|
405
|
-
item.start = group.start;
|
|
406
|
-
item.end = group.end;
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
branches.push({
|
|
411
|
-
type: group.type,
|
|
412
|
-
start: group.start,
|
|
413
|
-
end: group.end,
|
|
414
|
-
locations: group.locations
|
|
415
|
-
});
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
// sort branches
|
|
419
|
-
branches.sort((a, b) => {
|
|
420
|
-
return a.start - b.start;
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
return branches;
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
module.exports = {
|
|
427
|
-
createBranches,
|
|
428
|
-
collectBranches
|
|
429
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const Util = require('../utils/util.js');
|
|
2
|
-
|
|
3
|
-
const quickFindRange = (position, ranges, startKey, endKey) => {
|
|
4
|
-
let start = 0;
|
|
5
|
-
let end = ranges.length - 1;
|
|
6
|
-
while (end - start > 1) {
|
|
7
|
-
const i = Math.floor((start + end) * 0.5);
|
|
8
|
-
const item = ranges[i];
|
|
9
|
-
if (position < item[startKey]) {
|
|
10
|
-
end = i;
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
if (position > item[endKey]) {
|
|
14
|
-
start = i;
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
return ranges[i];
|
|
18
|
-
}
|
|
19
|
-
// last two items, less is start
|
|
20
|
-
const endItem = ranges[end];
|
|
21
|
-
if (position < endItem[startKey]) {
|
|
22
|
-
return ranges[start];
|
|
23
|
-
}
|
|
24
|
-
return ranges[end];
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const findInRanges = (start, end, ranges, startKey = 'startOffset', endKey = 'endOffset') => {
|
|
29
|
-
if (!Util.isList(ranges)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const range = quickFindRange(start, ranges, startKey, endKey);
|
|
33
|
-
if (start >= range[startKey] && end <= range[endKey]) {
|
|
34
|
-
return range;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
module.exports = findInRanges;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module.exports = class InfoLine {
|
|
2
|
-
constructor(line, column, count = 1) {
|
|
3
|
-
// 1 based
|
|
4
|
-
this.line = line;
|
|
5
|
-
this.column = column;
|
|
6
|
-
this.count = count;
|
|
7
|
-
// covered full line, could be false even count > 0
|
|
8
|
-
this.covered = count > 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
generate() {
|
|
12
|
-
return {
|
|
13
|
-
start: {
|
|
14
|
-
line: this.line,
|
|
15
|
-
column: 0
|
|
16
|
-
},
|
|
17
|
-
end: {
|
|
18
|
-
line: this.line,
|
|
19
|
-
column: this.column
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
};
|