Skip to content

Commit

Permalink
-> 0.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Mar 27, 2015
1 parent 557f7ce commit 2271c63
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# changelog

## 0.4.6

* Overlapping ranges can be removed
* Non-string content is rejected ([#9](https://github.com/Rich-Harris/magic-string/pull/9))

## 0.4.5

* Implement `source.addSourcemapLocation()`
Expand Down
42 changes: 40 additions & 2 deletions dist/magic-string.deps.js
Expand Up @@ -13,7 +13,7 @@
return new Buffer( str ).toString( 'base64' );
};
} else {
throw new Error( 'Unsupported environment' );
throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
}

var btoa = _btoa;
Expand Down Expand Up @@ -502,6 +502,10 @@
},

append: function ( content ) {
if ( typeof content !== 'string' ) {
throw new TypeError( 'appended content must be a string' );
}

this.str += content;
return this;
},
Expand Down Expand Up @@ -648,6 +652,10 @@
},

insert: function ( index, content ) {
if ( typeof content !== 'string' ) {
throw new TypeError( 'inserted content must be a string' );
}

if ( index === 0 ) {
this.prepend( content );
} else if ( index === this.original.length ) {
Expand Down Expand Up @@ -702,11 +710,41 @@
},

remove: function ( start, end ) {
this.replace( start, end, '' );
var loc, d, i, currentStart, currentEnd;

if ( start < 0 || end > this.mappings.length ) {
throw new Error( 'Character is out of bounds' );
}

d = 0;
currentStart = -1;
currentEnd = -1;
for ( i = start; i < end; i += 1 ) {
loc = this.mappings[i];

if ( loc !== -1 ) {
if ( !~currentStart ) {
currentStart = loc;
}

currentEnd = loc + 1;

this.mappings[i] = -1;
d += 1;
}
}

this.str = this.str.slice( 0, currentStart ) + this.str.slice( currentEnd );

adjust( this.mappings, end, this.mappings.length, -d );
return this;
},

replace: function ( start, end, content ) {
if ( typeof content !== 'string' ) {
throw new TypeError( 'replacement content must be a string' );
}

var firstChar, lastChar, d;

firstChar = this.locate( start );
Expand Down
42 changes: 40 additions & 2 deletions dist/magic-string.js
Expand Up @@ -13,7 +13,7 @@
return new Buffer( str ).toString( 'base64' );
};
} else {
throw new Error( 'Unsupported environment' );
throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
}

var btoa = _btoa;
Expand Down Expand Up @@ -416,6 +416,10 @@
},

append: function ( content ) {
if ( typeof content !== 'string' ) {
throw new TypeError( 'appended content must be a string' );
}

this.str += content;
return this;
},
Expand Down Expand Up @@ -562,6 +566,10 @@
},

insert: function ( index, content ) {
if ( typeof content !== 'string' ) {
throw new TypeError( 'inserted content must be a string' );
}

if ( index === 0 ) {
this.prepend( content );
} else if ( index === this.original.length ) {
Expand Down Expand Up @@ -616,11 +624,41 @@
},

remove: function ( start, end ) {
this.replace( start, end, '' );
var loc, d, i, currentStart, currentEnd;

if ( start < 0 || end > this.mappings.length ) {
throw new Error( 'Character is out of bounds' );
}

d = 0;
currentStart = -1;
currentEnd = -1;
for ( i = start; i < end; i += 1 ) {
loc = this.mappings[i];

if ( loc !== -1 ) {
if ( !~currentStart ) {
currentStart = loc;
}

currentEnd = loc + 1;

this.mappings[i] = -1;
d += 1;
}
}

this.str = this.str.slice( 0, currentStart ) + this.str.slice( currentEnd );

adjust( this.mappings, end, this.mappings.length, -d );
return this;
},

replace: function ( start, end, content ) {
if ( typeof content !== 'string' ) {
throw new TypeError( 'replacement content must be a string' );
}

var firstChar, lastChar, d;

firstChar = this.locate( start );
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "magic-string",
"description": "Modify strings, generate sourcemaps",
"author": "Rich Harris",
"version": "0.4.5",
"version": "0.4.6",
"repository": "https://github.com/rich-harris/magic-string",
"main": "dist/magic-string.js",
"jsnext:main": "src/MagicString/index.js",
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Expand Up @@ -444,7 +444,7 @@ describe( 'MagicString', function () {
assert.equal( s.toString(), 'afghi' );
});

it.only( 'should remove overlapping ranges', function () {
it( 'should remove overlapping ranges', function () {
var s = new MagicString( 'abcdefghijkl' );

s.remove( 3, 7 ).remove( 5, 9 );
Expand Down

0 comments on commit 2271c63

Please sign in to comment.