From b77b51aa704a5cd3a43a4f157a827c0edd6de84c Mon Sep 17 00:00:00 2001 From: cin Date: Fri, 2 Feb 2024 15:42:48 +0800 Subject: [PATCH] refactor(console): prepare for `noUncheckedIndexedAccess` (#4269) --- console/_run_length.ts | 2 +- console/unicode_width.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/console/_run_length.ts b/console/_run_length.ts index 25b8c4715d89..4bf2add29e0f 100644 --- a/console/_run_length.ts +++ b/console/_run_length.ts @@ -32,7 +32,7 @@ export function runLengthDecode({ d, r }: { d: string; r: string }) { let out = ""; for (const [i, ch] of [...runLengths].entries()) { - out += data[i].repeat(ch.codePointAt(0)!); + out += data[i]!.repeat(ch.codePointAt(0)!); } return Uint8Array.from([...out].map((x) => x.codePointAt(0)!)); diff --git a/console/unicode_width.ts b/console/unicode_width.ts index 0d2ac23c606e..71ebe4c00ddb 100644 --- a/console/unicode_width.ts +++ b/console/unicode_width.ts @@ -8,9 +8,11 @@ let tables: Uint8Array[] | null = null; function lookupWidth(cp: number) { if (!tables) tables = data.tables.map(runLengthDecode); - const t1Offset = tables[0][(cp >> 13) & 0xff]; - const t2Offset = tables[1][128 * t1Offset + ((cp >> 6) & 0x7f)]; - const packedWidths = tables[2][16 * t2Offset + ((cp >> 2) & 0xf)]; + const t1Offset = (tables[0] as Uint8Array)[(cp >> 13) & 0xff] as number; + const t2Offset = + (tables[1] as Uint8Array)[128 * t1Offset + ((cp >> 6) & 0x7f)] as number; + const packedWidths = + (tables[2] as Uint8Array)[16 * t2Offset + ((cp >> 2) & 0xf)] as number; const width = (packedWidths >> (2 * (cp & 0b11))) & 0b11;