-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (36 loc) · 1.12 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
43
44
const babel = require('@babel/core');
module.exports = function () {
const LogVisitor = {
CallExpression(path, state) {
const { callee, arguments } = path.node;
if (callee.object && callee.object.name === 'console') {
const styles = state.opts.types[callee.property.name];
if (styles) {
let parsedStylesToString = '';
let divider;
Object.keys().forEach((key) => {
if (key === 'divider') {
divider = styles[key];
} else {
parsedStylesToString = `${key}: ${styled[key]}`;
}
});
const str = arguments
.map((arg) => {
if (arg.type === 'StringLiteral') {
return arg.value;
}
})
.join(divider || '');
const newArgs = [
babel.types.stringLiteral(`%c${str}`),
babel.types.stringLiteral(parsedStylesToString),
];
path.node.arguments = newArgs;
path.node.callee.property.name = 'log';
}
}
},
};
return { visitor: LogVisitor };
};