From d09e5315edcdd11602de829bc04b6e33360f45fa Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 7 Jan 2025 18:53:53 +0000 Subject: [PATCH] perf: use optional chaining (#299) --- boot.js | 10 +++++----- lib/get-plugin-name.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/boot.js b/boot.js index ff8460a..7897b65 100644 --- a/boot.js +++ b/boot.js @@ -417,7 +417,7 @@ Boot.prototype._loadPlugin = function (plugin, callback) { return } - let server = (last && last.server) || instance._server + let server = last?.server || instance._server if (!plugin.isAfter) { // Skip override for after @@ -547,7 +547,7 @@ function encapsulateTwoParam (func, that) { let res if (func.length === 0) { res = func() - if (res && res.then) { + if (res?.then) { res.then(function () { process.nextTick(cb) }, cb) @@ -557,7 +557,7 @@ function encapsulateTwoParam (func, that) { } else if (func.length === 1) { res = func(this) - if (res && res.then) { + if (res?.then) { res.then(function () { process.nextTick(cb) }, cb) @@ -580,7 +580,7 @@ function encapsulateThreeParam (func, that) { process.nextTick(cb) } else if (func.length === 0) { res = func() - if (res && res.then) { + if (res?.then) { res.then(function () { process.nextTick(cb, err) }, cb) @@ -589,7 +589,7 @@ function encapsulateThreeParam (func, that) { } } else if (func.length === 1) { res = func(err) - if (res && res.then) { + if (res?.then) { res.then(function () { process.nextTick(cb) }, cb) diff --git a/lib/get-plugin-name.js b/lib/get-plugin-name.js index 79bf79a..dad82a9 100644 --- a/lib/get-plugin-name.js +++ b/lib/get-plugin-name.js @@ -11,12 +11,12 @@ const { kPluginMeta } = require('./symbols') */ function getPluginName (plugin, options) { // use explicit function metadata if set - if (plugin[kPluginMeta] && plugin[kPluginMeta].name) { + if (plugin[kPluginMeta]?.name) { return plugin[kPluginMeta].name } // use explicit name option if set - if (options && options.name) { + if (options?.name) { return options.name }