Skip to content

Commit

Permalink
fix(babel): use path.data instead of scope.data (fixes #1300) (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Jul 25, 2023
1 parent 69d32d7 commit 10bcd24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/slimy-cougars-hammer.md
@@ -0,0 +1,6 @@
---
'@linaria/babel-preset': patch
'@linaria/utils': patch
---

Fix for "The expression evaluated to 'undefined'" in Webpack (fixes #1300 and #1287)
2 changes: 1 addition & 1 deletion packages/babel/src/plugins/preeval.ts
Expand Up @@ -98,7 +98,7 @@ export default function preeval(
dependencies: [],
};

const linariaPreval = file.path.scope.getData('__linariaPreval');
const linariaPreval = file.path.getData('__linariaPreval');
if (!linariaPreval) {
// Event if there is no dependencies, we still need to add __linariaPreval
const linariaExport = t.expressionStatement(
Expand Down
8 changes: 4 additions & 4 deletions packages/utils/src/addIdentifierToLinariaPreval.ts
Expand Up @@ -15,13 +15,13 @@ export function getOrAddLinariaPreval(
scope: Scope
): NodePath<ObjectExpression> {
const rootScope = scope.getProgramParent();
let object = rootScope.getData('__linariaPreval');
const programPath = rootScope.path as NodePath<Program>;

let object = programPath.getData('__linariaPreval');
if (object) {
return object;
}

const programPath = rootScope.path as NodePath<Program>;

if (programPath.node.sourceType === 'script') {
// CJS exports.__linariaPreval = {};
const prevalExport: ExpressionStatement = {
Expand Down Expand Up @@ -71,7 +71,7 @@ export function getOrAddLinariaPreval(
) as NodePath<ObjectExpression>;
}

rootScope.setData('__linariaPreval', object);
programPath.setData('__linariaPreval', object);
return object;
}

Expand Down

0 comments on commit 10bcd24

Please sign in to comment.