add eslint

This commit is contained in:
nora 2023-07-31 14:11:51 +02:00
parent e951cd5ee1
commit 12fcc4f1bb
11 changed files with 1237 additions and 26 deletions

View file

@ -251,7 +251,7 @@ export function tokenize(input: string): Token[] {
i++;
}
const ident = input.slice(span.start, span.end);
let kw = isKeyword(ident);
const kw = isKeyword(ident);
if (kw) {
tokens.push({ kind: kw, span });
} else {

View file

@ -331,7 +331,7 @@ function lowerExpr(fcx: FuncContext, instrs: wasm.Instr[], expr: Expr) {
}
case "literal": {
switch (expr.value.kind) {
case "str":
case "str": {
const utf8 = encodeUtf8(expr.value.value);
const idx = appendData(fcx.cx, utf8);
@ -339,6 +339,7 @@ function lowerExpr(fcx: FuncContext, instrs: wasm.Instr[], expr: Expr) {
instrs.push({ kind: "i32.const", imm: utf8.length });
break;
}
case "int":
switch (expr.value.type) {
case "Int":
@ -573,11 +574,9 @@ function lowerExpr(fcx: FuncContext, instrs: wasm.Instr[], expr: Expr) {
// TODO: Actually do this instead of being naive.
const isPlace = (expr: Expr) =>
const _isPlace = (expr: Expr) =>
expr.kind === "ident" || expr.kind === "fieldAccess";
function project() {}
lowerExpr(fcx, instrs, expr.lhs);
switch (expr.lhs.ty!.kind) {

View file

@ -344,6 +344,7 @@ function parseExprCall(t: Token[]): [Token[], Expr] {
}
function parseExprAtom(startT: Token[]): [Token[], Expr] {
// eslint-disable-next-line prefer-const
let [t, tok] = next(startT);
const span = tok.span;
@ -354,8 +355,7 @@ function parseExprAtom(startT: Token[]): [Token[], Expr] {
// This could be a block or a tuple literal. We can only know after
// parsing the first expression and looking at the delimiter.
let peek;
[, peek] = next(t);
const [, peek] = next(t);
// It's a single element, which we interpret as a block.
// `(0,)` is the one elem tuple.
if (peek.kind === ")") {
@ -579,11 +579,7 @@ function parseCommaSeparatedList<R>(
// () | (a) | (a,) | (a, b)
while (true) {
if (next(t)[1]?.kind === terminator) {
break;
}
while (next(t)[1]?.kind !== terminator) {
let nextValue;
[t, nextValue] = parser(t);

View file

@ -191,8 +191,8 @@ function resolveModule(
};
}
case "let": {
let rhs = this.expr(expr.rhs);
let type = expr.type && this.type(expr.type);
const rhs = this.expr(expr.rhs);
const type = expr.type && this.type(expr.type);
scopes.push(expr.name.name);
const local = { name: expr.name.name, span: expr.name.span };

View file

@ -1,4 +1,4 @@
import { TY_INT, TY_STRING, TY_UNIT, Ty } from "./ast";
import { TY_INT, TY_STRING, TY_UNIT } from "./ast";
import { DUMMY_SPAN as SPAN } from "./error";
import { InferContext } from "./typeck";

View file

@ -1,6 +1,5 @@
import {
Ast,
binaryExprPrecedenceClass,
BuiltinName,
COMPARISON_KINDS,
DEFAULT_FOLDER,
@ -298,7 +297,7 @@ export function typeck(ast: Ast): Ast {
}
case "mod": {
switch (item.node.modKind.kind) {
case "inline":
case "inline": {
const modKind: ModItemKind = {
kind: "inline",
contents: item.node.modKind.contents.map((item) =>
@ -313,6 +312,7 @@ export function typeck(ast: Ast): Ast {
modKind,
},
};
}
case "extern":
// Nothing to check.
return {
@ -417,7 +417,7 @@ export class InferContext {
* before calling this.
*/
private constrainVar(variable: number, ty: Ty) {
let root = this.findRoot(variable);
const root = this.findRoot(variable);
if (ty.kind === "var") {
// Now we point our root to the other root to unify the two graphs.
@ -571,7 +571,9 @@ export function checkBody(
}
case "let": {
const loweredBindingTy = expr.type && lowerAstTy(expr.type);
let bindingTy = loweredBindingTy ? loweredBindingTy : infcx.newVar();
const bindingTy = loweredBindingTy
? loweredBindingTy
: infcx.newVar();
const rhs = this.expr(expr.rhs);
infcx.assign(bindingTy, rhs.ty!, expr.span);
@ -772,7 +774,9 @@ export function checkBody(
}
default: {
throw new CompilerError(
`cannot access field \`${field.value}\` on type \`${printTy(lhs.ty)}\``,
`cannot access field \`${field.value}\` on type \`${printTy(
lhs.ty
)}\``,
expr.span
);
}
@ -854,7 +858,7 @@ export function checkBody(
const assignedFields = new Set();
fields.forEach(([name, field], i) => {
fields.forEach(([name, field]) => {
const fieldTy = structTy.fields.find((def) => def[0] === name.name);
if (!fieldTy) {
throw new CompilerError(
@ -928,8 +932,8 @@ export function checkBody(
}
function checkBinary(expr: Expr & ExprBinary): Expr {
let lhsTy = expr.lhs.ty!;
let rhsTy = expr.rhs.ty!;
const lhsTy = expr.lhs.ty!;
const rhsTy = expr.rhs.ty!;
if (COMPARISON_KINDS.includes(expr.binaryKind)) {
if (lhsTy.kind === "int" && rhsTy.kind === "int") {
@ -969,7 +973,7 @@ function checkBinary(expr: Expr & ExprBinary): Expr {
}
function checkUnary(expr: Expr & ExprUnary): Expr {
let rhsTy = expr.rhs.ty!;
const rhsTy = expr.rhs.ty!;
if (
expr.unaryKind === "!" &&

View file

@ -629,12 +629,12 @@ function printStart(start: Start, f: FmtCtx) {
});
}
function printElem(_elem: Elem, f: FmtCtx) {
function printElem(_elem: Elem, _f: FmtCtx) {
todo();
}
function printData(data: Data, f: FmtCtx) {
let mode = data.mode;
const mode = data.mode;
f.sexpr(() => {
f.keyword("data");