Skip to content

Commit cf96d07

Browse files
committed
hot fix to address feedback from @pcaversaccio
1 parent 57ac1c6 commit cf96d07

File tree

4 files changed

+34
-29
lines changed

4 files changed

+34
-29
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prettier-plugin-solidity",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "A Prettier Plugin for automatically formatting your Solidity code.",
55
"type": "module",
66
"main": "./src/index.js",
@@ -103,7 +103,7 @@
103103
"jest-snapshot-serializer-raw": "^2.0.0",
104104
"jest-watch-typeahead": "^2.2.2",
105105
"lines-and-columns": "^2.0.3",
106-
"prettier": "^3.1.0",
106+
"prettier": "^3.1.1",
107107
"proxyquire": "^2.1.3",
108108
"solc": "^0.8.23-fixed",
109109
"webpack": "^5.88.2",

src/parser.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,19 @@ function parse(text, _parsers, options = _parsers) {
6161
ctx.value = options.singleQuote ? `hex'${value}'` : `hex"${value}"`;
6262
},
6363
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;
64+
// TODO: while the behaviour is not stable, it should be behind the
65+
// experimentalTernaries flag.
66+
if (options.experimentalTernaries) {
67+
// We can remove parentheses only because we are sure that the
68+
// `condition` must be a single `bool` value.
69+
while (
70+
ctx.condition.type === 'TupleExpression' &&
71+
!ctx.condition.isArray &&
72+
ctx.condition.components.length === 1 &&
73+
ctx.condition.components[0].type !== 'Conditional'
74+
) {
75+
[ctx.condition] = ctx.condition.components;
76+
}
7377
}
7478
},
7579
BinaryOperation(ctx) {

tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,13 +1895,13 @@ contract Conditional {
18951895
18961896
// multiline conditions and consequents/alternates:
18971897
string
1898-
storage multilineConditionsConsequentsAndAlternates = isAnAdorableKittyCat() &&
1899-
(someReallyLongCondition || moreInThisLongCondition)
1898+
storage multilineConditionsConsequentsAndAlternates = (isAnAdorableKittyCat() &&
1899+
(someReallyLongCondition || moreInThisLongCondition))
19001900
? someReallyLargeExpression
19011901
.thatWouldCauseALineBreak()
19021902
.willCauseAnIndentButNotParens()
1903-
: isNotAnAdorableKittyCat() &&
1904-
(someReallyLongCondition || moreInThisLongCondition)
1903+
: (isNotAnAdorableKittyCat() &&
1904+
(someReallyLongCondition || moreInThisLongCondition))
19051905
? bark()
19061906
: shortCondition()
19071907
? shortConsequent()
@@ -1910,13 +1910,13 @@ contract Conditional {
19101910
.willCauseAnIndentButNotParens();
19111911
19121912
// Assignment also groups and indents as Variable Declaration:
1913-
assignment = isAnAdorableKittyCat() &&
1914-
(someReallyLongCondition || moreInThisLongCondition)
1913+
assignment = (isAnAdorableKittyCat() &&
1914+
(someReallyLongCondition || moreInThisLongCondition))
19151915
? someReallyLargeExpression
19161916
.thatWouldCauseALineBreak()
19171917
.willCauseAnIndentButNotParens()
1918-
: isNotAnAdorableKittyCat() &&
1919-
(someReallyLongCondition || moreInThisLongCondition)
1918+
: (isNotAnAdorableKittyCat() &&
1919+
(someReallyLongCondition || moreInThisLongCondition))
19201920
? bark()
19211921
: shortCondition()
19221922
? shortConsequent()
@@ -1931,32 +1931,33 @@ contract Conditional {
19311931
? "two"
19321932
: x == 3
19331933
? "three"
1934-
: x == 5 &&
1934+
: (x == 5 &&
19351935
y == 7 &&
19361936
someOtherThing
19371937
.thatIsSoLong
1938-
.thatItBreaksTheTestCondition()
1938+
.thatItBreaksTheTestCondition())
19391939
? "four"
19401940
: x == 6
19411941
? "six"
19421942
: "idk";
19431943
19441944
// long conditional, short consequent/alternate, not chained - do indent after ?
1945-
string storage longConditional = bifornCringerMoshedPerplexSawder ==
1945+
string storage longConditional = (bifornCringerMoshedPerplexSawder ==
19461946
2 / askTrovenaBeenaDependsRowans &&
19471947
glimseGlyphsHazardNoopsTieTie >=
1948-
averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol()
1948+
averredBathersBoxroomBuggyNurl()
1949+
.anodyneCondosMalateOverateRetinol())
19491950
? "foo"
19501951
: "bar";
19511952
19521953
// long conditional, short consequent/alternate, chained
19531954
// (break on short consequents iff in chained ternary and its conditional broke)
19541955
string
1955-
storage longConditionalChained = bifornCringerMoshedPerplexSawder ==
1956+
storage longConditionalChained = (bifornCringerMoshedPerplexSawder ==
19561957
2 / askTrovenaBeenaDependsRowans &&
19571958
glimseGlyphsHazardNoopsTieTie >=
19581959
averredBathersBoxroomBuggyNurl()
1959-
.anodyneCondosMalateOverateRetinol()
1960+
.anodyneCondosMalateOverateRetinol())
19601961
? "foo"
19611962
: anotherCondition
19621963
? "bar"
@@ -1977,7 +1978,7 @@ contract Conditional {
19771978
);
19781979
19791980
// Conditional as a condition
1980-
(foo ? 1 : bar) ? 3 : 4;
1981+
(((foo ? 1 : bar))) ? 3 : 4;
19811982
(
19821983
isCat()
19831984
? meow()

0 commit comments

Comments
 (0)