source: trip-planner-front/node_modules/istanbul-lib-instrument/dist/source-coverage.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.SourceCoverage = void 0;
7
8var _istanbulLibCoverage = require("istanbul-lib-coverage");
9
10function cloneLocation(loc) {
11 return {
12 start: {
13 line: loc && loc.start.line,
14 column: loc && loc.start.column
15 },
16 end: {
17 line: loc && loc.end.line,
18 column: loc && loc.end.column
19 }
20 };
21}
22/**
23 * SourceCoverage provides mutation methods to manipulate the structure of
24 * a file coverage object. Used by the instrumenter to create a full coverage
25 * object for a file incrementally.
26 *
27 * @private
28 * @param pathOrObj {String|Object} - see the argument for {@link FileCoverage}
29 * @extends FileCoverage
30 * @constructor
31 */
32
33
34class SourceCoverage extends _istanbulLibCoverage.classes.FileCoverage {
35 constructor(pathOrObj) {
36 super(pathOrObj);
37 this.meta = {
38 last: {
39 s: 0,
40 f: 0,
41 b: 0
42 }
43 };
44 }
45
46 newStatement(loc) {
47 const s = this.meta.last.s;
48 this.data.statementMap[s] = cloneLocation(loc);
49 this.data.s[s] = 0;
50 this.meta.last.s += 1;
51 return s;
52 }
53
54 newFunction(name, decl, loc) {
55 const f = this.meta.last.f;
56 name = name || '(anonymous_' + f + ')';
57 this.data.fnMap[f] = {
58 name,
59 decl: cloneLocation(decl),
60 loc: cloneLocation(loc),
61 // DEPRECATED: some legacy reports require this info.
62 line: loc && loc.start.line
63 };
64 this.data.f[f] = 0;
65 this.meta.last.f += 1;
66 return f;
67 }
68
69 newBranch(type, loc) {
70 const b = this.meta.last.b;
71 this.data.b[b] = [];
72 this.data.branchMap[b] = {
73 loc: cloneLocation(loc),
74 type,
75 locations: [],
76 // DEPRECATED: some legacy reports require this info.
77 line: loc && loc.start.line
78 };
79 this.meta.last.b += 1;
80 return b;
81 }
82
83 addBranchPath(name, location) {
84 const bMeta = this.data.branchMap[name];
85 const counts = this.data.b[name];
86 /* istanbul ignore if: paranoid check */
87
88 if (!bMeta) {
89 throw new Error('Invalid branch ' + name);
90 }
91
92 bMeta.locations.push(cloneLocation(location));
93 counts.push(0);
94 return counts.length - 1;
95 }
96 /**
97 * Assigns an input source map to the coverage that can be used
98 * to remap the coverage output to the original source
99 * @param sourceMap {object} the source map
100 */
101
102
103 inputSourceMap(sourceMap) {
104 this.data.inputSourceMap = sourceMap;
105 }
106
107 freeze() {
108 // prune empty branches
109 const map = this.data.branchMap;
110 const branches = this.data.b;
111 Object.keys(map).forEach(b => {
112 if (map[b].locations.length === 0) {
113 delete map[b];
114 delete branches[b];
115 }
116 });
117 }
118
119}
120
121exports.SourceCoverage = SourceCoverage;
Note: See TracBrowser for help on using the repository browser.