Skip to content

Commit

Permalink
fix(rename+cmp): Rename only whole modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jubnzv committed Aug 16, 2024
1 parent 16d16d6 commit 87e12b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 5 additions & 6 deletions src/grammar/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ export class AstComparator {
return false;
}

if (this.canonialize === true) {
const renamer = AstRenamer.make({ sort: this.sort });
node1 = renamer.rename(node1);
node2 = renamer.rename(node2);
}

switch (node1.kind) {
case "module": {
if (this.canonialize === true) {
const renamer = AstRenamer.make({ sort: this.sort });
node1 = renamer.renameModule(node1 as AstModule);
node2 = renamer.renameModule(node2 as AstModule);
}
const { imports: imports1, items: items1 } = node1 as AstModule;
const { imports: imports2, items: items2 } = node2 as AstModule;
return (
Expand Down
12 changes: 8 additions & 4 deletions src/grammar/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AstConstantDef,
AstModuleItem,
AstStatement,
AstModule,
AstTraitDeclaration,
AstContractDeclaration,
AstExpression,
Expand Down Expand Up @@ -44,13 +45,16 @@ export class AstRenamer {
/**
* Renames the given node based on its AST.
*/
public rename(node: AstNode): AstNode {
switch (node.kind) {
public renameModule(module: AstModule): AstNode {
switch (module.kind) {
case "module":
return { ...node, items: this.renameModuleItems(node.items) };
return {
...module,
items: this.renameModuleItems(module.items),
};
default:
throwInternalCompilerError(
`Unsupported node kind: ${node.kind}`,
`Unsupported node kind: ${module.kind}`,
);
}
}
Expand Down

0 comments on commit 87e12b9

Please sign in to comment.