Skip to content

Commit

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

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

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

const program = state.file.path

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

const { bindings } = program.scope

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

0 comments on commit ae36dfe

Please sign in to comment.