-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* including the last ')' in the group so if the call reaches the charLimit with the ')' it will break * function calls now set up a groupId and expose it via labels * MemberAccess reacts accordingly to the function calls groupId
- Loading branch information
Showing
4 changed files
with
80 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,59 @@ | ||
const { | ||
doc: { | ||
builders: { group, line, softline } | ||
builders: { label, line, softline } | ||
} | ||
} = require('prettier/standalone'); | ||
|
||
const printSeparatedList = require('./print-separated-list'); | ||
|
||
const printObject = (node, path, print, options) => | ||
group([ | ||
'{', | ||
printSeparatedList( | ||
path | ||
.map(print, 'arguments') | ||
.map((arg, index) => [node.names[index], ': ', arg]), | ||
{ firstSeparator: options.bracketSpacing ? line : softline } | ||
), | ||
'}' | ||
]); | ||
let functionCallId = 0; | ||
|
||
const printArguments = (node, path, print, options) => { | ||
if (node.names && node.names.length > 0) { | ||
return printObject(node, path, print, options); | ||
} | ||
if (node.arguments && node.arguments.length > 0) { | ||
return printSeparatedList(path.map(print, 'arguments')); | ||
} | ||
return ''; | ||
}; | ||
const printObject = (node, path, print, options, groupId) => [ | ||
'{', | ||
printSeparatedList( | ||
path | ||
.map(print, 'arguments') | ||
.map((arg, index) => [node.names[index], ': ', arg]), | ||
{ | ||
groupId, | ||
firstSeparator: options.bracketSpacing ? line : softline, | ||
lastSeparator: [options.bracketSpacing ? line : softline, '})'] | ||
} | ||
) | ||
]; | ||
|
||
const printArguments = (path, print, groupId) => | ||
printSeparatedList(path.map(print, 'arguments'), { | ||
groupId, | ||
lastSeparator: [softline, ')'] | ||
}); | ||
|
||
const FunctionCall = { | ||
print: ({ node, path, print, options }) => [ | ||
path.call(print, 'expression'), | ||
'(', | ||
printArguments(node, path, print, options), | ||
')' | ||
] | ||
print: ({ node, path, print, options }) => { | ||
let argumentsDoc = ')'; | ||
const functionCallLabel = { type: 'FunctionCall', groupId: null }; | ||
if (node.arguments && node.arguments.length > 0) { | ||
functionCallLabel.groupId = `FunctionCall-${functionCallId}`; | ||
functionCallId += 1; | ||
if (node.names && node.names.length > 0) { | ||
argumentsDoc = printObject( | ||
node, | ||
path, | ||
print, | ||
options, | ||
functionCallLabel.groupId | ||
); | ||
} else { | ||
argumentsDoc = printArguments(path, print, functionCallLabel.groupId); | ||
} | ||
} | ||
|
||
return label(JSON.stringify(functionCallLabel), [ | ||
path.call(print, 'expression'), | ||
'(', | ||
argumentsDoc | ||
]); | ||
} | ||
}; | ||
|
||
module.exports = FunctionCall; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters