浏览代码

Fix version checker using later javascript features

KernelDeimos 1 年之前
父节点
当前提交
79f98795c7
共有 1 个文件被更改,包括 11 次插入3 次删除
  1. 11 3
      run-selfhosted.js

+ 11 - 3
run-selfhosted.js

@@ -93,10 +93,18 @@ const early_init_errors = [
     }
 ];
 
+const newstuff = {
+    // Nullish coalescing operator
+    nco: (...a) => a.reduce((acc, val) => acc == undefined ? val : acc),
+    // Optional chaining
+    oc: (obj, ...keys) => keys.reduce((acc, key) => acc ? acc[key] : undefined, obj),
+    oc_call: (maybe_fn, ...args) => maybe_fn ? maybe_fn(...args) : undefined,
+};1
+
 const _print_error_help = (error_help) => {
     const lines = [];
-    lines.push(error_help.title ?? error_help.text);
-    for ( const note of (error_help.notes ?? []) ) {
+    lines.push(nco(error_help.title, error_help.text));
+    for ( const note of (nco(error_help.notes, [])) ) {
         lines.push(`📝 ${note}`)
     }
     if ( error_help.suggestions ) {
@@ -120,7 +128,7 @@ const _print_error_help = (error_help) => {
         await main();
     } catch (e) {
         for ( const error_help of early_init_errors ) {
-            if ( e?.message?.includes(error_help.text) ) {
+            if ( oc_call(oc(e, message, includes), error_help.text) ) {
                 _print_error_help(error_help);
                 break;
             }