Skip to content

Commit 44d0d4b

Browse files
ericglauAmxx
andauthored
Fix Hardhat compile error when variable has whitespace before semicolon (#1020)
Co-authored-by: Hadrien Croubois <[email protected]>
1 parent d3dcf9d commit 44d0d4b

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

packages/core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.33.1 (2024-04-25)
4+
5+
- Fix Hardhat compile error when variable has whitespace before semicolon. ([#1020](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1020))
6+
37
## 1.33.0 (2024-04-24)
48

59
- Enable changing default network files directory with environment variable. ([#1011](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1011))

packages/core/contracts/test/NamespacedToModify.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ contract Example {
6666
* @dev a custom error inside a contract
6767
*/
6868
error CustomErrorInsideContract(address a);
69+
70+
uint256 public spaceSemicolon ;
71+
uint256 public twoSpacesSemicolon ;
72+
uint256 public tabSemicolon ;
73+
uint256 public lineBreakSemicolon
74+
;
75+
error SpaceSemicolon(uint256 a) ;
6976
}
7077

7178
contract HasFunction {

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openzeppelin/upgrades-core",
3-
"version": "1.33.0",
3+
"version": "1.33.1",
44
"description": "",
55
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/core",
66
"license": "MIT",

packages/core/src/utils/make-namespaced.test.ts.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ Generated by [AVA](https://avajs.dev).
9090
* @dev a custom error inside a contract␊
9191
*/␊
9292
enum $astId_id_random { dummy }␊
93+
94+
enum $astId_id_random { dummy }␊
95+
enum $astId_id_random { dummy }␊
96+
enum $astId_id_random { dummy }␊
97+
enum $astId_id_random { dummy }␊
98+
enum $astId_id_random { dummy }␊
9399
}␊
94100
95101
contract HasFunction {␊
1 Byte
Binary file not shown.

packages/core/src/utils/make-namespaced.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,14 @@ function makeInsertAfter(node: Node, text: string): Modification {
178178
function makeDelete(node: Node, orig: Buffer): Modification {
179179
const positions = getPositions(node);
180180
let end = positions.end;
181-
// If the next character is a semicolon for variables, skip over it
182-
if (isNodeType('VariableDeclaration', node) && end + 1 < orig.length && orig.toString('utf8', end, end + 1) === ';') {
183-
end += 1;
181+
// For variables, skip past whitespaces and the first semicolon
182+
if (isNodeType('VariableDeclaration', node)) {
183+
while (end + 1 < orig.length && orig.toString('utf8', end, end + 1).trim() === '') {
184+
end += 1;
185+
}
186+
if (end + 1 < orig.length && orig.toString('utf8', end, end + 1) === ';') {
187+
end += 1;
188+
}
184189
}
185190
return { start: positions.start, end };
186191
}

0 commit comments

Comments
 (0)