Skip to content

Commit c74437c

Browse files
author
Evan Jacobs
committed
Revert "one more tweak for babel macro"
This reverts commit ae36dfe.
1 parent 63bfeff commit c74437c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/utils/detectors.js

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

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

3031
let localName = state.styledRequired

src/visitors/transpileCssProp.js

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

4545
const program = state.file.path
4646

47-
let importName = importLocalName('default', state)
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)
4850

4951
const { bindings } = program.scope
5052

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

0 commit comments

Comments
 (0)