Skip to content

Commit

Permalink
Merge pull request #803 from zemse/mapping-named-parameters
Browse files Browse the repository at this point in the history
Add support for named parameters in mappings
  • Loading branch information
fvictorio authored Feb 6, 2023
2 parents a8cf709 + 7368dbf commit ae6d1e1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"webpack-cli": "^5.0.1"
},
"dependencies": {
"@solidity-parser/parser": "^0.14.5",
"@solidity-parser/parser": "^0.15.0",
"semver": "^7.3.8",
"solidity-comments-extractor": "^0.0.7"
},
Expand Down
22 changes: 15 additions & 7 deletions src/nodes/Mapping.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
const Mapping = {
print: ({ path, print }) => [
'mapping(',
path.call(print, 'keyType'),
' => ',
path.call(print, 'valueType'),
')'
]
print: ({ path, print }) => {
const keyType = path.call(print, 'keyType');
const keyName = path.call(print, 'keyName');
const valueType = path.call(print, 'valueType');
const valueName = path.call(print, 'valueName');
return [
'mapping(',
keyType,
keyName ? ` ${keyName}` : '',
' => ',
valueType,
valueName ? ` ${valueName}` : '',
')'
];
}
};

module.exports = Mapping;
2 changes: 2 additions & 0 deletions tests/format/AllSolidityFeatures/AllSolidityFeatures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ contract c {
function setData(uint pos, uint value) internal { data[pos] = value; }
function getData(uint pos) internal { return data[pos]; }
mapping(uint => uint) data;
mapping(uint id => uint ) data;
mapping(address owner => mapping(address spender => uint amount)) allowances;
}

contract Sharer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ contract c {
function setData(uint pos, uint value) internal { data[pos] = value; }
function getData(uint pos) internal { return data[pos]; }
mapping(uint => uint) data;
mapping(uint id => uint ) data;
mapping(address owner => mapping(address spender => uint amount)) allowances;
}
contract Sharer {
Expand Down Expand Up @@ -651,6 +653,8 @@ contract c {
}
mapping(uint => uint) data;
mapping(uint id => uint) data;
mapping(address owner => mapping(address spender => uint amount)) allowances;
}
contract Sharer {
Expand Down

0 comments on commit ae6d1e1

Please sign in to comment.