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

Identifiers in function calls with an object are now processed #693

Merged
merged 2 commits into from
Jul 11, 2022
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
31 changes: 17 additions & 14 deletions src/nodes/FunctionCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ const {

const printSeparatedList = require('./print-separated-list');

const printObject = (node, path, print, options) => [
'{',
printSeparatedList(
path
.map(print, 'arguments')
.map((arg, index) => [node.names[index], ': ', arg]),
{
firstSeparator: options.bracketSpacing ? line : softline,
lastSeparator: [options.bracketSpacing ? line : softline, '})']
}
)
];
const printObject = (path, print, options) => {
const identifiers = path.map(print, 'identifiers');
return [
'{',
printSeparatedList(
path
.map(print, 'arguments')
.map((arg, index) => [identifiers[index], ': ', arg]),
{
firstSeparator: options.bracketSpacing ? line : softline,
lastSeparator: [options.bracketSpacing ? line : softline, '})']
}
)
];
};

const printArguments = (path, print) =>
printSeparatedList(path.map(print, 'arguments'), {
Expand All @@ -31,8 +34,8 @@ const FunctionCall = {
let argumentsDoc = ')';

if (node.arguments && node.arguments.length > 0) {
if (node.names && node.names.length > 0) {
argumentsDoc = printObject(node, path, print, options);
if (node.identifiers && node.identifiers.length > 0) {
argumentsDoc = printObject(path, print, options);
} else {
argumentsDoc = printArguments(path, print);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/config/format-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const RANGE_END_PLACEHOLDER = "<<<PRETTIER_RANGE_END>>>";

// Here we add files that will not be the same when formatting a second time.
const unstableTests = new Map(
[].map((fixture) => {
["Comments/Comments.sol"].map((fixture) => {
const [file, isUnstable = () => true] = Array.isArray(fixture)
? fixture
: [fixture];
Expand Down
12 changes: 12 additions & 0 deletions tests/format/Comments/Comments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,15 @@ contract Comments11 {
// this should not be removed
}
}

contract Comments12 {
function f() public {
purchaseData[0] = DomainPurchaseData({
/* test */prices: _rootPrices,
// test2
subdomainMintingEnabled: /* test3 */_rootPrices.short > 0,
allowSubdomainsToMint: true, // test4
wasAllowedToSubdomainMintOnCreation: true
});
}
}
26 changes: 26 additions & 0 deletions tests/format/Comments/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ contract Comments11 {
}
}

contract Comments12 {
function f() public {
purchaseData[0] = DomainPurchaseData({
/* test */prices: _rootPrices,
// test2
subdomainMintingEnabled: /* test3 */_rootPrices.short > 0,
allowSubdomainsToMint: true, // test4
wasAllowedToSubdomainMintOnCreation: true
});
}
}

=====================================output=====================================
pragma solidity ^0.4.24;

Expand Down Expand Up @@ -240,5 +252,19 @@ contract Comments11 {
}
}

contract Comments12 {
function f() public {
purchaseData[0] = DomainPurchaseData({
/* test */
prices: _rootPrices,
// test2
subdomainMintingEnabled: /* test3 */
_rootPrices.short > 0,
allowSubdomainsToMint: true, // test4
wasAllowedToSubdomainMintOnCreation: true
});
}
}

================================================================================
`;