@openzeppelin/upgrades-core 1.39.0 → 1.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/make-namespaced.d.ts +5 -1
- package/dist/utils/make-namespaced.d.ts.map +1 -1
- package/dist/utils/make-namespaced.js +36 -7
- package/dist/utils/make-namespaced.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/cli.test.ts.snap +0 -0
- package/src/cli/validate/project-report.test.ts.snap +0 -0
- package/src/cli/validate/validate-upgrade-safety.test.ts.snap +0 -0
- package/src/cli/validate/validations.test.ts.snap +0 -0
- package/src/index.ts +1 -0
- package/src/scripts/migrate-oz-cli-project.test.ts.snap +0 -0
- package/src/storage/report-gap.test.ts.snap +0 -0
- package/src/storage/report-rename-retype.test.ts.snap +0 -0
- package/src/storage/report.test.ts.snap +0 -0
- package/src/storage-0.8.test.ts.snap +0 -0
- package/src/storage-memory-0.5.test.ts.snap +0 -0
- package/src/storage-namespaced-conflicts-layout.test.ts.snap +0 -0
- package/src/storage-namespaced-conflicts.test.ts.snap +0 -0
- package/src/storage-namespaced-layout.test.ts.snap +0 -0
- package/src/storage-namespaced.test.ts.snap +0 -0
- package/src/storage.test.ts.snap +0 -0
- package/src/utils/make-namespaced.test.ts.md +89 -37
- package/src/utils/make-namespaced.test.ts.snap +0 -0
- package/src/utils/make-namespaced.ts +53 -15
- package/src/utils/parse-type-id.test.ts.snap +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.40.0 (2024-10-10)
|
|
4
|
+
|
|
5
|
+
- Fix Hardhat compile error when overriding interface functions with public constant variables. ([#1091](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1091))
|
|
6
|
+
- Support ignoring Hardhat compile errors when extracting detailed namespaced storage layouts for validations. ([#1090](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1090))
|
|
7
|
+
|
|
3
8
|
## 1.39.0 (2024-10-02)
|
|
4
9
|
|
|
5
10
|
- Fix Hardhat compile error when library or interface has struct with namespace annotation. ([#1086](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1086))
|
package/dist/index.d.ts
CHANGED
|
@@ -25,4 +25,5 @@ export { getUpgradeInterfaceVersion } from './upgrade-interface-version';
|
|
|
25
25
|
export { makeNamespacedInput } from './utils/make-namespaced';
|
|
26
26
|
export { isNamespaceSupported } from './storage/namespace';
|
|
27
27
|
export { inferProxyAdmin } from './infer-proxy-admin';
|
|
28
|
+
export { assertUnreachable } from './utils/assert';
|
|
28
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC7F,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,qBAAqB,EACrB,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,QAAQ,EACR,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,0BAA0B,EAAE,MA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E,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.inferProxyAdmin = exports.isNamespaceSupported = exports.makeNamespacedInput = exports.getUpgradeInterfaceVersion = exports.ReferenceContractNotFound = exports.ProjectReport = exports.validateUpgradeSafety = exports.assertNotProxy = exports.InitialOwnerUnsupportedKindError = exports.PrepareUpgradeRequiresKindError = exports.ValidateUpdateRequiresKindError = exports.NoContractImportError = exports.ForceImportUnsupportedError = exports.DeployBeaconProxyKindError = exports.DeployBeaconProxyImplUnknownError = exports.DeployBeaconProxyUnsupportedError = exports.PrepareUpgradeUnsupportedError = exports.LoadProxyUnsupportedError = exports.BeaconProxyUnsupportedError = exports.addProxyToManifest = exports.isBeacon = exports.getImplementationAddressFromProxy = exports.getImplementationAddressFromBeacon = exports.isTransparentProxy = exports.isBeaconProxy = exports.isTransparentOrUUPSProxy = exports.UpgradeableContract = exports.detectProxyKind = exports.processProxyKind = exports.setProxyKind = exports.logWarning = exports.getStorageLayoutForAddress = exports.DeploymentNotFound = exports.migrateManifest = exports.Manifest = exports.isEmptySlot = exports.toFallbackEip1967Hash = exports.toEip1967Hash = exports.getImplementationAddress = exports.getBeaconAddress = exports.getAdminAddress = exports.EIP1967ImplementationNotFound = exports.EIP1967BeaconNotFound = exports.fetchOrDeployGetDeployment = exports.fetchOrDeployAdmin = exports.fetchOrDeploy = void 0;
|
|
17
|
+
exports.assertUnreachable = exports.inferProxyAdmin = exports.isNamespaceSupported = exports.makeNamespacedInput = exports.getUpgradeInterfaceVersion = exports.ReferenceContractNotFound = exports.ProjectReport = exports.validateUpgradeSafety = exports.assertNotProxy = exports.InitialOwnerUnsupportedKindError = exports.PrepareUpgradeRequiresKindError = exports.ValidateUpdateRequiresKindError = exports.NoContractImportError = exports.ForceImportUnsupportedError = exports.DeployBeaconProxyKindError = exports.DeployBeaconProxyImplUnknownError = exports.DeployBeaconProxyUnsupportedError = exports.PrepareUpgradeUnsupportedError = exports.LoadProxyUnsupportedError = exports.BeaconProxyUnsupportedError = exports.addProxyToManifest = exports.isBeacon = exports.getImplementationAddressFromProxy = exports.getImplementationAddressFromBeacon = exports.isTransparentProxy = exports.isBeaconProxy = exports.isTransparentOrUUPSProxy = exports.UpgradeableContract = exports.detectProxyKind = exports.processProxyKind = exports.setProxyKind = exports.logWarning = exports.getStorageLayoutForAddress = exports.DeploymentNotFound = exports.migrateManifest = exports.Manifest = exports.isEmptySlot = exports.toFallbackEip1967Hash = exports.toEip1967Hash = exports.getImplementationAddress = exports.getBeaconAddress = exports.getAdminAddress = exports.EIP1967ImplementationNotFound = exports.EIP1967BeaconNotFound = exports.fetchOrDeployGetDeployment = exports.fetchOrDeployAdmin = exports.fetchOrDeploy = void 0;
|
|
18
18
|
__exportStar(require("./validate"), exports);
|
|
19
19
|
var impl_store_1 = require("./impl-store");
|
|
20
20
|
Object.defineProperty(exports, "fetchOrDeploy", { enumerable: true, get: function () { return impl_store_1.fetchOrDeploy; } });
|
|
@@ -88,4 +88,6 @@ var namespace_1 = require("./storage/namespace");
|
|
|
88
88
|
Object.defineProperty(exports, "isNamespaceSupported", { enumerable: true, get: function () { return namespace_1.isNamespaceSupported; } });
|
|
89
89
|
var infer_proxy_admin_1 = require("./infer-proxy-admin");
|
|
90
90
|
Object.defineProperty(exports, "inferProxyAdmin", { enumerable: true, get: function () { return infer_proxy_admin_1.inferProxyAdmin; } });
|
|
91
|
+
var assert_1 = require("./utils/assert");
|
|
92
|
+
Object.defineProperty(exports, "assertUnreachable", { enumerable: true, get: function () { return assert_1.assertUnreachable; } });
|
|
91
93
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,2CAA6F;AAApF,2GAAA,aAAa,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAAE,wHAAA,0BAA0B,OAAA;AACtE,4CAA0B;AAC1B,4CAA0B;AAC1B,uCASoB;AARlB,iHAAA,qBAAqB,OAAA;AACrB,yHAAA,6BAA6B,OAAA;AAC7B,2GAAA,eAAe,OAAA;AACf,4GAAA,gBAAgB,OAAA;AAChB,oHAAA,wBAAwB,OAAA;AACxB,yGAAA,aAAa,OAAA;AACb,iHAAA,qBAAqB,OAAA;AACrB,uGAAA,WAAW,OAAA;AAEb,6CAA2B;AAC3B,gDAA8B;AAC9B,6CAA2B;AAC3B,+CAA6B;AAC7B,8CAA4B;AAC5B,0CAAwB;AAExB,uCAOoB;AAHlB,oGAAA,QAAQ,OAAA;AACR,2GAAA,eAAe,OAAA;AACf,8GAAA,kBAAkB,OAAA;AAGpB,qEAAuE;AAA9D,qIAAA,0BAA0B,OAAA;AAEnC,mEAAiD;AAEjD,mCAAyC;AAAhC,iGAAA,UAAU,OAAA;AACnB,2CAA+E;AAAtE,0GAAA,YAAY,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AAAE,6GAAA,eAAe,OAAA;AAExD,2CAAmD;AAA1C,iHAAA,mBAAmB,OAAA;AAE5B,iDAA8F;AAArF,yHAAA,wBAAwB,OAAA;AAAE,8GAAA,aAAa,OAAA;AAAE,mHAAA,kBAAkB,OAAA;AACpE,+CAAuG;AAA9F,kIAAA,kCAAkC,OAAA;AAA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;AAA7C,oHAAA,eAAe,OAAA;AACxB,yCAAmD;AAA1C,2GAAA,iBAAiB,OAAA"}
|
|
@@ -6,10 +6,14 @@ import { SolcInput, SolcOutput } from '../solc-api';
|
|
|
6
6
|
* This makes the following modifications to the input:
|
|
7
7
|
* - Adds a state variable for each namespaced struct definition
|
|
8
8
|
* - For each contract, for all node types that are not needed for storage layout or may call functions and constructors, converts them to dummy enums with random id
|
|
9
|
+
* - Mark contracts as abstract, since state variables are converted to dummy enums which would not generate public getters for inherited interface functions
|
|
9
10
|
* - Converts all using for directives (at file level and in contracts) to dummy enums with random id (do not delete them to avoid orphaning possible NatSpec documentation)
|
|
10
11
|
* - Converts all custom errors and constants (at file level) to dummy enums with the same name (do not delete them since they might be imported by other files)
|
|
11
12
|
* - Replaces functions as follows:
|
|
12
|
-
* - For regular function and free function, keep declarations since they may be referenced by constants (free functions may also be imported by other files). But simplify compilation
|
|
13
|
+
* - For regular function and free function, keep declarations since they may be referenced by constants (free functions may also be imported by other files). But simplify compilation as follows:
|
|
14
|
+
* - Avoid having to initialize return parameters: convert function to virtual if possible, or convert return parameters to bools which can be default initialized.
|
|
15
|
+
* - Delete modifiers
|
|
16
|
+
* - Delete function bodies
|
|
13
17
|
* - Constructors are not needed, since we removed anything that may call constructors. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
14
18
|
* - Fallback and receive functions are not needed, since they don't have signatures. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
15
19
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-namespaced.d.ts","sourceRoot":"","sources":["../../src/utils/make-namespaced.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAYpD
|
|
1
|
+
{"version":3,"file":"make-namespaced.d.ts","sourceRoot":"","sources":["../../src/utils/make-namespaced.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAYpD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAoIzG"}
|
|
@@ -17,10 +17,14 @@ const OUTPUT_SELECTION = {
|
|
|
17
17
|
* This makes the following modifications to the input:
|
|
18
18
|
* - Adds a state variable for each namespaced struct definition
|
|
19
19
|
* - For each contract, for all node types that are not needed for storage layout or may call functions and constructors, converts them to dummy enums with random id
|
|
20
|
+
* - Mark contracts as abstract, since state variables are converted to dummy enums which would not generate public getters for inherited interface functions
|
|
20
21
|
* - Converts all using for directives (at file level and in contracts) to dummy enums with random id (do not delete them to avoid orphaning possible NatSpec documentation)
|
|
21
22
|
* - Converts all custom errors and constants (at file level) to dummy enums with the same name (do not delete them since they might be imported by other files)
|
|
22
23
|
* - Replaces functions as follows:
|
|
23
|
-
* - For regular function and free function, keep declarations since they may be referenced by constants (free functions may also be imported by other files). But simplify compilation
|
|
24
|
+
* - For regular function and free function, keep declarations since they may be referenced by constants (free functions may also be imported by other files). But simplify compilation as follows:
|
|
25
|
+
* - Avoid having to initialize return parameters: convert function to virtual if possible, or convert return parameters to bools which can be default initialized.
|
|
26
|
+
* - Delete modifiers
|
|
27
|
+
* - Delete function bodies
|
|
24
28
|
* - Constructors are not needed, since we removed anything that may call constructors. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
25
29
|
* - Fallback and receive functions are not needed, since they don't have signatures. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
26
30
|
*
|
|
@@ -62,7 +66,7 @@ function makeNamespacedInput(input, output, solcVersion) {
|
|
|
62
66
|
for (const contractNode of contractNodes) {
|
|
63
67
|
switch (contractNode.nodeType) {
|
|
64
68
|
case 'FunctionDefinition': {
|
|
65
|
-
replaceFunction(contractNode, orig, modifications);
|
|
69
|
+
replaceFunction(contractNode, orig, modifications, contractDef);
|
|
66
70
|
break;
|
|
67
71
|
}
|
|
68
72
|
case 'VariableDeclaration': {
|
|
@@ -210,20 +214,45 @@ function toDummyEnumWithName(name) {
|
|
|
210
214
|
function toDummyEnumWithAstId(astId) {
|
|
211
215
|
return `enum $astId_${astId}_${(Math.random() * 1e6).toFixed(0)} { dummy }`;
|
|
212
216
|
}
|
|
213
|
-
function replaceFunction(node, orig, modifications) {
|
|
217
|
+
function replaceFunction(node, orig, modifications, contractDef) {
|
|
214
218
|
switch (node.kind) {
|
|
215
219
|
case 'freeFunction':
|
|
216
220
|
case 'function': {
|
|
221
|
+
let virtual = node.virtual;
|
|
222
|
+
if (contractDef !== undefined &&
|
|
223
|
+
contractDef.contractKind === 'contract' &&
|
|
224
|
+
node.visibility !== 'private' &&
|
|
225
|
+
!virtual) {
|
|
226
|
+
(0, assert_1.assert)(node.kind !== 'freeFunction');
|
|
227
|
+
// If this is a contract function and not private, it could possibly override an interface function.
|
|
228
|
+
// We don't want to change its return parameters because that might cause a mismatch with the interface.
|
|
229
|
+
// Simply convert the function to virtual (if not already)
|
|
230
|
+
modifications.push(makeInsertAfter(node.parameters, ' virtual '));
|
|
231
|
+
virtual = true;
|
|
232
|
+
}
|
|
217
233
|
if (node.modifiers.length > 0) {
|
|
234
|
+
// Delete modifiers
|
|
218
235
|
for (const modifier of node.modifiers) {
|
|
219
236
|
modifications.push(makeDelete(modifier, orig));
|
|
220
237
|
}
|
|
221
238
|
}
|
|
222
|
-
if (node.returnParameters.parameters.length > 0) {
|
|
223
|
-
modifications.push(makeReplace(node.returnParameters, orig, `(${node.returnParameters.parameters.map(param => toReturnParameterReplacement(param)).join(', ')})`));
|
|
224
|
-
}
|
|
225
239
|
if (node.body) {
|
|
226
|
-
|
|
240
|
+
// Delete body
|
|
241
|
+
if (virtual) {
|
|
242
|
+
modifications.push(makeReplace(node.body, orig, ';'));
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
// This is a non-virtual function with a body, so that means it is not an interface function.
|
|
246
|
+
(0, assert_1.assert)(contractDef?.contractKind !== 'interface');
|
|
247
|
+
// Since all contract functions that are non-private were converted to virtual above, this cannot possibly override another function.
|
|
248
|
+
(0, assert_1.assert)(!node.overrides);
|
|
249
|
+
// The remaining scenarios may mean this is a library function, free function, or private function.
|
|
250
|
+
// In any of these cases, we can convert the return parameters to bools so that they can be default initialized.
|
|
251
|
+
if (node.returnParameters.parameters.length > 0) {
|
|
252
|
+
modifications.push(makeReplace(node.returnParameters, orig, `(${node.returnParameters.parameters.map(param => toReturnParameterReplacement(param)).join(', ')})`));
|
|
253
|
+
}
|
|
254
|
+
modifications.push(makeReplace(node.body, orig, '{}'));
|
|
255
|
+
}
|
|
227
256
|
}
|
|
228
257
|
break;
|
|
229
258
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-namespaced.js","sourceRoot":"","sources":["../../src/utils/make-namespaced.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"make-namespaced.js","sourceRoot":"","sources":["../../src/utils/make-namespaced.ts"],"names":[],"mappings":";;AAuCA,kDAoIC;AA3KD,8CAAgD;AAGhD,oDAAoE;AACpE,qCAAqD;AAGrD,MAAM,gBAAgB,GAAG;IACvB,GAAG,EAAE;QACH,GAAG,EAAE,CAAC,eAAe,CAAC;QACtB,EAAE,EAAE,CAAC,KAAK,CAAC;KACZ;CACF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,mBAAmB,CAAC,KAAgB,EAAE,MAAkB,EAAE,WAAoB;IAC5F,MAAM,eAAe,GAAyC,EAAE,CAAC;IAEjE,KAAK,MAAM,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACzD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAEzC,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACjC,eAAe,CAAC,U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GAAG,IAAI,CAAC,CAAC;QACX,CAAC;QACD,IAAI,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACzE,GAAG,IAAI,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IACD,OAAO,eAAe,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,eAAe,CAAC,KAAa,EAAE,GAAW;IACjD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACxB,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,aAA6B;IACpE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,IAAA,eAAM,EAAC,YAAY,CAAC,KAAK,IAAI,aAAa,CAAC,CAAC;QAC5C,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAEnE,IAAI,YAAY,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACpC,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC;QAC9B,CAAC;QAED,aAAa,GAAG,YAAY,CAAC,GAAG,CAAC;IACnC,CAAC;IAED,IAAA,eAAM,EAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAE/C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
package/src/cli/cli.test.ts.snap
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/index.ts
CHANGED
|
@@ -63,3 +63,4 @@ export { getUpgradeInterfaceVersion } from './upgrade-interface-version';
|
|
|
63
63
|
export { makeNamespacedInput } from './utils/make-namespaced';
|
|
64
64
|
export { isNamespaceSupported } from './storage/namespace';
|
|
65
65
|
export { inferProxyAdmin } from './infer-proxy-admin';
|
|
66
|
+
export { assertUnreachable } from './utils/assert';
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/storage.test.ts.snap
CHANGED
|
Binary file
|
|
@@ -53,13 +53,13 @@ Generated by [AVA](https://avajs.dev).
|
|
|
53
53
|
} StorageWithComment $StorageWithComment_random;␊
|
|
54
54
|
␊
|
|
55
55
|
␊
|
|
56
|
-
function foo() public
|
|
56
|
+
function foo() virtual public ;␊
|
|
57
57
|
␊
|
|
58
58
|
␊
|
|
59
|
-
function foo1(uint a) public
|
|
59
|
+
function foo1(uint a) virtual public ;␊
|
|
60
60
|
␊
|
|
61
61
|
␊
|
|
62
|
-
function foo2(uint a) internal
|
|
62
|
+
function foo2(uint a) virtual internal ;␊
|
|
63
63
|
struct MyStruct { uint b; }␊
|
|
64
64
|
␊
|
|
65
65
|
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊
|
|
@@ -68,7 +68,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
68
68
|
␊
|
|
69
69
|
function _getMainStorage() private pure returns (bool $) {}␊
|
|
70
70
|
␊
|
|
71
|
-
function _getXTimesY() internal view returns (
|
|
71
|
+
function _getXTimesY() virtual internal view returns (uint256) ;␊
|
|
72
72
|
␊
|
|
73
73
|
␊
|
|
74
74
|
␊
|
|
@@ -80,10 +80,10 @@ Generated by [AVA](https://avajs.dev).
|
|
|
80
80
|
␊
|
|
81
81
|
␊
|
|
82
82
|
␊
|
|
83
|
-
function foo3() public
|
|
83
|
+
function foo3() virtual public ;␊
|
|
84
84
|
␊
|
|
85
85
|
␊
|
|
86
|
-
function foo4() public
|
|
86
|
+
function foo4() virtual public ;␊
|
|
87
87
|
␊
|
|
88
88
|
␊
|
|
89
89
|
enum $astId_id_random { dummy }␊
|
|
@@ -99,7 +99,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
99
99
|
␊
|
|
100
100
|
enum $astId_id_random { dummy }␊
|
|
101
101
|
␊
|
|
102
|
-
function foo() pure public returns (
|
|
102
|
+
function foo() virtual pure public returns (uint) ;␊
|
|
103
103
|
}␊
|
|
104
104
|
␊
|
|
105
105
|
abstract contract UsingFunction is HasFunction {␊
|
|
@@ -119,11 +119,11 @@ Generated by [AVA](https://avajs.dev).
|
|
|
119
119
|
abstract contract Consumer {␊
|
|
120
120
|
enum $astId_id_random { dummy }␊
|
|
121
121
|
␊
|
|
122
|
-
function usingFreeFunction() pure public returns (
|
|
122
|
+
function usingFreeFunction() virtual pure public returns (bytes4) ;␊
|
|
123
123
|
␊
|
|
124
|
-
function usingConstant() pure public returns (
|
|
124
|
+
function usingConstant() virtual pure public returns (bytes4) ;␊
|
|
125
125
|
␊
|
|
126
|
-
function usingLibraryFunction() pure public returns (
|
|
126
|
+
function usingLibraryFunction() virtual pure public returns (bytes4) ;␊
|
|
127
127
|
}␊
|
|
128
128
|
␊
|
|
129
129
|
abstract contract HasConstantWithSelector {␊
|
|
@@ -150,7 +150,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
150
150
|
abstract contract UsingForDirectives {␊
|
|
151
151
|
enum $astId_id_random { dummy }␊
|
|
152
152
|
␊
|
|
153
|
-
function usingFor(uint x) pure public returns (
|
|
153
|
+
function usingFor(uint x) virtual pure public returns (uint) ;␊
|
|
154
154
|
}␊
|
|
155
155
|
␊
|
|
156
156
|
␊
|
|
@@ -190,7 +190,14 @@ Generated by [AVA](https://avajs.dev).
|
|
|
190
190
|
␊
|
|
191
191
|
abstract contract HasFunctionWithRequiredReturn {␊
|
|
192
192
|
struct S { uint x; }␊
|
|
193
|
-
|
|
193
|
+
enum $astId_id_random { dummy }␊
|
|
194
|
+
function foo(S calldata s) virtual internal pure returns (S calldata) ;␊
|
|
195
|
+
}␊
|
|
196
|
+
␊
|
|
197
|
+
library LibWithRequiredReturn {␊
|
|
198
|
+
struct S { uint x; }␊
|
|
199
|
+
enum $astId_id_random { dummy }␊
|
|
200
|
+
function foo(S calldata s) internal pure returns (bool) {}␊
|
|
194
201
|
}␊
|
|
195
202
|
␊
|
|
196
203
|
␊
|
|
@@ -204,17 +211,17 @@ Generated by [AVA](https://avajs.dev).
|
|
|
204
211
|
␊
|
|
205
212
|
abstract contract HasNatSpecWithMultipleReturns {␊
|
|
206
213
|
␊
|
|
207
|
-
function hasMultipleReturnsInContract() public pure returns (
|
|
214
|
+
function hasMultipleReturnsInContract() virtual public pure returns (uint, uint) ;␊
|
|
208
215
|
␊
|
|
209
216
|
␊
|
|
210
|
-
function hasMultipleNamedReturnsInContract() public pure returns (
|
|
217
|
+
function hasMultipleNamedReturnsInContract() virtual public pure returns (uint a, uint b) ;␊
|
|
211
218
|
␊
|
|
212
219
|
␊
|
|
213
|
-
function hasReturnsDocumentedAsParamsInContract() public pure returns (
|
|
220
|
+
function hasReturnsDocumentedAsParamsInContract() virtual public pure returns (uint a, uint b) ;␊
|
|
214
221
|
}␊
|
|
215
222
|
␊
|
|
216
223
|
interface IHasExternalViewFunction {␊
|
|
217
|
-
function foo() external view returns (
|
|
224
|
+
function foo() external view returns (uint256);␊
|
|
218
225
|
}␊
|
|
219
226
|
␊
|
|
220
227
|
abstract contract HasExternalViewFunction is IHasExternalViewFunction {␊
|
|
@@ -240,7 +247,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
240
247
|
enum $astId_id_random { dummy }␊
|
|
241
248
|
␊
|
|
242
249
|
// Regular function but payable␊
|
|
243
|
-
function hasPayable() public payable
|
|
250
|
+
function hasPayable() virtual public payable ;␊
|
|
244
251
|
␊
|
|
245
252
|
bytes4 constant PAYABLE_SELECTOR = this.hasPayable.selector;␊
|
|
246
253
|
}␊
|
|
@@ -261,7 +268,26 @@ Generated by [AVA](https://avajs.dev).
|
|
|
261
268
|
uint256 y;␊
|
|
262
269
|
}␊
|
|
263
270
|
}␊
|
|
264
|
-
|
|
271
|
+
␊
|
|
272
|
+
interface IHasConstantGetter {␊
|
|
273
|
+
function a() external view returns (bytes32);␊
|
|
274
|
+
}␊
|
|
275
|
+
␊
|
|
276
|
+
abstract contract HasConstantGetter is IHasConstantGetter {␊
|
|
277
|
+
bytes32 public override constant a = bytes32("foo");␊
|
|
278
|
+
}␊
|
|
279
|
+
␊
|
|
280
|
+
abstract contract AbstractHasConstantGetter {␊
|
|
281
|
+
function a() virtual external pure returns (bytes32) ;␊
|
|
282
|
+
}␊
|
|
283
|
+
␊
|
|
284
|
+
abstract contract HasConstantGetterOverride is AbstractHasConstantGetter {␊
|
|
285
|
+
bytes32 public override constant a = bytes32("foo");␊
|
|
286
|
+
}␊
|
|
287
|
+
␊
|
|
288
|
+
abstract contract HasFunctionOverride is AbstractHasConstantGetter {␊
|
|
289
|
+
function a() override virtual external pure returns (bytes32) ;␊
|
|
290
|
+
}`,
|
|
265
291
|
},
|
|
266
292
|
'contracts/test/NamespacedToModifyImported.sol': {
|
|
267
293
|
content: `// SPDX-License-Identifier: MIT␊
|
|
@@ -324,13 +350,13 @@ Generated by [AVA](https://avajs.dev).
|
|
|
324
350
|
} StorageWithComment $StorageWithComment_random;␊
|
|
325
351
|
␊
|
|
326
352
|
/// @notice some natspec␊
|
|
327
|
-
function foo() public
|
|
353
|
+
function foo() virtual public ;␊
|
|
328
354
|
␊
|
|
329
355
|
/// @param a docs␊
|
|
330
|
-
function foo1(uint a) public
|
|
356
|
+
function foo1(uint a) virtual public ;␊
|
|
331
357
|
␊
|
|
332
358
|
/// @param a docs␊
|
|
333
|
-
function foo2(uint a) internal
|
|
359
|
+
function foo2(uint a) virtual internal ;␊
|
|
334
360
|
struct MyStruct { uint b; }␊
|
|
335
361
|
␊
|
|
336
362
|
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊
|
|
@@ -339,7 +365,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
339
365
|
␊
|
|
340
366
|
function _getMainStorage() private pure returns (bool $) {}␊
|
|
341
367
|
␊
|
|
342
|
-
function _getXTimesY() internal view returns (
|
|
368
|
+
function _getXTimesY() virtual internal view returns (uint256) ;␊
|
|
343
369
|
␊
|
|
344
370
|
/// @notice standlone natspec␊
|
|
345
371
|
␊
|
|
@@ -355,14 +381,14 @@ Generated by [AVA](https://avajs.dev).
|
|
|
355
381
|
/**␊
|
|
356
382
|
* doc block without natspec␊
|
|
357
383
|
*/␊
|
|
358
|
-
function foo3() public
|
|
384
|
+
function foo3() virtual public ;␊
|
|
359
385
|
␊
|
|
360
386
|
/**␊
|
|
361
387
|
* doc block with natspec␊
|
|
362
388
|
*␊
|
|
363
389
|
* @notice some natspec␊
|
|
364
390
|
*/␊
|
|
365
|
-
function foo4() public
|
|
391
|
+
function foo4() virtual public ;␊
|
|
366
392
|
␊
|
|
367
393
|
/**␊
|
|
368
394
|
* @dev a custom error inside a contract␊
|
|
@@ -380,7 +406,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
380
406
|
/// @param myInt an integer␊
|
|
381
407
|
enum $astId_id_random { dummy }␊
|
|
382
408
|
␊
|
|
383
|
-
function foo() pure public returns (
|
|
409
|
+
function foo() virtual pure public returns (uint) ;␊
|
|
384
410
|
}␊
|
|
385
411
|
␊
|
|
386
412
|
abstract contract UsingFunction is HasFunction {␊
|
|
@@ -400,11 +426,11 @@ Generated by [AVA](https://avajs.dev).
|
|
|
400
426
|
abstract contract Consumer {␊
|
|
401
427
|
enum $astId_id_random { dummy }␊
|
|
402
428
|
␊
|
|
403
|
-
function usingFreeFunction() pure public returns (
|
|
429
|
+
function usingFreeFunction() virtual pure public returns (bytes4) ;␊
|
|
404
430
|
␊
|
|
405
|
-
function usingConstant() pure public returns (
|
|
431
|
+
function usingConstant() virtual pure public returns (bytes4) ;␊
|
|
406
432
|
␊
|
|
407
|
-
function usingLibraryFunction() pure public returns (
|
|
433
|
+
function usingLibraryFunction() virtual pure public returns (bytes4) ;␊
|
|
408
434
|
}␊
|
|
409
435
|
␊
|
|
410
436
|
abstract contract HasConstantWithSelector {␊
|
|
@@ -442,7 +468,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
442
468
|
abstract contract UsingForDirectives {␊
|
|
443
469
|
enum $astId_id_random { dummy }␊
|
|
444
470
|
␊
|
|
445
|
-
function usingFor(uint x) pure public returns (
|
|
471
|
+
function usingFor(uint x) virtual pure public returns (uint) ;␊
|
|
446
472
|
}␊
|
|
447
473
|
␊
|
|
448
474
|
/**␊
|
|
@@ -494,7 +520,14 @@ Generated by [AVA](https://avajs.dev).
|
|
|
494
520
|
␊
|
|
495
521
|
abstract contract HasFunctionWithRequiredReturn {␊
|
|
496
522
|
struct S { uint x; }␊
|
|
497
|
-
|
|
523
|
+
enum $astId_id_random { dummy }␊
|
|
524
|
+
function foo(S calldata s) virtual internal pure returns (S calldata) ;␊
|
|
525
|
+
}␊
|
|
526
|
+
␊
|
|
527
|
+
library LibWithRequiredReturn {␊
|
|
528
|
+
struct S { uint x; }␊
|
|
529
|
+
enum $astId_id_random { dummy }␊
|
|
530
|
+
function foo(S calldata s) internal pure returns (bool) {}␊
|
|
498
531
|
}␊
|
|
499
532
|
␊
|
|
500
533
|
/**␊
|
|
@@ -520,23 +553,23 @@ Generated by [AVA](https://avajs.dev).
|
|
|
520
553
|
* @return uint 1␊
|
|
521
554
|
* @return uint 2␊
|
|
522
555
|
*/␊
|
|
523
|
-
function hasMultipleReturnsInContract() public pure returns (
|
|
556
|
+
function hasMultipleReturnsInContract() virtual public pure returns (uint, uint) ;␊
|
|
524
557
|
␊
|
|
525
558
|
/**␊
|
|
526
559
|
* @return a first␊
|
|
527
560
|
* @return b second␊
|
|
528
561
|
*/␊
|
|
529
|
-
function hasMultipleNamedReturnsInContract() public pure returns (
|
|
562
|
+
function hasMultipleNamedReturnsInContract() virtual public pure returns (uint a, uint b) ;␊
|
|
530
563
|
␊
|
|
531
564
|
/**␊
|
|
532
565
|
* @param a first␊
|
|
533
566
|
* @param b second␊
|
|
534
567
|
*/␊
|
|
535
|
-
function hasReturnsDocumentedAsParamsInContract() public pure returns (
|
|
568
|
+
function hasReturnsDocumentedAsParamsInContract() virtual public pure returns (uint a, uint b) ;␊
|
|
536
569
|
}␊
|
|
537
570
|
␊
|
|
538
571
|
interface IHasExternalViewFunction {␊
|
|
539
|
-
function foo() external view returns (
|
|
572
|
+
function foo() external view returns (uint256);␊
|
|
540
573
|
}␊
|
|
541
574
|
␊
|
|
542
575
|
abstract contract HasExternalViewFunction is IHasExternalViewFunction {␊
|
|
@@ -562,7 +595,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
562
595
|
enum $astId_id_random { dummy }␊
|
|
563
596
|
␊
|
|
564
597
|
// Regular function but payable␊
|
|
565
|
-
function hasPayable() public payable
|
|
598
|
+
function hasPayable() virtual public payable ;␊
|
|
566
599
|
␊
|
|
567
600
|
bytes4 constant PAYABLE_SELECTOR = this.hasPayable.selector;␊
|
|
568
601
|
}␊
|
|
@@ -583,7 +616,26 @@ Generated by [AVA](https://avajs.dev).
|
|
|
583
616
|
uint256 y;␊
|
|
584
617
|
}␊
|
|
585
618
|
}␊
|
|
586
|
-
|
|
619
|
+
␊
|
|
620
|
+
interface IHasConstantGetter {␊
|
|
621
|
+
function a() external view returns (bytes32);␊
|
|
622
|
+
}␊
|
|
623
|
+
␊
|
|
624
|
+
abstract contract HasConstantGetter is IHasConstantGetter {␊
|
|
625
|
+
bytes32 public override constant a = bytes32("foo");␊
|
|
626
|
+
}␊
|
|
627
|
+
␊
|
|
628
|
+
abstract contract AbstractHasConstantGetter {␊
|
|
629
|
+
function a() virtual external pure returns (bytes32) ;␊
|
|
630
|
+
}␊
|
|
631
|
+
␊
|
|
632
|
+
abstract contract HasConstantGetterOverride is AbstractHasConstantGetter {␊
|
|
633
|
+
bytes32 public override constant a = bytes32("foo");␊
|
|
634
|
+
}␊
|
|
635
|
+
␊
|
|
636
|
+
abstract contract HasFunctionOverride is AbstractHasConstantGetter {␊
|
|
637
|
+
function a() override virtual external pure returns (bytes32) ;␊
|
|
638
|
+
}`,
|
|
587
639
|
},
|
|
588
640
|
'contracts/test/NamespacedToModifyImported.sol': {
|
|
589
641
|
content: `// SPDX-License-Identifier: MIT␊
|
|
@@ -626,7 +678,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
626
678
|
␊
|
|
627
679
|
abstract contract HasFunction {␊
|
|
628
680
|
enum $astId_id_random { dummy }␊
|
|
629
|
-
function foo() pure public returns (
|
|
681
|
+
function foo() virtual pure public returns (uint) ;␊
|
|
630
682
|
}␊
|
|
631
683
|
␊
|
|
632
684
|
abstract contract UsingFunction is HasFunction {␊
|
|
Binary file
|
|
@@ -3,7 +3,7 @@ import { Node } from 'solidity-ast/node';
|
|
|
3
3
|
import { SolcInput, SolcOutput } from '../solc-api';
|
|
4
4
|
import { getStorageLocationAnnotation } from '../storage/namespace';
|
|
5
5
|
import { assert, assertUnreachable } from './assert';
|
|
6
|
-
import { FunctionDefinition, VariableDeclaration } from 'solidity-ast';
|
|
6
|
+
import { ContractDefinition, FunctionDefinition, VariableDeclaration } from 'solidity-ast';
|
|
7
7
|
|
|
8
8
|
const OUTPUT_SELECTION = {
|
|
9
9
|
'*': {
|
|
@@ -19,10 +19,14 @@ const OUTPUT_SELECTION = {
|
|
|
19
19
|
* This makes the following modifications to the input:
|
|
20
20
|
* - Adds a state variable for each namespaced struct definition
|
|
21
21
|
* - For each contract, for all node types that are not needed for storage layout or may call functions and constructors, converts them to dummy enums with random id
|
|
22
|
+
* - Mark contracts as abstract, since state variables are converted to dummy enums which would not generate public getters for inherited interface functions
|
|
22
23
|
* - Converts all using for directives (at file level and in contracts) to dummy enums with random id (do not delete them to avoid orphaning possible NatSpec documentation)
|
|
23
24
|
* - Converts all custom errors and constants (at file level) to dummy enums with the same name (do not delete them since they might be imported by other files)
|
|
24
25
|
* - Replaces functions as follows:
|
|
25
|
-
* - For regular function and free function, keep declarations since they may be referenced by constants (free functions may also be imported by other files). But simplify compilation
|
|
26
|
+
* - For regular function and free function, keep declarations since they may be referenced by constants (free functions may also be imported by other files). But simplify compilation as follows:
|
|
27
|
+
* - Avoid having to initialize return parameters: convert function to virtual if possible, or convert return parameters to bools which can be default initialized.
|
|
28
|
+
* - Delete modifiers
|
|
29
|
+
* - Delete function bodies
|
|
26
30
|
* - Constructors are not needed, since we removed anything that may call constructors. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
27
31
|
* - Fallback and receive functions are not needed, since they don't have signatures. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
28
32
|
*
|
|
@@ -72,7 +76,7 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput, solcVe
|
|
|
72
76
|
for (const contractNode of contractNodes) {
|
|
73
77
|
switch (contractNode.nodeType) {
|
|
74
78
|
case 'FunctionDefinition': {
|
|
75
|
-
replaceFunction(contractNode, orig, modifications);
|
|
79
|
+
replaceFunction(contractNode, orig, modifications, contractDef);
|
|
76
80
|
break;
|
|
77
81
|
}
|
|
78
82
|
case 'VariableDeclaration': {
|
|
@@ -243,28 +247,62 @@ function toDummyEnumWithAstId(astId: number) {
|
|
|
243
247
|
return `enum $astId_${astId}_${(Math.random() * 1e6).toFixed(0)} { dummy }`;
|
|
244
248
|
}
|
|
245
249
|
|
|
246
|
-
function replaceFunction(
|
|
250
|
+
function replaceFunction(
|
|
251
|
+
node: FunctionDefinition,
|
|
252
|
+
orig: Buffer,
|
|
253
|
+
modifications: Modification[],
|
|
254
|
+
contractDef?: ContractDefinition,
|
|
255
|
+
) {
|
|
247
256
|
switch (node.kind) {
|
|
248
257
|
case 'freeFunction':
|
|
249
258
|
case 'function': {
|
|
259
|
+
let virtual = node.virtual;
|
|
260
|
+
|
|
261
|
+
if (
|
|
262
|
+
contractDef !== undefined &&
|
|
263
|
+
contractDef.contractKind === 'contract' &&
|
|
264
|
+
node.visibility !== 'private' &&
|
|
265
|
+
!virtual
|
|
266
|
+
) {
|
|
267
|
+
assert(node.kind !== 'freeFunction');
|
|
268
|
+
|
|
269
|
+
// If this is a contract function and not private, it could possibly override an interface function.
|
|
270
|
+
// We don't want to change its return parameters because that might cause a mismatch with the interface.
|
|
271
|
+
// Simply convert the function to virtual (if not already)
|
|
272
|
+
modifications.push(makeInsertAfter(node.parameters, ' virtual '));
|
|
273
|
+
virtual = true;
|
|
274
|
+
}
|
|
275
|
+
|
|
250
276
|
if (node.modifiers.length > 0) {
|
|
277
|
+
// Delete modifiers
|
|
251
278
|
for (const modifier of node.modifiers) {
|
|
252
279
|
modifications.push(makeDelete(modifier, orig));
|
|
253
280
|
}
|
|
254
281
|
}
|
|
255
282
|
|
|
256
|
-
if (node.returnParameters.parameters.length > 0) {
|
|
257
|
-
modifications.push(
|
|
258
|
-
makeReplace(
|
|
259
|
-
node.returnParameters,
|
|
260
|
-
orig,
|
|
261
|
-
`(${node.returnParameters.parameters.map(param => toReturnParameterReplacement(param)).join(', ')})`,
|
|
262
|
-
),
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
283
|
if (node.body) {
|
|
267
|
-
|
|
284
|
+
// Delete body
|
|
285
|
+
if (virtual) {
|
|
286
|
+
modifications.push(makeReplace(node.body, orig, ';'));
|
|
287
|
+
} else {
|
|
288
|
+
// This is a non-virtual function with a body, so that means it is not an interface function.
|
|
289
|
+
assert(contractDef?.contractKind !== 'interface');
|
|
290
|
+
// Since all contract functions that are non-private were converted to virtual above, this cannot possibly override another function.
|
|
291
|
+
assert(!node.overrides);
|
|
292
|
+
|
|
293
|
+
// The remaining scenarios may mean this is a library function, free function, or private function.
|
|
294
|
+
// In any of these cases, we can convert the return parameters to bools so that they can be default initialized.
|
|
295
|
+
if (node.returnParameters.parameters.length > 0) {
|
|
296
|
+
modifications.push(
|
|
297
|
+
makeReplace(
|
|
298
|
+
node.returnParameters,
|
|
299
|
+
orig,
|
|
300
|
+
`(${node.returnParameters.parameters.map(param => toReturnParameterReplacement(param)).join(', ')})`,
|
|
301
|
+
),
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
modifications.push(makeReplace(node.body, orig, '{}'));
|
|
305
|
+
}
|
|
268
306
|
}
|
|
269
307
|
|
|
270
308
|
break;
|
|
Binary file
|