Skip to content

Commit

Permalink
fix(exports): fix calculating export is clause for the contacts
Browse files Browse the repository at this point in the history
When contact has no extra space between the is and start of the contract body the bracket is counting
as the is part of the contact. For example:

`A is B{` the is clause will be `is B{` instead of `is B`

Closes #73
  • Loading branch information
RyuuGan committed Dec 10, 2023
1 parent 4f613c7 commit fd6483a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/exportsAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface ExportsAnalyzerResultUsingDirective {
}

export class ExportsAnalyzer {
constructor(private contents: string) {}
constructor(private contents: string) { }

/**
* Analyzes all the exports of the file (Contract, Interface, Library)
Expand Down Expand Up @@ -97,7 +97,7 @@ export class ExportsAnalyzer {
name: e.name,
body: this.contents.substring(e.body.start, e.body.end + 1).trim(),
is: e.is
? this.contents.substring(e.is.start, e.is.end + 1).trimLeft()
? this.contents.substring(e.is.start, e.is.end).trimLeft() + ' '
: '',
});
});
Expand Down
5 changes: 5 additions & 0 deletions test/compiled/ContractWithoutSpaceBeforeBracket.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract B {
}

contract A is B {
}
4 changes: 4 additions & 0 deletions test/contracts/ContractWithoutSpaceBeforeBracket.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contract B{
}
contract A is B{
}
4 changes: 4 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@ describe('Solidity Merger', () => {
assert.isOk(e);
}
});

it('should compile file without extra spaces before bracket in contract defininition', async () => {
await testFile('ContractWithoutSpaceBeforeBracket');
});
});

0 comments on commit fd6483a

Please sign in to comment.