Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hardhat compile error when variable has whitespace before semicolon #1020

Merged
merged 7 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Fix Hardhat compile error when variable has whitespace before semicolon.

## 1.33.0 (2024-04-24)

- Enable changing default network files directory with environment variable. ([#1011](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1011))
Expand Down
7 changes: 7 additions & 0 deletions packages/core/contracts/test/NamespacedToModify.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ contract Example {
* @dev a custom error inside a contract
*/
error CustomErrorInsideContract(address a);

uint256 public spaceSemicolon ;
uint256 public twoSpacesSemicolon ;
uint256 public tabSemicolon ;
uint256 public lineBreakSemicolon
;
error SpaceSemicolon(uint256 a) ;
}

contract HasFunction {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/utils/make-namespaced.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ Generated by [AVA](https://avajs.dev).
* @dev a custom error inside a contract␊
*/␊
enum $astId_id_random { dummy }␊
enum $astId_id_random { dummy }␊
enum $astId_id_random { dummy }␊
enum $astId_id_random { dummy }␊
enum $astId_id_random { dummy }␊
enum $astId_id_random { dummy }␊
}␊
contract HasFunction {␊
Expand Down
Binary file modified packages/core/src/utils/make-namespaced.test.ts.snap
Binary file not shown.
13 changes: 10 additions & 3 deletions packages/core/src/utils/make-namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,17 @@ function makeInsertAfter(node: Node, text: string): Modification {
function makeDelete(node: Node, orig: Buffer): Modification {
const positions = getPositions(node);
let end = positions.end;
// If the next character is a semicolon for variables, skip over it
if (isNodeType('VariableDeclaration', node) && end + 1 < orig.length && orig.toString('utf8', end, end + 1) === ';') {
end += 1;
// If the next character (after whitespaces) is a semicolon for variables, skip over it
if (isNodeType('VariableDeclaration', node)) {
while (end < orig.length && orig.toString('utf8', end, end + 1).trim() === '') {
end += 1;
}
if (end < orig.length && orig.toString('utf8', end, end + 1) === ';') {
end += 1;
}
console.log('end', end, 'orig.length', orig.length);
ericglau marked this conversation as resolved.
Show resolved Hide resolved
}

Amxx marked this conversation as resolved.
Show resolved Hide resolved
return { start: positions.start, end };
}

Expand Down
Loading