Skip to content

Commit

Permalink
fix(babel): imported value is undefined/not a function (fixes #1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Jul 27, 2022
1 parent 2abc55b commit fbdf555
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-fans-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@linaria/babel-preset': patch
---

In some cases, Linaria threw an error that the imported value is undefined.
14 changes: 12 additions & 2 deletions packages/babel/src/transform-stages/1-prepare-for-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,19 @@ export default async function prepareForEval(
const promise = resolve(importedFile, name, stack).then(
(resolved) => {
log('stage-1:async-resolve', `✅ ${importedFile} -> ${resolved}`);
const resolveCacheKey = `${name} -> ${importedFile}`;
const cached = resolveCache.get(resolveCacheKey);
const importsOnlySet = new Set(importsOnly);
if (cached) {
const [, cachedOnly] = cached.split('\0');
cachedOnly?.split(',').forEach((token) => {
importsOnlySet.add(token);
});
}

resolveCache.set(
`${name} -> ${importedFile}`,
`${resolved}\0${importsOnly.join(',')}`
resolveCacheKey,
`${resolved}\0${[...importsOnlySet].join(',')}`
);
const fileContent = readFileSync(resolved, 'utf8');
return {
Expand Down

0 comments on commit fbdf555

Please sign in to comment.