Skip to content

Commit

Permalink
fix: compare identifiers map correctly in ast comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich committed Oct 11, 2024
1 parent ac8c614 commit cc4ac30
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/grammar/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,26 @@ export class AstComparator {
identifiers: destructIdentifiers2,
expression: destructExpression2,
} = node2 as AstStatementDestruct;
for (const [name1, field1] of destructIdentifiers1) {
const name2 = destructIdentifiers2.get(field1);
if (name1 !== name2) {
const sortedIdentifiers1 =
Array.from(destructIdentifiers1).sort();
const sortedIdentifiers2 =
Array.from(destructIdentifiers2).sort();
if (sortedIdentifiers1.length !== sortedIdentifiers2.length) {
return false;
}
for (let i = 0; i < sortedIdentifiers1.length; i++) {
if (
!this.compare(
sortedIdentifiers1[i]![0],
sortedIdentifiers2[i]![0],
) ||
!this.compare(
sortedIdentifiers1[i]![1],
sortedIdentifiers2[i]![1],
)
) {
return false;
}
destructIdentifiers2.delete(field1);
}
if (destructIdentifiers2.size > 0) {
return false;
}
return (
this.compare(destructType1, destructType2) &&
Expand Down

0 comments on commit cc4ac30

Please sign in to comment.