diff --git a/src/grammar/compare.ts b/src/grammar/compare.ts index 06956770d..0409c6304 100644 --- a/src/grammar/compare.ts +++ b/src/grammar/compare.ts @@ -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 ( diff --git a/src/grammar/rename.ts b/src/grammar/rename.ts index 6b2c5f3f7..9bf6d6a1d 100644 --- a/src/grammar/rename.ts +++ b/src/grammar/rename.ts @@ -2,6 +2,7 @@ import { AstConstantDef, AstModuleItem, AstStatement, + AstModule, AstTraitDeclaration, AstContractDeclaration, AstExpression, @@ -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}`, ); } }