Skip to content

Commit

Permalink
fix: Use optional chaining and nullish coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed Sep 5, 2023
1 parent 889dc2e commit f812d33
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions lib/util/get-typescript-extension-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand All @@ -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]
}
Expand All @@ -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
)
Expand Down

0 comments on commit f812d33

Please sign in to comment.