Skip to content

Commit 13c2100

Browse files
JosephTLyonslpil
authored andcommitted
Minor improvements to .mjs code
1 parent 0d8d847 commit 13c2100

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

src/gleam_stdlib.mjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
} from "./gleam.mjs";
1414
import { DecodeError } from "./gleam/dynamic.mjs";
1515
import { Some, None } from "./gleam/option.mjs";
16-
import { Eq, Gt, Lt } from "./gleam/order.mjs";
1716
import Dict from "./dict.mjs";
1817

1918
const Nil = undefined;
@@ -885,7 +884,7 @@ export function inspect(v) {
885884
function inspectString(str) {
886885
let new_str = '"';
887886
for (let i = 0; i < str.length; i++) {
888-
let char = str[i];
887+
const char = str[i];
889888
switch (char) {
890889
case "\n":
891890
new_str += "\\n";

src/gleam_stdlib_decode_ffi.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function index(data, key) {
4040

4141
export function list(data, decode, pushPath, index, emptyList) {
4242
if (!(data instanceof List || Array.isArray(data))) {
43-
let error = new DecodeError("List", classify(data), emptyList);
43+
const error = new DecodeError("List", classify(data), emptyList);
4444
return [emptyList, List.fromArray([error])];
4545
}
4646

test/gleam_stdlib_test_ffi.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export function uint8array(list) {
2-
let ints = list.toArray();
3-
let array = new Uint8Array(ints.length);
2+
const ints = list.toArray();
3+
const array = new Uint8Array(ints.length);
44
for (let i = 0; i < ints.length; i++) {
55
array[i] = ints[i];
66
}

test/gleeunit.mjs

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// This file is a verbatim copy of gleeunit 0.10.0's <https://github.com/lpil/gleeunit/blob/main/src/gleeunit_ffi.mjs>
22

33
async function* gleamFiles(directory) {
4-
for (let entry of await read_dir(directory)) {
5-
let path = join_path(directory, entry);
4+
for (const entry of await read_dir(directory)) {
5+
const path = join_path(directory, entry);
66
if (path.endsWith(".gleam")) {
77
yield path;
88
} else {
@@ -16,9 +16,9 @@ async function* gleamFiles(directory) {
1616
}
1717

1818
async function readRootPackageName() {
19-
let toml = await read_file("gleam.toml", "utf-8");
20-
for (let line of toml.split("\n")) {
21-
let matches = line.match(/\s*name\s*=\s*"([a-z][a-z0-9_]*)"/); // Match regexp in compiler-cli/src/new.rs in validate_name()
19+
const toml = await read_file("gleam.toml", "utf-8");
20+
for (const line of toml.split("\n")) {
21+
const matches = line.match(/\s*name\s*=\s*"([a-z][a-z0-9_]*)"/); // Match regexp in compiler-cli/src/new.rs in validate_name()
2222
if (matches) return matches[1];
2323
}
2424
throw new Error("Could not determine package name from gleam.toml");
@@ -28,21 +28,21 @@ export async function main() {
2828
let passes = 0;
2929
let failures = 0;
3030

31-
let packageName = await readRootPackageName();
32-
let dist = `../${packageName}/`;
31+
const packageName = await readRootPackageName();
32+
const dist = `../${packageName}/`;
3333

34-
for await (let path of await gleamFiles("test")) {
35-
let js_path = path.slice("test/".length).replace(".gleam", ".mjs");
36-
let module = await import(join_path(dist, js_path));
37-
for (let fnName of Object.keys(module)) {
34+
for await (const path of await gleamFiles("test")) {
35+
const js_path = path.slice("test/".length).replace(".gleam", ".mjs");
36+
const module = await import(join_path(dist, js_path));
37+
for (const fnName of Object.keys(module)) {
3838
if (!fnName.endsWith("_test")) continue;
3939
try {
4040
await module[fnName]();
4141
write(`\u001b[32m.\u001b[0m`);
4242
passes++;
4343
} catch (error) {
44-
let moduleName = "\n" + js_path.slice(0, -4);
45-
let line = error.line ? `:${error.line}` : "";
44+
const moduleName = "\n" + js_path.slice(0, -4);
45+
const line = error.line ? `:${error.line}` : "";
4646
write(`\n❌ ${moduleName}.${fnName}${line}: ${error}\n`);
4747
failures++;
4848
}
@@ -76,8 +76,8 @@ function exit(code) {
7676

7777
async function read_dir(path) {
7878
if (globalThis.Deno) {
79-
let items = [];
80-
for await (let item of Deno.readDir(path, { withFileTypes: true })) {
79+
const items = [];
80+
for await (const item of Deno.readDir(path, { withFileTypes: true })) {
8181
items.push(item.name);
8282
}
8383
return items;
@@ -96,8 +96,8 @@ async function read_file(path) {
9696
if (globalThis.Deno) {
9797
return Deno.readTextFile(path);
9898
} else {
99-
let { readFile } = await import("fs/promises");
100-
let contents = await readFile(path);
99+
const { readFile } = await import("fs/promises");
100+
const contents = await readFile(path);
101101
return contents.toString();
102102
}
103103
}

0 commit comments

Comments
 (0)