From 79f98795c7c4c925a96548fe2a3fd93430e98dab Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Mon, 8 Apr 2024 17:05:47 -0400 Subject: [PATCH] Fix version checker using later javascript features --- run-selfhosted.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/run-selfhosted.js b/run-selfhosted.js index 3c63230c..c2ddc113 100644 --- a/run-selfhosted.js +++ b/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; }