From eea4d4bf3eac9d0ed7967d771234a5a60a57d24c Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 30 May 2018 12:44:03 +0200 Subject: [PATCH] fix trim intro/outro bug --- src/Chunk.js | 8 ++++---- test/MagicString.js | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Chunk.js b/src/Chunk.js index 9798f59..117a917 100644 --- a/src/Chunk.js +++ b/src/Chunk.js @@ -121,12 +121,12 @@ export default class Chunk { if (trimmed.length) { if (trimmed !== this.content) { - this.split(this.start + trimmed.length).edit('', false); + this.split(this.start + trimmed.length).edit('', undefined, true); } return true; } else { - this.edit('', false); + this.edit('', undefined, true); this.intro = this.intro.replace(rx, ''); if (this.intro.length) return true; @@ -142,12 +142,12 @@ export default class Chunk { if (trimmed.length) { if (trimmed !== this.content) { this.split(this.end - trimmed.length); - this.edit('', false); + this.edit('', undefined, true); } return true; } else { - this.edit('', false); + this.edit('', undefined, true); this.outro = this.outro.replace(rx, ''); if (this.outro.length) return true; diff --git a/test/MagicString.js b/test/MagicString.js index 80421b7..0880bf1 100644 --- a/test/MagicString.js +++ b/test/MagicString.js @@ -1162,6 +1162,12 @@ describe( 'MagicString', () => { const s = new MagicString( ' abcdefghijkl ' ); assert.strictEqual( s.trim(), s ); }); + + it( 'should support trimming chunks with intro and outro', () => { + const s = new MagicString( ' \n' ); + s.appendRight(4, 'test'); + assert.strictEqual( s.trim().toString(), 'test' ); + }); }); describe( 'trimLines', () => {