From f812d3307eb5dfd0531c959b04148e1184c4cd8c Mon Sep 17 00:00:00 2001 From: Sebastian Good <2230835+scagood@users.noreply.github.com> Date: Tue, 5 Sep 2023 11:57:32 +0300 Subject: [PATCH] fix: Use optional chaining and nullish coalescing --- lib/util/get-typescript-extension-map.js | 28 ++++++------------------ 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/lib/util/get-typescript-extension-map.js b/lib/util/get-typescript-extension-map.js index 776d71a2..9c91587e 100644 --- a/lib/util/get-typescript-extension-map.js +++ b/lib/util/get-typescript-extension-map.js @@ -54,19 +54,17 @@ function normalise(typescriptExtensionMap) { * @returns {ExtensionMap} The `typescriptExtensionMap` value, or `null`. */ function get(option) { - if (!option || !option.typescriptExtensionMap) { - return null - } - if ( - {}.hasOwnProperty.call(tsConfigMapping, option.typescriptExtensionMap) + {}.hasOwnProperty.call(tsConfigMapping, option?.typescriptExtensionMap) ) { return tsConfigMapping[option.typescriptExtensionMap] } - if (Array.isArray(option.typescriptExtensionMap)) { + if (Array.isArray(option?.typescriptExtensionMap)) { return normalise(option.typescriptExtensionMap) } + + return null } /** @@ -78,17 +76,7 @@ function get(option) { function getFromTSConfig(filename) { const tsconfig = getTsconfig(filename, "tsconfig.json", fsCache) - if ( - !tsconfig || - !tsconfig.config || - !tsconfig.config.compilerOptions || - !tsconfig.config.compilerOptions.jsx - ) { - return null - } - - const jsx = tsconfig.config.compilerOptions.jsx - + const jsx = tsconfig?.config?.compilerOptions?.jsx if ({}.hasOwnProperty.call(tsConfigMapping, jsx)) { return tsConfigMapping[jsx] } @@ -113,10 +101,8 @@ function getFromTSConfig(filename) { */ module.exports = function getTypescriptExtensionMap(context) { return ( - get(context.options && context.options[0]) || - get( - context.settings && (context.settings.n || context.settings.node) - ) || + get(context.options?.[0]) || + get(context.settings?.n ?? context.settings?.node) || getFromTSConfig(context.filename) || PRESERVE_MAPPING )