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 all 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

## 1.33.1 (2024-04-25)

- Fix Hardhat compile error when variable has whitespace before semicolon. ([#1020](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1020))

## 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
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openzeppelin/upgrades-core",
"version": "1.33.0",
"version": "1.33.1",
"description": "",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/core",
"license": "MIT",
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.
11 changes: 8 additions & 3 deletions packages/core/src/utils/make-namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,14 @@ 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;
// For variables, skip past whitespaces and the first semicolon
if (isNodeType('VariableDeclaration', node)) {
while (end + 1 < orig.length && orig.toString('utf8', end, end + 1).trim() === '') {
end += 1;
}
if (end + 1 < orig.length && orig.toString('utf8', end, end + 1) === ';') {
end += 1;
}
}
return { start: positions.start, end };
}
Expand Down
Loading