From 271a100e8f72ab5810362c6ee2a20ebdb5ea02f2 Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Sat, 24 Feb 2024 21:22:50 +0100 Subject: [PATCH] refactor(streams): prepare for `noUncheckedIndexedAccess` (#4377) --- streams/_common.ts | 2 +- streams/delimiter_stream.ts | 10 +++++----- streams/merge_readable_streams.ts | 4 ++-- streams/text_delimiter_stream.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/streams/_common.ts b/streams/_common.ts index 978ffcda0..031915257 100644 --- a/streams/_common.ts +++ b/streams/_common.ts @@ -20,7 +20,7 @@ export function createLPS(pat: Uint8Array): Uint8Array { lps[i] = 0; i++; } else { - prefixEnd = lps[prefixEnd - 1]; + prefixEnd = lps[prefixEnd - 1]!; } } return lps; diff --git a/streams/delimiter_stream.ts b/streams/delimiter_stream.ts index 5d7acdf61..b7a77ad49 100644 --- a/streams/delimiter_stream.ts +++ b/streams/delimiter_stream.ts @@ -116,7 +116,7 @@ export class DelimiterStream extends TransformStream { // they are (with concatenation). if (bufs.length === 1) { // Concat not needed when a single buffer is passed. - controller.enqueue(bufs[0]); + controller.enqueue(bufs[0]!); } else { controller.enqueue(concat(bufs)); } @@ -134,7 +134,7 @@ export class DelimiterStream extends TransformStream { } else if (delimitedChunkEnd < 0 && bufs.length > 0) { // Our chunk started by finishing a partial delimiter match. const lastIndex = bufs.length - 1; - const last = bufs[lastIndex]; + const last = bufs[lastIndex]!; const lastSliceIndex = last.byteLength + delimitedChunkEnd; const lastSliced = last.subarray(0, lastSliceIndex); if (lastIndex === 0) { @@ -173,7 +173,7 @@ export class DelimiterStream extends TransformStream { // but now got a new 'A', then we'll drop down to having matched // just 'A'. The while loop will turn around again and we'll rematch // to 'AA' and proceed onwards to try and match on 'B' again. - matchIndex = lps[matchIndex - 1]; + matchIndex = lps[matchIndex - 1]!; } } // Save match index. @@ -231,7 +231,7 @@ export class DelimiterStream extends TransformStream { // they are (with concatenation). if (bufs.length === 1) { // Concat not needed when a single buffer is passed. - controller.enqueue(bufs[0]); + controller.enqueue(bufs[0]!); } else { controller.enqueue(concat(bufs)); } @@ -275,7 +275,7 @@ export class DelimiterStream extends TransformStream { if (length === 0) { controller.enqueue(new Uint8Array()); } else if (length === 1) { - controller.enqueue(bufs[0]); + controller.enqueue(bufs[0]!); } else { controller.enqueue(concat(bufs)); } diff --git a/streams/merge_readable_streams.ts b/streams/merge_readable_streams.ts index 3d258c67a..2ee8d2a1a 100644 --- a/streams/merge_readable_streams.ts +++ b/streams/merge_readable_streams.ts @@ -40,9 +40,9 @@ export function mergeReadableStreams( } controller.enqueue(data); } - resolvePromises[index].resolve(); + resolvePromises[index]!.resolve(); } catch (error) { - resolvePromises[index].reject(error); + resolvePromises[index]!.reject(error); } })(); } diff --git a/streams/text_delimiter_stream.ts b/streams/text_delimiter_stream.ts index 2025cc332..90bb913d4 100644 --- a/streams/text_delimiter_stream.ts +++ b/streams/text_delimiter_stream.ts @@ -73,7 +73,7 @@ export class TextDelimiterStream extends TransformStream { this.#inspectIndex++; localIndex++; } else { - this.#matchIndex = this.#delimLPS[this.#matchIndex - 1]; + this.#matchIndex = this.#delimLPS[this.#matchIndex - 1]!; } } }