prettier-plugin-solidity 1.1.4-dev → 1.3.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.
package/src/parser.js CHANGED
@@ -43,7 +43,7 @@ function parse(text, _parsers, options = _parsers) {
43
43
  FunctionDefinition(ctx) {
44
44
  if (!ctx.isConstructor) {
45
45
  ctx.modifiers.forEach((modifier) => {
46
- if (modifier.arguments && modifier.arguments.length === 0) {
46
+ if (modifier.arguments?.length === 0) {
47
47
  // eslint-disable-next-line no-param-reassign
48
48
  modifier.arguments = null;
49
49
  }
@@ -57,9 +57,20 @@ function parse(text, _parsers, options = _parsers) {
57
57
  ctx.loopExpression.omitSemicolon = true;
58
58
  },
59
59
  HexLiteral(ctx) {
60
- ctx.value = options.singleQuote
61
- ? `hex'${ctx.value.slice(4, -1)}'`
62
- : `hex"${ctx.value.slice(4, -1)}"`;
60
+ const value = ctx.value.slice(4, -1);
61
+ ctx.value = options.singleQuote ? `hex'${value}'` : `hex"${value}"`;
62
+ },
63
+ Conditional(ctx) {
64
+ // We can remove parentheses only because we are sure that the
65
+ // `condition` must be a single `bool` value.
66
+ while (
67
+ ctx.condition.type === 'TupleExpression' &&
68
+ !ctx.condition.isArray &&
69
+ ctx.condition.components.length === 1 &&
70
+ ctx.condition.components[0].type !== 'Conditional'
71
+ ) {
72
+ [ctx.condition] = ctx.condition.components;
73
+ }
63
74
  },
64
75
  BinaryOperation(ctx) {
65
76
  switch (ctx.operator) {
@@ -78,34 +89,34 @@ function parse(text, _parsers, options = _parsers) {
78
89
  ctx.left = tryHug(ctx.left, ['*', '/', '%']);
79
90
  break;
80
91
  case '**':
81
- // If the compiler has not been given as an option using we leave a**b**c.
92
+ // If the compiler has not been given as an option using we leave
93
+ // a**b**c.
82
94
  if (!compiler) break;
83
95
 
84
- if (satisfies(compiler, '<0.8.0')) {
85
- // If the compiler is less than 0.8.0 then a**b**c is formatted as
86
- // (a**b)**c.
87
- ctx.left = tryHug(ctx.left, ['**']);
96
+ if (satisfies(compiler, '>=0.8.0')) {
97
+ // If the compiler is greater than or equal to 0.8.0 then a**b**c
98
+ // is formatted as a**(b**c).
99
+ ctx.right = tryHug(ctx.right, ['**']);
88
100
  break;
89
101
  }
90
102
  if (
91
- ctx.left.type === 'BinaryOperation' &&
92
- ctx.left.operator === '**'
103
+ ctx.right.type === 'BinaryOperation' &&
104
+ ctx.right.operator === '**'
93
105
  ) {
94
- // the parser still organizes the a**b**c as (a**b)**c so we need
95
- // to restructure it.
96
- ctx.right = {
106
+ // the parser organizes the a**b**c as a**(b**c) so we need to
107
+ // restructure it.
108
+ const left = {
109
+ type: 'BinaryOperation',
110
+ operator: '**',
111
+ left: ctx.left,
112
+ right: ctx.right.left
113
+ };
114
+ ctx.left = {
97
115
  type: 'TupleExpression',
98
- components: [
99
- {
100
- type: 'BinaryOperation',
101
- operator: '**',
102
- left: ctx.left.right,
103
- right: ctx.right
104
- }
105
- ],
116
+ components: [left],
106
117
  isArray: false
107
118
  };
108
- ctx.left = ctx.left.left;
119
+ ctx.right = ctx.right.right;
109
120
  }
110
121
  break;
111
122
  case '<<':
@@ -1,5 +1,5 @@
1
1
  import { util } from "prettier";
2
- import { getNextNonSpaceNonCommentCharacter } from "../../common/util.js";
2
+ import { getNextNonSpaceNonCommentCharacter } from "../../common/backward-compatibility.js";
3
3
 
4
4
  const {
5
5
  addLeadingComment,
@@ -1,15 +0,0 @@
1
- /*!
2
- * Copyright 2016 The ANTLR Project. All rights reserved.
3
- * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
4
- */
5
-
6
- /*!
7
- * The buffer module from node.js, for the browser.
8
- *
9
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
10
- * @license MIT
11
- */
12
-
13
- /*! https://mths.be/codepointat v0.2.0 by @mathias */
14
-
15
- /*! https://mths.be/fromcodepoint v0.2.1 by @mathias */