monocart-coverage-reports 2.5.9 → 2.6.1
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/LICENSE +21 -21
- package/README.md +791 -778
- package/lib/cli.js +250 -215
- package/lib/converter/ast-visitor.js +675 -666
- package/lib/converter/ast.js +353 -353
- package/lib/converter/collect-source-maps.js +201 -201
- package/lib/converter/converter.js +1487 -1429
- package/lib/converter/find-original-range.js +737 -737
- package/lib/converter/ignore.js +163 -163
- package/lib/converter/info-branch.js +93 -93
- package/lib/converter/info-function.js +63 -63
- package/lib/converter/info-statement.js +43 -43
- package/lib/default/options.js +84 -84
- package/lib/default/template.html +47 -47
- package/lib/generate.js +720 -532
- package/lib/index.d.ts +360 -324
- package/lib/index.js +187 -180
- package/lib/index.mjs +5 -3
- package/lib/istanbul/istanbul-summary.js +70 -63
- package/lib/istanbul/istanbul.js +146 -146
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/platform/concurrency.js +74 -74
- package/lib/platform/share.js +484 -484
- package/lib/utils/dedupe.js +118 -118
- package/lib/utils/request.js +62 -62
- package/lib/utils/snapshot.js +381 -0
- package/lib/utils/source-path.js +179 -179
- package/lib/utils/util.js +526 -526
- package/lib/v8/v8-summary.js +138 -138
- package/lib/v8/v8.js +400 -630
- package/package.json +81 -80
package/lib/converter/ignore.js
CHANGED
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
const Util = require('../utils/util.js');
|
|
2
|
-
|
|
3
|
-
const getNextN = (content, currentLine, item, locator) => {
|
|
4
|
-
|
|
5
|
-
// v-8 ignore next N
|
|
6
|
-
if (content) {
|
|
7
|
-
const n = parseInt(content);
|
|
8
|
-
if (n && n > 0) {
|
|
9
|
-
return n;
|
|
10
|
-
}
|
|
11
|
-
return 1;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// block comment not end of line, same line
|
|
15
|
-
if (item.block) {
|
|
16
|
-
// has code between comment and line end
|
|
17
|
-
const text = locator.getSlice(item.end, currentLine.end).trim();
|
|
18
|
-
if (text) {
|
|
19
|
-
return 0;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// v-8 ignore next
|
|
24
|
-
return 1;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const extendStart = (start, source) => {
|
|
28
|
-
// extend left, include
|
|
29
|
-
while (start > 0 && Util.isBlank(source[start - 1])) {
|
|
30
|
-
start -= 1;
|
|
31
|
-
}
|
|
32
|
-
return start;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const extendEnd = (end, source, maxLength) => {
|
|
36
|
-
// extend right, exclude
|
|
37
|
-
while (end < maxLength && Util.isBlank(source[end])) {
|
|
38
|
-
end += 1;
|
|
39
|
-
}
|
|
40
|
-
return end;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const addNextIgnore = (list, content, item, locator) => {
|
|
44
|
-
|
|
45
|
-
const { lineParser, source } = locator;
|
|
46
|
-
const maxLength = source.length;
|
|
47
|
-
|
|
48
|
-
const start = extendStart(item.start, source);
|
|
49
|
-
|
|
50
|
-
// findLine 0-base
|
|
51
|
-
const currentLine = lineParser.findLine(item.end);
|
|
52
|
-
const n = getNextN(content, currentLine, item, locator);
|
|
53
|
-
|
|
54
|
-
// console.log('current line', currentLine.line, 'lines', lines);
|
|
55
|
-
|
|
56
|
-
// getLine 1-base
|
|
57
|
-
const line = currentLine.line + 1;
|
|
58
|
-
const endLine = locator.getLine(line + n);
|
|
59
|
-
const end = extendEnd(endLine ? endLine.end : maxLength, source, maxLength);
|
|
60
|
-
|
|
61
|
-
const nextItem = {
|
|
62
|
-
type: 'next',
|
|
63
|
-
n,
|
|
64
|
-
start,
|
|
65
|
-
end
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
list.push(nextItem);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// both v8 or c8
|
|
72
|
-
const hasIgnoreKey = (content) => {
|
|
73
|
-
const v8Key = 'v8 ignore';
|
|
74
|
-
if (content.startsWith(v8Key)) {
|
|
75
|
-
return v8Key.length;
|
|
76
|
-
}
|
|
77
|
-
const c8Key = 'c8 ignore';
|
|
78
|
-
if (content.startsWith(c8Key)) {
|
|
79
|
-
return c8Key.length;
|
|
80
|
-
}
|
|
81
|
-
// istanbul ignore has different rules, can not support it
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const getIgnoredRanges = (locator, options) => {
|
|
85
|
-
if (!options.v8Ignore) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const { lineParser, source } = locator;
|
|
90
|
-
const maxLength = source.length;
|
|
91
|
-
|
|
92
|
-
const comments = lineParser.comments;
|
|
93
|
-
if (!Util.isList(comments)) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const list = [];
|
|
98
|
-
let ignoreStart = null;
|
|
99
|
-
|
|
100
|
-
comments.forEach((item) => {
|
|
101
|
-
const {
|
|
102
|
-
block, start, end, text
|
|
103
|
-
} = item;
|
|
104
|
-
let content = block ? text.slice(2, -2) : text.slice(2);
|
|
105
|
-
content = content.trim();
|
|
106
|
-
|
|
107
|
-
const ignoreKey = hasIgnoreKey(content);
|
|
108
|
-
if (!ignoreKey) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
content = content.slice(ignoreKey).trim();
|
|
113
|
-
|
|
114
|
-
if (ignoreStart) {
|
|
115
|
-
// v-8 ignore stop
|
|
116
|
-
if (content === 'stop') {
|
|
117
|
-
ignoreStart.end = extendEnd(end, source, maxLength);
|
|
118
|
-
ignoreStart = null;
|
|
119
|
-
}
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// v-8 ignore start
|
|
124
|
-
if (content === 'start') {
|
|
125
|
-
// add first for sort by start
|
|
126
|
-
ignoreStart = {
|
|
127
|
-
type: 'start-stop',
|
|
128
|
-
start: extendStart(start, source),
|
|
129
|
-
end: start
|
|
130
|
-
};
|
|
131
|
-
list.push(ignoreStart);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
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);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// ignore not stop
|
|
145
|
-
if (ignoreStart) {
|
|
146
|
-
ignoreStart.end = locator.source.length;
|
|
147
|
-
ignoreStart = null;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (!list.length) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// console.log('=============================================');
|
|
155
|
-
// console.log(list);
|
|
156
|
-
|
|
157
|
-
return list;
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
module.exports = {
|
|
162
|
-
getIgnoredRanges
|
|
163
|
-
};
|
|
1
|
+
const Util = require('../utils/util.js');
|
|
2
|
+
|
|
3
|
+
const getNextN = (content, currentLine, item, locator) => {
|
|
4
|
+
|
|
5
|
+
// v-8 ignore next N
|
|
6
|
+
if (content) {
|
|
7
|
+
const n = parseInt(content);
|
|
8
|
+
if (n && n > 0) {
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// block comment not end of line, same line
|
|
15
|
+
if (item.block) {
|
|
16
|
+
// has code between comment and line end
|
|
17
|
+
const text = locator.getSlice(item.end, currentLine.end).trim();
|
|
18
|
+
if (text) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// v-8 ignore next
|
|
24
|
+
return 1;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const extendStart = (start, source) => {
|
|
28
|
+
// extend left, include
|
|
29
|
+
while (start > 0 && Util.isBlank(source[start - 1])) {
|
|
30
|
+
start -= 1;
|
|
31
|
+
}
|
|
32
|
+
return start;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const extendEnd = (end, source, maxLength) => {
|
|
36
|
+
// extend right, exclude
|
|
37
|
+
while (end < maxLength && Util.isBlank(source[end])) {
|
|
38
|
+
end += 1;
|
|
39
|
+
}
|
|
40
|
+
return end;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const addNextIgnore = (list, content, item, locator) => {
|
|
44
|
+
|
|
45
|
+
const { lineParser, source } = locator;
|
|
46
|
+
const maxLength = source.length;
|
|
47
|
+
|
|
48
|
+
const start = extendStart(item.start, source);
|
|
49
|
+
|
|
50
|
+
// findLine 0-base
|
|
51
|
+
const currentLine = lineParser.findLine(item.end);
|
|
52
|
+
const n = getNextN(content, currentLine, item, locator);
|
|
53
|
+
|
|
54
|
+
// console.log('current line', currentLine.line, 'lines', lines);
|
|
55
|
+
|
|
56
|
+
// getLine 1-base
|
|
57
|
+
const line = currentLine.line + 1;
|
|
58
|
+
const endLine = locator.getLine(line + n);
|
|
59
|
+
const end = extendEnd(endLine ? endLine.end : maxLength, source, maxLength);
|
|
60
|
+
|
|
61
|
+
const nextItem = {
|
|
62
|
+
type: 'next',
|
|
63
|
+
n,
|
|
64
|
+
start,
|
|
65
|
+
end
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
list.push(nextItem);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// both v8 or c8
|
|
72
|
+
const hasIgnoreKey = (content) => {
|
|
73
|
+
const v8Key = 'v8 ignore';
|
|
74
|
+
if (content.startsWith(v8Key)) {
|
|
75
|
+
return v8Key.length;
|
|
76
|
+
}
|
|
77
|
+
const c8Key = 'c8 ignore';
|
|
78
|
+
if (content.startsWith(c8Key)) {
|
|
79
|
+
return c8Key.length;
|
|
80
|
+
}
|
|
81
|
+
// istanbul ignore has different rules, can not support it
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const getIgnoredRanges = (locator, options) => {
|
|
85
|
+
if (!options.v8Ignore) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const { lineParser, source } = locator;
|
|
90
|
+
const maxLength = source.length;
|
|
91
|
+
|
|
92
|
+
const comments = lineParser.comments;
|
|
93
|
+
if (!Util.isList(comments)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const list = [];
|
|
98
|
+
let ignoreStart = null;
|
|
99
|
+
|
|
100
|
+
comments.forEach((item) => {
|
|
101
|
+
const {
|
|
102
|
+
block, start, end, text
|
|
103
|
+
} = item;
|
|
104
|
+
let content = block ? text.slice(2, -2) : text.slice(2);
|
|
105
|
+
content = content.trim();
|
|
106
|
+
|
|
107
|
+
const ignoreKey = hasIgnoreKey(content);
|
|
108
|
+
if (!ignoreKey) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
content = content.slice(ignoreKey).trim();
|
|
113
|
+
|
|
114
|
+
if (ignoreStart) {
|
|
115
|
+
// v-8 ignore stop
|
|
116
|
+
if (content === 'stop') {
|
|
117
|
+
ignoreStart.end = extendEnd(end, source, maxLength);
|
|
118
|
+
ignoreStart = null;
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// v-8 ignore start
|
|
124
|
+
if (content === 'start') {
|
|
125
|
+
// add first for sort by start
|
|
126
|
+
ignoreStart = {
|
|
127
|
+
type: 'start-stop',
|
|
128
|
+
start: extendStart(start, source),
|
|
129
|
+
end: start
|
|
130
|
+
};
|
|
131
|
+
list.push(ignoreStart);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
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);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// ignore not stop
|
|
145
|
+
if (ignoreStart) {
|
|
146
|
+
ignoreStart.end = locator.source.length;
|
|
147
|
+
ignoreStart = null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!list.length) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// console.log('=============================================');
|
|
155
|
+
// console.log(list);
|
|
156
|
+
|
|
157
|
+
return list;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
module.exports = {
|
|
162
|
+
getIgnoredRanges
|
|
163
|
+
};
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
const Util = require('../utils/util.js');
|
|
2
|
-
module.exports = class InfoBranch {
|
|
3
|
-
constructor(data, original) {
|
|
4
|
-
const {
|
|
5
|
-
start, end, locations, type
|
|
6
|
-
} = data;
|
|
7
|
-
|
|
8
|
-
this.start = start;
|
|
9
|
-
this.end = end;
|
|
10
|
-
this.locations = locations;
|
|
11
|
-
this.type = type;
|
|
12
|
-
this.data = data;
|
|
13
|
-
this.original = original;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getRanges() {
|
|
17
|
-
return this.locations.map((item) => {
|
|
18
|
-
const range = {
|
|
19
|
-
start: item.start,
|
|
20
|
-
end: item.end,
|
|
21
|
-
count: item.count
|
|
22
|
-
};
|
|
23
|
-
if (item.none) {
|
|
24
|
-
range.none = true;
|
|
25
|
-
}
|
|
26
|
-
if (item.ignored) {
|
|
27
|
-
range.ignored = true;
|
|
28
|
-
}
|
|
29
|
-
// for debug
|
|
30
|
-
if (Util.isDebug() && this.original) {
|
|
31
|
-
range.generatedStart = item.generatedStart;
|
|
32
|
-
range.generatedEnd = item.generatedEnd;
|
|
33
|
-
}
|
|
34
|
-
return range;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
generate(locator) {
|
|
39
|
-
const groupLoc = {
|
|
40
|
-
start: this.start,
|
|
41
|
-
end: this.end
|
|
42
|
-
};
|
|
43
|
-
Util.updateOffsetToLocation(locator, groupLoc);
|
|
44
|
-
const line = groupLoc.start.line;
|
|
45
|
-
|
|
46
|
-
// remove ignored
|
|
47
|
-
// do NOT change previous number type to object, need used for sourcemap
|
|
48
|
-
const newLocations = this.locations.filter((it) => !it.ignored).map((it) => {
|
|
49
|
-
const item = {
|
|
50
|
-
start: it.start,
|
|
51
|
-
end: it.end,
|
|
52
|
-
none: it.none,
|
|
53
|
-
count: it.count
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// [ { start:{line,column}, end:{line,column}, count }, ...]
|
|
57
|
-
Util.updateOffsetToLocation(locator, item);
|
|
58
|
-
|
|
59
|
-
return item;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const map = {
|
|
63
|
-
loc: groupLoc,
|
|
64
|
-
type: this.type,
|
|
65
|
-
locations: newLocations.map((item) => {
|
|
66
|
-
const {
|
|
67
|
-
start, end, none
|
|
68
|
-
} = item;
|
|
69
|
-
if (none) {
|
|
70
|
-
// none with group start/end, should be empty for istanbul
|
|
71
|
-
return {
|
|
72
|
-
start: {},
|
|
73
|
-
end: {}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
start,
|
|
78
|
-
end
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
}),
|
|
82
|
-
line: line
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const counts = newLocations.map((item) => item.count);
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
map,
|
|
89
|
-
counts
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
};
|
|
1
|
+
const Util = require('../utils/util.js');
|
|
2
|
+
module.exports = class InfoBranch {
|
|
3
|
+
constructor(data, original) {
|
|
4
|
+
const {
|
|
5
|
+
start, end, locations, type
|
|
6
|
+
} = data;
|
|
7
|
+
|
|
8
|
+
this.start = start;
|
|
9
|
+
this.end = end;
|
|
10
|
+
this.locations = locations;
|
|
11
|
+
this.type = type;
|
|
12
|
+
this.data = data;
|
|
13
|
+
this.original = original;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getRanges() {
|
|
17
|
+
return this.locations.map((item) => {
|
|
18
|
+
const range = {
|
|
19
|
+
start: item.start,
|
|
20
|
+
end: item.end,
|
|
21
|
+
count: item.count
|
|
22
|
+
};
|
|
23
|
+
if (item.none) {
|
|
24
|
+
range.none = true;
|
|
25
|
+
}
|
|
26
|
+
if (item.ignored) {
|
|
27
|
+
range.ignored = true;
|
|
28
|
+
}
|
|
29
|
+
// for debug
|
|
30
|
+
if (Util.isDebug() && this.original) {
|
|
31
|
+
range.generatedStart = item.generatedStart;
|
|
32
|
+
range.generatedEnd = item.generatedEnd;
|
|
33
|
+
}
|
|
34
|
+
return range;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
generate(locator) {
|
|
39
|
+
const groupLoc = {
|
|
40
|
+
start: this.start,
|
|
41
|
+
end: this.end
|
|
42
|
+
};
|
|
43
|
+
Util.updateOffsetToLocation(locator, groupLoc);
|
|
44
|
+
const line = groupLoc.start.line;
|
|
45
|
+
|
|
46
|
+
// remove ignored
|
|
47
|
+
// do NOT change previous number type to object, need used for sourcemap
|
|
48
|
+
const newLocations = this.locations.filter((it) => !it.ignored).map((it) => {
|
|
49
|
+
const item = {
|
|
50
|
+
start: it.start,
|
|
51
|
+
end: it.end,
|
|
52
|
+
none: it.none,
|
|
53
|
+
count: it.count
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// [ { start:{line,column}, end:{line,column}, count }, ...]
|
|
57
|
+
Util.updateOffsetToLocation(locator, item);
|
|
58
|
+
|
|
59
|
+
return item;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const map = {
|
|
63
|
+
loc: groupLoc,
|
|
64
|
+
type: this.type,
|
|
65
|
+
locations: newLocations.map((item) => {
|
|
66
|
+
const {
|
|
67
|
+
start, end, none
|
|
68
|
+
} = item;
|
|
69
|
+
if (none) {
|
|
70
|
+
// none with group start/end, should be empty for istanbul
|
|
71
|
+
return {
|
|
72
|
+
start: {},
|
|
73
|
+
end: {}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
start,
|
|
78
|
+
end
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
}),
|
|
82
|
+
line: line
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const counts = newLocations.map((item) => item.count);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
map,
|
|
89
|
+
counts
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
};
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
const Util = require('../utils/util.js');
|
|
2
|
-
module.exports = class InfoFunction {
|
|
3
|
-
constructor(data, original) {
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
start, end, bodyStart, bodyEnd, functionName, count
|
|
7
|
-
} = data;
|
|
8
|
-
|
|
9
|
-
this.start = start;
|
|
10
|
-
this.end = end;
|
|
11
|
-
this.bodyStart = bodyStart;
|
|
12
|
-
this.bodyEnd = bodyEnd;
|
|
13
|
-
this.count = count;
|
|
14
|
-
this.functionName = functionName;
|
|
15
|
-
this.data = data;
|
|
16
|
-
this.original = original;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getRange() {
|
|
20
|
-
const range = {
|
|
21
|
-
start: this.start,
|
|
22
|
-
end: this.end,
|
|
23
|
-
count: this.count
|
|
24
|
-
};
|
|
25
|
-
if (this.ignored) {
|
|
26
|
-
range.ignored = true;
|
|
27
|
-
}
|
|
28
|
-
// for debug
|
|
29
|
-
if (Util.isDebug() && this.original) {
|
|
30
|
-
range.generatedStart = this.data.generatedStart;
|
|
31
|
-
range.generatedEnd = this.data.generatedEnd;
|
|
32
|
-
}
|
|
33
|
-
return range;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
generate(locator, index) {
|
|
37
|
-
|
|
38
|
-
const decl = {
|
|
39
|
-
start: this.start,
|
|
40
|
-
end: this.bodyStart
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
Util.updateOffsetToLocation(locator, decl);
|
|
44
|
-
|
|
45
|
-
const loc = {
|
|
46
|
-
start: this.bodyStart,
|
|
47
|
-
end: this.end
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
Util.updateOffsetToLocation(locator, loc);
|
|
51
|
-
|
|
52
|
-
const line = loc.start.line;
|
|
53
|
-
|
|
54
|
-
const functionName = this.functionName || `(anonymous_${index})`;
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
name: functionName,
|
|
58
|
-
decl: decl,
|
|
59
|
-
loc: loc,
|
|
60
|
-
line: line
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
};
|
|
1
|
+
const Util = require('../utils/util.js');
|
|
2
|
+
module.exports = class InfoFunction {
|
|
3
|
+
constructor(data, original) {
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
start, end, bodyStart, bodyEnd, functionName, count
|
|
7
|
+
} = data;
|
|
8
|
+
|
|
9
|
+
this.start = start;
|
|
10
|
+
this.end = end;
|
|
11
|
+
this.bodyStart = bodyStart;
|
|
12
|
+
this.bodyEnd = bodyEnd;
|
|
13
|
+
this.count = count;
|
|
14
|
+
this.functionName = functionName;
|
|
15
|
+
this.data = data;
|
|
16
|
+
this.original = original;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getRange() {
|
|
20
|
+
const range = {
|
|
21
|
+
start: this.start,
|
|
22
|
+
end: this.end,
|
|
23
|
+
count: this.count
|
|
24
|
+
};
|
|
25
|
+
if (this.ignored) {
|
|
26
|
+
range.ignored = true;
|
|
27
|
+
}
|
|
28
|
+
// for debug
|
|
29
|
+
if (Util.isDebug() && this.original) {
|
|
30
|
+
range.generatedStart = this.data.generatedStart;
|
|
31
|
+
range.generatedEnd = this.data.generatedEnd;
|
|
32
|
+
}
|
|
33
|
+
return range;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
generate(locator, index) {
|
|
37
|
+
|
|
38
|
+
const decl = {
|
|
39
|
+
start: this.start,
|
|
40
|
+
end: this.bodyStart
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
Util.updateOffsetToLocation(locator, decl);
|
|
44
|
+
|
|
45
|
+
const loc = {
|
|
46
|
+
start: this.bodyStart,
|
|
47
|
+
end: this.end
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
Util.updateOffsetToLocation(locator, loc);
|
|
51
|
+
|
|
52
|
+
const line = loc.start.line;
|
|
53
|
+
|
|
54
|
+
const functionName = this.functionName || `(anonymous_${index})`;
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
name: functionName,
|
|
58
|
+
decl: decl,
|
|
59
|
+
loc: loc,
|
|
60
|
+
line: line
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|