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,11 +1,9 @@
1
- const {
2
- doc: {
3
- builders: { join, hardline }
4
- }
5
- } = require('prettier');
6
- const { printString } = require('../common/util');
1
+ import { doc } from 'prettier';
2
+ import { printString } from '../common/util.js';
3
+
4
+ const { join, hardline } = doc.builders;
7
5
 
8
- const StringLiteral = {
6
+ export const StringLiteral = {
9
7
  print: ({ node, options }) => {
10
8
  const list = node.parts.map(
11
9
  (part, index) =>
@@ -17,5 +15,3 @@ const StringLiteral = {
17
15
  return join(hardline, list);
18
16
  }
19
17
  };
20
-
21
- module.exports = StringLiteral;
@@ -1,29 +1,20 @@
1
- const {
2
- doc: {
3
- builders: { 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 { hardline } = doc.builders;
8
5
 
9
- const StructDefinition = {
10
- print: ({ node, path, print }) => {
11
- const parts = ['struct ', node.name, ' {'];
12
-
13
- if (node.members.length > 0) {
14
- parts.push(
15
- printSeparatedList(path.map(print, 'members'), {
6
+ export const StructDefinition = {
7
+ print: ({ node, path, print }) => [
8
+ 'struct ',
9
+ node.name,
10
+ ' {',
11
+ node.members.length > 0
12
+ ? printSeparatedList(path.map(print, 'members'), {
16
13
  firstSeparator: hardline,
17
14
  separator: [';', hardline],
18
15
  lastSeparator: [';', hardline]
19
16
  })
20
- );
21
- }
22
-
23
- parts.push('}');
24
-
25
- return parts;
26
- }
17
+ : '',
18
+ '}'
19
+ ]
27
20
  };
28
-
29
- module.exports = StructDefinition;
@@ -1,5 +1,3 @@
1
- const ThrowStatement = {
1
+ export const ThrowStatement = {
2
2
  print: () => 'throw;'
3
3
  };
4
-
5
- module.exports = ThrowStatement;
@@ -1,13 +1,10 @@
1
- const {
2
- doc: {
3
- builders: { join, 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 { join, line } = doc.builders;
11
8
 
12
9
  const returnParameters = (node, path, print) =>
13
10
  node.returnParameters
@@ -18,7 +15,7 @@ const returnParameters = (node, path, print) =>
18
15
  ]
19
16
  : '';
20
17
 
21
- const TryStatement = {
18
+ export const TryStatement = {
22
19
  print: ({ node, path, print }) => {
23
20
  let parts = [
24
21
  'try',
@@ -41,5 +38,3 @@ const TryStatement = {
41
38
  return parts;
42
39
  }
43
40
  };
44
-
45
- module.exports = TryStatement;
@@ -1,10 +1,7 @@
1
- const {
2
- doc: {
3
- builders: { group }
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 } = doc.builders;
8
5
 
9
6
  const contents = (node, path, print) =>
10
7
  node.components &&
@@ -13,7 +10,7 @@ const contents = (node, path, print) =>
13
10
  ? path.map(print, 'components')
14
11
  : [printSeparatedList(path.map(print, 'components'))];
15
12
 
16
- const TupleExpression = {
13
+ export const TupleExpression = {
17
14
  print: ({ node, path, print }) =>
18
15
  group([
19
16
  node.isArray ? '[' : '(',
@@ -21,5 +18,3 @@ const TupleExpression = {
21
18
  node.isArray ? ']' : ')'
22
19
  ])
23
20
  };
24
-
25
- module.exports = TupleExpression;
@@ -1,5 +1,3 @@
1
- const TypeDefinition = {
1
+ export const TypeDefinition = {
2
2
  print: ({ node }) => ['type ', node.name, ' is ', node.definition.name, ';']
3
3
  };
4
-
5
- module.exports = TypeDefinition;
@@ -1,4 +1,4 @@
1
- const UnaryOperation = {
1
+ export const UnaryOperation = {
2
2
  print: ({ node, path, print }) =>
3
3
  node.isPrefix
4
4
  ? [
@@ -8,5 +8,3 @@ const UnaryOperation = {
8
8
  ]
9
9
  : [path.call(print, 'subExpression'), node.operator]
10
10
  };
11
-
12
- module.exports = UnaryOperation;
@@ -1,11 +1,7 @@
1
- const {
2
- doc: {
3
- builders: { group }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
6
2
 
7
- const UncheckedStatement = {
3
+ const { group } = doc.builders;
4
+
5
+ export const UncheckedStatement = {
8
6
  print: ({ path, print }) => group(['unchecked ', path.call(print, 'block')])
9
7
  };
10
-
11
- module.exports = UncheckedStatement;
@@ -1,5 +1,3 @@
1
- const UserDefinedTypeName = {
1
+ export const UserDefinedTypeName = {
2
2
  print: ({ node }) => node.namePath
3
3
  };
4
-
5
- module.exports = UserDefinedTypeName;
@@ -1,45 +1,29 @@
1
- const {
2
- doc: {
3
- builders: { line, softline }
4
- }
5
- } = require('prettier');
6
-
7
- const { printSeparatedList } = require('../common/printer-helpers');
8
-
9
- const UsingForDeclaration = {
10
- print: ({ node, path, print, options }) => {
11
- const parts = ['using '];
12
-
13
- if (node.functions && node.functions.length) {
14
- const importedFunctions = [];
15
- for (let i = 0; i < node.functions.length; i += 1) {
16
- const fun = node.functions[i];
17
- const operator = node.operators[i];
18
-
19
- if (operator) {
20
- importedFunctions.push(`${fun} as ${operator}`);
21
- } else {
22
- importedFunctions.push(fun);
23
- }
24
- }
25
-
26
- parts.push('{');
27
- parts.push(
28
- printSeparatedList(importedFunctions, {
29
- firstSeparator: options.bracketSpacing ? line : softline
30
- })
31
- );
32
- parts.push('}');
33
- } else {
34
- parts.push(node.libraryName);
35
- }
36
-
37
- parts.push(' for ');
38
- parts.push(node.typeName ? path.call(print, 'typeName') : '*');
39
- parts.push(node.isGlobal ? ' global;' : ';');
40
-
41
- return parts;
42
- }
1
+ import { doc } from 'prettier';
2
+ import { printSeparatedList } from '../common/printer-helpers.js';
3
+
4
+ const { line, softline } = doc.builders;
5
+
6
+ export const UsingForDeclaration = {
7
+ print: ({ node, path, print, options }) => [
8
+ 'using ',
9
+ node.functions && node.functions.length
10
+ ? [
11
+ '{',
12
+ printSeparatedList(
13
+ node.functions.map((functionName, i) =>
14
+ node.operators[i]
15
+ ? [functionName, ' as ', node.operators[i]]
16
+ : functionName
17
+ ),
18
+ {
19
+ firstSeparator: options.bracketSpacing ? line : softline
20
+ }
21
+ ),
22
+ '}'
23
+ ]
24
+ : node.libraryName,
25
+ ' for ',
26
+ node.typeName ? path.call(print, 'typeName') : '*',
27
+ node.isGlobal ? ' global;' : ';'
28
+ ]
43
29
  };
44
-
45
- module.exports = UsingForDeclaration;
@@ -1,10 +1,7 @@
1
- const {
2
- doc: {
3
- builders: { group, indent, 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 { group, indent, line } = doc.builders;
8
5
 
9
6
  const indexed = (node) => (node.isIndexed ? ' indexed' : '');
10
7
 
@@ -35,7 +32,7 @@ const override = (node, path, print) => {
35
32
 
36
33
  const name = (node) => (node.name ? [' ', node.name] : '');
37
34
 
38
- const VariableDeclaration = {
35
+ export const VariableDeclaration = {
39
36
  print: ({ node, path, print }) =>
40
37
  node.typeName
41
38
  ? group([
@@ -52,5 +49,3 @@ const VariableDeclaration = {
52
49
  ])
53
50
  : node.name
54
51
  };
55
-
56
- module.exports = VariableDeclaration;
@@ -1,19 +1,16 @@
1
- const {
2
- doc: {
3
- builders: { group, indentIfBreak }
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, indentIfBreak } = doc.builders;
8
5
 
9
- const embraceVariables = (doc, embrace) =>
10
- embrace ? ['(', printSeparatedList(doc), ')'] : doc;
6
+ const embraceVariables = (document, embrace) =>
7
+ embrace ? ['(', printSeparatedList(document), ')'] : document;
11
8
 
12
9
  const initialValue = (node, path, print) =>
13
10
  node.initialValue ? [' = ', path.call(print, 'initialValue')] : '';
14
11
 
15
12
  let groupIndex = 0;
16
- const VariableDeclarationStatement = {
13
+ export const VariableDeclarationStatement = {
17
14
  print: ({ node, path, print }) => {
18
15
  const startsWithVar =
19
16
  node.variables.filter((x) => x && x.typeName).length === 0;
@@ -40,5 +37,3 @@ const VariableDeclarationStatement = {
40
37
  ]);
41
38
  }
42
39
  };
43
-
44
- module.exports = VariableDeclarationStatement;
@@ -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')]));
13
10
 
14
- const WhileStatement = {
11
+ export const WhileStatement = {
15
12
  print: ({ node, path, print }) => [
16
13
  'while (',
17
14
  printSeparatedItem(path.call(print, 'condition')),
@@ -19,5 +16,3 @@ const WhileStatement = {
19
16
  printBody(node, path, print)
20
17
  ]
21
18
  };
22
-
23
- module.exports = WhileStatement;
@@ -1,78 +1,72 @@
1
- /* This file was automatically generated on 1666691919.885 */
2
-
3
- /* eslint-disable global-require */
4
-
5
- module.exports = {
6
- ArrayTypeName: require('./ArrayTypeName'),
7
- AssemblyAssignment: require('./AssemblyAssignment'),
8
- AssemblyBlock: require('./AssemblyBlock'),
9
- AssemblyCall: require('./AssemblyCall'),
10
- AssemblyCase: require('./AssemblyCase'),
11
- AssemblyFor: require('./AssemblyFor'),
12
- AssemblyFunctionDefinition: require('./AssemblyFunctionDefinition'),
13
- AssemblyIf: require('./AssemblyIf'),
14
- AssemblyLocalDefinition: require('./AssemblyLocalDefinition'),
15
- AssemblyMemberAccess: require('./AssemblyMemberAccess'),
16
- AssemblyStackAssignment: require('./AssemblyStackAssignment'),
17
- AssemblySwitch: require('./AssemblySwitch'),
18
- BinaryOperation: require('./BinaryOperation'),
19
- Block: require('./Block'),
20
- BooleanLiteral: require('./BooleanLiteral'),
21
- Break: require('./Break'),
22
- BreakStatement: require('./BreakStatement'),
23
- CatchClause: require('./CatchClause'),
24
- Conditional: require('./Conditional'),
25
- Continue: require('./Continue'),
26
- ContinueStatement: require('./ContinueStatement'),
27
- ContractDefinition: require('./ContractDefinition'),
28
- CustomErrorDefinition: require('./CustomErrorDefinition'),
29
- DecimalNumber: require('./DecimalNumber'),
30
- DoWhileStatement: require('./DoWhileStatement'),
31
- ElementaryTypeName: require('./ElementaryTypeName'),
32
- EmitStatement: require('./EmitStatement'),
33
- EnumDefinition: require('./EnumDefinition'),
34
- EnumValue: require('./EnumValue'),
35
- EventDefinition: require('./EventDefinition'),
36
- ExpressionStatement: require('./ExpressionStatement'),
37
- FileLevelConstant: require('./FileLevelConstant'),
38
- ForStatement: require('./ForStatement'),
39
- FunctionCall: require('./FunctionCall'),
40
- FunctionDefinition: require('./FunctionDefinition'),
41
- FunctionTypeName: require('./FunctionTypeName'),
42
- HexLiteral: require('./HexLiteral'),
43
- HexNumber: require('./HexNumber'),
44
- Identifier: require('./Identifier'),
45
- IfStatement: require('./IfStatement'),
46
- ImportDirective: require('./ImportDirective'),
47
- IndexAccess: require('./IndexAccess'),
48
- IndexRangeAccess: require('./IndexRangeAccess'),
49
- InheritanceSpecifier: require('./InheritanceSpecifier'),
50
- InlineAssemblyStatement: require('./InlineAssemblyStatement'),
51
- LabelDefinition: require('./LabelDefinition'),
52
- Mapping: require('./Mapping'),
53
- MemberAccess: require('./MemberAccess'),
54
- ModifierDefinition: require('./ModifierDefinition'),
55
- ModifierInvocation: require('./ModifierInvocation'),
56
- NameValueExpression: require('./NameValueExpression'),
57
- NameValueList: require('./NameValueList'),
58
- NewExpression: require('./NewExpression'),
59
- NumberLiteral: require('./NumberLiteral'),
60
- PragmaDirective: require('./PragmaDirective'),
61
- ReturnStatement: require('./ReturnStatement'),
62
- RevertStatement: require('./RevertStatement'),
63
- SourceUnit: require('./SourceUnit'),
64
- StateVariableDeclaration: require('./StateVariableDeclaration'),
65
- StringLiteral: require('./StringLiteral'),
66
- StructDefinition: require('./StructDefinition'),
67
- ThrowStatement: require('./ThrowStatement'),
68
- TryStatement: require('./TryStatement'),
69
- TupleExpression: require('./TupleExpression'),
70
- TypeDefinition: require('./TypeDefinition'),
71
- UnaryOperation: require('./UnaryOperation'),
72
- UncheckedStatement: require('./UncheckedStatement'),
73
- UserDefinedTypeName: require('./UserDefinedTypeName'),
74
- UsingForDeclaration: require('./UsingForDeclaration'),
75
- VariableDeclaration: require('./VariableDeclaration'),
76
- VariableDeclarationStatement: require('./VariableDeclarationStatement'),
77
- WhileStatement: require('./WhileStatement')
78
- };
1
+ export * from './ArrayTypeName.js';
2
+ export * from './AssemblyAssignment.js';
3
+ export * from './AssemblyBlock.js';
4
+ export * from './AssemblyCall.js';
5
+ export * from './AssemblyCase.js';
6
+ export * from './AssemblyFor.js';
7
+ export * from './AssemblyFunctionDefinition.js';
8
+ export * from './AssemblyIf.js';
9
+ export * from './AssemblyLocalDefinition.js';
10
+ export * from './AssemblyMemberAccess.js';
11
+ export * from './AssemblyStackAssignment.js';
12
+ export * from './AssemblySwitch.js';
13
+ export * from './BinaryOperation.js';
14
+ export * from './Block.js';
15
+ export * from './BooleanLiteral.js';
16
+ export * from './Break.js';
17
+ export * from './BreakStatement.js';
18
+ export * from './CatchClause.js';
19
+ export * from './Conditional.js';
20
+ export * from './Continue.js';
21
+ export * from './ContinueStatement.js';
22
+ export * from './ContractDefinition.js';
23
+ export * from './CustomErrorDefinition.js';
24
+ export * from './DecimalNumber.js';
25
+ export * from './DoWhileStatement.js';
26
+ export * from './ElementaryTypeName.js';
27
+ export * from './EmitStatement.js';
28
+ export * from './EnumDefinition.js';
29
+ export * from './EnumValue.js';
30
+ export * from './EventDefinition.js';
31
+ export * from './ExpressionStatement.js';
32
+ export * from './FileLevelConstant.js';
33
+ export * from './ForStatement.js';
34
+ export * from './FunctionCall.js';
35
+ export * from './FunctionDefinition.js';
36
+ export * from './FunctionTypeName.js';
37
+ export * from './HexLiteral.js';
38
+ export * from './HexNumber.js';
39
+ export * from './Identifier.js';
40
+ export * from './IfStatement.js';
41
+ export * from './ImportDirective.js';
42
+ export * from './IndexAccess.js';
43
+ export * from './IndexRangeAccess.js';
44
+ export * from './InheritanceSpecifier.js';
45
+ export * from './InlineAssemblyStatement.js';
46
+ export * from './LabelDefinition.js';
47
+ export * from './Mapping.js';
48
+ export * from './MemberAccess.js';
49
+ export * from './ModifierDefinition.js';
50
+ export * from './ModifierInvocation.js';
51
+ export * from './NameValueExpression.js';
52
+ export * from './NameValueList.js';
53
+ export * from './NewExpression.js';
54
+ export * from './NumberLiteral.js';
55
+ export * from './PragmaDirective.js';
56
+ export * from './ReturnStatement.js';
57
+ export * from './RevertStatement.js';
58
+ export * from './SourceUnit.js';
59
+ export * from './StateVariableDeclaration.js';
60
+ export * from './StringLiteral.js';
61
+ export * from './StructDefinition.js';
62
+ export * from './ThrowStatement.js';
63
+ export * from './TryStatement.js';
64
+ export * from './TupleExpression.js';
65
+ export * from './TypeDefinition.js';
66
+ export * from './UnaryOperation.js';
67
+ export * from './UncheckedStatement.js';
68
+ export * from './UserDefinedTypeName.js';
69
+ export * from './UsingForDeclaration.js';
70
+ export * from './VariableDeclaration.js';
71
+ export * from './VariableDeclarationStatement.js';
72
+ export * from './WhileStatement.js';
package/src/options.js CHANGED
@@ -48,4 +48,4 @@ const options = {
48
48
  }
49
49
  };
50
50
 
51
- module.exports = options;
51
+ export default options;
package/src/parser.js CHANGED
@@ -1,8 +1,8 @@
1
- const extractComments = require('solidity-comments-extractor');
1
+ import extractComments from 'solidity-comments-extractor';
2
2
  // https://prettier.io/docs/en/plugins.html#parsers
3
- const parser = require('@solidity-parser/parser');
4
- const coerce = require('semver/functions/coerce');
5
- const satisfies = require('semver/functions/satisfies');
3
+ import parser from '@solidity-parser/parser';
4
+ import coerce from 'semver/functions/coerce.js';
5
+ import satisfies from 'semver/functions/satisfies.js';
6
6
 
7
7
  const tryHug = (node, operators) => {
8
8
  if (node.type === 'BinaryOperation' && operators.includes(node.operator))
@@ -61,13 +61,6 @@ function parse(text, _parsers, options = _parsers) {
61
61
  ? `hex'${ctx.value.slice(4, -1)}'`
62
62
  : `hex"${ctx.value.slice(4, -1)}"`;
63
63
  },
64
- ElementaryTypeName(ctx) {
65
- // if the compiler is below 0.8.0 we will recognize the type 'byte' as an
66
- // alias of 'bytes1'. Otherwise we will ignore this and enforce always
67
- // 'bytes1'.
68
- const pre080 = compiler && satisfies(compiler, '<0.8.0');
69
- if (!pre080 && ctx.name === 'byte') ctx.name = 'bytes1';
70
- },
71
64
  BinaryOperation(ctx) {
72
65
  switch (ctx.operator) {
73
66
  case '+':
@@ -184,4 +177,4 @@ function parse(text, _parsers, options = _parsers) {
184
177
  return parsed;
185
178
  }
186
179
 
187
- module.exports = parse;
180
+ export default parse;
@@ -1,18 +1,15 @@
1
- "use strict";
1
+ import { util } from "prettier";
2
+ import { getNextNonSpaceNonCommentCharacter } from "../../common/util.js";
2
3
 
3
4
  const {
4
- util: {
5
- addLeadingComment,
6
- addTrailingComment,
7
- addDanglingComment,
8
- getNextNonSpaceNonCommentCharacterIndex,
9
- hasNewline,
10
- hasNewlineInRange
11
- }
12
- } = require('prettier');
13
- const { getNextNonSpaceNonCommentCharacter } = require("../../common/util");
14
-
15
- function handleOwnLineComment(comment, text, options, ast, isLastComment) {
5
+ addLeadingComment,
6
+ addTrailingComment,
7
+ addDanglingComment,
8
+ hasNewline,
9
+ hasNewlineInRange
10
+ } = util
11
+
12
+ export function handleOwnLineComment(comment, text, options, ast, isLastComment) {
16
13
  const { precedingNode, enclosingNode, followingNode } = comment;
17
14
  if (
18
15
  handleLastFunctionArgComments(
@@ -77,7 +74,7 @@ function handleOwnLineComment(comment, text, options, ast, isLastComment) {
77
74
  return false;
78
75
  }
79
76
 
80
- function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
77
+ export function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
81
78
  const { precedingNode, enclosingNode, followingNode } = comment;
82
79
  if (
83
80
  handleLastFunctionArgComments(
@@ -132,7 +129,7 @@ function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
132
129
  return false;
133
130
  }
134
131
 
135
- function handleRemainingComment(comment, text, options, ast, isLastComment) {
132
+ export function handleRemainingComment(comment, text, options, ast, isLastComment) {
136
133
  const { precedingNode, enclosingNode, followingNode } = comment;
137
134
 
138
135
  if (
@@ -834,13 +831,6 @@ function handleTSMappedTypeComments(
834
831
  return false;
835
832
  }
836
833
 
837
- function isBlockComment(comment) {
834
+ export function isBlockComment(comment) {
838
835
  return comment.type === "Block" || comment.type === "CommentBlock";
839
836
  }
840
-
841
- module.exports = {
842
- handleOwnLineComment,
843
- handleEndOfLineComment,
844
- handleRemainingComment,
845
- isBlockComment
846
- };
package/src/printer.js CHANGED
@@ -1,15 +1,15 @@
1
- const nodes = require('./nodes');
2
- const {
1
+ import * as nodes from './nodes/index.js';
2
+ import {
3
3
  hasNodeIgnoreComment,
4
4
  prettierVersionSatisfies
5
- } = require('./common/util');
6
- const ignoreComments = require('./comments/ignore');
5
+ } from './common/util.js';
6
+ import ignoreComments from './comments/ignore.js';
7
7
 
8
8
  let checked = false;
9
9
 
10
10
  function prettierVersionCheck() {
11
11
  if (checked) return;
12
- if (!prettierVersionSatisfies('>=2.3.0 || >=3.0.0-alpha.0')) {
12
+ if (!prettierVersionSatisfies('>=2.3.0')) {
13
13
  throw new Error(
14
14
  'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
15
15
  );
@@ -41,4 +41,4 @@ function genericPrint(path, options, print) {
41
41
  return nodes[node.type].print({ node, options, path, print });
42
42
  }
43
43
 
44
- module.exports = genericPrint;
44
+ export default genericPrint;