Skip to content

Commit

Permalink
ensure a cache miss (styled-components#283)
Browse files Browse the repository at this point in the history
Co-authored-by: Evan Jacobs <570070+probablyup@users.noreply.github.com>
  • Loading branch information
nickhudkins and quantizor committed Jul 29, 2020
1 parent 4187ada commit b1dcfda
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils/detectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const VALID_TOP_LEVEL_IMPORT_PATHS = [
'styled-components/native',
'styled-components/primitives',
]
const CACHE_MISS = Symbol('CACHE_MISS');

export const isValidTopLevelImport = x =>
VALID_TOP_LEVEL_IMPORT_PATHS.includes(x)
Expand All @@ -13,15 +14,15 @@ const localNameCache = {}
export const importLocalName = (name, state, bypassCache = false) => {
const cacheKey = name + state.file.opts.filename

if (!bypassCache && cacheKey in localNameCache) {
if (!bypassCache && cacheKey in localNameCache && localNameCache[cacheKey] !== CACHE_MISS) {
return localNameCache[cacheKey]
}

let localName = state.styledRequired
? name === 'default'
? 'styled'
: name
: false
: CACHE_MISS

state.file.path.traverse({
ImportDeclaration: {
Expand Down

0 comments on commit b1dcfda

Please sign in to comment.