@@ -11,26 +11,20 @@ import type { PrintFunction } from '../types.d.ts';
1111
1212const { group, hardline, ifBreak, indent, line, softline } = doc . builders ;
1313
14- function fillTab ( { useTabs, tabWidth } : ParserOptions < AstNode > ) : Doc {
15- if ( useTabs ) return '\t' ;
16- // For the odd case of `tabWidth` of 1 or 0 we initiate `fillTab` as a single
17- // space.
18- return tabWidth > 2 ? ' ' . repeat ( tabWidth - 1 ) : ' ' ;
19- }
20-
2114function experimentalTernaries (
2215 node : ConditionalExpression ,
2316 path : AstPath < ConditionalExpression > ,
2417 print : PrintFunction ,
25- options : ParserOptions < AstNode >
18+ { useTabs , tabWidth } : ParserOptions < AstNode >
2619) : Doc {
2720 const grandparent = path . grandparent as StrictAstNode ;
2821 const isNested = grandparent . kind === NonterminalKind . ConditionalExpression ;
2922 const isNestedAsTrueExpression =
3023 isNested && grandparent . trueExpression . variant === node ;
24+ const falseExpressionVariantKind = node . falseExpression . variant . kind ;
3125 const falseExpressionInSameLine =
32- node . falseExpression . variant . kind === NonterminalKind . TupleExpression ||
33- node . falseExpression . variant . kind === NonterminalKind . ConditionalExpression ;
26+ falseExpressionVariantKind === NonterminalKind . TupleExpression ||
27+ falseExpressionVariantKind === NonterminalKind . ConditionalExpression ;
3428
3529 // If the `condition` breaks into multiple lines, we add parentheses,
3630 // unless it already is a `TupleExpression`.
@@ -56,14 +50,22 @@ function experimentalTernaries(
5650 { id : groupId }
5751 ) ;
5852
53+ // For the odd case of `tabWidth` of 1 or 0 we initiate `fillTab` as a single
54+ // space.
55+ const fillTab = useTabs
56+ ? '\t'
57+ : tabWidth > 2
58+ ? ' ' . repeat ( tabWidth - 1 )
59+ : ' ' ;
60+
5961 const falseExpression = path . call ( print , 'falseExpression' ) ;
6062 const falseExpressionDoc = [
6163 isNested ? hardline : line ,
6264 ':' ,
6365 falseExpressionInSameLine
6466 ? [ ' ' , falseExpression ]
6567 : ifBreak (
66- [ fillTab ( options ) , indent ( falseExpression ) ] ,
68+ [ fillTab , indent ( falseExpression ) ] ,
6769 [ ' ' , falseExpression ] ,
6870 // We only add `fillTab` if we are sure the trueExpression is
6971 // indented.
0 commit comments