Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/printers/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default {
const shouldExtraIndent = shouldExtraIndentForTernaryExpression(path);

const result = maybeGroup([
printTernaryTest(path, print),
printTernaryTest(path, print, options),
forceNoIndent ? parts : indent(parts),
breakClosingParen && !shouldExtraIndent ? softline : ""
]);
Expand Down Expand Up @@ -1567,7 +1567,8 @@ function isHopefullyShortCallArgument(node: NamedNode) {

function printTernaryTest(
path: AstPath<TernaryExpressionNode>,
print: PrintFunction
print: PrintFunction,
options: JavaParserOptions
) {
const { node, parent } = path;

Expand All @@ -1583,7 +1584,7 @@ function printTernaryTest(
* : e
*/
if (parent?.type === node.type && parent.alternativeNode === node) {
return align(2, printed);
return options.useTabs ? indent(printed) : align(2, printed);
}
return printed;
}
Expand Down
6 changes: 6 additions & 0 deletions test/unit-test/conditional-expression/spaces/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ int ternaryOperationThatShouldNotBreak() {

void nestedTernary() {
aaaaaaaaaa ? bbbbbbbbbb : cccccccccc ? dddddddddd : eeeeeeeeee ? ffffffffff : gggggggggg;
return a
? a
: bbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
? a
: null;
}

void ternaryWithComments() {
Expand Down
6 changes: 6 additions & 0 deletions test/unit-test/conditional-expression/spaces/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ void nestedTernary() {
: eeeeeeeeee
? ffffffffff
: gggggggggg;
return a
? a
: bbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
? a
: null;
}

void ternaryWithComments() {
Expand Down
6 changes: 6 additions & 0 deletions test/unit-test/conditional-expression/tabs/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ int ternaryOperationThatShouldNotBreak() {

void nestedTernary() {
aaaaaaaaaa ? bbbbbbbbbb : cccccccccc ? dddddddddd : eeeeeeeeee ? ffffffffff : gggggggggg;
return a
? a
: bbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
? a
: null;
}

void ternaryWithComments() {
Expand Down
6 changes: 6 additions & 0 deletions test/unit-test/conditional-expression/tabs/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ void nestedTernary() {
: eeeeeeeeee
? ffffffffff
: gggggggggg;
return a
? a
: bbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
? a
: null;
}

void ternaryWithComments() {
Expand Down