Skip to content

Commit f242e01

Browse files
committed
revise the variable name back to "t" for consistency
1 parent 54c8a96 commit f242e01

File tree

10 files changed

+66
-72
lines changed

10 files changed

+66
-72
lines changed

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import templateLiterals from './visitors/templateLiterals'
55
import assignStyledRequired from './visitors/assignStyledRequired'
66
import rewriteStyledImport from './visitors/rewriteStyledImport'
77

8-
export default function({ types }) {
8+
export default function({ types: t }) {
99
return {
1010
visitor: {
1111
ImportDeclaration(path, state) {
12-
rewriteStyledImport(types)(path, state)
12+
rewriteStyledImport(t)(path, state)
1313
},
1414
MemberExpression(path, state) {
15-
desugarStyled(types)(path, state)
15+
desugarStyled(t)(path, state)
1616
},
1717
TaggedTemplateExpression(path, state) {
18-
minify(types)(path, state)
19-
displayNameAndId(types)(path, state)
20-
templateLiterals(types)(path, state)
18+
minify(t)(path, state)
19+
displayNameAndId(t)(path, state)
20+
templateLiterals(t)(path, state)
2121
},
2222
VariableDeclarator(path, state) {
23-
assignStyledRequired(types)(path, state)
23+
assignStyledRequired(t)(path, state)
2424
},
2525
},
2626
}

src/utils/detectors.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ const importLocalName = (name, state) => {
4141
return localName
4242
}
4343

44-
export const isStyled = types => (tag, state) => {
44+
export const isStyled = t => (tag, state) => {
4545
if (
46-
types.isCallExpression(tag) &&
47-
types.isMemberExpression(tag.callee) &&
46+
t.isCallExpression(tag) &&
47+
t.isMemberExpression(tag.callee) &&
4848
tag.callee.property.name !== 'default' /** ignore default for #93 below */
4949
) {
5050
// styled.something()
51-
return isStyled(types)(tag.callee.object, state)
51+
return isStyled(t)(tag.callee.object, state)
5252
} else {
5353
return (
54-
(types.isMemberExpression(tag) &&
54+
(t.isMemberExpression(tag) &&
5555
tag.object.name === importLocalName('default', state)) ||
56-
(types.isCallExpression(tag) &&
56+
(t.isCallExpression(tag) &&
5757
tag.callee.name === importLocalName('default', state)) ||
5858
/**
5959
* #93 Support require()
@@ -63,31 +63,31 @@ export const isStyled = types => (tag, state) => {
6363
* - styled.default.something()
6464
*/
6565
(state.styledRequired &&
66-
types.isMemberExpression(tag) &&
67-
types.isMemberExpression(tag.object) &&
66+
t.isMemberExpression(tag) &&
67+
t.isMemberExpression(tag.object) &&
6868
tag.object.property.name === 'default' &&
6969
tag.object.object.name === state.styledRequired) ||
7070
(state.styledRequired &&
71-
types.isCallExpression(tag) &&
72-
types.isMemberExpression(tag.callee) &&
71+
t.isCallExpression(tag) &&
72+
t.isMemberExpression(tag.callee) &&
7373
tag.callee.property.name === 'default' &&
7474
tag.callee.object.name === state.styledRequired)
7575
)
7676
}
7777
}
7878

79-
export const isCSSHelper = types => (tag, state) =>
80-
types.isIdentifier(tag) && tag.name === importLocalName('css', state)
79+
export const isCSSHelper = t => (tag, state) =>
80+
t.isIdentifier(tag) && tag.name === importLocalName('css', state)
8181

82-
export const isCreateGlobalStyleHelper = types => (tag, state) =>
83-
types.isIdentifier(tag) &&
82+
export const isCreateGlobalStyleHelper = t => (tag, state) =>
83+
t.isIdentifier(tag) &&
8484
tag.name === importLocalName('createGlobalStyle', state)
8585

86-
export const isInjectGlobalHelper = types => (tag, state) =>
87-
types.isIdentifier(tag) && tag.name === importLocalName('injectGlobal', state)
86+
export const isInjectGlobalHelper = t => (tag, state) =>
87+
t.isIdentifier(tag) && tag.name === importLocalName('injectGlobal', state)
8888

89-
export const isKeyframesHelper = types => (tag, state) =>
90-
types.isIdentifier(tag) && tag.name === importLocalName('keyframes', state)
89+
export const isKeyframesHelper = t => (tag, state) =>
90+
t.isIdentifier(tag) && tag.name === importLocalName('keyframes', state)
9191

92-
export const isHelper = types => (tag, state) =>
93-
isCSSHelper(types)(tag, state) || isKeyframesHelper(types)(tag, state)
92+
export const isHelper = t => (tag, state) =>
93+
isCSSHelper(t)(tag, state) || isKeyframesHelper(t)(tag, state)

src/utils/getName.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @return {String} The target
77
*/
88

9-
export default types => path => {
9+
export default t => path => {
1010
let namedNode
1111

1212
path.find(path => {
@@ -32,10 +32,10 @@ export default types => path => {
3232
})
3333

3434
// foo.bar -> bar
35-
if (types.isMemberExpression(namedNode)) {
35+
if (t.isMemberExpression(namedNode)) {
3636
namedNode = namedNode.property
3737
}
3838

3939
// identifiers are the only thing we can reliably get a name from
40-
return types.isIdentifier(namedNode) ? namedNode.name : undefined
40+
return t.isIdentifier(namedNode) ? namedNode.name : undefined
4141
}

src/visitors/assignStyledRequired.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { isValidTopLevelImport } from '../utils/detectors'
22

3-
export default types => (path, state) => {
3+
export default t => (path, state) => {
44
if (
5-
types.isCallExpression(path.node.init) &&
6-
types.isIdentifier(path.node.init.callee) &&
5+
t.isCallExpression(path.node.init) &&
6+
t.isIdentifier(path.node.init.callee) &&
77
path.node.init.callee.name === 'require' &&
88
path.node.init.arguments &&
99
path.node.init.arguments[0] &&
10-
types.isLiteral(path.node.init.arguments[0]) &&
10+
t.isLiteral(path.node.init.arguments[0]) &&
1111
isValidTopLevelImport(path.node.init.arguments[0].value)
1212
) {
1313
state.styledRequired = path.node.id.name

src/visitors/desugarStyled.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import get from 'lodash/get'
22
import { isStyled } from '../utils/detectors'
33

4-
export default types => (path, state) => {
4+
export default t => (path, state) => {
55
/**
66
* Handles both "styled.div" and "styled_default.default.div" (transpiled output)
77
*/
8-
if (isStyled(types)(path.node, state)) {
8+
if (isStyled(t)(path.node, state)) {
99
/**
1010
* e.g. "div"
1111
*/
@@ -16,17 +16,15 @@ export default types => (path, state) => {
1616
* "styled_default.default.div", we want to preserve the "styled_default.default"
1717
* part and just reuse that AST object.
1818
*/
19-
const leftSide = types.isMemberExpression(path.node.object)
19+
const leftSide = t.isMemberExpression(path.node.object)
2020
? path.node.object
21-
: types.identifier(path.node.object.name)
21+
: t.identifier(path.node.object.name)
2222

2323
if (sugar) {
2424
/**
2525
* "styled.div" -> "styled('div')"
2626
*/
27-
path.replaceWith(
28-
types.callExpression(leftSide, [types.stringLiteral(sugar)])
29-
)
27+
path.replaceWith(t.callExpression(leftSide, [t.stringLiteral(sugar)]))
3028
}
3129
}
3230
}

src/visitors/displayNameAndId.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ import prefixLeadingDigit from '../utils/prefixDigit'
66
import hash from '../utils/hash'
77
import { isStyled } from '../utils/detectors'
88

9-
const addConfig = types => (path, displayName, componentId) => {
9+
const addConfig = t => (path, displayName, componentId) => {
1010
if (!displayName && !componentId) {
1111
return
1212
}
1313

1414
const withConfigProps = []
1515
if (displayName) {
1616
withConfigProps.push(
17-
types.objectProperty(
18-
types.identifier('displayName'),
19-
types.stringLiteral(displayName)
17+
t.objectProperty(
18+
t.identifier('displayName'),
19+
t.stringLiteral(displayName)
2020
)
2121
)
2222
}
2323
if (componentId) {
2424
withConfigProps.push(
25-
types.objectProperty(
26-
types.identifier('componentId'),
27-
types.stringLiteral(componentId)
25+
t.objectProperty(
26+
t.identifier('componentId'),
27+
t.stringLiteral(componentId)
2828
)
2929
)
3030
}
3131

3232
// Replace x`...` with x.withConfig({ })`...`
33-
path.node.tag = types.callExpression(
34-
types.memberExpression(path.node.tag, types.identifier('withConfig')),
35-
[types.objectExpression(withConfigProps)]
33+
path.node.tag = t.callExpression(
34+
t.memberExpression(path.node.tag, t.identifier('withConfig')),
35+
[t.objectExpression(withConfigProps)]
3636
)
3737
}
3838

@@ -46,9 +46,9 @@ const getBlockName = file => {
4646
: path.basename(path.dirname(file.opts.filename))
4747
}
4848

49-
const getDisplayName = types => (path, state) => {
49+
const getDisplayName = t => (path, state) => {
5050
const { file } = state
51-
const componentName = getName(types)(path)
51+
const componentName = getName(t)(path)
5252
if (file) {
5353
const blockName = getBlockName(file)
5454
if (blockName === componentName) {
@@ -121,13 +121,13 @@ const getComponentId = state => {
121121
return `${prefixLeadingDigit(getFileHash(state))}-${getNextId(state)}`
122122
}
123123

124-
export default types => (path, state) => {
125-
if (isStyled(types)(path.node.tag, state)) {
124+
export default t => (path, state) => {
125+
if (isStyled(t)(path.node.tag, state)) {
126126
const displayName =
127127
useDisplayName(state) &&
128-
getDisplayName(types)(path, useFileName(state) && state)
128+
getDisplayName(t)(path, useFileName(state) && state)
129129

130-
addConfig(types)(
130+
addConfig(t)(
131131
path,
132132
displayName && displayName.replace(/[^_a-zA-Z0-9-]/g, ''),
133133
useSSR(state) && getComponentId(state)

src/visitors/minify.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { useMinify } from '../utils/options'
22
import { isStyled, isHelper } from '../utils/detectors'
33
import { minifyRawValues, minifyCookedValues } from '../minify'
44

5-
export default types => (path, state) => {
5+
export default t => (path, state) => {
66
if (
77
useMinify(state) &&
8-
(isStyled(types)(path.node.tag, state) ||
9-
isHelper(types)(path.node.tag, state))
8+
(isStyled(t)(path.node.tag, state) || isHelper(t)(path.node.tag, state))
109
) {
1110
const templateLiteral = path.node.quasi
1211
const quasisLength = templateLiteral.quasis.length

src/visitors/rewriteStyledImport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* then use a lighter-weight version of s-c since those element names don't need to be kept around
44
* ahead of time.
55
*/
6-
export default types => path => {
6+
export default t => path => {
77
if (path.node.source.value === 'styled-components') {
8-
path.node.source = types.stringLiteral('styled-components/no-tags')
8+
path.node.source = t.stringLiteral('styled-components/no-tags')
99
}
1010
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useTranspileTemplateLiterals } from '../../utils/options'
22
import transpile from './transpile'
33

4-
export default types => (path, state) => {
4+
export default t => (path, state) => {
55
if (useTranspileTemplateLiterals(state)) {
6-
transpile(types)(path, state)
6+
transpile(t)(path, state)
77
}
88
}
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import { isStyled, isHelper } from '../../utils/detectors'
22

3-
export default types => (path, state) => {
4-
if (
5-
isStyled(types)(path.node.tag, state) ||
6-
isHelper(types)(path.node.tag, state)
7-
) {
3+
export default t => (path, state) => {
4+
if (isStyled(t)(path.node.tag, state) || isHelper(t)(path.node.tag, state)) {
85
const {
96
tag: callee,
107
quasi: { quasis, expressions },
118
} = path.node
129

13-
const values = types.arrayExpression(
14-
quasis.map(quasi => types.stringLiteral(quasi.value.cooked))
10+
const values = t.arrayExpression(
11+
quasis.map(quasi => t.stringLiteral(quasi.value.cooked))
1512
)
1613

17-
path.replaceWith(types.callExpression(callee, [values, ...expressions]))
14+
path.replaceWith(t.callExpression(callee, [values, ...expressions]))
1815
}
1916
}

0 commit comments

Comments
 (0)