prettier-plugin-solidity 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/standalone.js +1 -1
  2. package/dist/standalone.js.map +1 -1
  3. package/package.json +5 -8
  4. package/src/clean.js +4 -6
  5. package/src/common/printer-helpers.js +116 -0
  6. package/src/common/util.js +6 -1
  7. package/src/nodes/AssemblyBlock.js +5 -3
  8. package/src/nodes/AssemblyCall.js +1 -1
  9. package/src/nodes/AssemblyFunctionDefinition.js +4 -2
  10. package/src/nodes/AssemblyLocalDefinition.js +1 -1
  11. package/src/nodes/BinaryOperation.js +10 -4
  12. package/src/nodes/Block.js +4 -2
  13. package/src/nodes/CatchClause.js +1 -1
  14. package/src/nodes/ContractDefinition.js +6 -4
  15. package/src/nodes/CustomErrorDefinition.js +1 -1
  16. package/src/nodes/DoWhileStatement.js +1 -1
  17. package/src/nodes/EnumDefinition.js +1 -1
  18. package/src/nodes/EventDefinition.js +1 -1
  19. package/src/nodes/ExpressionStatement.js +2 -2
  20. package/src/nodes/ForStatement.js +1 -1
  21. package/src/nodes/FunctionCall.js +1 -1
  22. package/src/nodes/FunctionDefinition.js +7 -7
  23. package/src/nodes/FunctionTypeName.js +1 -1
  24. package/src/nodes/IfStatement.js +4 -2
  25. package/src/nodes/ImportDirective.js +1 -1
  26. package/src/nodes/InheritanceSpecifier.js +1 -1
  27. package/src/nodes/InlineAssemblyStatement.js +1 -1
  28. package/src/nodes/Mapping.js +15 -7
  29. package/src/nodes/ModifierDefinition.js +1 -1
  30. package/src/nodes/ModifierInvocation.js +4 -2
  31. package/src/nodes/NameValueList.js +1 -1
  32. package/src/nodes/SourceUnit.js +1 -1
  33. package/src/nodes/StructDefinition.js +1 -1
  34. package/src/nodes/TryStatement.js +4 -2
  35. package/src/nodes/TupleExpression.js +1 -1
  36. package/src/nodes/UsingForDeclaration.js +1 -1
  37. package/src/nodes/VariableDeclaration.js +1 -1
  38. package/src/nodes/VariableDeclarationStatement.js +1 -1
  39. package/src/nodes/WhileStatement.js +1 -1
  40. package/src/parser.js +1 -1
  41. package/src/printer.js +5 -4
  42. package/src/nodes/print-comments.js +0 -27
  43. package/src/nodes/print-preserving-empty-lines.js +0 -53
  44. package/src/nodes/print-separated-item.js +0 -21
  45. package/src/nodes/print-separated-list.js +0 -23
@@ -1,27 +0,0 @@
1
- const {
2
- doc: {
3
- builders: { join, line }
4
- }
5
- } = require('prettier');
6
-
7
- const printComments = (node, path, options, filter = () => true) =>
8
- node.comments
9
- ? join(
10
- line,
11
- path
12
- .map((commentPath) => {
13
- const comment = commentPath.getValue();
14
- if (comment.trailing || comment.leading || comment.printed) {
15
- return null;
16
- }
17
- if (!filter(comment)) {
18
- return null;
19
- }
20
- comment.printed = true;
21
- return options.printer.printComment(commentPath);
22
- }, 'comments')
23
- .filter(Boolean)
24
- )
25
- : '';
26
-
27
- module.exports = printComments;
@@ -1,53 +0,0 @@
1
- const {
2
- doc: {
3
- builders: { hardline }
4
- },
5
- util: { isNextLineEmptyAfterIndex }
6
- } = require('prettier');
7
-
8
- function printPreservingEmptyLines(path, key, options, print) {
9
- const parts = [];
10
- path.each((childPath) => {
11
- const node = childPath.getValue();
12
- const nodeType = node.type;
13
-
14
- if (
15
- // Avoid adding a hardline at the beginning of the document.
16
- parts.length !== 0 &&
17
- // LabelDefinition adds a dedented line so we don't have to prepend a
18
- // hardline.
19
- nodeType !== 'LabelDefinition'
20
- ) {
21
- parts.push(hardline);
22
- }
23
-
24
- if (childPath.getName() > 0) {
25
- if (
26
- ['ContractDefinition', 'FunctionDefinition'].includes(nodeType) &&
27
- parts[parts.length - 2] !== hardline
28
- ) {
29
- parts.push(hardline);
30
- }
31
- }
32
-
33
- parts.push(print(childPath));
34
-
35
- if (
36
- isNextLineEmptyAfterIndex(
37
- options.originalText,
38
- options.locEnd(node) + 1
39
- ) ||
40
- nodeType === 'FunctionDefinition'
41
- ) {
42
- parts.push(hardline);
43
- }
44
- }, key);
45
-
46
- if (parts.length > 1 && parts[parts.length - 1] === hardline) {
47
- parts.pop();
48
- }
49
-
50
- return parts;
51
- }
52
-
53
- module.exports = printPreservingEmptyLines;
@@ -1,21 +0,0 @@
1
- const {
2
- doc: {
3
- builders: { group, indent, softline }
4
- }
5
- } = require('prettier');
6
-
7
- // This function will add an indentation to the `item` and separate it from the
8
- // rest of the `doc` in most cases by a `softline`.
9
- const printSeparatedItem = (
10
- item,
11
- {
12
- firstSeparator = softline,
13
- lastSeparator = firstSeparator,
14
- grouped = true
15
- } = {}
16
- ) => {
17
- const doc = [indent([firstSeparator, item]), lastSeparator];
18
- return grouped ? group(doc) : doc;
19
- };
20
-
21
- module.exports = printSeparatedItem;
@@ -1,23 +0,0 @@
1
- const {
2
- doc: {
3
- builders: { group, indent, join, line, softline }
4
- }
5
- } = require('prettier');
6
-
7
- // This function will add an indentation to the `list` and separate it from the
8
- // rest of the `doc` in most cases by a `softline`.
9
- // the list itself will be printed with a separator that in most cases is a
10
- // comma (,) and a `line`
11
- const printSeparatedList = (
12
- list,
13
- {
14
- firstSeparator = softline,
15
- separator = [',', line],
16
- lastSeparator = firstSeparator,
17
- grouped = true
18
- } = {}
19
- ) => {
20
- const doc = [indent([firstSeparator, join(separator, list)]), lastSeparator];
21
- return grouped ? group(doc) : doc;
22
- };
23
- module.exports = printSeparatedList;