diff --git a/package-lock.json b/package-lock.json index 1f4aa51d7..83c71d688 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1767,9 +1767,9 @@ } }, "@solidity-parser/parser": { - "version": "0.14.1", - "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.14.1.tgz", - "integrity": "sha512-eLjj2L6AuQjBB6s/ibwCAc0DwrR5Ge+ys+wgWo+bviU7fV2nTMQhU63CGaDKXg9iTmMxwhkyoggdIR7ZGRfMgw==", + "version": "0.14.2-beta.1", + "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.14.2-beta.1.tgz", + "integrity": "sha512-UU/LD1nG4XjZ4D9FxpjHeG5/i5MXc3CwJHIvLRI90sn+Ij9cGSyq9sBnSLGAubyhYULnH4/lB3pcbkXB9iO3MA==", "requires": { "antlr4ts": "^0.5.0-alpha.4" } diff --git a/package.json b/package.json index c731b8802..eb4990b3d 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "solc": "^0.8.14-fixed" }, "dependencies": { - "@solidity-parser/parser": "^0.14.1", + "@solidity-parser/parser": "^0.14.2-beta.1", "emoji-regex": "^10.1.0", "escape-string-regexp": "^4.0.0", "semver": "^7.3.7", diff --git a/src/binary-operator-printers/index.js b/src/binary-operator-printers/index.js index 0e7adfc11..a0d9d1755 100644 --- a/src/binary-operator-printers/index.js +++ b/src/binary-operator-printers/index.js @@ -1,4 +1,4 @@ -/* This file was automatically generated on 1621622090.188 */ +/* This file was automatically generated on 1653243394.809 */ /* eslint-disable global-require */ diff --git a/src/nodes/TypeNameExpression.js b/src/nodes/TypeNameExpression.js deleted file mode 100644 index 0eaf1b846..000000000 --- a/src/nodes/TypeNameExpression.js +++ /dev/null @@ -1,5 +0,0 @@ -const TypeNameExpression = { - print: ({ path, print }) => path.call(print, 'typeName') -}; - -module.exports = TypeNameExpression; diff --git a/src/nodes/UsingForDeclaration.js b/src/nodes/UsingForDeclaration.js index 86b064f39..1edddabdd 100644 --- a/src/nodes/UsingForDeclaration.js +++ b/src/nodes/UsingForDeclaration.js @@ -1,10 +1,26 @@ +const { + doc: { + builders: { line, softline } + } +} = require('prettier'); + +const printSeparatedList = require('./print-separated-list'); + const UsingForDeclaration = { - print: ({ node, path, print }) => [ + print: ({ node, path, print, options }) => [ 'using ', - node.libraryName, + node.functions && node.functions.length + ? [ + '{', + printSeparatedList(node.functions, { + firstSeparator: options.bracketSpacing ? line : softline + }), + '}' + ] + : node.libraryName, ' for ', node.typeName ? path.call(print, 'typeName') : '*', - ';' + node.isGlobal ? ' global;' : ';' ] }; diff --git a/src/nodes/index.js b/src/nodes/index.js index 1bba523b3..77bff4abd 100644 --- a/src/nodes/index.js +++ b/src/nodes/index.js @@ -1,4 +1,4 @@ -/* This file was automatically generated on 1621622090.034 */ +/* This file was automatically generated on 1653243394.65 */ /* eslint-disable global-require */ @@ -66,7 +66,6 @@ module.exports = { TryStatement: require('./TryStatement'), TupleExpression: require('./TupleExpression'), TypeDefinition: require('./TypeDefinition'), - TypeNameExpression: require('./TypeNameExpression'), UnaryOperation: require('./UnaryOperation'), UncheckedStatement: require('./UncheckedStatement'), UserDefinedTypeName: require('./UserDefinedTypeName'), diff --git a/tests/format/Libraries/Libraries.sol b/tests/format/Libraries/Libraries.sol new file mode 100644 index 000000000..09dfa2f2d --- /dev/null +++ b/tests/format/Libraries/Libraries.sol @@ -0,0 +1,10 @@ + using Lib for uint; +using Lib for + uint global; +using { f} for uint; +using {f } for uint global; +using { a, very, long, and, complex, Function, list, with, long, names } for + uint; +using { a, very, + long, and, complex, Function, + list, with, long, names } for uint global; diff --git a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..7fc513be1 --- /dev/null +++ b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,102 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Libraries.sol - {"bracketSpacing":true} format 1`] = ` +====================================options===================================== +bracketSpacing: true +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== + using Lib for uint; +using Lib for + uint global; +using { f} for uint; +using {f } for uint global; +using { a, very, long, and, complex, Function, list, with, long, names } for + uint; +using { a, very, + long, and, complex, Function, + list, with, long, names } for uint global; + +=====================================output===================================== +using Lib for uint256; +using Lib for uint256 global; +using { f } for uint256; +using { f } for uint256 global; +using { + a, + very, + long, + and, + complex, + Function, + list, + with, + long, + names +} for uint256; +using { + a, + very, + long, + and, + complex, + Function, + list, + with, + long, + names +} for uint256 global; + +================================================================================ +`; + +exports[`Libraries.sol format 1`] = ` +====================================options===================================== +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== + using Lib for uint; +using Lib for + uint global; +using { f} for uint; +using {f } for uint global; +using { a, very, long, and, complex, Function, list, with, long, names } for + uint; +using { a, very, + long, and, complex, Function, + list, with, long, names } for uint global; + +=====================================output===================================== +using Lib for uint256; +using Lib for uint256 global; +using {f} for uint256; +using {f} for uint256 global; +using { + a, + very, + long, + and, + complex, + Function, + list, + with, + long, + names +} for uint256; +using { + a, + very, + long, + and, + complex, + Function, + list, + with, + long, + names +} for uint256 global; + +================================================================================ +`; diff --git a/tests/format/Libraries/jsfmt.spec.js b/tests/format/Libraries/jsfmt.spec.js new file mode 100644 index 000000000..ba3fe57a9 --- /dev/null +++ b/tests/format/Libraries/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ['solidity-parse']); +run_spec(__dirname, ['solidity-parse'], { bracketSpacing: true });