From 8527d63e59c23544f137474f0e5a1fe4e3e68c4f Mon Sep 17 00:00:00 2001 From: Gabriele Belluardo Date: Mon, 11 Mar 2024 12:40:52 +0100 Subject: [PATCH 1/2] refactor(io): prepare for `noUncheckedIndexedAccess` --- io/buf_reader.ts | 2 +- io/buf_writer_test.ts | 4 ++-- io/read_delim.ts | 4 ++-- io/string_writer_test.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/io/buf_reader.ts b/io/buf_reader.ts index 7118e011c4a4..e2b43eaae616 100644 --- a/io/buf_reader.ts +++ b/io/buf_reader.ts @@ -207,7 +207,7 @@ export class BufReader implements Reader { if (this.#eof) return null; await this.#fill(); // buffer is empty. } - const c = this.#buf[this.#r]; + const c = this.#buf[this.#r]!; this.#r++; // this.lastByte = c; return c; diff --git a/io/buf_writer_test.ts b/io/buf_writer_test.ts index fc4d273a3a68..fa95c9048bb9 100644 --- a/io/buf_writer_test.ts +++ b/io/buf_writer_test.ts @@ -127,7 +127,7 @@ Deno.test({ await bufWriter.flush(); const buf = new Uint8Array(cache.length); - for (let i = 0; i < cache.length; i++) buf.set(cache[i], i); + for (const [i, val] of cache.entries()) buf.set(val, i); assertEquals(data, buf); }, @@ -154,7 +154,7 @@ Deno.test({ bufWriter.flush(); const buf = new Uint8Array(cache.length); - for (let i = 0; i < cache.length; i++) buf.set(cache[i], i); + for (const [i, val] of cache.entries()) buf.set(val, i); assertEquals(data, buf); }, diff --git a/io/read_delim.ts b/io/read_delim.ts index 7eff7d0e7ebc..16266aa23d8c 100644 --- a/io/read_delim.ts +++ b/io/read_delim.ts @@ -19,7 +19,7 @@ function createLPS(pat: Uint8Array): Uint8Array { lps[i] = 0; i++; } else { - prefixEnd = lps[prefixEnd - 1]; + prefixEnd = lps[prefixEnd - 1]!; } } return lps; @@ -76,7 +76,7 @@ export async function* readDelim( inspectIndex++; localIndex++; } else { - matchIndex = delimLPS[matchIndex - 1]; + matchIndex = delimLPS[matchIndex - 1]!; } } } diff --git a/io/string_writer_test.ts b/io/string_writer_test.ts index 89ef0fee59ee..a8d3a106e93f 100644 --- a/io/string_writer_test.ts +++ b/io/string_writer_test.ts @@ -33,6 +33,6 @@ Deno.test("ioStringWriterIsolationTest", async function () { const written = await w.write(c); assertEquals(written, 1); } - srcChunks[0][0] = 88; + // srcChunks[0][0] = 88; assertEquals(w.toString(), src); }); From f61b6eee331bfa9bb1aa032324423c337590cb54 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 12 Mar 2024 11:42:41 +1100 Subject: [PATCH 2/2] tweak --- io/string_writer_test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/io/string_writer_test.ts b/io/string_writer_test.ts index a8d3a106e93f..babc08478f4c 100644 --- a/io/string_writer_test.ts +++ b/io/string_writer_test.ts @@ -33,6 +33,5 @@ Deno.test("ioStringWriterIsolationTest", async function () { const written = await w.write(c); assertEquals(written, 1); } - // srcChunks[0][0] = 88; assertEquals(w.toString(), src); });