-
-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (50 loc) · 1.7 KB
/
Copy pathindex.js
File metadata and controls
51 lines (50 loc) · 1.7 KB
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
45
46
47
48
49
50
51
import syntax from 'babel-plugin-syntax-jsx'
import pureAnnotation from './visitors/pure'
import pureInlineCalculations from './visitors/pureInlineCalculations'
import minify from './visitors/minify'
import displayNameAndId from './visitors/displayNameAndId'
import templateLiterals from './visitors/templateLiterals'
import assignStyledRequired from './visitors/assignStyledRequired'
import transpileCssProp from './visitors/transpileCssProp'
import pureWrapStaticProps from './visitors/pureWrapStaticProps'
export default function({ types: t }) {
return {
inherits: syntax,
visitor: {
Program(path, state) {
path.traverse(
{
JSXAttribute(path, state) {
transpileCssProp(t)(path, state)
},
VariableDeclarator(path, state) {
assignStyledRequired(t)(path, state)
},
},
state
)
},
CallExpression(path, state) {
displayNameAndId(t)(path, state)
pureAnnotation(t)(path, state)
},
TaggedTemplateExpression(path, state) {
pureInlineCalculations(t)(path, state)
minify(t)(path, state)
displayNameAndId(t)(path, state)
templateLiterals(t)(path, state)
pureAnnotation(t)(path, state)
},
FunctionDeclaration(path, state) {
// technically this is more like,
// "mark pure if it's a function component that consumes a styled component and also has static properties",
// but that's rather long ;)
pureWrapStaticProps(t)(path, state)
},
VariableDeclarator(path, state) {
// same thing for arrow functions
pureWrapStaticProps(t)(path, state)
},
},
}
}