monocart-coverage-reports 2.9.2 → 2.10.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.
@@ -1,166 +1,186 @@
1
- const { decode } = require('@jridgewell/sourcemap-codec');
2
-
3
- function getLine(arr, index) {
4
- for (let i = arr.length; i <= index; i++) {
5
- arr[i] = [];
6
- }
7
- return arr[index];
8
- }
9
-
10
- function addMappings(options, sourcesOffset) {
11
-
12
- const {
13
- input,
14
- lineOffset,
15
- columnOffset,
16
- stopLine,
17
- stopColumn
18
- } = options;
19
-
20
- const decoded = decode(input.mappings);
21
- const COLUMN = 0;
22
- const SOURCES_INDEX = 1;
23
- const SOURCE_LINE = 2;
24
- const SOURCE_COLUMN = 3;
25
-
26
- for (let i = 0; i < decoded.length; i++) {
27
- const lineI = lineOffset + i;
28
-
29
- if (lineI > stopLine) {
30
- return;
31
- }
32
-
33
- const out = getLine(options.decodedMappings, lineI);
34
- const cOffset = i === 0 ? columnOffset : 0;
35
-
36
- const line = decoded[i];
37
- for (let j = 0; j < line.length; j++) {
38
- const seg = line[j];
39
- const column = cOffset + seg[COLUMN];
40
-
41
- if (lineI === stopLine && column >= stopColumn) {
42
- return;
43
- }
44
-
45
- if (seg.length === 1) {
46
- out.push([column]);
47
- continue;
48
- }
49
-
50
- const sourcesIndex = sourcesOffset + seg[SOURCES_INDEX];
51
- const sourceLine = seg[SOURCE_LINE];
52
- const sourceColumn = seg[SOURCE_COLUMN];
53
- out.push([column, sourcesIndex, sourceLine, sourceColumn]);
54
- }
55
- }
56
- }
57
-
58
- function addSection(options) {
59
-
60
- const { input } = options;
61
-
62
- const { sections } = input;
63
- if (sections) {
64
- return flatten(options);
65
- }
66
-
67
- const sourcesOffset = options.sources.length;
68
-
69
- if (!input.sourcesContent) {
70
- input.sourcesContent = [];
71
- }
72
- input.sources.forEach((src, i) => {
73
- options.sources.push(src);
74
- options.sourcesContent.push(input.sourcesContent[i] || null);
75
- });
76
-
77
- addMappings(options, sourcesOffset);
78
-
79
- }
80
-
81
- function flatten(options) {
82
-
83
- const {
84
- input,
85
- lineOffset,
86
- columnOffset,
87
- stopLine,
88
- stopColumn
89
- } = options;
90
-
91
- const { sections } = input;
92
-
93
- for (let i = 0, l = sections.length; i < l; i++) {
94
- const { map, offset } = sections[i];
95
-
96
- let sl = stopLine;
97
- let sc = stopColumn;
98
- if (i + 1 < sections.length) {
99
- const nextOffset = sections[i + 1].offset;
100
- sl = Math.min(stopLine, lineOffset + nextOffset.line);
101
-
102
- if (sl === stopLine) {
103
- sc = Math.min(stopColumn, columnOffset + nextOffset.column);
104
- } else if (sl < stopLine) {
105
- sc = columnOffset + nextOffset.column;
106
- }
107
- }
108
-
109
- options.input = map;
110
- options.lineOffset = lineOffset + offset.line;
111
- options.columnOffset = columnOffset + offset.column;
112
- options.stopLine = sl;
113
- options.stopColumn = sc;
114
-
115
- addSection(options);
116
- }
117
- }
118
-
119
- const flattenSourceMaps = function(indexedMap, mapUrl) {
120
-
121
- const sections = indexedMap.sections;
122
- if (!sections) {
123
- return indexedMap;
124
- }
125
-
126
- const decodedMappings = [];
127
- const sources = [];
128
- const sourcesContent = [];
129
- const names = [];
130
- const ignoreList = [];
131
-
132
- const lineOffset = 0;
133
- const columnOffset = 0;
134
- const stopLine = Infinity;
135
- const stopColumn = Infinity;
136
-
137
- flatten({
138
- input: indexedMap,
139
-
140
- mapUrl,
141
-
142
- decodedMappings,
143
- sources,
144
- sourcesContent,
145
-
146
- names,
147
- ignoreList,
148
-
149
- lineOffset,
150
- columnOffset,
151
- stopLine,
152
- stopColumn
153
- });
154
-
155
- indexedMap.sources = sources;
156
- indexedMap.sourcesContent = sourcesContent;
157
- indexedMap.decodedMappings = decodedMappings;
158
-
159
- // console.log(decodedMappings);
160
-
161
- return indexedMap;
162
- };
163
-
164
- module.exports = {
165
- flattenSourceMaps
166
- };
1
+ const { decode } = require('@jridgewell/sourcemap-codec');
2
+
3
+ const COLUMN = 0;
4
+ const SOURCES_INDEX = 1;
5
+ const SOURCE_LINE = 2;
6
+ const SOURCE_COLUMN = 3;
7
+ const NAMES_INDEX = 4;
8
+
9
+ function getLine(arr, index) {
10
+ for (let i = arr.length; i <= index; i++) {
11
+ arr[i] = [];
12
+ }
13
+ return arr[index];
14
+ }
15
+
16
+ function getMapping(seg, column, sourcesOffset, namesOffset) {
17
+
18
+ const sourcesIndex = sourcesOffset + seg[SOURCES_INDEX];
19
+ const sourceLine = seg[SOURCE_LINE];
20
+ const sourceColumn = seg[SOURCE_COLUMN];
21
+
22
+ if (seg.length === 4) {
23
+ return [column, sourcesIndex, sourceLine, sourceColumn];
24
+ }
25
+
26
+ return [column, sourcesIndex, sourceLine, sourceColumn, namesOffset + seg[NAMES_INDEX]];
27
+ }
28
+
29
+ function addMappings(options, sourcesOffset, namesOffset) {
30
+
31
+ const {
32
+ input,
33
+ lineOffset,
34
+ columnOffset,
35
+ stopLine,
36
+ stopColumn
37
+ } = options;
38
+
39
+ const decoded = decode(input.mappings);
40
+
41
+ for (let i = 0; i < decoded.length; i++) {
42
+ const lineI = lineOffset + i;
43
+
44
+ if (lineI > stopLine) {
45
+ return;
46
+ }
47
+
48
+ const out = getLine(options.decodedMappings, lineI);
49
+ const cOffset = i === 0 ? columnOffset : 0;
50
+
51
+ const line = decoded[i];
52
+ for (let j = 0; j < line.length; j++) {
53
+ const seg = line[j];
54
+ const column = cOffset + seg[COLUMN];
55
+
56
+ if (lineI === stopLine && column >= stopColumn) {
57
+ return;
58
+ }
59
+
60
+ if (seg.length === 1) {
61
+ out.push([column]);
62
+ continue;
63
+ }
64
+
65
+ out.push(getMapping(seg, column, sourcesOffset, namesOffset));
66
+ }
67
+ }
68
+ }
69
+
70
+ function addSection(options) {
71
+
72
+ const { input } = options;
73
+
74
+ const { sections } = input;
75
+ if (sections) {
76
+ return flatten(options);
77
+ }
78
+
79
+ const sourcesOffset = options.sources.length;
80
+ const namesOffset = options.names.length;
81
+
82
+ // sources and sourcesContent
83
+ if (!input.sourcesContent) {
84
+ input.sourcesContent = [];
85
+ }
86
+ input.sources.forEach((src, i) => {
87
+ options.sources.push(src);
88
+ options.sourcesContent.push(input.sourcesContent[i] || null);
89
+ });
90
+
91
+ // names
92
+ if (input.names) {
93
+ input.names.forEach((n) => {
94
+ options.names.push(n);
95
+ });
96
+ }
97
+
98
+ addMappings(options, sourcesOffset, namesOffset);
99
+
100
+ }
101
+
102
+ function flatten(options) {
103
+
104
+ const {
105
+ input,
106
+ lineOffset,
107
+ columnOffset,
108
+ stopLine,
109
+ stopColumn
110
+ } = options;
111
+
112
+ const { sections } = input;
113
+
114
+ for (let i = 0, l = sections.length; i < l; i++) {
115
+ const { map, offset } = sections[i];
116
+
117
+ let sl = stopLine;
118
+ let sc = stopColumn;
119
+ if (i + 1 < sections.length) {
120
+ const nextOffset = sections[i + 1].offset;
121
+ sl = Math.min(stopLine, lineOffset + nextOffset.line);
122
+
123
+ if (sl === stopLine) {
124
+ sc = Math.min(stopColumn, columnOffset + nextOffset.column);
125
+ } else if (sl < stopLine) {
126
+ sc = columnOffset + nextOffset.column;
127
+ }
128
+ }
129
+
130
+ options.input = map;
131
+ options.lineOffset = lineOffset + offset.line;
132
+ options.columnOffset = columnOffset + offset.column;
133
+ options.stopLine = sl;
134
+ options.stopColumn = sc;
135
+
136
+ addSection(options);
137
+ }
138
+ }
139
+
140
+ const flattenSourceMaps = function(indexedMap, mapUrl) {
141
+
142
+ const sections = indexedMap.sections;
143
+ if (!sections) {
144
+ return indexedMap;
145
+ }
146
+
147
+ const decodedMappings = [];
148
+ const sources = [];
149
+ const sourcesContent = [];
150
+ const names = [];
151
+
152
+ const lineOffset = 0;
153
+ const columnOffset = 0;
154
+ const stopLine = Infinity;
155
+ const stopColumn = Infinity;
156
+
157
+ flatten({
158
+ input: indexedMap,
159
+
160
+ mapUrl,
161
+
162
+ decodedMappings,
163
+ sources,
164
+ sourcesContent,
165
+
166
+ names,
167
+
168
+ lineOffset,
169
+ columnOffset,
170
+ stopLine,
171
+ stopColumn
172
+ });
173
+
174
+ indexedMap.sources = sources;
175
+ indexedMap.sourcesContent = sourcesContent;
176
+ indexedMap.names = names;
177
+ indexedMap.decodedMappings = decodedMappings;
178
+
179
+ // console.log(decodedMappings);
180
+
181
+ return indexedMap;
182
+ };
183
+
184
+ module.exports = {
185
+ flattenSourceMaps
186
+ };
@@ -69,16 +69,77 @@ const addNextIgnore = (list, content, item, locator) => {
69
69
  };
70
70
 
71
71
  // both v8 or c8
72
- const hasIgnoreKey = (content) => {
73
- const v8Key = 'v8 ignore';
74
- if (content.startsWith(v8Key)) {
75
- return v8Key.length;
72
+ const getStartEndNextInfo = (content) => {
73
+ content = content.trim();
74
+
75
+ const start = 'start';
76
+ const stop = 'stop';
77
+ const next = 'next';
78
+ if (content.startsWith(start)) {
79
+ return {
80
+ type: 'range',
81
+ value: stop
82
+ };
76
83
  }
77
- const c8Key = 'c8 ignore';
78
- if (content.startsWith(c8Key)) {
79
- return c8Key.length;
84
+ if (content.startsWith(stop)) {
85
+ return {
86
+ type: 'range',
87
+ value: stop
88
+ };
89
+ }
90
+ if (content.startsWith(next)) {
91
+ return {
92
+ type: 'next',
93
+ value: content.slice(next.length)
94
+ };
95
+ }
96
+ };
97
+
98
+ const getDisableEnableNextInfo = (content) => {
99
+ content = content.trim();
100
+
101
+ const start = 'disable';
102
+ const stop = 'enable';
103
+ const next = 'ignore next';
104
+ if (content.startsWith(start)) {
105
+ return {
106
+ type: 'range',
107
+ value: stop
108
+ };
109
+ }
110
+ if (content.startsWith(stop)) {
111
+ return {
112
+ type: 'range',
113
+ value: stop
114
+ };
115
+ }
116
+ if (content.startsWith(next)) {
117
+ return {
118
+ type: 'next',
119
+ value: content.slice(next.length)
120
+ };
80
121
  }
81
- // istanbul ignore has different rules, can not support it
122
+ };
123
+
124
+
125
+ const getIgnoreInfo = (content) => {
126
+ content = content.trim();
127
+
128
+ const v8_ignore = 'v8 ignore';
129
+ if (content.startsWith(v8_ignore)) {
130
+ return getStartEndNextInfo(content.slice(v8_ignore.length));
131
+ }
132
+
133
+ const c8_ignore = 'c8 ignore';
134
+ if (content.startsWith(c8_ignore)) {
135
+ return getStartEndNextInfo(content.slice(c8_ignore.length));
136
+ }
137
+
138
+ const node_coverage = 'node:coverage';
139
+ if (content.startsWith(node_coverage)) {
140
+ return getDisableEnableNextInfo(content.slice(node_coverage.length));
141
+ }
142
+
82
143
  };
83
144
 
84
145
  const getIgnoredRanges = (locator, options) => {
@@ -101,42 +162,43 @@ const getIgnoredRanges = (locator, options) => {
101
162
  const {
102
163
  block, start, end, text
103
164
  } = item;
104
- let content = block ? text.slice(2, -2) : text.slice(2);
105
- content = content.trim();
106
165
 
107
- const ignoreKey = hasIgnoreKey(content);
108
- if (!ignoreKey) {
166
+ const content = block ? text.slice(2, -2) : text.slice(2);
167
+ const ignoreInfo = getIgnoreInfo(content);
168
+ if (!ignoreInfo) {
109
169
  return;
110
170
  }
111
171
 
112
- content = content.slice(ignoreKey).trim();
172
+ const { type, value } = ignoreInfo;
113
173
 
114
174
  if (ignoreStart) {
115
175
  // v-8 ignore stop
116
- if (content === 'stop') {
117
- ignoreStart.end = extendEnd(end, source, maxLength);
176
+ if (type === 'range' && value === ignoreStart.value) {
177
+ ignoreStart.ignoreData.end = extendEnd(end, source, maxLength);
118
178
  ignoreStart = null;
119
179
  }
120
180
  return;
121
181
  }
122
182
 
123
183
  // v-8 ignore start
124
- if (content === 'start') {
184
+ if (type === 'range') {
125
185
  // add first for sort by start
126
- ignoreStart = {
127
- type: 'start-stop',
186
+ const ignoreData = {
187
+ type,
128
188
  start: extendStart(start, source),
129
189
  end: start
130
190
  };
131
- list.push(ignoreStart);
191
+ list.push(ignoreData);
192
+ ignoreStart = {
193
+ ignoreData,
194
+ value
195
+ };
132
196
  return;
133
197
  }
134
198
 
135
- // v-8 ignore next N
136
- const nextKey = 'next';
137
- if (content.startsWith(nextKey)) {
138
- content = content.slice(nextKey.length).trim();
139
- addNextIgnore(list, content, item, locator);
199
+ // next N
200
+ if (type === 'next') {
201
+ addNextIgnore(list, value.trim(), item, locator);
140
202
  }
141
203
 
142
204
  });
@@ -16,8 +16,13 @@ module.exports = class InfoFunction {
16
16
  this.original = original;
17
17
  }
18
18
 
19
- getRange() {
19
+ getName(index) {
20
+ return this.functionName || `(anonymous_${index})`;
21
+ }
22
+
23
+ getRange(index) {
20
24
  const range = {
25
+ name: this.getName(index),
21
26
  start: this.start,
22
27
  end: this.end,
23
28
  count: this.count
@@ -51,10 +56,8 @@ module.exports = class InfoFunction {
51
56
 
52
57
  const line = loc.start.line;
53
58
 
54
- const functionName = this.functionName || `(anonymous_${index})`;
55
-
56
59
  return {
57
- name: functionName,
60
+ name: this.getName(index),
58
61
  decl: decl,
59
62
  loc: loc,
60
63
  line: line