Skip to content

Commit

Permalink
fix(babel): lookup referencedIdentifiers after tree mutations (#1180)
Browse files Browse the repository at this point in the history
* fix: lookup referencedIdentifiers after tree mutations

* fix(babel): lookup referencedIdentifiers after tree mutations (fixes #1112)

---------

Co-authored-by: Victor Lin <victor.lin@airbnb.com>
Co-authored-by: Anton Evzhakov <anton@evz.name>
  • Loading branch information
3 people committed Feb 6, 2023
1 parent 4dd089c commit 61d49a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/yellow-cougars-invite.md
@@ -0,0 +1,6 @@
---
'@linaria/utils': patch
'@linaria/babel-preset': patch
---

Fix for #1112 "Cannot read properties of undefined (reading 'localeCompare')"
8 changes: 4 additions & 4 deletions packages/utils/src/scopeHelpers.ts
Expand Up @@ -369,6 +369,10 @@ function removeWithRelated(paths: NodePath[]) {
const affectedPaths = actions.map(getPathFromAction);

let referencedIdentifiers = findIdentifiers(affectedPaths, 'referenced');
referencedIdentifiers.sort((a, b) =>
a.node?.name.localeCompare(b.node?.name)
);

const referencesOfBinding = findIdentifiers(affectedPaths, 'binding')
.map((i) => (i.node && getScope(i).getBinding(i.node.name)) ?? null)
.filter(isNotNull)
Expand All @@ -391,10 +395,6 @@ function removeWithRelated(paths: NodePath[]) {

removeWithRelated(referencesOfBinding);

referencedIdentifiers.sort((a, b) =>
a.node?.name.localeCompare(b.node?.name)
);

let clean = false;
while (!clean && referencedIdentifiers.length > 0) {
const referenced = removeUnreferenced(referencedIdentifiers);
Expand Down

0 comments on commit 61d49a3

Please sign in to comment.