Introduced use of conditional chaining operator

This commit is contained in:
n1474335 2022-10-28 13:24:03 +01:00
parent 570206af77
commit b92501ee35
14 changed files with 493 additions and 495 deletions

View File

@ -1,7 +1,7 @@
{
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 9,
"ecmaVersion": 2022,
"ecmaFeatures": {
"impliedStrict": true
},

View File

@ -230,14 +230,12 @@ class Recipe {
this.lastRunOp = op;
} catch (err) {
// Return expected errors as output
if (err instanceof OperationError ||
(err.type && err.type === "OperationError")) {
if (err instanceof OperationError || err?.type === "OperationError") {
// Cannot rely on `err instanceof OperationError` here as extending
// native types is not fully supported yet.
dish.set(err.message, "string");
return i;
} else if (err instanceof DishError ||
(err.type && err.type === "DishError")) {
} else if (err instanceof DishError || err?.type === "DishError") {
dish.set(err.message, "string");
return i;
} else {

View File

@ -65,7 +65,7 @@ class DetectFileType extends Operation {
Extension: ${type.extension}
MIME type: ${type.mime}\n`;
if (type.description && type.description.length) {
if (type?.description?.length) {
output += `Description: ${type.description}\n`;
}

View File

@ -60,7 +60,7 @@ class ScanForEmbeddedFiles extends Operation {
Extension: ${type.fileDetails.extension}
MIME type: ${type.fileDetails.mime}\n`;
if (type.fileDetails.description && type.fileDetails.description.length) {
if (type?.fileDetails?.description?.length) {
output += ` Description: ${type.fileDetails.description}\n`;
}
});

View File

@ -198,7 +198,7 @@ function randomSeed(e) {
function buffer(d) {
if (d instanceof CryptoOperationData)
return d;
else if (d && d.buffer && d.buffer instanceof CryptoOperationData)
else if (d && d?.buffer instanceof CryptoOperationData)
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
else
@ -2076,7 +2076,7 @@ function GostCipher(algorithm) // <editor-fold defaultstate="collapsed">
((algorithm.keyWrapping || 'NO') !== 'NO' ? algorithm.keyWrapping : '') + 'KW' :
(algorithm.block || 'ECB') + ((algorithm.block === 'CFB' || algorithm.block === 'OFB' ||
(algorithm.block === 'CTR' && algorithm.version === 2015)) &&
algorithm.shiftBits && algorithm.shiftBits !== this.blockLength ? '-' + algorithm.shiftBits : '') +
algorithm?.shiftBits !== this.blockLength ? '-' + algorithm.shiftBits : '') +
(algorithm.padding ? '-' + (algorithm.padding || (algorithm.block === 'CTR' ||
algorithm.block === 'CFB' || algorithm.block === 'OFB' ? 'NO' : 'ZERO')) + 'PADDING' : '') +
((algorithm.keyMeshing || 'NO') !== 'NO' ? '-CPKEYMESHING' : '')) +

View File

@ -48,7 +48,7 @@ var Date = Date;
function buffer(d) {
if (d instanceof CryptoOperationData)
return d;
else if (d && d.buffer && d.buffer instanceof CryptoOperationData)
else if (d && d?.buffer instanceof CryptoOperationData)
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
else

View File

@ -611,7 +611,7 @@ if (!Promise) {
return;
}
value = mswrap(value);
if (value && value.then && value.then.call) {
if (value && value?.then?.call) {
value.then(resolve, reject);
} else {
resolve(value);
@ -627,7 +627,7 @@ if (!Promise) {
return;
}
reason = mswrap(reason);
if (reason && reason.then && reason.then.call) {
if (reason && reason?.then?.call) {
reason.then(resolve, reject);
} else {
reject(reason);
@ -698,7 +698,7 @@ if (!Promise) {
for (var i = 0, n = promises.length; i < n; i++) {
var data = promises[i];
if (data.then && data.then.call)
if (data?.then?.call)
data.then(asyncResolve(i), asyncReject);
else
result[i] = data;
@ -1492,7 +1492,7 @@ SubtleCrypto.prototype.exportKey = function (format, key) // <editor-fold defaul
var raw = extractKey(null, null, key);
if (format === 'raw')
return raw;
else if (format === 'pkcs8' && key.algorithm && key.algorithm.id) {
else if (format === 'pkcs8' && key?.algorithm?.id) {
if (key.algorithm.procreator === 'VN') {
// Add masks for ViPNet
var algorithm = key.algorithm, mask;
@ -1514,7 +1514,7 @@ SubtleCrypto.prototype.exportKey = function (format, key) // <editor-fold defaul
});
} else
return gostCrypto.asn1.GostPrivateKeyInfo.encode(key);
} else if (format === 'spki' && key.algorithm && key.algorithm.id)
} else if (format === 'spki' && key?.algorithm?.id)
return gostCrypto.asn1.GostSubjectPublicKeyInfo.encode(key);
else
throw new NotSupportedError('Key format not supported');

View File

@ -113,7 +113,7 @@ function getSeed(length) {
function buffer(d) {
if (d instanceof ArrayBuffer)
return d;
else if (d && d.buffer && d.buffer instanceof ArrayBuffer)
else if (d && d?.buffer instanceof ArrayBuffer)
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
else

View File

@ -1445,7 +1445,7 @@ function hash(d) {
function buffer(d) {
if (d instanceof CryptoOperationData)
return d;
else if (d && d.buffer && d.buffer instanceof CryptoOperationData)
else if (d && d?.buffer instanceof CryptoOperationData)
return d.byteOffset === 0 && d.byteLength === d.buffer.byteLength ?
d.buffer : new Uint8Array(new Uint8Array(d, d.byteOffset, d.byteLength)).buffer;
else

View File

@ -342,7 +342,7 @@ class App {
let favourites;
if (this.isLocalStorageAvailable()) {
favourites = localStorage.favourites && localStorage.favourites.length > 2 ?
favourites = localStorage?.favourites?.length > 2 ?
JSON.parse(localStorage.favourites) :
this.dfavourites;
favourites = this.validFavourites(favourites);

View File

@ -159,7 +159,7 @@ class StatusBarPanel {
* @param {boolean} selectionSet
*/
updateSelection(state, selectionSet) {
const selLen = state.selection && state.selection.main ?
const selLen = state?.selection?.main ?
state.selection.main.to - state.selection.main.from :
0;

View File

@ -807,7 +807,7 @@ class InputWaiter {
// Dropped text is handled by the editor itself
if (e.dataTransfer.getData("Text")) return;
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
if (e?.dataTransfer?.files?.length > 0) {
this.loadUIFiles(e.dataTransfer.files);
}
}

View File

@ -155,7 +155,7 @@ class OutputWaiter {
getEOLSeq() {
const currentTabNum = this.manager.tabs.getActiveTab("output");
if (currentTabNum < 0) {
return this.outputEditorConf.state.lineBreak;
return this.outputEditorConf.state?.lineBreak || "\n";
}
return this.outputs[currentTabNum].eolSequence;
}

View File

@ -133,7 +133,7 @@ class RecipeWaiter {
// Reinitialise the popover on the original element in the ops list because for some reason it
// gets destroyed and recreated. If the clone isn't in the ops list, we use the original item instead.
let enableOpsElement;
if (evt.clone.parentNode && evt.clone.parentNode.classList.contains("op-list")) {
if (evt.clone?.parentNode?.classList?.contains("op-list")) {
enableOpsElement = evt.clone;
} else {
enableOpsElement = evt.item;
@ -163,13 +163,13 @@ class RecipeWaiter {
e.stopPropagation();
e.preventDefault();
if (e.target.className && e.target.className.indexOf("category-title") > -1) {
if (e.target?.className?.indexOf("category-title") > -1) {
// Hovering over the a
e.target.classList.add("favourites-hover");
} else if (e.target.parentNode.className && e.target.parentNode.className.indexOf("category-title") > -1) {
} else if (e.target?.parentNode?.className?.indexOf("category-title") > -1) {
// Hovering over the Edit button
e.target.parentNode.classList.add("favourites-hover");
} else if (e.target.parentNode.parentNode.className && e.target.parentNode.parentNode.className.indexOf("category-title") > -1) {
} else if (e.target?.parentNode?.parentNode?.className?.indexOf("category-title") > -1) {
// Hovering over the image on the Edit button
e.target.parentNode.parentNode.classList.add("favourites-hover");
}
@ -211,7 +211,7 @@ class RecipeWaiter {
* @fires Manager#statechange
*/
ingChange(e) {
if (e && e.target && e.target.classList.contains("no-state-change")) return;
if (e && e?.target?.classList?.contains("no-state-change")) return;
window.dispatchEvent(this.manager.statechange);
}