-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel-logger-transformer.js
40 lines (35 loc) · 1.42 KB
/
babel-logger-transformer.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
// Injects nashorn global for filename and the typescript line number
// as arguments for our custom logger functions
const transformLogger = ({ types: t }) => {
class BabelTransformLogger {
constructor() {
return {
visitor: {
CallExpression: {
exit(path) {
const { node } = path;
if (!node.callee.object || node.callee.object.name !== 'logger') {
return;
}
const line = node.loc.start.line.toString();
if (!node.arguments[1]) {
node.arguments[1] = t.identifier('undefined');
}
if (!node.arguments[2]) {
node.arguments[2] = t.identifier('undefined');
}
if (!node.arguments[3]) {
node.arguments[3] = t.identifier('__FILE__');
}
if (!node.arguments[4]) {
node.arguments[4] = t.stringLiteral(line);
}
},
},
},
};
}
}
return new BabelTransformLogger();
};
export default transformLogger;