diff --git a/src/utils/deindent.js b/src/utils/deindent.js index 63730254b3..f618dd5277 100644 --- a/src/utils/deindent.js +++ b/src/utils/deindent.js @@ -9,13 +9,24 @@ export default function deindent ( strings, ...values ) { let trailingIndentation = getTrailingIndentation( result ); for ( let i = 1; i < strings.length; i += 1 ) { - const value = String( values[ i - 1 ] ).replace( /\n/g, `\n${trailingIndentation}` ); - result += value + strings[i].replace( pattern, '' ); + const expression = values[ i - 1 ]; + const string = strings[i].replace( pattern, '' ); + + if ( expression || expression === '' ) { + const value = String( expression ).replace( /\n/g, `\n${trailingIndentation}` ); + result += value + string; + } + + else { + let c = result.length; + while ( /\s/.test( result[ c - 1 ] ) ) c -= 1; + result = result.slice( 0, c ) + string; + } trailingIndentation = getTrailingIndentation( result ); } - return result.trim(); + return result.trim().replace( /\t+$/gm, '' ); } function getTrailingIndentation ( str ) {