Skip to content

Commit ac2affe

Browse files
authored
runtime(js): fix useOptionalChain (#1861)
Signed-off-by: Sora Morimoto <sora@morimoto.io>
1 parent d8faae3 commit ac2affe

11 files changed

+16
-17
lines changed

biome.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"rules": {
1919
"recommended": true,
2020
"complexity": {
21-
"useArrowFunction": "off",
22-
"useOptionalChain": "off"
21+
"useArrowFunction": "off"
2322
},
2423
"correctness": {
2524
"noInnerDeclarations": "off",

runtime/js/compare.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ function caml_compare_val_tag(a) {
3636
return 12520; // javascript string, like string_tag (252)
3737
else if (a instanceof Number)
3838
return 1000; // int_tag (we use it for all numbers)
39-
else if (a && a.caml_custom)
39+
else if (a?.caml_custom)
4040
return 1255; // like custom_tag (255)
41-
else if (a && a.compare)
41+
else if (a?.compare)
4242
return 1256; // like custom_tag (255)
4343
else if (typeof a === "function")
4444
return 1247; // like closure_tag (247)

runtime/js/dynlink.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function caml_dynlink_lookup_symbol(idx, fun_name) {
5050
var name = caml_jsstring_of_string(fun_name);
5151
console.log("Dynlink: looking for symbol", name);
5252
var current_libs = get_current_libs();
53-
if (current_libs[idx] && current_libs[idx][name])
53+
if (current_libs[idx]?.[name])
5454
return { name: name, symbol: current_libs[idx][name] };
5555
return 0;
5656
}

runtime/js/effect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ function caml_resume(f, arg, stack, last) {
342342
joo_direct: 1,
343343
};
344344
}
345-
} while (res && res.joo_args);
345+
} while (res?.joo_args);
346346
return res;
347347
} finally {
348348
caml_stack_depth = saved_stack_depth;

runtime/js/fs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function resolve_fs_device(name) {
161161
}
162162
if (!res && fs_node_supported()) {
163163
var root = caml_get_root(name);
164-
if (root && root.match(/^[a-zA-Z]:\/$/)) {
164+
if (root?.match(/^[a-zA-Z]:\/$/)) {
165165
var m = { path: root, device: new MlNodeDevice(root) };
166166
jsoo_mount_point.push(m);
167167
res = {

runtime/js/fs_fake.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class MlFakeDevice {
9191
this.nm(name),
9292
);
9393
var parent = /^(.*)\/[^/]+/.exec(name);
94-
parent = (parent && parent[1]) || "";
94+
parent = parent?.[1] || "";
9595
if (!this.exists(parent))
9696
caml_raise_system_error(
9797
raise_unix,

runtime/js/hash.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function caml_hash_univ_param(count, limit, obj) {
7272
count--;
7373
var p = caml_int64_to_bytes(caml_int64_bits_of_float(obj));
7474
for (var i = 7; i >= 0; i--) hash_accu = (hash_accu * 19 + p[i]) | 0;
75-
} else if (obj && obj.caml_custom) {
75+
} else if (obj?.caml_custom) {
7676
if (
7777
caml_custom_ops[obj.caml_custom] &&
7878
caml_custom_ops[obj.caml_custom].hash
@@ -216,7 +216,7 @@ function caml_hash(count, limit, seed, obj) {
216216
wr = 1;
217217
while (rd < wr && num > 0) {
218218
v = queue[rd++];
219-
if (v && v.caml_custom) {
219+
if (v?.caml_custom) {
220220
if (
221221
caml_custom_ops[v.caml_custom] &&
222222
caml_custom_ops[v.caml_custom].hash

runtime/js/jslib.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function caml_js_typeof(o) {
5353
//Provides:caml_trampoline
5454
function caml_trampoline(res) {
5555
var c = 1;
56-
while (res && res.joo_tramp) {
56+
while (res?.joo_tramp) {
5757
res = res.joo_tramp.apply(null, res.joo_args);
5858
c++;
5959
}
@@ -108,7 +108,7 @@ function caml_callback(f, args) {
108108
caml_current_stack.x = caml_current_stack.x.t;
109109
res = { joo_tramp: handler, joo_args: [caml_wrap_exception(e)] };
110110
}
111-
} while (res && res.joo_args);
111+
} while (res?.joo_args);
112112
} finally {
113113
caml_stack_depth = saved_stack_depth;
114114
caml_current_stack = saved_current_stack;

runtime/js/obj.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function caml_obj_tag(x) {
5151
else if (caml_is_ml_bytes(x)) return 252;
5252
else if (caml_is_ml_string(x)) return 252;
5353
else if (x instanceof Function || typeof x === "function") return 247;
54-
else if (x && x.caml_custom) return 255;
54+
else if (x?.caml_custom) return 255;
5555
else return 1000;
5656
}
5757

runtime/js/sys.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ var caml_argv = (function () {
146146
var main = "a.out";
147147
var args = [];
148148

149-
if (process && process.argv && process.argv.length > 1) {
149+
if (process?.argv?.length > 1) {
150150
var argv = process.argv;
151151
//nodejs
152152
main = argv[1];
@@ -195,7 +195,7 @@ function caml_sys_system_command(cmd) {
195195
var cmd = caml_jsstring_of_string(cmd);
196196
if (typeof require !== "undefined") {
197197
var child_process = require("node:child_process");
198-
if (child_process && child_process.execSync)
198+
if (child_process?.execSync)
199199
try {
200200
child_process.execSync(cmd, { stdio: "inherit" });
201201
return 0;
@@ -374,7 +374,7 @@ function caml_sys_is_regular_file(name) {
374374
//If: !wasm
375375
function caml_setup_uncaught_exception_handler() {
376376
var process = globalThis.process;
377-
if (process && process.on) {
377+
if (process?.on) {
378378
process.on("uncaughtException", function (err, origin) {
379379
caml_fatal_uncaught_exception(err);
380380
process.exit(2);

runtime/wasm/runtime.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@
631631

632632
start_fiber = make_promising(caml_start_fiber);
633633
var _initialize = make_promising(_initialize);
634-
if (globalThis.process && globalThis.process.on) {
634+
if (globalThis.process?.on) {
635635
globalThis.process.on("uncaughtException", (err, origin) =>
636636
caml_handle_uncaught_exception(err),
637637
);

0 commit comments

Comments
 (0)