Skip to content

Commit

Permalink
Simplify constant checking
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Jul 17, 2024
1 parent c8167fa commit c37dfb5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/utils/make-namespaced.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Generated by [AVA](https://avajs.dev).
}␊
contract UsesAddress {␊
enum $astId_id_random { dummy }
IDummy public constant MY_CONTRACT = IDummy(MY_ADDRESS);
}␊
contract HasFunctionWithRequiredReturn {␊
Expand Down
Binary file modified packages/core/src/utils/make-namespaced.test.ts.snap
Binary file not shown.
8 changes: 2 additions & 6 deletions packages/core/src/utils/make-namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI
}
case 'VariableDeclaration': {
// If variable is a constant, keep it since it may be referenced in a struct
if (isConstant(contractNode)) {
if (contractNode.constant) {
break;
}
// Otherwise, fall through to convert to dummy enum
Expand Down Expand Up @@ -115,7 +115,7 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI
// We do this by converting them to dummy enums, but avoiding duplicate names.
case 'VariableDeclaration': {
// If variable is a constant, keep it since it may be referenced in a struct
if (isConstant(node)) {
if (node.constant) {
break;
}
// Otherwise, fall through to convert to dummy enum
Expand Down Expand Up @@ -163,10 +163,6 @@ interface Modification {
text?: string;
}

function isConstant(contractNode: VariableDeclaration) {
return contractNode.constant && contractNode.typeName?.nodeType === 'ElementaryTypeName';
}

function toDummyEnumWithName(name: string) {
return `enum ${name} { dummy }`;
}
Expand Down

0 comments on commit c37dfb5

Please sign in to comment.