monocart-coverage-reports 2.3.4 → 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 +3 -1
- package/lib/converter/ast-visitor.js +646 -0
- package/lib/converter/ast.js +115 -135
- package/lib/converter/collect-source-maps.js +1 -1
- package/lib/converter/converter.js +288 -197
- package/lib/converter/find-original-range.js +471 -411
- 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/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 -440
- package/lib/converter/info-line.js +0 -23
|
@@ -17,17 +17,36 @@ const {
|
|
|
17
17
|
const { getSourceType, initSourceMapSourcePath } = require('../utils/source-path.js');
|
|
18
18
|
const { decode } = require('../packages/monocart-coverage-vendor.js');
|
|
19
19
|
|
|
20
|
-
const InfoLine = require('./info-line.js');
|
|
21
20
|
const InfoBranch = require('./info-branch.js');
|
|
22
21
|
const InfoFunction = require('./info-function.js');
|
|
22
|
+
const InfoStatement = require('./info-statement.js');
|
|
23
|
+
|
|
24
|
+
// ========================================================================================================
|
|
25
|
+
|
|
26
|
+
// debug info
|
|
27
|
+
const logMappingErrors = (type, result) => {
|
|
28
|
+
|
|
29
|
+
// const {
|
|
30
|
+
// errors, start, end, sourcePath
|
|
31
|
+
// } = result;
|
|
32
|
+
// // if (!sourcePath.endsWith('monocart-v8.js') || type !== 'byte') {
|
|
33
|
+
// // return;
|
|
34
|
+
// // }
|
|
35
|
+
// const list = [
|
|
36
|
+
// Util.EC.red('[Mapping]'),
|
|
37
|
+
// Util.EC.magenta(type),
|
|
38
|
+
// errors.join(' -> '),
|
|
39
|
+
// Util.EC.blue(`${start} ~ ${end}`),
|
|
40
|
+
// sourcePath
|
|
41
|
+
// ];
|
|
42
|
+
// console.log(list.join(' '));
|
|
43
|
+
|
|
44
|
+
};
|
|
23
45
|
|
|
24
46
|
// ========================================================================================================
|
|
25
47
|
|
|
26
48
|
const handleIgnoredRanges = (list, ignoredRanges) => {
|
|
27
49
|
list.forEach((item) => {
|
|
28
|
-
if (item.count > 0) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
50
|
const range = Util.findInRanges(item.start, item.end, ignoredRanges, 'start', 'end');
|
|
32
51
|
if (range) {
|
|
33
52
|
// console.log(item, range);
|
|
@@ -36,7 +55,6 @@ const handleIgnoredRanges = (list, ignoredRanges) => {
|
|
|
36
55
|
});
|
|
37
56
|
};
|
|
38
57
|
|
|
39
|
-
// ========================================================================================================
|
|
40
58
|
|
|
41
59
|
const applyBytesToLines = (bytes, locator, lineMap) => {
|
|
42
60
|
bytes.forEach((range) => {
|
|
@@ -68,10 +86,10 @@ const applyBytesToLines = (bytes, locator, lineMap) => {
|
|
|
68
86
|
it.count = count;
|
|
69
87
|
|
|
70
88
|
// default is covered, so only focus on
|
|
71
|
-
// 1,
|
|
89
|
+
// 1, biggest covered count
|
|
72
90
|
// 2, uncovered entire and pieces
|
|
73
91
|
if (count > 0) {
|
|
74
|
-
lineItem.coveredCount = count;
|
|
92
|
+
lineItem.coveredCount = Math.max(lineItem.coveredCount, count);
|
|
75
93
|
} else {
|
|
76
94
|
if (it.entire) {
|
|
77
95
|
lineItem.uncoveredEntire = it;
|
|
@@ -82,6 +100,37 @@ const applyBytesToLines = (bytes, locator, lineMap) => {
|
|
|
82
100
|
});
|
|
83
101
|
|
|
84
102
|
});
|
|
103
|
+
|
|
104
|
+
// no ignore items
|
|
105
|
+
lineMap.forEach((lineItem, line) => {
|
|
106
|
+
|
|
107
|
+
const {
|
|
108
|
+
uncoveredEntire, uncoveredPieces, coveredCount
|
|
109
|
+
} = lineItem;
|
|
110
|
+
|
|
111
|
+
// default count to 1, both js and css
|
|
112
|
+
let count = 1;
|
|
113
|
+
// full covered true/false for entire line
|
|
114
|
+
let covered = true;
|
|
115
|
+
|
|
116
|
+
if (uncoveredEntire) {
|
|
117
|
+
count = 0;
|
|
118
|
+
covered = false;
|
|
119
|
+
} else {
|
|
120
|
+
count = coveredCount;
|
|
121
|
+
const uncoveredLen = uncoveredPieces.length;
|
|
122
|
+
if (uncoveredLen > 0) {
|
|
123
|
+
covered = false;
|
|
124
|
+
// uncovered
|
|
125
|
+
count = `1/${uncoveredLen + 1}`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
lineItem.covered = covered;
|
|
130
|
+
lineItem.count = count;
|
|
131
|
+
|
|
132
|
+
});
|
|
133
|
+
|
|
85
134
|
};
|
|
86
135
|
|
|
87
136
|
const handleLinesCoverage = (bytes, locator, ignoredRanges) => {
|
|
@@ -115,120 +164,60 @@ const handleLinesCoverage = (bytes, locator, ignoredRanges) => {
|
|
|
115
164
|
|
|
116
165
|
applyBytesToLines(bytes, locator, lineMap);
|
|
117
166
|
|
|
118
|
-
const
|
|
167
|
+
const summaryLines = {
|
|
168
|
+
total: 0,
|
|
169
|
+
covered: 0,
|
|
170
|
+
blank: blankCount,
|
|
171
|
+
comment: commentCount
|
|
172
|
+
};
|
|
119
173
|
// data lines for codecov
|
|
120
174
|
// https://docs.codecov.com/docs/codecov-custom-coverage-format
|
|
121
175
|
const dataLines = {};
|
|
122
176
|
|
|
123
177
|
// no ignore items
|
|
124
178
|
lineMap.forEach((lineItem, line) => {
|
|
125
|
-
|
|
126
|
-
const {
|
|
127
|
-
uncoveredEntire, uncoveredPieces, coveredCount
|
|
128
|
-
} = lineItem;
|
|
129
|
-
|
|
130
|
-
// default count to 1, both js and css
|
|
131
|
-
let count = 1;
|
|
132
|
-
// full covered true/false for entire line
|
|
133
|
-
let covered = true;
|
|
134
|
-
|
|
135
|
-
if (uncoveredEntire) {
|
|
136
|
-
count = 0;
|
|
137
|
-
covered = false;
|
|
138
|
-
} else {
|
|
139
|
-
|
|
140
|
-
count = coveredCount;
|
|
141
|
-
const uncoveredLen = uncoveredPieces.length;
|
|
142
|
-
if (uncoveredLen > 0) {
|
|
143
|
-
covered = false;
|
|
144
|
-
|
|
145
|
-
// uncovered
|
|
146
|
-
count = `1/${uncoveredLen + 1}`;
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
179
|
+
const { count, covered } = lineItem;
|
|
152
180
|
// data lines
|
|
153
181
|
dataLines[line] = count;
|
|
154
182
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
183
|
+
summaryLines.total += 1;
|
|
184
|
+
if (covered) {
|
|
185
|
+
summaryLines.covered += 1;
|
|
186
|
+
}
|
|
158
187
|
});
|
|
159
188
|
|
|
160
189
|
return {
|
|
161
|
-
lines,
|
|
162
190
|
dataLines,
|
|
163
|
-
|
|
164
|
-
commentCount
|
|
191
|
+
summaryLines
|
|
165
192
|
};
|
|
166
193
|
};
|
|
167
194
|
|
|
168
195
|
// ========================================================================================================
|
|
169
196
|
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
const v8Functions = {
|
|
173
|
-
total: 0,
|
|
174
|
-
covered: 0
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
functions.forEach((fn) => {
|
|
178
|
-
if (fn.ignored) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
v8Functions.total += 1;
|
|
183
|
-
if (fn.count > 0) {
|
|
184
|
-
v8Functions.covered += 1;
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
return v8Functions;
|
|
189
|
-
};
|
|
197
|
+
const calculateV8Summary = (list) => {
|
|
190
198
|
|
|
191
|
-
const
|
|
192
|
-
const v8Branches = {
|
|
199
|
+
const summary = {
|
|
193
200
|
total: 0,
|
|
194
201
|
covered: 0
|
|
195
202
|
};
|
|
196
203
|
|
|
197
|
-
|
|
198
|
-
if (
|
|
204
|
+
list.forEach((item) => {
|
|
205
|
+
if (item.ignored) {
|
|
199
206
|
return;
|
|
200
207
|
}
|
|
201
|
-
v8Branches.total += 1;
|
|
202
|
-
if (branch.count > 0) {
|
|
203
|
-
v8Branches.covered += 1;
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
return v8Branches;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const calculateV8Lines = (lines, blankCount, commentCount) => {
|
|
211
|
-
const v8Lines = {
|
|
212
|
-
total: 0,
|
|
213
|
-
covered: 0,
|
|
214
|
-
blank: blankCount,
|
|
215
|
-
comment: commentCount
|
|
216
|
-
};
|
|
217
208
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// full line covered
|
|
222
|
-
if (ln.covered) {
|
|
223
|
-
v8Lines.covered += 1;
|
|
209
|
+
summary.total += 1;
|
|
210
|
+
if (item.count > 0) {
|
|
211
|
+
summary.covered += 1;
|
|
224
212
|
}
|
|
225
213
|
});
|
|
226
214
|
|
|
227
|
-
return
|
|
215
|
+
return summary;
|
|
228
216
|
};
|
|
229
217
|
|
|
230
218
|
// ========================================================================================================
|
|
231
219
|
// istanbul coverage format
|
|
220
|
+
// https://github.com/istanbuljs/istanbuljs/blob/master/docs/raw-output.md
|
|
232
221
|
/**
|
|
233
222
|
* * `path` - the file path for which coverage is being tracked
|
|
234
223
|
* * `statementMap` - map of statement locations keyed by statement index
|
|
@@ -244,6 +233,7 @@ const collectFileCoverage = (v8Data, state, options) => {
|
|
|
244
233
|
bytes,
|
|
245
234
|
functions,
|
|
246
235
|
branches,
|
|
236
|
+
statements,
|
|
247
237
|
|
|
248
238
|
sourcePath,
|
|
249
239
|
locator
|
|
@@ -254,7 +244,8 @@ const collectFileCoverage = (v8Data, state, options) => {
|
|
|
254
244
|
const data = {
|
|
255
245
|
bytes: dedupeCountRanges(bytes),
|
|
256
246
|
functions: [],
|
|
257
|
-
branches: []
|
|
247
|
+
branches: [],
|
|
248
|
+
statements: []
|
|
258
249
|
};
|
|
259
250
|
|
|
260
251
|
// ==========================================
|
|
@@ -267,10 +258,10 @@ const collectFileCoverage = (v8Data, state, options) => {
|
|
|
267
258
|
// data bytes is start/end/count object
|
|
268
259
|
handleIgnoredRanges(data.bytes, ignoredRanges);
|
|
269
260
|
|
|
270
|
-
// functions
|
|
261
|
+
// functions start/end/count instance
|
|
271
262
|
handleIgnoredRanges(functions, ignoredRanges);
|
|
272
263
|
|
|
273
|
-
// branches
|
|
264
|
+
// branches start/end/count instance
|
|
274
265
|
handleIgnoredRanges(branches, ignoredRanges);
|
|
275
266
|
|
|
276
267
|
// branch locations start/end/count object
|
|
@@ -285,10 +276,24 @@ const collectFileCoverage = (v8Data, state, options) => {
|
|
|
285
276
|
}
|
|
286
277
|
});
|
|
287
278
|
|
|
279
|
+
// statements start/end/count instance
|
|
280
|
+
handleIgnoredRanges(statements, ignoredRanges);
|
|
281
|
+
|
|
288
282
|
// console.log(ignoredRanges);
|
|
289
283
|
|
|
290
284
|
}
|
|
291
285
|
|
|
286
|
+
// ==========================================
|
|
287
|
+
// lines
|
|
288
|
+
// after bytes with ignored, before calculateV8Lines
|
|
289
|
+
const { dataLines, summaryLines } = handleLinesCoverage(data.bytes, locator, ignoredRanges);
|
|
290
|
+
|
|
291
|
+
data.lines = dataLines;
|
|
292
|
+
|
|
293
|
+
// console.log('statements', state.sourcePath, statements.length);
|
|
294
|
+
|
|
295
|
+
// ==========================================
|
|
296
|
+
|
|
292
297
|
data.functions = functions.map((info) => {
|
|
293
298
|
return info.getRange();
|
|
294
299
|
});
|
|
@@ -300,23 +305,24 @@ const collectFileCoverage = (v8Data, state, options) => {
|
|
|
300
305
|
}).flat();
|
|
301
306
|
sortRanges(data.branches);
|
|
302
307
|
|
|
308
|
+
data.statements = statements.map((info) => {
|
|
309
|
+
return info.getRange();
|
|
310
|
+
});
|
|
311
|
+
sortRanges(data.statements);
|
|
312
|
+
|
|
303
313
|
// ==========================================
|
|
304
|
-
// lines
|
|
305
|
-
// after bytes with ignored, before calculateV8Lines
|
|
306
|
-
const {
|
|
307
|
-
lines, dataLines, blankCount, commentCount
|
|
308
|
-
} = handleLinesCoverage(data.bytes, locator, ignoredRanges);
|
|
309
314
|
|
|
310
|
-
|
|
315
|
+
const summary = {
|
|
316
|
+
functions: calculateV8Summary(data.functions),
|
|
317
|
+
branches: calculateV8Summary(data.branches),
|
|
318
|
+
statements: calculateV8Summary(data.statements),
|
|
319
|
+
lines: summaryLines
|
|
320
|
+
};
|
|
311
321
|
|
|
312
322
|
// ==========================================
|
|
313
323
|
// v8 data and summary
|
|
314
324
|
v8Data.data = data;
|
|
315
|
-
v8Data.summary =
|
|
316
|
-
functions: calculateV8Functions(data.functions),
|
|
317
|
-
branches: calculateV8Branches(data.branches),
|
|
318
|
-
lines: calculateV8Lines(lines, blankCount, commentCount)
|
|
319
|
-
};
|
|
325
|
+
v8Data.summary = summary;
|
|
320
326
|
|
|
321
327
|
// ==========================================
|
|
322
328
|
// istanbul
|
|
@@ -332,14 +338,13 @@ const collectFileCoverage = (v8Data, state, options) => {
|
|
|
332
338
|
b: {}
|
|
333
339
|
};
|
|
334
340
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
istanbulData.
|
|
338
|
-
istanbulData.s[`${index}`] = line.count;
|
|
341
|
+
statements.filter((it) => !it.ignored).forEach((statement, index) => {
|
|
342
|
+
istanbulData.statementMap[`${index}`] = statement.generate(locator);
|
|
343
|
+
istanbulData.s[`${index}`] = statement.count;
|
|
339
344
|
});
|
|
340
345
|
|
|
341
346
|
functions.filter((it) => !it.ignored).forEach((fn, index) => {
|
|
342
|
-
istanbulData.fnMap[`${index}`] = fn.generate(locator);
|
|
347
|
+
istanbulData.fnMap[`${index}`] = fn.generate(locator, index);
|
|
343
348
|
istanbulData.f[`${index}`] = fn.count;
|
|
344
349
|
});
|
|
345
350
|
|
|
@@ -349,7 +354,6 @@ const collectFileCoverage = (v8Data, state, options) => {
|
|
|
349
354
|
istanbulData.b[`${index}`] = counts;
|
|
350
355
|
});
|
|
351
356
|
|
|
352
|
-
// istanbul data
|
|
353
357
|
return istanbulData;
|
|
354
358
|
|
|
355
359
|
};
|
|
@@ -361,11 +365,17 @@ const addJsBytesCoverage = (state, range) => {
|
|
|
361
365
|
startOffset, endOffset, count
|
|
362
366
|
} = range;
|
|
363
367
|
// add bytes range
|
|
364
|
-
|
|
368
|
+
const byte = {
|
|
365
369
|
start: startOffset,
|
|
366
370
|
end: endOffset,
|
|
367
371
|
count
|
|
368
|
-
}
|
|
372
|
+
};
|
|
373
|
+
// for debug
|
|
374
|
+
if (Util.isDebug() && state.original) {
|
|
375
|
+
byte.generatedStart = range.generatedStart;
|
|
376
|
+
byte.generatedEnd = range.generatedEnd;
|
|
377
|
+
}
|
|
378
|
+
state.bytes.push(byte);
|
|
369
379
|
};
|
|
370
380
|
|
|
371
381
|
const addCssBytesCoverage = (state, range) => {
|
|
@@ -391,11 +401,14 @@ const handleFunctionsCoverage = (state) => {
|
|
|
391
401
|
|
|
392
402
|
const { functions, astInfo } = state;
|
|
393
403
|
astInfo.functions.forEach((it) => {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
404
|
+
|
|
405
|
+
const { start, end } = it;
|
|
406
|
+
if (start >= end) {
|
|
407
|
+
// console.log('invalid function', start, end);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
functions.push(new InfoFunction(it, state.original));
|
|
399
412
|
});
|
|
400
413
|
|
|
401
414
|
};
|
|
@@ -409,11 +422,35 @@ const handleBranchesCoverage = (state) => {
|
|
|
409
422
|
|
|
410
423
|
const { branches, astInfo } = state;
|
|
411
424
|
astInfo.branches.forEach((it) => {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
425
|
+
|
|
426
|
+
const { start, end } = it;
|
|
427
|
+
if (start >= end) {
|
|
428
|
+
// console.log('invalid branch', state.sourcePath, it);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
branches.push(new InfoBranch(it, state.original));
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
const handleStatementsCoverage = (state) => {
|
|
438
|
+
|
|
439
|
+
// statement only for js
|
|
440
|
+
if (!state.js) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const { statements, astInfo } = state;
|
|
445
|
+
astInfo.statements.forEach((it) => {
|
|
446
|
+
|
|
447
|
+
const { start, end } = it;
|
|
448
|
+
if (start >= end) {
|
|
449
|
+
// console.log('invalid statement', start, end);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
statements.push(new InfoStatement(it, state.original));
|
|
417
454
|
});
|
|
418
455
|
|
|
419
456
|
};
|
|
@@ -447,10 +484,22 @@ const handleOriginalFunctionsCoverage = (state, originalStateMap) => {
|
|
|
447
484
|
|
|
448
485
|
// console.log(state.astInfo.functions);
|
|
449
486
|
|
|
487
|
+
const updateFunctionBodyRange = (start, end, bodyStart, bodyEnd, originalFunction) => {
|
|
488
|
+
if (bodyStart !== start || bodyEnd !== end) {
|
|
489
|
+
const result = findOriginalRange(bodyStart, bodyEnd, state, originalStateMap);
|
|
490
|
+
if (result.error) {
|
|
491
|
+
logMappingErrors('function body', result);
|
|
492
|
+
} else {
|
|
493
|
+
originalFunction.bodyStart = result.start;
|
|
494
|
+
originalFunction.bodyEnd = result.end;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
|
|
450
499
|
// function count
|
|
451
500
|
state.astInfo.functions.forEach((it) => {
|
|
452
501
|
const {
|
|
453
|
-
start, end, wrap
|
|
502
|
+
start, end, bodyStart, bodyEnd, wrap
|
|
454
503
|
} = it;
|
|
455
504
|
|
|
456
505
|
// remove webpack wrap functions for functions count, not for ranges here
|
|
@@ -458,31 +507,27 @@ const handleOriginalFunctionsCoverage = (state, originalStateMap) => {
|
|
|
458
507
|
return;
|
|
459
508
|
}
|
|
460
509
|
|
|
461
|
-
|
|
462
|
-
const range = {
|
|
463
|
-
startOffset: start,
|
|
464
|
-
endOffset: end
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
const result = findOriginalRange(range, state, originalStateMap);
|
|
510
|
+
const result = findOriginalRange(start, end, state, originalStateMap);
|
|
468
511
|
if (result.error) {
|
|
512
|
+
logMappingErrors('function', result);
|
|
469
513
|
return;
|
|
470
514
|
}
|
|
471
|
-
const { originalRange, originalState } = result;
|
|
472
515
|
|
|
473
|
-
|
|
474
|
-
originalState.astInfo.functions.push({
|
|
516
|
+
const originalFunction = {
|
|
475
517
|
... it,
|
|
476
518
|
generatedStart: start,
|
|
477
519
|
generatedEnd: end,
|
|
478
|
-
start:
|
|
479
|
-
end:
|
|
480
|
-
|
|
520
|
+
start: result.start,
|
|
521
|
+
end: result.end,
|
|
522
|
+
bodyStart: result.start,
|
|
523
|
+
bodyEnd: result.end
|
|
524
|
+
};
|
|
481
525
|
|
|
482
|
-
//
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
//
|
|
526
|
+
// body start and end
|
|
527
|
+
updateFunctionBodyRange(start, end, bodyStart, bodyEnd, originalFunction);
|
|
528
|
+
|
|
529
|
+
// add back to original ast
|
|
530
|
+
result.originalState.astInfo.functions.push(originalFunction);
|
|
486
531
|
|
|
487
532
|
});
|
|
488
533
|
|
|
@@ -498,26 +543,20 @@ const handleOriginalBranchesCoverage = (state, originalStateMap) => {
|
|
|
498
543
|
// console.log(state.astInfo.branches);
|
|
499
544
|
|
|
500
545
|
// function count
|
|
501
|
-
state.astInfo.branches.forEach((
|
|
502
|
-
|
|
503
|
-
const { type, locations } = it;
|
|
546
|
+
state.astInfo.branches.forEach((group) => {
|
|
504
547
|
|
|
505
|
-
|
|
506
|
-
const bRange = {
|
|
507
|
-
startOffset: it.start,
|
|
508
|
-
endOffset: it.end
|
|
509
|
-
};
|
|
548
|
+
const { type, locations } = group;
|
|
510
549
|
|
|
511
550
|
// start
|
|
512
|
-
const result = findOriginalRange(
|
|
551
|
+
const result = findOriginalRange(group.start, group.end, state, originalStateMap);
|
|
513
552
|
if (result.error) {
|
|
514
|
-
|
|
553
|
+
logMappingErrors('branch group', result);
|
|
515
554
|
return;
|
|
516
555
|
}
|
|
517
|
-
const { originalRange, originalState } = result;
|
|
518
556
|
|
|
519
|
-
|
|
520
|
-
const
|
|
557
|
+
// new group start and end
|
|
558
|
+
const groupStart = result.start;
|
|
559
|
+
const groupEnd = result.end;
|
|
521
560
|
|
|
522
561
|
let hasError;
|
|
523
562
|
const newLocations = locations.map((oLoc) => {
|
|
@@ -532,29 +571,19 @@ const handleOriginalBranchesCoverage = (state, originalStateMap) => {
|
|
|
532
571
|
return newLoc;
|
|
533
572
|
}
|
|
534
573
|
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
const lRange = {
|
|
538
|
-
startOffset: start,
|
|
539
|
-
endOffset: end
|
|
540
|
-
};
|
|
541
|
-
const res = findOriginalRange(lRange, state, originalStateMap);
|
|
542
|
-
if (res.error) {
|
|
574
|
+
const locResult = findOriginalRange(newLoc.start, newLoc.end, state, originalStateMap);
|
|
575
|
+
if (locResult.error) {
|
|
543
576
|
// It should not happen unless it is minify files, the SourceMap has some order problems
|
|
544
|
-
|
|
577
|
+
logMappingErrors('branch', locResult);
|
|
545
578
|
hasError = true;
|
|
546
|
-
|
|
547
|
-
// console.log('====================================', state.sourcePath, loc);
|
|
548
|
-
// console.log(res.errors);
|
|
549
|
-
// Util.logError(`Not found original branch. start: ${start}, end: ${end}`);
|
|
550
|
-
|
|
551
579
|
return newLoc;
|
|
552
580
|
}
|
|
553
581
|
|
|
554
582
|
// mapping to new range
|
|
555
|
-
|
|
556
|
-
newLoc.
|
|
557
|
-
newLoc.
|
|
583
|
+
newLoc.start = locResult.start;
|
|
584
|
+
newLoc.end = locResult.end;
|
|
585
|
+
newLoc.generatedStart = newLoc.start;
|
|
586
|
+
newLoc.generatedEnd = newLoc.end;
|
|
558
587
|
|
|
559
588
|
return newLoc;
|
|
560
589
|
});
|
|
@@ -565,7 +594,7 @@ const handleOriginalBranchesCoverage = (state, originalStateMap) => {
|
|
|
565
594
|
}
|
|
566
595
|
|
|
567
596
|
// add back to original ast
|
|
568
|
-
originalState.astInfo.branches.push({
|
|
597
|
+
result.originalState.astInfo.branches.push({
|
|
569
598
|
type,
|
|
570
599
|
start: groupStart,
|
|
571
600
|
end: groupEnd,
|
|
@@ -576,6 +605,50 @@ const handleOriginalBranchesCoverage = (state, originalStateMap) => {
|
|
|
576
605
|
|
|
577
606
|
};
|
|
578
607
|
|
|
608
|
+
const handleOriginalStatementsCoverage = (state, originalStateMap) => {
|
|
609
|
+
|
|
610
|
+
// statements only for js
|
|
611
|
+
if (!state.js) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// statement count
|
|
616
|
+
state.astInfo.statements.forEach((it) => {
|
|
617
|
+
const { start, end } = it;
|
|
618
|
+
|
|
619
|
+
const result = findOriginalRange(start, end, state, originalStateMap);
|
|
620
|
+
if (result.error) {
|
|
621
|
+
logMappingErrors('statement', result);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// add back to original ast
|
|
626
|
+
result.originalState.astInfo.statements.push({
|
|
627
|
+
... it,
|
|
628
|
+
generatedStart: start,
|
|
629
|
+
generatedEnd: end,
|
|
630
|
+
start: result.start,
|
|
631
|
+
end: result.end
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
originalStateMap.forEach((originalState) => {
|
|
637
|
+
const statements = originalState.astInfo.statements;
|
|
638
|
+
if (Util.isList(statements)) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
// fake source nothing matched
|
|
642
|
+
statements.push({
|
|
643
|
+
start: 0,
|
|
644
|
+
end: originalState.source.length,
|
|
645
|
+
count: 1
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
};
|
|
651
|
+
|
|
579
652
|
const handleOriginalBytesCoverage = (state, originalStateMap) => {
|
|
580
653
|
|
|
581
654
|
const { js, coverageList } = state;
|
|
@@ -592,18 +665,23 @@ const handleOriginalBytesCoverage = (state, originalStateMap) => {
|
|
|
592
665
|
return;
|
|
593
666
|
}
|
|
594
667
|
|
|
595
|
-
const
|
|
668
|
+
const {
|
|
669
|
+
startOffset, endOffset, count
|
|
670
|
+
} = range;
|
|
671
|
+
|
|
672
|
+
const result = findOriginalRange(startOffset, endOffset, state, originalStateMap);
|
|
596
673
|
if (result.error) {
|
|
674
|
+
logMappingErrors('byte', result);
|
|
597
675
|
return;
|
|
598
676
|
}
|
|
599
677
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
678
|
+
addJsBytesCoverage(result.originalState, {
|
|
679
|
+
generatedStart: startOffset,
|
|
680
|
+
generatedEnd: endOffset,
|
|
681
|
+
startOffset: result.start,
|
|
682
|
+
endOffset: result.end,
|
|
683
|
+
count
|
|
684
|
+
});
|
|
607
685
|
|
|
608
686
|
});
|
|
609
687
|
});
|
|
@@ -633,7 +711,15 @@ const handleOriginalBytesCoverage = (state, originalStateMap) => {
|
|
|
633
711
|
const endMapping = decodedMappings[len - 1];
|
|
634
712
|
// console.log(startMapping, endMapping);
|
|
635
713
|
const startOffset = startMapping.generatedOffset;
|
|
636
|
-
|
|
714
|
+
|
|
715
|
+
if (!endMapping.generatedEndOffset) {
|
|
716
|
+
// line last one
|
|
717
|
+
const line = state.locator.getLine(endMapping.generatedLine + 1);
|
|
718
|
+
// last column
|
|
719
|
+
const toEndLength = line.length - endMapping.generatedColumn;
|
|
720
|
+
endMapping.generatedEndOffset = endMapping.generatedOffset + toEndLength;
|
|
721
|
+
}
|
|
722
|
+
const endOffset = endMapping.generatedEndOffset;
|
|
637
723
|
|
|
638
724
|
// console.log('===========================================================', originalState.sourcePath);
|
|
639
725
|
// console.log(originalState.source.length, endMapping);
|
|
@@ -674,11 +760,22 @@ const decodeSourceMappings = (state, originalDecodedMap) => {
|
|
|
674
760
|
});
|
|
675
761
|
|
|
676
762
|
const allDecodedMappings = [];
|
|
677
|
-
let generatedIndex = 0;
|
|
678
763
|
decodedList.forEach((segments, generatedLine) => {
|
|
679
764
|
let info = null;
|
|
680
765
|
segments.forEach((segment) => {
|
|
766
|
+
|
|
767
|
+
// const COLUMN = 0;
|
|
768
|
+
// const SOURCES_INDEX = 1;
|
|
769
|
+
// const SOURCE_LINE = 2;
|
|
770
|
+
// const SOURCE_COLUMN = 3;
|
|
771
|
+
// const NAMES_INDEX = 4;
|
|
681
772
|
const [generatedColumn, sourceIndex, originalLine, originalColumn] = segment;
|
|
773
|
+
// the segment length could be 1, 4 or 5
|
|
774
|
+
|
|
775
|
+
if (typeof sourceIndex === 'undefined') {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
|
|
682
779
|
const generatedOffset = generatedLocator.locationToOffset({
|
|
683
780
|
// 1-base
|
|
684
781
|
line: generatedLine + 1,
|
|
@@ -689,7 +786,6 @@ const decodeSourceMappings = (state, originalDecodedMap) => {
|
|
|
689
786
|
generatedOffset,
|
|
690
787
|
generatedLine,
|
|
691
788
|
generatedColumn,
|
|
692
|
-
generatedIndex,
|
|
693
789
|
|
|
694
790
|
sourceIndex,
|
|
695
791
|
originalLine,
|
|
@@ -697,23 +793,11 @@ const decodeSourceMappings = (state, originalDecodedMap) => {
|
|
|
697
793
|
};
|
|
698
794
|
|
|
699
795
|
allDecodedMappings.push(info);
|
|
700
|
-
generatedIndex += 1;
|
|
701
|
-
|
|
702
|
-
if (typeof sourceIndex === 'undefined') {
|
|
703
|
-
return;
|
|
704
|
-
}
|
|
705
796
|
|
|
706
797
|
originalDecodedMap.get(sourceIndex).push(info);
|
|
707
798
|
|
|
708
799
|
});
|
|
709
800
|
|
|
710
|
-
// line last one
|
|
711
|
-
if (info) {
|
|
712
|
-
const line = generatedLocator.getLine(info.generatedLine + 1);
|
|
713
|
-
// last column
|
|
714
|
-
info.generatedEndOffset = info.generatedOffset + (line.length - info.generatedColumn);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
801
|
});
|
|
718
802
|
|
|
719
803
|
// defaults to sort by generated offset, not need sort
|
|
@@ -802,9 +886,11 @@ const initOriginalList = (state, originalDecodedMap, options) => {
|
|
|
802
886
|
bytes: [],
|
|
803
887
|
functions: [],
|
|
804
888
|
branches: [],
|
|
889
|
+
statements: [],
|
|
805
890
|
astInfo: {
|
|
806
891
|
functions: [],
|
|
807
|
-
branches: []
|
|
892
|
+
branches: [],
|
|
893
|
+
statements: []
|
|
808
894
|
},
|
|
809
895
|
// coverage data
|
|
810
896
|
v8Data: {}
|
|
@@ -857,6 +943,7 @@ const generateCoverageForDist = (state) => {
|
|
|
857
943
|
|
|
858
944
|
handleFunctionsCoverage(state);
|
|
859
945
|
handleBranchesCoverage(state);
|
|
946
|
+
handleStatementsCoverage(state);
|
|
860
947
|
handleBytesCoverage(state);
|
|
861
948
|
|
|
862
949
|
};
|
|
@@ -888,12 +975,14 @@ const unpackSourceMap = (state, options) => {
|
|
|
888
975
|
// handle functions before handle original state functions
|
|
889
976
|
handleOriginalFunctionsCoverage(state, originalStateMap);
|
|
890
977
|
handleOriginalBranchesCoverage(state, originalStateMap);
|
|
978
|
+
handleOriginalStatementsCoverage(state, originalStateMap);
|
|
891
979
|
|
|
892
980
|
// handle lines info before handle ranges to update line count
|
|
893
981
|
originalStateMap.forEach((originalState) => {
|
|
894
982
|
|
|
895
983
|
handleFunctionsCoverage(originalState);
|
|
896
984
|
handleBranchesCoverage(originalState);
|
|
985
|
+
handleStatementsCoverage(originalState);
|
|
897
986
|
|
|
898
987
|
// if (originalState.sourcePath.endsWith('demo.js')) {
|
|
899
988
|
// console.log('=================================', originalState.sourcePath);
|
|
@@ -901,7 +990,7 @@ const unpackSourceMap = (state, options) => {
|
|
|
901
990
|
|
|
902
991
|
});
|
|
903
992
|
|
|
904
|
-
// handle ranges
|
|
993
|
+
// handle bytes ranges
|
|
905
994
|
handleOriginalBytesCoverage(state, originalStateMap);
|
|
906
995
|
|
|
907
996
|
// collect coverage for original list
|
|
@@ -912,7 +1001,7 @@ const unpackSourceMap = (state, options) => {
|
|
|
912
1001
|
const unpackDistFile = (item, state, options) => {
|
|
913
1002
|
|
|
914
1003
|
if (state.sourceMap) {
|
|
915
|
-
if (Util.
|
|
1004
|
+
if (Util.isDebug()) {
|
|
916
1005
|
// js self
|
|
917
1006
|
item.debug = true;
|
|
918
1007
|
generateCoverageForDist(state);
|
|
@@ -1217,7 +1306,7 @@ const convertV8List = (v8list, options) => {
|
|
|
1217
1306
|
if (js) {
|
|
1218
1307
|
coverageList = filterCoverageList(item);
|
|
1219
1308
|
// remove original functions
|
|
1220
|
-
if (Util.
|
|
1309
|
+
if (!Util.isDebug()) {
|
|
1221
1310
|
delete item.functions;
|
|
1222
1311
|
}
|
|
1223
1312
|
astInfo = getJsAstInfo(item, coverageList);
|
|
@@ -1225,11 +1314,12 @@ const convertV8List = (v8list, options) => {
|
|
|
1225
1314
|
// convent css covered ranges to rules ranges and include uncovered ranges
|
|
1226
1315
|
astInfo = getCssAstInfo(item, coverageList);
|
|
1227
1316
|
// remove original ranges
|
|
1228
|
-
if (Util.
|
|
1317
|
+
if (!Util.isDebug()) {
|
|
1229
1318
|
delete item.ranges;
|
|
1230
1319
|
}
|
|
1231
1320
|
}
|
|
1232
1321
|
|
|
1322
|
+
// console.log(sourcePath, astInfo.statements.length);
|
|
1233
1323
|
// ============================
|
|
1234
1324
|
|
|
1235
1325
|
// current file and it's sources from sourceMap
|
|
@@ -1246,6 +1336,7 @@ const convertV8List = (v8list, options) => {
|
|
|
1246
1336
|
bytes: [],
|
|
1247
1337
|
functions: [],
|
|
1248
1338
|
branches: [],
|
|
1339
|
+
statements: [],
|
|
1249
1340
|
astInfo,
|
|
1250
1341
|
// for sub source files
|
|
1251
1342
|
coverageList,
|