@@ -21,6 +21,7 @@ const fill = docBuilders.fill;
2121const ifBreak = docBuilders . ifBreak ;
2222const breakParent = docBuilders . breakParent ;
2323const lineSuffixBoundary = docBuilders . lineSuffixBoundary ;
24+ const addAlignmentToDoc = docBuilders . addAlignmentToDoc ;
2425
2526const docUtils = require ( "./doc-utils" ) ;
2627const willBreak = docUtils . willBreak ;
@@ -1668,7 +1669,11 @@ function genericPrintNoParens(path, options, print, args) {
16681669 size = util . getAlignmentSize ( value , tabWidth , index + 1 ) ;
16691670 }
16701671
1671- let aligned = addAlignmentToDoc ( expressions [ i ] , size , tabWidth ) ;
1672+ let aligned = addAlignmentToDoc (
1673+ removeLines ( expressions [ i ] ) ,
1674+ size ,
1675+ tabWidth
1676+ ) ;
16721677
16731678 parts . push (
16741679 "${" ,
@@ -4246,26 +4251,14 @@ function printAstToDoc(ast, options, addAlignmentSize) {
42464251 if ( addAlignmentSize > 0 ) {
42474252 // Add a hardline to make the indents take effect
42484253 // It should be removed in index.js format()
4249- doc = addAlignmentToDoc ( concat ( [ hardline , doc ] ) , addAlignmentSize , options . tabWidth ) ;
4254+ doc = addAlignmentToDoc (
4255+ removeLines ( concat ( [ hardline , doc ] ) ) ,
4256+ addAlignmentSize ,
4257+ options . tabWidth
4258+ ) ;
42504259 }
42514260 docUtils . propagateBreaks ( doc ) ;
42524261 return doc ;
42534262}
42544263
4255- function addAlignmentToDoc ( doc , size , tabWidth ) {
4256- let aligned = removeLines ( doc ) ;
4257- if ( size > 0 ) {
4258- // Use indent to add tabs for all the levels of tabs we need
4259- for ( let i = 0 ; i < Math . floor ( size / tabWidth ) ; ++ i ) {
4260- aligned = indent ( aligned ) ;
4261- }
4262- // Use align for all the spaces that are needed
4263- aligned = align ( size % tabWidth , aligned ) ;
4264- // size is absolute from 0 and not relative to the current
4265- // indentation, so we use -Infinity to reset the indentation to 0
4266- aligned = align ( - Infinity , aligned ) ;
4267- }
4268- return aligned ;
4269- }
4270-
42714264module . exports = { printAstToDoc } ;
0 commit comments