-
Notifications
You must be signed in to change notification settings - Fork 6
/
macro.js
31 lines (29 loc) · 887 Bytes
/
macro.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
const { createMacro } = require('babel-plugin-macros');
const { getLogFunction, handleLabeledStatement } = require('.');
function macro({
babel,
config: {
aliases,
strip,
warningLabels = ['warn']
} = {},
references,
state
}) {
const refNames = Object.keys(references).filter(ref => ref !== 'default');
if (refNames.length > 0) {
aliases = refNames.reduce((map, key) => {
const logLevel = warningLabels && warningLabels.includes(key) ? 'warn' : 'log';
map[key] = getLogFunction(babel, logLevel);
return map;
}, {});
}
if (references.default) references.default.forEach(({ parentPath }) => parentPath.remove());
const opts = { aliases, strip };
state.file.path.traverse({
LabeledStatement (path) {
handleLabeledStatement(babel, path, opts);
}
});
}
module.exports = createMacro(macro, { configName: 'trace' });