Skip to content

Commit ae36dfe

Browse files
author
Evan Jacobs
committed
one more tweak for babel macro
1 parent 84660e3 commit ae36dfe

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/utils/detectors.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ export const importLocalName = (name, state, options = {}) => {
2121
const cacheKeyAffix = cacheIdentifier ? `|${cacheIdentifier}` : ''
2222
const cacheKey = name + state.file.opts.filename + cacheKeyAffix
2323

24-
if (!bypassCache && cacheKey in localNameCache) {
25-
return localNameCache[cacheKey]
26-
// state.customImportName is injected by the babel macro
27-
} else if (state.customImportName) {
24+
if (state.customImportName && !localNameCache[cacheKey]) {
2825
return state.customImportName.name
26+
} else if (!bypassCache && localNameCache[cacheKey]) {
27+
return localNameCache[cacheKey]
2928
}
3029

3130
let localName = state.styledRequired

src/visitors/transpileCssProp.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ export default t => (path, state) => {
4444

4545
const program = state.file.path
4646

47-
// state.customImportName is passed through from styled-components/macro if it's used
48-
// since the macro also inserts the import
49-
let importName = state.customImportName || importLocalName('default', state)
47+
let importName = importLocalName('default', state)
5048

5149
const { bindings } = program.scope
5250

5351
// Insert import if it doesn't exist yet
54-
if (!importName || !bindings[importName.name] || !bindings[importName]) {
52+
if (!importName) {
5553
addDefault(path, 'styled-components', {
5654
nameHint: 'styled',
5755
})

0 commit comments

Comments
 (0)