prettier-plugin-solidity 1.1.3 → 1.2.0

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 (106) 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/backward-compatibility.js +46 -0
  22. package/src/common/printer-helpers.js +63 -41
  23. package/src/common/util.js +6 -22
  24. package/src/index.js +14 -12
  25. package/src/loc.js +1 -1
  26. package/src/nodes/ArrayTypeName.js +1 -3
  27. package/src/nodes/AssemblyAssignment.js +4 -8
  28. package/src/nodes/AssemblyBlock.js +6 -11
  29. package/src/nodes/AssemblyCall.js +2 -4
  30. package/src/nodes/AssemblyCase.js +1 -3
  31. package/src/nodes/AssemblyFor.js +4 -8
  32. package/src/nodes/AssemblyFunctionDefinition.js +6 -11
  33. package/src/nodes/AssemblyIf.js +1 -3
  34. package/src/nodes/AssemblyLocalDefinition.js +4 -9
  35. package/src/nodes/AssemblyMemberAccess.js +1 -3
  36. package/src/nodes/AssemblyStackAssignment.js +1 -3
  37. package/src/nodes/AssemblySwitch.js +4 -8
  38. package/src/nodes/BinaryOperation.js +2 -5
  39. package/src/nodes/Block.js +6 -11
  40. package/src/nodes/BooleanLiteral.js +1 -3
  41. package/src/nodes/Break.js +1 -3
  42. package/src/nodes/BreakStatement.js +1 -3
  43. package/src/nodes/CatchClause.js +2 -4
  44. package/src/nodes/Conditional.js +4 -8
  45. package/src/nodes/Continue.js +1 -3
  46. package/src/nodes/ContinueStatement.js +1 -3
  47. package/src/nodes/ContractDefinition.js +11 -17
  48. package/src/nodes/CustomErrorDefinition.js +2 -4
  49. package/src/nodes/DecimalNumber.js +1 -3
  50. package/src/nodes/DoWhileStatement.js +4 -9
  51. package/src/nodes/ElementaryTypeName.js +1 -3
  52. package/src/nodes/EmitStatement.js +1 -3
  53. package/src/nodes/EnumDefinition.js +4 -9
  54. package/src/nodes/EnumValue.js +1 -3
  55. package/src/nodes/EventDefinition.js +2 -4
  56. package/src/nodes/ExpressionStatement.js +4 -9
  57. package/src/nodes/FileLevelConstant.js +1 -3
  58. package/src/nodes/ForStatement.js +4 -9
  59. package/src/nodes/FunctionCall.js +4 -9
  60. package/src/nodes/FunctionDefinition.js +11 -18
  61. package/src/nodes/FunctionTypeName.js +4 -9
  62. package/src/nodes/HexLiteral.js +4 -9
  63. package/src/nodes/HexNumber.js +1 -3
  64. package/src/nodes/Identifier.js +1 -3
  65. package/src/nodes/IfStatement.js +6 -11
  66. package/src/nodes/ImportDirective.js +12 -17
  67. package/src/nodes/IndexAccess.js +4 -8
  68. package/src/nodes/IndexRangeAccess.js +1 -3
  69. package/src/nodes/InheritanceSpecifier.js +2 -4
  70. package/src/nodes/InlineAssemblyStatement.js +3 -4
  71. package/src/nodes/LabelDefinition.js +4 -8
  72. package/src/nodes/Mapping.js +17 -18
  73. package/src/nodes/MemberAccess.js +6 -10
  74. package/src/nodes/ModifierDefinition.js +4 -9
  75. package/src/nodes/ModifierInvocation.js +3 -5
  76. package/src/nodes/NameValueExpression.js +1 -3
  77. package/src/nodes/NameValueList.js +4 -9
  78. package/src/nodes/NewExpression.js +1 -3
  79. package/src/nodes/NumberLiteral.js +1 -3
  80. package/src/nodes/PragmaDirective.js +1 -3
  81. package/src/nodes/ReturnStatement.js +4 -8
  82. package/src/nodes/RevertStatement.js +1 -3
  83. package/src/nodes/SourceUnit.js +4 -9
  84. package/src/nodes/StateVariableDeclaration.js +4 -8
  85. package/src/nodes/StringLiteral.js +5 -9
  86. package/src/nodes/StructDefinition.js +13 -22
  87. package/src/nodes/ThrowStatement.js +1 -3
  88. package/src/nodes/TryStatement.js +6 -11
  89. package/src/nodes/TupleExpression.js +4 -9
  90. package/src/nodes/TypeDefinition.js +1 -3
  91. package/src/nodes/UnaryOperation.js +1 -3
  92. package/src/nodes/UncheckedStatement.js +4 -8
  93. package/src/nodes/UserDefinedTypeName.js +1 -3
  94. package/src/nodes/UsingForDeclaration.js +28 -44
  95. package/src/nodes/VariableDeclaration.js +4 -9
  96. package/src/nodes/VariableDeclarationStatement.js +6 -11
  97. package/src/nodes/WhileStatement.js +4 -9
  98. package/src/nodes/index.js +72 -78
  99. package/src/options.js +1 -1
  100. package/src/parser.js +5 -12
  101. package/src/prettier-comments/language-js/comments.js +13 -23
  102. package/src/printer.js +6 -6
  103. package/dist/standalone.js +0 -3
  104. package/dist/standalone.js.map +0 -1
  105. package/src/prettier-comments/index.js +0 -3
  106. /package/dist/{standalone.js.LICENSE.txt → standalone.cjs.LICENSE.txt} +0 -0
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/backward-compatibility.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;