Skip to content

Commit 1b36ea6

Browse files
ziadziad
authored andcommitted
minor cleanup
1 parent 48c1fd1 commit 1b36ea6

13 files changed

Lines changed: 1413 additions & 227 deletions

package-lock.json

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

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"test": "jest",
1616
"test:ci": "jest --ci --coverage --reporters=default --reporters=jest-junit",
1717
"test:coverage": "jest --coverage",
18+
"lint": "eslint src/ playground/ tests/",
19+
"lint:fix": "eslint src/ playground/ tests/ --fix",
20+
"format": "prettier --write 'src/**/*.ts' 'playground/**/*.ts' 'tests/**/*.ts'",
21+
"format:check": "prettier --check 'src/**/*.ts' 'playground/**/*.ts' 'tests/**/*.ts'",
1822
"build:release": "npm run clean:build && npm run build && npm run test:ci",
1923
"build:playground": "npm run build && npx tsx playground/build.ts",
2024
"playground": "npx tsx playground/build.ts --serve",
@@ -48,10 +52,15 @@
4852
],
4953
"devDependencies": {
5054
"@types/jest": "^29.5.12",
55+
"@typescript-eslint/eslint-plugin": "^8.57.2",
56+
"@typescript-eslint/parser": "^8.57.2",
5157
"esbuild": "^0.27.3",
58+
"eslint": "^10.1.0",
59+
"eslint-config-prettier": "^10.1.8",
5260
"husky": "^9.1.7",
5361
"jest": "^29.7.0",
5462
"jest-junit": "^16.0.0",
63+
"prettier": "^3.8.1",
5564
"ts-jest": "^29.1.2",
5665
"ts-node": "^10.9.2",
5766
"typescript": "^5.4.0"

playground/explorer.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ function buildByteRanges(data: Uint8Array): ByteRangeMap {
3131
1: 'Type', 2: 'Import', 3: 'Function', 4: 'Table', 5: 'Memory',
3232
6: 'Global', 7: 'Export', 9: 'Element', 10: 'Code', 11: 'Data', 0: 'Custom',
3333
};
34-
const sectionToByteRange: Record<number, ByteRangeSection> = {
35-
1: 'type', 2: 'import', 3: 'function', 4: 'table', 5: 'memory',
36-
6: 'global', 7: 'export', 9: 'element', 11: 'data',
37-
};
38-
3934
let offset = 8; // skip magic + version
4035
while (offset < data.length) {
4136
const sectionId = data[offset];
@@ -97,11 +92,11 @@ function buildByteRanges(data: Uint8Array): ByteRangeMap {
9792
},
9893
};
9994
}
100-
import { parseDwarfDebugInfo, getLineEntriesForAddressRange } from '../src/DwarfParser';
101-
import type { DwarfDebugInfo, DwarfLineInfo } from '../src/DwarfParser';
95+
import { parseDwarfDebugInfo } from '../src/DwarfParser';
96+
import type { DwarfDebugInfo } from '../src/DwarfParser';
10297
import { decompileFunction, createNameResolver } from './WasmDecompiler';
10398
import type { NameResolver, FieldResolver } from './WasmDecompiler';
104-
import { parseSourceMap, lookupMapping, getSourceLine } from '../src/SourceMapParser';
99+
import { parseSourceMap, lookupMapping } from '../src/SourceMapParser';
105100
import type { ParsedSourceMap, SourceMapping } from '../src/SourceMapParser';
106101

107102
interface TreeNode {
@@ -323,19 +318,17 @@ function renderHighlightedC(container: HTMLElement, source: string, options?: Hi
323318
if (char === '(' && position + 1 < source.length) {
324319
let end = position + 1;
325320
while (end < source.length && source[end] === ' ') { end++; }
326-
let wordStart = end;
321+
const wordStart = end;
327322
while (end < source.length && /[a-zA-Z]/.test(source[end])) { end++; }
328323
const castWord = source.slice(wordStart, end);
329324
// Allow "unsigned long", "unsigned int" etc.
330-
let fullCast = castWord;
331325
let castEnd = end;
332326
while (castEnd < source.length && source[castEnd] === ' ') { castEnd++; }
333327
if (castEnd < source.length && /[a-zA-Z]/.test(source[castEnd])) {
334328
let nextWordEnd = castEnd;
335329
while (nextWordEnd < source.length && /[a-zA-Z]/.test(source[nextWordEnd])) { nextWordEnd++; }
336330
const nextWord = source.slice(castEnd, nextWordEnd);
337331
if (C_CAST_TYPES.has(nextWord)) {
338-
fullCast = castWord + ' ' + nextWord;
339332
castEnd = nextWordEnd;
340333
}
341334
}
@@ -434,7 +427,6 @@ function buildInstructionByteClasses(bytes: Uint8Array): Map<number, string> {
434427
try {
435428
const instructions = InstructionDecoder.decodeFunctionBody(bytes);
436429
for (const instruction of instructions) {
437-
const opcodeEnd = instruction.offset + (instruction.length - (instruction.immediates.values.length > 0 ? 1 : 0));
438430
for (let bytePos = instruction.offset; bytePos < instruction.offset + instruction.length; bytePos++) {
439431
if (bytePos < instruction.offset + 1 || (instruction.opCode.prefix !== undefined && bytePos < instruction.offset + 2)) {
440432
classes.set(bytePos, 'hex-opcode');
@@ -443,7 +435,7 @@ function buildInstructionByteClasses(bytes: Uint8Array): Map<number, string> {
443435
}
444436
}
445437
}
446-
} catch (decodeError) {
438+
} catch {
447439
// fall back to uncolored
448440
}
449441
return classes;
@@ -2448,14 +2440,14 @@ export default class Explorer {
24482440
this.addInfoRow(table, 'Kind', 'array');
24492441
this.addInfoRow(table, 'Element type', getValueTypeName(typeEntry.elementType));
24502442
this.addInfoRow(table, 'Mutable', String(typeEntry.mutable));
2451-
if ((typeEntry as any).superTypes && (typeEntry as any).superTypes.length > 0) {
2452-
for (const superIdx of (typeEntry as any).superTypes) {
2443+
if (typeEntry.superTypes && typeEntry.superTypes.length > 0) {
2444+
for (const superIdx of typeEntry.superTypes) {
24532445
const topLevelIdx = this.findTopLevelTypeIndex(superIdx);
24542446
this.addLinkedInfoRow(table, 'Extends', `type ${superIdx}`, 'type', topLevelIdx);
24552447
}
24562448
}
2457-
if ((typeEntry as any).final !== undefined) {
2458-
this.addInfoRow(table, 'Final', String((typeEntry as any).final));
2449+
if (typeEntry.final !== undefined) {
2450+
this.addInfoRow(table, 'Final', String(typeEntry.final));
24592451
}
24602452
detail.appendChild(table);
24612453
} else if (typeEntry.kind === 'rec') {
@@ -3729,7 +3721,7 @@ export default class Explorer {
37293721
const globalIndex = importedFuncCount + funcIndex;
37303722

37313723
for (const instruction of instructions) {
3732-
const feature = (instruction.opCode as any).feature as string | undefined;
3724+
const feature = instruction.opCode.feature;
37333725
if (feature) {
37343726
if (!featureOpcodes.has(feature)) {
37353727
featureOpcodes.set(feature, []);
@@ -3770,7 +3762,7 @@ export default class Explorer {
37703762
const name = readStr();
37713763
targetFeatures.set(name, prefixLabels[prefix] || 'unknown');
37723764
}
3773-
} catch (parseError) {
3765+
} catch {
37743766
// ignore parse failures
37753767
}
37763768
}
@@ -3782,7 +3774,6 @@ export default class Explorer {
37823774
for (const name of targetFeatures.keys()) { allFeatureNames.add(name); }
37833775

37843776
// Determine target spec level
3785-
const postMvpOpcodeFeatures = new Set(['bulk-memory', 'sign-extend', 'sat-trunc', 'mutable-globals', 'multi-value', 'reference-types', 'simd', 'tail-call', 'relaxed-simd', 'extended-const']);
37863777
const postMvpFeatures = new Set<string>();
37873778
for (const name of allFeatureNames) { postMvpFeatures.add(name); }
37883779
for (const name of targetFeatures.keys()) { postMvpFeatures.add(name); }
@@ -4440,7 +4431,7 @@ export default class Explorer {
44404431
}
44414432
detail.appendChild(table);
44424433
}
4443-
} catch (parseError) {
4434+
} catch {
44444435
const errorElement = document.createElement('div');
44454436
errorElement.className = 'detail-description';
44464437
errorElement.textContent = 'Failed to parse producers section.';
@@ -4834,7 +4825,7 @@ export default class Explorer {
48344825
let instructions: import('../src/InstructionDecoder').DecodedInstruction[];
48354826
try {
48364827
instructions = InstructionDecoder.decodeFunctionBody(funcBody);
4837-
} catch (decodeError) {
4828+
} catch {
48384829
this.appendByteRange(parent, 'function', funcIndex);
48394830
return;
48404831
}

0 commit comments

Comments
 (0)