Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trim bug with intro/outro #144

Merged
merged 1 commit into from May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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