From c508616ec8d5b66bfd84415c83083fef7225ac11 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Thu, 1 Dec 2016 11:16:16 -0500 Subject: [PATCH] optimisation - remove empty chunks when overwriting --- src/MagicString.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/MagicString.js b/src/MagicString.js index da357b4..7fc93d1 100644 --- a/src/MagicString.js +++ b/src/MagicString.js @@ -330,15 +330,15 @@ MagicString.prototype = { if ( first ) { first.edit( content, storeName ); - if ( first !== last ) { - let chunk = first.next; - while ( chunk !== last ) { - chunk.edit( '', false ); - chunk = chunk.next; - } - - chunk.edit( '', false ); + if ( last ) { + first.next = last.next; + } else { + first.next = null; + this.lastChunk = first; } + + first.original = this.original.slice( start, end ); + first.end = end; } else {