/
index.js
35 lines (32 loc) · 1.04 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
const jsx = require('@babel/plugin-syntax-jsx');
const TaggedTemplateExpression = require('./visitors/TaggedTemplateExpression');
const CallExpression = require('./visitors/CallExpression');
const StyleSheet = require('../StyleSheet');
function cssZeroBabelPlugin(babel) {
const {types} = babel;
return {
name: 'css-zero',
inherits: jsx.default,
visitor: {
Program: {
enter(path, state) {
state.styleSheet = new StyleSheet();
// We need our transforms to run before anything else
// So we traverse here instead of a in a visitor
path.traverse({
TaggedTemplateExpression: p => TaggedTemplateExpression(p, state, types),
});
},
exit(_path, state) {
const {styleSheet} = state;
// Store the result as the file metadata
state.file.metadata = {cssZero: styleSheet};
},
},
CallExpression(path, state) {
CallExpression(path, state, types);
},
},
};
}
module.exports = cssZeroBabelPlugin;