prettier-plugin-solidity
Advanced tools
Comparing version 1.0.0-alpha.23 to 1.0.0-alpha.24
{ | ||
"name": "prettier-plugin-solidity", | ||
"version": "1.0.0-alpha.23", | ||
"version": "1.0.0-alpha.24", | ||
"description": "prettier plugin for solidity", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable implicit-arrow-linebreak */ | ||
const { | ||
@@ -7,43 +8,55 @@ doc: { | ||
const FunctionCall = { | ||
print: ({ node, path, print }) => { | ||
let doc; | ||
if (node.names && node.names.length > 0) { | ||
doc = concat([ | ||
'{', | ||
group( | ||
concat([ | ||
indent( | ||
concat([ | ||
softline, | ||
join( | ||
concat([',', line]), | ||
path | ||
.map(print, 'arguments') | ||
.map((arg, index) => concat([node.names[index], ': ', arg])) | ||
) | ||
]) | ||
), | ||
softline | ||
]) | ||
), | ||
'}' | ||
]); | ||
} else { | ||
doc = group( | ||
const printObject = (node, path, print) => | ||
group( | ||
concat([ | ||
'{', | ||
indent( | ||
concat([ | ||
indent( | ||
concat([ | ||
softline, | ||
join(concat([',', line]), path.map(print, 'arguments')) | ||
]) | ||
), | ||
softline | ||
softline, | ||
join( | ||
concat([',', line]), | ||
path | ||
.map(print, 'arguments') | ||
.map((arg, index) => concat([node.names[index], ': ', arg])) | ||
) | ||
]) | ||
); | ||
} | ||
return concat([path.call(print, 'expression'), '(', doc, ')']); | ||
), | ||
softline, | ||
'}' | ||
]) | ||
); | ||
const printParameters = (node, path, print) => | ||
group( | ||
concat([ | ||
indent( | ||
concat([ | ||
softline, | ||
join(concat([',', line]), path.map(print, 'arguments')) | ||
]) | ||
), | ||
softline | ||
]) | ||
); | ||
const printArguments = (node, path, print) => { | ||
if (node.names && node.names.length > 0) { | ||
return printObject(node, path, print); | ||
} | ||
if (node.arguments && node.arguments.length > 0) { | ||
return printParameters(node, path, print); | ||
} | ||
return ''; | ||
}; | ||
const FunctionCall = { | ||
print: ({ node, path, print }) => | ||
concat([ | ||
path.call(print, 'expression'), | ||
'(', | ||
printArguments(node, path, print), | ||
')' | ||
]) | ||
}; | ||
module.exports = FunctionCall; |
@@ -0,4 +1,5 @@ | ||
/* eslint-disable implicit-arrow-linebreak */ | ||
const { | ||
doc: { | ||
builders: { concat, join } | ||
builders: { concat, group, indent, join, line, softline } | ||
} | ||
@@ -8,17 +9,22 @@ } = require('prettier'); | ||
const TupleExpression = { | ||
print: ({ node, path, print }) => { | ||
let doc; | ||
// @TODO: remove hack once solidity-parser-antlr is fixed | ||
if (node.components) { | ||
doc = join(', ', path.map(print, 'components')); | ||
} else { | ||
doc = join(', ', path.map(print, 'elements')); | ||
} | ||
if (node.isArray) { | ||
return concat(['[', doc, ']']); | ||
} | ||
return concat(['(', doc, ')']); | ||
} | ||
// @TODO: remove hack once solidity-parser-antlr is fixed | ||
print: ({ node, path, print }) => | ||
group( | ||
concat([ | ||
node.isArray ? '[' : '(', | ||
indent( | ||
concat([ | ||
softline, | ||
join( | ||
concat([',', line]), | ||
path.map(print, node.components ? 'components' : 'elements') | ||
) | ||
]) | ||
), | ||
softline, | ||
node.isArray ? ']' : ')' | ||
]) | ||
) | ||
}; | ||
module.exports = TupleExpression; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
300795
157
2785