prettier-plugin-solidity 1.1.3 → 1.1.4-dev

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 (105) hide show
  1. package/README.md +48 -9
  2. package/dist/standalone.cjs +3 -0
  3. package/dist/standalone.cjs.map +1 -0
  4. package/package.json +42 -33
  5. package/src/binary-operator-printers/arithmetic.js +12 -14
  6. package/src/binary-operator-printers/assignment.js +4 -6
  7. package/src/binary-operator-printers/bit.js +2 -2
  8. package/src/binary-operator-printers/comparison.js +11 -13
  9. package/src/binary-operator-printers/exponentiation.js +4 -6
  10. package/src/binary-operator-printers/index.js +7 -13
  11. package/src/binary-operator-printers/logical.js +12 -14
  12. package/src/binary-operator-printers/shift.js +2 -2
  13. package/src/clean.js +1 -1
  14. package/src/comments/handler.js +7 -15
  15. package/src/comments/handlers/handleContractDefinitionComments.js +9 -11
  16. package/src/comments/handlers/handleModifierInvocationComments.js +9 -11
  17. package/src/comments/handlers/index.js +5 -3
  18. package/src/comments/ignore.js +1 -1
  19. package/src/comments/index.js +2 -4
  20. package/src/comments/printer.js +5 -10
  21. package/src/common/printer-helpers.js +15 -28
  22. package/src/common/util.js +30 -20
  23. package/src/index.js +14 -12
  24. package/src/loc.js +1 -1
  25. package/src/nodes/ArrayTypeName.js +1 -3
  26. package/src/nodes/AssemblyAssignment.js +4 -8
  27. package/src/nodes/AssemblyBlock.js +6 -11
  28. package/src/nodes/AssemblyCall.js +2 -4
  29. package/src/nodes/AssemblyCase.js +1 -3
  30. package/src/nodes/AssemblyFor.js +4 -8
  31. package/src/nodes/AssemblyFunctionDefinition.js +6 -11
  32. package/src/nodes/AssemblyIf.js +1 -3
  33. package/src/nodes/AssemblyLocalDefinition.js +4 -9
  34. package/src/nodes/AssemblyMemberAccess.js +1 -3
  35. package/src/nodes/AssemblyStackAssignment.js +1 -3
  36. package/src/nodes/AssemblySwitch.js +4 -8
  37. package/src/nodes/BinaryOperation.js +2 -5
  38. package/src/nodes/Block.js +6 -11
  39. package/src/nodes/BooleanLiteral.js +1 -3
  40. package/src/nodes/Break.js +1 -3
  41. package/src/nodes/BreakStatement.js +1 -3
  42. package/src/nodes/CatchClause.js +2 -4
  43. package/src/nodes/Conditional.js +4 -8
  44. package/src/nodes/Continue.js +1 -3
  45. package/src/nodes/ContinueStatement.js +1 -3
  46. package/src/nodes/ContractDefinition.js +11 -17
  47. package/src/nodes/CustomErrorDefinition.js +2 -4
  48. package/src/nodes/DecimalNumber.js +1 -3
  49. package/src/nodes/DoWhileStatement.js +4 -9
  50. package/src/nodes/ElementaryTypeName.js +1 -3
  51. package/src/nodes/EmitStatement.js +1 -3
  52. package/src/nodes/EnumDefinition.js +4 -9
  53. package/src/nodes/EnumValue.js +1 -3
  54. package/src/nodes/EventDefinition.js +2 -4
  55. package/src/nodes/ExpressionStatement.js +4 -9
  56. package/src/nodes/FileLevelConstant.js +1 -3
  57. package/src/nodes/ForStatement.js +4 -9
  58. package/src/nodes/FunctionCall.js +4 -9
  59. package/src/nodes/FunctionDefinition.js +11 -18
  60. package/src/nodes/FunctionTypeName.js +4 -9
  61. package/src/nodes/HexLiteral.js +4 -9
  62. package/src/nodes/HexNumber.js +1 -3
  63. package/src/nodes/Identifier.js +1 -3
  64. package/src/nodes/IfStatement.js +6 -11
  65. package/src/nodes/ImportDirective.js +12 -17
  66. package/src/nodes/IndexAccess.js +4 -8
  67. package/src/nodes/IndexRangeAccess.js +1 -3
  68. package/src/nodes/InheritanceSpecifier.js +2 -4
  69. package/src/nodes/InlineAssemblyStatement.js +3 -4
  70. package/src/nodes/LabelDefinition.js +4 -8
  71. package/src/nodes/Mapping.js +17 -18
  72. package/src/nodes/MemberAccess.js +6 -10
  73. package/src/nodes/ModifierDefinition.js +4 -9
  74. package/src/nodes/ModifierInvocation.js +3 -5
  75. package/src/nodes/NameValueExpression.js +1 -3
  76. package/src/nodes/NameValueList.js +4 -9
  77. package/src/nodes/NewExpression.js +1 -3
  78. package/src/nodes/NumberLiteral.js +1 -3
  79. package/src/nodes/PragmaDirective.js +1 -3
  80. package/src/nodes/ReturnStatement.js +4 -8
  81. package/src/nodes/RevertStatement.js +1 -3
  82. package/src/nodes/SourceUnit.js +4 -9
  83. package/src/nodes/StateVariableDeclaration.js +4 -8
  84. package/src/nodes/StringLiteral.js +5 -9
  85. package/src/nodes/StructDefinition.js +13 -22
  86. package/src/nodes/ThrowStatement.js +1 -3
  87. package/src/nodes/TryStatement.js +6 -11
  88. package/src/nodes/TupleExpression.js +4 -9
  89. package/src/nodes/TypeDefinition.js +1 -3
  90. package/src/nodes/UnaryOperation.js +1 -3
  91. package/src/nodes/UncheckedStatement.js +4 -8
  92. package/src/nodes/UserDefinedTypeName.js +1 -3
  93. package/src/nodes/UsingForDeclaration.js +28 -44
  94. package/src/nodes/VariableDeclaration.js +4 -9
  95. package/src/nodes/VariableDeclarationStatement.js +6 -11
  96. package/src/nodes/WhileStatement.js +4 -9
  97. package/src/nodes/index.js +72 -78
  98. package/src/options.js +1 -1
  99. package/src/parser.js +5 -12
  100. package/src/prettier-comments/language-js/comments.js +13 -23
  101. package/src/printer.js +6 -6
  102. package/dist/standalone.js +0 -3
  103. package/dist/standalone.js.map +0 -1
  104. package/src/prettier-comments/index.js +0 -3
  105. /package/dist/{standalone.js.LICENSE.txt → standalone.cjs.LICENSE.txt} +0 -0
@@ -1,18 +1,35 @@
1
- const {
2
- util: { getNextNonSpaceNonCommentCharacterIndex, makeString },
3
- version
4
- } = require('prettier');
5
- const satisfies = require('semver/functions/satisfies');
1
+ import { util, version } from 'prettier';
2
+ import satisfies from 'semver/functions/satisfies.js';
6
3
 
7
- const prettierVersionSatisfies = (range) => satisfies(version, range);
4
+ export const prettierVersionSatisfies = (range) => satisfies(version, range);
5
+ export const isPrettier2 = () => prettierVersionSatisfies('^2.3.0');
8
6
 
9
- function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
10
- return text.charAt(
11
- getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
12
- );
7
+ // The following functions will never be 100% covered in a single run
8
+ // since it depends on the version of Prettier being used.
9
+ // Mocking the behaviour will introduce a lot of maintenance in the tests.
10
+ /* c8 ignore start */
11
+ export function isNextLineEmpty(text, startIndex) {
12
+ return isPrettier2()
13
+ ? util.isNextLineEmptyAfterIndex(text, startIndex)
14
+ : util.isNextLineEmpty(text, startIndex); // V3 deprecated `isNextLineEmptyAfterIndex`
15
+ }
16
+
17
+ export function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
18
+ return isPrettier2()
19
+ ? util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
20
+ : util.getNextNonSpaceNonCommentCharacterIndex(text, locEnd(node)); // V3 signature changed
13
21
  }
14
22
 
15
- function printString(rawContent, options) {
23
+ export function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
24
+ return isPrettier2()
25
+ ? text.charAt(
26
+ util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
27
+ )
28
+ : util.getNextNonSpaceNonCommentCharacter(text, locEnd(node)); // V3 exposes this function directly
29
+ }
30
+ /* c8 ignore stop */
31
+
32
+ export function printString(rawContent, options) {
16
33
  const double = { quote: '"', regex: /"/g };
17
34
  const single = { quote: "'", regex: /'/g };
18
35
 
@@ -44,10 +61,10 @@ function printString(rawContent, options) {
44
61
  // is enclosed with `enclosingQuote`, but it isn't. The string could contain
45
62
  // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
46
63
  // sure that we consistently output the minimum amount of escaped quotes.
47
- return makeString(rawContent, enclosingQuote);
64
+ return util.makeString(rawContent, enclosingQuote);
48
65
  }
49
66
 
50
- function hasNodeIgnoreComment(node) {
67
+ export function hasNodeIgnoreComment(node) {
51
68
  return (
52
69
  node &&
53
70
  node.comments &&
@@ -55,10 +72,3 @@ function hasNodeIgnoreComment(node) {
55
72
  node.comments.some((comment) => comment.value.trim() === 'prettier-ignore')
56
73
  );
57
74
  }
58
-
59
- module.exports = {
60
- getNextNonSpaceNonCommentCharacter,
61
- printString,
62
- prettierVersionSatisfies,
63
- hasNodeIgnoreComment
64
- };
package/src/index.js CHANGED
@@ -1,9 +1,9 @@
1
- const { handleComments, printComment } = require('./comments');
2
- const massageAstNode = require('./clean');
3
- const loc = require('./loc');
4
- const options = require('./options');
5
- const parse = require('./parser');
6
- const print = require('./printer');
1
+ import * as comments from './comments/index.js';
2
+ import massageAstNode from './clean.js';
3
+ import loc from './loc.js';
4
+ import options from './options.js';
5
+ import parse from './parser.js';
6
+ import print from './printer.js';
7
7
 
8
8
  // https://prettier.io/docs/en/plugins.html#languages
9
9
  // https://github.com/ikatyang/linguist-languages/blob/master/data/Solidity.json
@@ -35,14 +35,14 @@ const printers = {
35
35
  'solidity-ast': {
36
36
  canAttachComment,
37
37
  handleComments: {
38
- ownLine: handleComments.handleOwnLineComment,
39
- endOfLine: handleComments.handleEndOfLineComment,
40
- remaining: handleComments.handleRemainingComment
38
+ ownLine: comments.solidityHandleOwnLineComment,
39
+ endOfLine: comments.solidityHandleEndOfLineComment,
40
+ remaining: comments.solidityHandleRemainingComment
41
41
  },
42
- isBlockComment: handleComments.isBlockComment,
42
+ isBlockComment: comments.isBlockComment,
43
43
  massageAstNode,
44
44
  print,
45
- printComment
45
+ printComment: comments.printComment
46
46
  }
47
47
  };
48
48
 
@@ -52,10 +52,12 @@ const defaultOptions = {
52
52
  tabWidth: 4
53
53
  };
54
54
 
55
- module.exports = {
55
+ const plugin = {
56
56
  languages,
57
57
  parsers,
58
58
  printers,
59
59
  options,
60
60
  defaultOptions
61
61
  };
62
+
63
+ export default plugin;
package/src/loc.js CHANGED
@@ -10,7 +10,7 @@ function getRange(index, node) {
10
10
  return null;
11
11
  }
12
12
 
13
- module.exports = {
13
+ export default {
14
14
  locEnd: (node) => getRange(1, node),
15
15
  locStart: (node) => getRange(0, node)
16
16
  };
@@ -1,4 +1,4 @@
1
- const ArrayTypeName = {
1
+ export const ArrayTypeName = {
2
2
  print: ({ node, path, print }) => [
3
3
  path.call(print, 'baseTypeName'),
4
4
  '[',
@@ -6,5 +6,3 @@ const ArrayTypeName = {
6
6
  ']'
7
7
  ]
8
8
  };
9
-
10
- module.exports = ArrayTypeName;
@@ -1,15 +1,11 @@
1
- const {
2
- doc: {
3
- builders: { join }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
6
2
 
7
- const AssemblyAssignment = {
3
+ const { join } = doc.builders;
4
+
5
+ export const AssemblyAssignment = {
8
6
  print: ({ path, print }) => [
9
7
  join(', ', path.map(print, 'names')),
10
8
  ' := ',
11
9
  path.call(print, 'expression')
12
10
  ]
13
11
  };
14
-
15
- module.exports = AssemblyAssignment;
@@ -1,16 +1,13 @@
1
- const {
2
- doc: {
3
- builders: { hardline }
4
- }
5
- } = require('prettier');
6
-
7
- const {
1
+ import { doc } from 'prettier';
2
+ import {
8
3
  printComments,
9
4
  printPreservingEmptyLines,
10
5
  printSeparatedItem
11
- } = require('../common/printer-helpers');
6
+ } from '../common/printer-helpers.js';
7
+
8
+ const { hardline } = doc.builders;
12
9
 
13
- const AssemblyBlock = {
10
+ export const AssemblyBlock = {
14
11
  print: ({ node, options, path, print }) => [
15
12
  '{',
16
13
  printSeparatedItem(
@@ -23,5 +20,3 @@ const AssemblyBlock = {
23
20
  '}'
24
21
  ]
25
22
  };
26
-
27
- module.exports = AssemblyBlock;
@@ -1,6 +1,6 @@
1
- const { printSeparatedList } = require('../common/printer-helpers');
1
+ import { printSeparatedList } from '../common/printer-helpers.js';
2
2
 
3
- const AssemblyCall = {
3
+ export const AssemblyCall = {
4
4
  print: ({ node, path, print, options }) =>
5
5
  node.arguments.length === 0 &&
6
6
  options.originalText.charAt(options.locEnd(node)) !== ')'
@@ -12,5 +12,3 @@ const AssemblyCall = {
12
12
  ')'
13
13
  ]
14
14
  };
15
-
16
- module.exports = AssemblyCall;
@@ -1,9 +1,7 @@
1
- const AssemblyCase = {
1
+ export const AssemblyCase = {
2
2
  print: ({ node, path, print }) => [
3
3
  node.default ? 'default' : ['case ', path.call(print, 'value')],
4
4
  ' ',
5
5
  path.call(print, 'block')
6
6
  ]
7
7
  };
8
-
9
- module.exports = AssemblyCase;
@@ -1,10 +1,8 @@
1
- const {
2
- doc: {
3
- builders: { join }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
6
2
 
7
- const AssemblyFor = {
3
+ const { join } = doc.builders;
4
+
5
+ export const AssemblyFor = {
8
6
  print: ({ path, print }) =>
9
7
  join(' ', [
10
8
  'for',
@@ -14,5 +12,3 @@ const AssemblyFor = {
14
12
  path.call(print, 'body')
15
13
  ])
16
14
  };
17
-
18
- module.exports = AssemblyFor;
@@ -1,15 +1,12 @@
1
- const {
2
- doc: {
3
- builders: { line }
4
- }
5
- } = require('prettier');
6
-
7
- const {
1
+ import { doc } from 'prettier';
2
+ import {
8
3
  printSeparatedItem,
9
4
  printSeparatedList
10
- } = require('../common/printer-helpers');
5
+ } from '../common/printer-helpers.js';
6
+
7
+ const { line } = doc.builders;
11
8
 
12
- const AssemblyFunctionDefinition = {
9
+ export const AssemblyFunctionDefinition = {
13
10
  print: ({ node, path, print }) => [
14
11
  'function ',
15
12
  node.name,
@@ -31,5 +28,3 @@ const AssemblyFunctionDefinition = {
31
28
  path.call(print, 'body')
32
29
  ]
33
30
  };
34
-
35
- module.exports = AssemblyFunctionDefinition;
@@ -1,4 +1,4 @@
1
- const AssemblyIf = {
1
+ export const AssemblyIf = {
2
2
  print: ({ path, print }) => [
3
3
  'if ',
4
4
  path.call(print, 'condition'),
@@ -6,5 +6,3 @@ const AssemblyIf = {
6
6
  path.call(print, 'body')
7
7
  ]
8
8
  };
9
-
10
- module.exports = AssemblyIf;
@@ -1,12 +1,9 @@
1
- const {
2
- doc: {
3
- builders: { line }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
2
+ import { printSeparatedList } from '../common/printer-helpers.js';
6
3
 
7
- const { printSeparatedList } = require('../common/printer-helpers');
4
+ const { line } = doc.builders;
8
5
 
9
- const AssemblyLocalDefinition = {
6
+ export const AssemblyLocalDefinition = {
10
7
  print: ({ node, path, print }) => {
11
8
  const parts = [
12
9
  'let',
@@ -21,5 +18,3 @@ const AssemblyLocalDefinition = {
21
18
  return parts;
22
19
  }
23
20
  };
24
-
25
- module.exports = AssemblyLocalDefinition;
@@ -1,9 +1,7 @@
1
- const AssemblyMemberAccess = {
1
+ export const AssemblyMemberAccess = {
2
2
  print: ({ path, print }) => [
3
3
  path.call(print, 'expression'),
4
4
  '.',
5
5
  path.call(print, 'memberName')
6
6
  ]
7
7
  };
8
-
9
- module.exports = AssemblyMemberAccess;
@@ -1,9 +1,7 @@
1
- const AssemblyStackAssignment = {
1
+ export const AssemblyStackAssignment = {
2
2
  print: ({ node, path, print }) => [
3
3
  path.call(print, 'expression'),
4
4
  ' =: ',
5
5
  node.name
6
6
  ]
7
7
  };
8
-
9
- module.exports = AssemblyStackAssignment;
@@ -1,10 +1,8 @@
1
- const {
2
- doc: {
3
- builders: { hardline, join }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
6
2
 
7
- const AssemblySwitch = {
3
+ const { hardline, join } = doc.builders;
4
+
5
+ export const AssemblySwitch = {
8
6
  print: ({ path, print }) => [
9
7
  'switch ',
10
8
  path.call(print, 'expression'),
@@ -12,5 +10,3 @@ const AssemblySwitch = {
12
10
  join(hardline, path.map(print, 'cases'))
13
11
  ]
14
12
  };
15
-
16
- module.exports = AssemblySwitch;
@@ -1,7 +1,6 @@
1
- /* eslint-disable consistent-return */
2
- const printers = require('../binary-operator-printers');
1
+ import * as printers from '../binary-operator-printers/index.js';
3
2
 
4
- const BinaryOperation = {
3
+ export const BinaryOperation = {
5
4
  print: ({ node, path, print, options }) => {
6
5
  const binaryOperationPrinter = Object.values(printers).find((printer) =>
7
6
  printer.match(node.operator)
@@ -16,5 +15,3 @@ const BinaryOperation = {
16
15
  return binaryOperationPrinter.print(node, path, print, options);
17
16
  }
18
17
  };
19
-
20
- module.exports = BinaryOperation;
@@ -1,15 +1,12 @@
1
- const {
2
- doc: {
3
- builders: { hardline, indent }
4
- }
5
- } = require('prettier');
6
-
7
- const {
1
+ import { doc } from 'prettier';
2
+ import {
8
3
  printComments,
9
4
  printPreservingEmptyLines
10
- } = require('../common/printer-helpers');
5
+ } from '../common/printer-helpers.js';
6
+
7
+ const { hardline, indent } = doc.builders;
11
8
 
12
- const Block = {
9
+ export const Block = {
13
10
  print: ({ node, options, path, print }) =>
14
11
  // if block is empty, just return the pair of braces
15
12
  node.statements.length === 0 && !node.comments
@@ -25,5 +22,3 @@ const Block = {
25
22
  '}'
26
23
  ]
27
24
  };
28
-
29
- module.exports = Block;
@@ -1,5 +1,3 @@
1
- const BooleanLiteral = {
1
+ export const BooleanLiteral = {
2
2
  print: ({ node }) => (node.value ? 'true' : 'false')
3
3
  };
4
-
5
- module.exports = BooleanLiteral;
@@ -1,5 +1,3 @@
1
- const Break = {
1
+ export const Break = {
2
2
  print: () => 'break'
3
3
  };
4
-
5
- module.exports = Break;
@@ -1,5 +1,3 @@
1
- const BreakStatement = {
1
+ export const BreakStatement = {
2
2
  print: () => 'break;'
3
3
  };
4
-
5
- module.exports = BreakStatement;
@@ -1,4 +1,4 @@
1
- const { printSeparatedList } = require('../common/printer-helpers');
1
+ import { printSeparatedList } from '../common/printer-helpers.js';
2
2
 
3
3
  const parameters = (node, path, print) =>
4
4
  node.parameters
@@ -10,12 +10,10 @@ const parameters = (node, path, print) =>
10
10
  ]
11
11
  : '';
12
12
 
13
- const CatchClause = {
13
+ export const CatchClause = {
14
14
  print: ({ node, path, print }) => [
15
15
  'catch ',
16
16
  parameters(node, path, print),
17
17
  path.call(print, 'body')
18
18
  ]
19
19
  };
20
-
21
- module.exports = CatchClause;
@@ -1,10 +1,8 @@
1
- const {
2
- doc: {
3
- builders: { group, indent, line }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
6
2
 
7
- const Conditional = {
3
+ const { group, indent, line } = doc.builders;
4
+
5
+ export const Conditional = {
8
6
  print: ({ path, print }) =>
9
7
  group([
10
8
  path.call(print, 'condition'),
@@ -18,5 +16,3 @@ const Conditional = {
18
16
  ])
19
17
  ])
20
18
  };
21
-
22
- module.exports = Conditional;
@@ -1,5 +1,3 @@
1
- const Continue = {
1
+ export const Continue = {
2
2
  print: () => 'continue'
3
3
  };
4
-
5
- module.exports = Continue;
@@ -1,5 +1,3 @@
1
- const ContinueStatement = {
1
+ export const ContinueStatement = {
2
2
  print: () => 'continue;'
3
3
  };
4
-
5
- module.exports = ContinueStatement;
@@ -1,15 +1,12 @@
1
- const {
2
- doc: {
3
- builders: { group, line, hardline }
4
- }
5
- } = require('prettier');
6
-
7
- const {
1
+ import { doc } from 'prettier';
2
+ import {
8
3
  printComments,
9
4
  printPreservingEmptyLines,
10
5
  printSeparatedItem,
11
6
  printSeparatedList
12
- } = require('../common/printer-helpers');
7
+ } from '../common/printer-helpers.js';
8
+
9
+ const { group, line, hardline } = doc.builders;
13
10
 
14
11
  const inheritance = (node, path, print) =>
15
12
  node.baseContracts.length > 0
@@ -21,18 +18,17 @@ const inheritance = (node, path, print) =>
21
18
  ]
22
19
  : line;
23
20
 
24
- const body = (node, path, options, print) =>
25
- node.subNodes.length > 0 || node.comments
21
+ const body = (node, path, options, print) => {
22
+ const comments = printComments(node, path, options);
23
+ return node.subNodes.length > 0 || (comments && comments.length)
26
24
  ? printSeparatedItem(
27
- [
28
- printPreservingEmptyLines(path, 'subNodes', options, print),
29
- printComments(node, path, options)
30
- ],
25
+ [printPreservingEmptyLines(path, 'subNodes', options, print), comments],
31
26
  { firstSeparator: hardline, grouped: false }
32
27
  )
33
28
  : '';
29
+ };
34
30
 
35
- const ContractDefinition = {
31
+ export const ContractDefinition = {
36
32
  print: ({ node, options, path, print }) => [
37
33
  group([
38
34
  node.kind === 'abstract' ? 'abstract contract' : node.kind,
@@ -45,5 +41,3 @@ const ContractDefinition = {
45
41
  '}'
46
42
  ]
47
43
  };
48
-
49
- module.exports = ContractDefinition;
@@ -1,11 +1,11 @@
1
- const { printSeparatedList } = require('../common/printer-helpers');
1
+ import { printSeparatedList } from '../common/printer-helpers.js';
2
2
 
3
3
  const parameters = (node, path, print) =>
4
4
  node.parameters && node.parameters.length > 0
5
5
  ? printSeparatedList(path.map(print, 'parameters'))
6
6
  : '';
7
7
 
8
- const CustomErrorDefinition = {
8
+ export const CustomErrorDefinition = {
9
9
  print: ({ node, path, print }) => [
10
10
  'error ',
11
11
  node.name,
@@ -14,5 +14,3 @@ const CustomErrorDefinition = {
14
14
  ');'
15
15
  ]
16
16
  };
17
-
18
- module.exports = CustomErrorDefinition;
@@ -1,5 +1,3 @@
1
- const DecimalNumber = {
1
+ export const DecimalNumber = {
2
2
  print: ({ node }) => node.value
3
3
  };
4
-
5
- module.exports = DecimalNumber;
@@ -1,17 +1,14 @@
1
- const {
2
- doc: {
3
- builders: { group, indent, line }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
2
+ import { printSeparatedItem } from '../common/printer-helpers.js';
6
3
 
7
- const { printSeparatedItem } = require('../common/printer-helpers');
4
+ const { group, indent, line } = doc.builders;
8
5
 
9
6
  const printBody = (node, path, print) =>
10
7
  node.body.type === 'Block'
11
8
  ? [' ', path.call(print, 'body'), ' ']
12
9
  : group([indent([line, path.call(print, 'body')]), line]);
13
10
 
14
- const DoWhileStatement = {
11
+ export const DoWhileStatement = {
15
12
  print: ({ node, path, print }) => [
16
13
  'do',
17
14
  printBody(node, path, print),
@@ -20,5 +17,3 @@ const DoWhileStatement = {
20
17
  ');'
21
18
  ]
22
19
  };
23
-
24
- module.exports = DoWhileStatement;
@@ -3,8 +3,6 @@ const stateMutability = (node) =>
3
3
  ? [' ', node.stateMutability]
4
4
  : '';
5
5
 
6
- const ElementaryTypeName = {
6
+ export const ElementaryTypeName = {
7
7
  print: ({ node }) => [node.name, stateMutability(node)]
8
8
  };
9
-
10
- module.exports = ElementaryTypeName;
@@ -1,5 +1,3 @@
1
- const EmitStatement = {
1
+ export const EmitStatement = {
2
2
  print: ({ path, print }) => ['emit ', path.call(print, 'eventCall'), ';']
3
3
  };
4
-
5
- module.exports = EmitStatement;
@@ -1,12 +1,9 @@
1
- const {
2
- doc: {
3
- builders: { group, hardline }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
2
+ import { printSeparatedList } from '../common/printer-helpers.js';
6
3
 
7
- const { printSeparatedList } = require('../common/printer-helpers');
4
+ const { group, hardline } = doc.builders;
8
5
 
9
- const EnumDefinition = {
6
+ export const EnumDefinition = {
10
7
  print: ({ node, path, print }) =>
11
8
  group([
12
9
  'enum ',
@@ -18,5 +15,3 @@ const EnumDefinition = {
18
15
  '}'
19
16
  ])
20
17
  };
21
-
22
- module.exports = EnumDefinition;
@@ -1,5 +1,3 @@
1
- const EnumValue = {
1
+ export const EnumValue = {
2
2
  print: ({ node }) => node.name
3
3
  };
4
-
5
- module.exports = EnumValue;
@@ -1,11 +1,11 @@
1
- const { printSeparatedList } = require('../common/printer-helpers');
1
+ import { printSeparatedList } from '../common/printer-helpers.js';
2
2
 
3
3
  const parameters = (node, path, print) =>
4
4
  node.parameters && node.parameters.length > 0
5
5
  ? printSeparatedList(path.map(print, 'parameters'))
6
6
  : '';
7
7
 
8
- const EventDefinition = {
8
+ export const EventDefinition = {
9
9
  print: ({ node, path, print }) => [
10
10
  'event ',
11
11
  node.name,
@@ -16,5 +16,3 @@ const EventDefinition = {
16
16
  ';'
17
17
  ]
18
18
  };
19
-
20
- module.exports = EventDefinition;