@samitouri / QOS-React-2 / commits / 7a6a0e5f72

[be] Fix various eslints

Lauren Tan committed Feb 28, 2023 at 19:19 UTC 7a6a0e5f72a9a0c962e017179a5fcfbb0a2c955d
5 files changed +22 -22
compiler/forget/src/HIR/HIRBuilder.ts
+10 -9
@@ -21,6 +21,7 @@ import {
21 GotoVariant,
22 HIR,
23 Identifier,
24 + IdentifierId,
25 Instruction,
26 makeBlockId,
27 makeInstructionId,
@@ -86,7 +87,7 @@ export default class HIRBuilder {
87 parentFunction: NodePath<t.Function>;
88 errors: CompilerError = new CompilerError();
89
89 - get nextIdentifierId() {
90 + get nextIdentifierId(): IdentifierId {
91 return this.#env.nextIdentifierId;
92 }
93
@@ -127,7 +128,7 @@ export default class HIRBuilder {
128 /**
129 * Push a statement or expression onto the current block
130 */
130 - push(instruction: Instruction) {
131 + push(instruction: Instruction): void {
132 this.#current.instructions.push(instruction);
133 }
134
@@ -272,7 +273,7 @@ export default class HIRBuilder {
273 /**
274 * Terminate the current block w the given terminal, and start a new block
275 */
275 - terminate(terminal: Terminal, nextBlockKind: BlockKind) {
276 + terminate(terminal: Terminal, nextBlockKind: BlockKind): void {
277 const { id: blockId, kind, instructions } = this.#current;
278 this.#completed.set(blockId, {
279 kind,
@@ -290,7 +291,7 @@ export default class HIRBuilder {
291 * Terminate the current block w the given terminal, and set the previously
292 * reserved block as the new current block
293 */
293 - terminateWithContinuation(terminal: Terminal, continuation: WipBlock) {
294 + terminateWithContinuation(terminal: Terminal, continuation: WipBlock): void {
295 const { id: blockId, kind, instructions } = this.#current;
296 this.#completed.set(blockId, {
297 kind: kind,
@@ -315,7 +316,7 @@ export default class HIRBuilder {
316 /**
317 * Save a previously reserved block as completed
318 */
318 - complete(block: WipBlock, terminal: Terminal) {
319 + complete(block: WipBlock, terminal: Terminal): void {
320 const { id: blockId, kind, instructions } = block;
321 this.#completed.set(blockId, {
322 kind,
@@ -536,7 +537,7 @@ export function removeUnreachableFallthroughs(func: HIR): void {
537 export function reversePostorderBlocks(func: HIR): void {
538 const visited: Set<BlockId> = new Set();
539 const postorder: Array<BlockId> = [];
539 - function visit(blockId: BlockId) {
540 + function visit(blockId: BlockId): void {
541 if (visited.has(blockId)) {
542 return;
543 }
@@ -634,7 +635,7 @@ export function reversePostorderBlocks(func: HIR): void {
635 func.blocks = blocks;
636 }
637
637 -export function markInstructionIds(func: HIR) {
638 +export function markInstructionIds(func: HIR): void {
639 let id = 0;
640 const visited = new Set<Instruction>();
641 for (const [_, block] of func.blocks) {
@@ -650,12 +651,12 @@ export function markInstructionIds(func: HIR) {
651 }
652 }
653
653 -export function markPredecessors(func: HIR) {
654 +export function markPredecessors(func: HIR): void {
655 for (const [, block] of func.blocks) {
656 block.preds.clear();
657 }
658 const visited: Set<BlockId> = new Set();
658 - function visit(blockId: BlockId, prevBlock: BasicBlock | null) {
659 + function visit(blockId: BlockId, prevBlock: BasicBlock | null): void {
660 const block = func.blocks.get(blockId)!;
661 if (prevBlock) {
662 block.preds.add(prevBlock.id);
compiler/forget/src/HIR/PrintHIR.ts
+1 -1
@@ -42,7 +42,7 @@ export function printFunction(fn: HIRFunction): string {
42 export function printHIR(ir: HIR, options: Options | null = null): string {
43 let output = [];
44 let indent = " ".repeat(options?.indent ?? 0);
45 - const push = (text: string, indent: string = " ") => {
45 + const push = (text: string, indent: string = " "): void => {
46 output.push(`${indent}${text}`);
47 };
48 for (const [blockId, block] of ir.blocks) {
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+4 -5
@@ -416,7 +416,7 @@ function codegenDependency(
416 return object;
417 }
418
419 -function withLoc<TNode extends t.Node, T extends (...args: any[]) => TNode>(
419 +function withLoc<T extends (...args: any[]) => t.Node>(
420 fn: T
421 ): (
422 loc: SourceLocation | null | undefined,
@@ -430,8 +430,7 @@ function withLoc<TNode extends t.Node, T extends (...args: any[]) => TNode>(
430 if (loc != null && loc != GeneratedSource) {
431 node.loc = loc;
432 }
433 - // @ts-ignore
434 - return node;
433 + return node as ReturnType<T>;
434 };
435 }
436
@@ -439,9 +438,9 @@ const createBinaryExpression = withLoc(t.binaryExpression);
438 const createCallExpression = withLoc(t.callExpression);
439 const createExpressionStatement = withLoc(t.expressionStatement);
440 const createFunctionDeclaration = withLoc(t.functionDeclaration);
442 -const createLabelledStatement = withLoc(t.labeledStatement);
441 +const _createLabelledStatement = withLoc(t.labeledStatement);
442 const createVariableDeclaration = withLoc(t.variableDeclaration);
444 -const createWhileStatement = withLoc(t.whileStatement);
443 +const _createWhileStatement = withLoc(t.whileStatement);
444 const createTaggedTemplateExpression = withLoc(t.taggedTemplateExpression);
445 const createLogicalExpression = withLoc(t.logicalExpression);
446 const createSequenceExpression = withLoc(t.sequenceExpression);
compiler/forget/src/ReactiveScopes/visitors.ts
+3 -3
@@ -30,9 +30,9 @@ export function visitReactiveFunction<TState>(
30 }
31
32 export class ReactiveFunctionVisitor<TState = void> {
33 - visitID(id: InstructionId, state: TState): void {}
34 - visitLValue(id: InstructionId, lvalue: LValue, state: TState): void {}
35 - visitPlace(id: InstructionId, place: Place, state: TState): void {}
33 + visitID(_id: InstructionId, _state: TState): void {}
34 + visitLValue(_id: InstructionId, _lvalue: LValue, _state: TState): void {}
35 + visitPlace(_id: InstructionId, _place: Place, _state: TState): void {}
36
37 visitValue(id: InstructionId, value: ReactiveValue, state: TState): void {
38 this.traverseValue(id, value, state);
compiler/forget/src/SSA/EnterSSA.ts
+4 -4
@@ -157,14 +157,14 @@ class SSABuilder {
157 return newId;
158 }
159
160 - fixIncompletePhis(block: BasicBlock) {
160 + fixIncompletePhis(block: BasicBlock): void {
161 const state = this.#states.get(block)!;
162 for (const phi of state.incompletePhis) {
163 this.addPhi(block, phi.oldId, phi.newId);
164 }
165 }
166
167 - startBlock(block: BasicBlock) {
167 + startBlock(block: BasicBlock): void {
168 this.#current = block;
169 this.#states.set(block, {
170 defs: new Map(),
@@ -172,7 +172,7 @@ class SSABuilder {
172 });
173 }
174
175 - print() {
175 + print(): void {
176 const text: string[] = [];
177 for (const [block, state] of this.#states) {
178 text.push(`bb${block.id}:`);
@@ -194,7 +194,7 @@ class SSABuilder {
194 }
195 }
196
197 -export default function enterSSA(func: HIRFunction) {
197 +export default function enterSSA(func: HIRFunction): void {
198 const visitedBlocks: Set<BasicBlock> = new Set();
199 const builder = new SSABuilder(func.env, func.body.blocks);
200 for (const [blockId, block] of func.body.blocks) {