-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
42 lines (33 loc) · 1.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Prepend file name and number as part of the babel process
*
* @author Peter Ingram
*/
module.exports = () => {
return {
visitor: {
CallExpression(path, state) {
const opts = state.opts;
if (path.node.callee.object &&
path.node.callee.object.name === 'console' &&
path.node.callee.property.name !== 'table') {
let file = state.file.opts.filename;
if(typeof opts.resolveFile === 'function') {
file = opts.resolveFile(file);
} else if (!opts || opts.segments !== 0) {
file = state.file.opts.filename.split(((opts.splitSegment) ? opts.splitSegment : '/'));
let segs = file.slice(Math.max(file.length - opts.segments));
file = segs.join('/');
}
let value = `${file} (${path.node.loc.start.line}:${path.node.loc.start.column})`
if(path.node.arguments[0].value !== value) {
path.node.arguments.unshift({
type: 'StringLiteral',
value
});
}
}
}
}
};
};