From 65064cb70c441956aa0065a08a0be94c8524db3b Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Mon, 1 May 2017 14:34:18 -0400 Subject: [PATCH] =?UTF-8?q?improve=20deindent=20slightly=20=E2=80=94=20all?= =?UTF-8?q?ow=20inline=20false=20expressions=20(which=20get=20removed),=20?= =?UTF-8?q?and=20trim=20trailing=20tabs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/deindent.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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 ) {