Skip to content

Commit

Permalink
fix trim intro/outro bug (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored and mourner committed May 31, 2018
1 parent b32e32f commit 5a71147
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Chunk.js
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/MagicString.js
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 5a71147

Please sign in to comment.