Skip to content

Commit 61f0245

Browse files
committed
add strict TS checking + fix some initial errors
1 parent 58203e9 commit 61f0245

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"license": "ISC",
1414
"devDependencies": {
1515
"@11ty/eleventy": "^3.1.2",
16+
"@types/js-yaml": "^4.0.9",
1617
"@types/node": "^25.2.3",
1718
"concurrently": "^9.2.1",
1819
"typescript": "^5.9.3"

src/lib/loadInstructions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ into an array of single characters, each representing one bit.
3333
3434
Returns null if the string isn’t 16 or 32 bits long.
3535
*/
36-
function parseMatchBits(matchStr) {
36+
function parseMatchBits(matchStr: string) {
3737
if (matchStr.length !== 16 && matchStr.length !== 32) {
3838
throw new Error(`Invalid match string length ${matchStr.length}; expected 16 or 32`);
3939
}
@@ -160,7 +160,7 @@ function detectEncodingType(doc) {
160160
const vars = Object.fromEntries(
161161
doc.encoding.variables.map((v) => [v.name, String(v.location)]),
162162
);
163-
const eq = (name, hi, lo) => vars[name] === hi + "-" + lo;
163+
const eq = (name: string, hi: number, lo: number) => vars[name] === hi + "-" + lo;
164164
if (eq("xd", 11, 7) && eq("xs1", 19, 15) && vars["imm"] === "31-20") return "I";
165165
if (eq("xd", 11, 7) && eq("xs1", 19, 15) && eq("xs2", 24, 20)) return "R";
166166
if (eq("xs2", 24, 20) && eq("xs1", 19, 15) && eq("imm", 11, 7)) return "S";
@@ -279,7 +279,7 @@ export default function loadInstructions() {
279279
if (doc.encoding && doc.encoding.match) {
280280
const m = parseMatchBits(doc.encoding.match);
281281
if (m) {
282-
const sliceBits = (hi, lo) => m.slice(31 - hi, 32 - lo).join("");
282+
const sliceBits = (hi: number, lo: number) => m.slice(31 - hi, 32 - lo).join("");
283283
opcode = sliceBits(6, 0);
284284
funct3 = sliceBits(14, 12);
285285
const f7 = sliceBits(31, 25);

src/scripts/search.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function applyFilters() {
5555
/* Check if the item matches an active extension filter
5656
- If no filters are active, match everything
5757
- Otherwise, show only if its extension is selected */
58-
const matchesExtension = !filtersActive || activeExtensions.has(li.dataset.extension);
58+
const matchesExtension = !filtersActive || activeExtensions.has(li.dataset.extension || "");
5959

6060
// Show or hide this <li> depending on whether both match conditions are true
6161
li.style.display = matchesQuery && matchesExtension ? "" : "none";
@@ -77,13 +77,13 @@ input.addEventListener("keydown", (e) => {
7777
const exact = items.find((li) => {
7878
if (li.dataset.mnemonic !== q) return false;
7979
if (!filtersActive) return true;
80-
return activeExtensions.has(li.dataset.extension);
80+
return activeExtensions.has(li.dataset.extension || "");
8181
});
8282

8383
// If an exact match is found, redirect to that instruction's detail page
8484
if (exact) {
85-
const link = exact.querySelector("a").getAttribute("href");
86-
location.href = link;
85+
const link = exact.querySelector("a")?.getAttribute("href");
86+
if (link) location.href = link;
8787
}
8888
});
8989

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"moduleResolution": "NodeNext",
66
"outDir": "src",
77
"rootDir": "src",
8+
"strict": true,
89
"allowJs": true,
910
"esModuleInterop": true,
1011
"skipLibCheck": true,

0 commit comments

Comments
 (0)