diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 0daf80a53c9..3f5d3207cdd 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -223,22 +223,25 @@ namespace ts { const entry = this.data[key]; delete this.data[key]; - // Adjust the linked list references. - const previousElement = entry.previousEntry!; - previousElement.nextEntry = entry.nextEntry; + // Adjust the linked list references of the neighbor entries. + const previousEntry = entry.previousEntry!; + previousEntry.nextEntry = entry.nextEntry; + if (entry.nextEntry) { + entry.nextEntry.previousEntry = previousEntry; + } + + // When the deleted entry was the last one, we need to + // adust the endElement reference. + if (this.linkedListEnd === entry) { + this.linkedListEnd = previousEntry; + } // Adjust the forward reference of the deleted element // in case an iterator still references it. entry.previousEntry = undefined; - entry.nextEntry = previousElement; + entry.nextEntry = previousEntry; entry.skipNext = true; - // When the deleted entry was the last one, we need to - // adust the endElement reference - if (this.linkedListEnd === entry) { - this.linkedListEnd = previousElement; - } - return true; } return false;