escover 1.3.0 → 1.3.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/ChangeLog +9 -0
- package/lib/c4.js +4 -4
- package/lib/coverage.js +47 -0
- package/lib/escover.js +7 -1
- package/lib/exit.js +1 -0
- package/lib/instrument/index.js +2 -2
- package/lib/instrument/plugin-mark/index.js +6 -7
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/c4.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
1
|
+
export const __fileEntries = new Map();
|
|
2
2
|
|
|
3
3
|
export const createFileEntry = (url) => {
|
|
4
|
-
const lines =
|
|
5
|
-
|
|
4
|
+
const lines = __fileEntries.get(url) || new Map();
|
|
5
|
+
__fileEntries.set(url, lines);
|
|
6
6
|
|
|
7
7
|
return {
|
|
8
8
|
'🧨': (line, column) => {
|
|
@@ -14,4 +14,4 @@ export const createFileEntry = (url) => {
|
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export const
|
|
17
|
+
export const getFileEntries = () => __fileEntries;
|
package/lib/coverage.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import tryCatch from 'try-catch';
|
|
2
|
+
import {
|
|
3
|
+
writeFileSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
} from 'fs';
|
|
6
|
+
import {getFileEntries} from './c4.js';
|
|
7
|
+
import {transform} from './transform.js';
|
|
8
|
+
import {merge} from './merge.js';
|
|
9
|
+
import findCacheDir from 'find-cache-dir';
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
stringify,
|
|
13
|
+
parse,
|
|
14
|
+
} = JSON;
|
|
15
|
+
|
|
16
|
+
const NAME = 'escover';
|
|
17
|
+
const buildName = (a) => `${a}/${NAME}.json`;
|
|
18
|
+
|
|
19
|
+
export const write = () => {
|
|
20
|
+
const files = getFileEntries();
|
|
21
|
+
|
|
22
|
+
if (!files.size)
|
|
23
|
+
return;
|
|
24
|
+
|
|
25
|
+
const parsed = transform(files);
|
|
26
|
+
const merged = merge(parsed);
|
|
27
|
+
const name = findCacheDir({
|
|
28
|
+
name: NAME,
|
|
29
|
+
create: true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
writeFileSync(buildName(name), stringify(merged, null, 4));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const read = () => {
|
|
36
|
+
const name = findCacheDir({
|
|
37
|
+
name: NAME,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const [error, data] = tryCatch(readFileSync, buildName(name), 'utf8');
|
|
41
|
+
|
|
42
|
+
if (error)
|
|
43
|
+
return [];
|
|
44
|
+
|
|
45
|
+
return parse(data);
|
|
46
|
+
};
|
|
47
|
+
|
package/lib/escover.js
CHANGED
|
@@ -10,7 +10,13 @@ global.__createC4 = createFileEntry;
|
|
|
10
10
|
|
|
11
11
|
process.once('exit', exit);
|
|
12
12
|
|
|
13
|
-
const EXCLUDE = [
|
|
13
|
+
const EXCLUDE = [
|
|
14
|
+
'.spec.',
|
|
15
|
+
'node_modules',
|
|
16
|
+
'/fixture/',
|
|
17
|
+
'.madrun.',
|
|
18
|
+
'/test/',
|
|
19
|
+
];
|
|
14
20
|
|
|
15
21
|
export async function load(url, context, defaultLoad) {
|
|
16
22
|
const {format, source: rawSource} = await defaultLoad(url, context, defaultLoad);
|
package/lib/exit.js
CHANGED
package/lib/instrument/index.js
CHANGED
|
@@ -3,11 +3,11 @@ import putout, {} from 'putout';
|
|
|
3
3
|
import * as mark from './plugin-mark/index.js';
|
|
4
4
|
|
|
5
5
|
export const instrument = (url, source) => {
|
|
6
|
-
const
|
|
6
|
+
const c4 = global.__createC4(url);
|
|
7
7
|
const options = {
|
|
8
8
|
rules: {
|
|
9
9
|
mark: ['on', {
|
|
10
|
-
|
|
10
|
+
c4,
|
|
11
11
|
}],
|
|
12
12
|
},
|
|
13
13
|
plugins: [
|
|
@@ -23,8 +23,8 @@ const buildLineNode = template(LINE, {
|
|
|
23
23
|
placeholderPattern: /^__[a-z]$/,
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
function getLineNode(
|
|
27
|
-
|
|
26
|
+
function getLineNode(c4, {line, column}) {
|
|
27
|
+
c4.init(line, column);
|
|
28
28
|
|
|
29
29
|
return buildLineNode({
|
|
30
30
|
__l: NumericLiteral(line),
|
|
@@ -46,13 +46,13 @@ export const fix = (path, {options}) => {
|
|
|
46
46
|
return;
|
|
47
47
|
|
|
48
48
|
const {
|
|
49
|
-
|
|
49
|
+
c4 = {
|
|
50
50
|
mark: () => {},
|
|
51
51
|
init: () => {},
|
|
52
52
|
},
|
|
53
53
|
} = options;
|
|
54
54
|
|
|
55
|
-
const lineNode = getLineNode(
|
|
55
|
+
const lineNode = getLineNode(c4, start);
|
|
56
56
|
|
|
57
57
|
if (path.isBlockStatement()) {
|
|
58
58
|
path.node.body.unshift(lineNode);
|
|
@@ -74,7 +74,7 @@ export const fix = (path, {options}) => {
|
|
|
74
74
|
path.node.left,
|
|
75
75
|
]));
|
|
76
76
|
replaceWith(path.get('right'), SequenceExpression([
|
|
77
|
-
getLineNode(
|
|
77
|
+
getLineNode(c4, path.node.right.loc.start).expression,
|
|
78
78
|
path.node.right,
|
|
79
79
|
]));
|
|
80
80
|
return;
|
|
@@ -99,9 +99,8 @@ export const fix = (path, {options}) => {
|
|
|
99
99
|
if (path.isReturnStatement())
|
|
100
100
|
return addMarkToReturn(path, lineNode);
|
|
101
101
|
|
|
102
|
-
if (path.isArrowFunctionExpression())
|
|
102
|
+
if (path.isArrowFunctionExpression())
|
|
103
103
|
return addMarkToArrowFunction(path, lineNode);
|
|
104
|
-
}
|
|
105
104
|
|
|
106
105
|
if (path.isThrowStatement())
|
|
107
106
|
return addMarkToThrow(path, lineNode);
|