@@ -85,41 +85,35 @@ function printConstructor(contract: Contract, helpers: Helpers): Lines[] {
8585 if ( helpers . upgradeable ) {
8686 const upgradeableParents = parentsWithInitializers . filter ( p => inferTranspiled ( p . contract ) ) ;
8787 const nonUpgradeableParents = parentsWithInitializers . filter ( p => ! inferTranspiled ( p . contract ) ) ;
88-
89- return spaceBetween (
90- // constructor
91- printFunction2 (
92- [
93- nonUpgradeableParents . length > 0
88+ const constructor = printFunction2 (
89+ [
90+ nonUpgradeableParents . length > 0
9491 ? '/// @custom:oz-upgrades-unsafe-allow-reachable constructor'
9592 : '/// @custom:oz-upgrades-unsafe-allow constructor' ,
96- ] ,
97- 'constructor' ,
98- [ ] ,
99- nonUpgradeableParents . flatMap ( p => printParentConstructor ( p , helpers ) ) ,
100- [ '_disableInitializers();' ]
93+ ] ,
94+ 'constructor' ,
95+ [ ] ,
96+ nonUpgradeableParents . flatMap ( p => printParentConstructor ( p , helpers ) ) ,
97+ [ '_disableInitializers();' ] ,
98+ ) ;
99+ const initializer = printFunction2 (
100+ [ ] ,
101+ 'function initialize' ,
102+ contract . constructorArgs . map ( a => printArgument ( a , helpers ) ) ,
103+ [ 'public' , 'initializer' ] ,
104+ spaceBetween (
105+ upgradeableParents . flatMap ( p => printParentConstructor ( p , helpers ) ) . map ( p => p + ';' ) ,
106+ contract . constructorCode ,
101107 ) ,
102- // initializer
103- upgradeableParents . length > 0
104- ? printFunction2 (
105- [ ] ,
106- 'function initialize' ,
107- contract . constructorArgs . map ( a => printArgument ( a , helpers ) ) ,
108- [ 'public' , 'initializer' ] ,
109- spaceBetween (
110- upgradeableParents . flatMap ( p => printParentConstructor ( p , helpers ) ) . map ( p => p + ';' ) ,
111- contract . constructorCode ,
112- )
113- )
114- : [ ] ,
115108 ) ;
109+ return spaceBetween ( constructor , upgradeableParents . length > 0 ? initializer : [ ] ) ;
116110 } else {
117111 return printFunction2 (
118112 [ ] ,
119113 'constructor' ,
120114 contract . constructorArgs . map ( a => printArgument ( a , helpers ) ) ,
121115 parentsWithInitializers . flatMap ( p => printParentConstructor ( p , helpers ) ) ,
122- contract . constructorCode
116+ contract . constructorCode ,
123117 ) ;
124118 }
125119 } else if ( ! helpers . upgradeable ) {
0 commit comments