Skip to content

Commit

Permalink
Revert "one more tweak for babel macro"
Browse files Browse the repository at this point in the history
This reverts commit ae36dfe.
  • Loading branch information
quantizor committed Feb 25, 2022
1 parent 63bfeff commit c74437c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/utils/detectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export const importLocalName = (name, state, options = {}) => {
const cacheKeyAffix = cacheIdentifier ? `|${cacheIdentifier}` : ''
const cacheKey = name + state.file.opts.filename + cacheKeyAffix

if (state.customImportName && !localNameCache[cacheKey]) {
return state.customImportName.name
} else if (!bypassCache && localNameCache[cacheKey]) {
if (!bypassCache && cacheKey in localNameCache) {
return localNameCache[cacheKey]
// state.customImportName is injected by the babel macro
} else if (state.customImportName) {
return state.customImportName.name
}

let localName = state.styledRequired
Expand Down
6 changes: 4 additions & 2 deletions src/visitors/transpileCssProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ export default t => (path, state) => {

const program = state.file.path

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

const { bindings } = program.scope

// Insert import if it doesn't exist yet
if (!importName) {
if (!importName || !bindings[importName.name] || !bindings[importName]) {
addDefault(path, 'styled-components', {
nameHint: 'styled',
})
Expand Down

0 comments on commit c74437c

Please sign in to comment.