Skip to content

Commit 620d293

Browse files
authored
more precise null coalescing (#1357)
1 parent 83397e1 commit 620d293

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/markdown.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,9 @@ function getHtml(
373373
data: FrontMatter,
374374
{path, [key]: defaultValue}: ParseOptions
375375
): string | null {
376-
return data[key] !== undefined
377-
? data[key]
378-
? String(data[key])
379-
: null
380-
: defaultValue != null
381-
? rewriteHtmlPaths(
382-
typeof defaultValue === "function" ? defaultValue({title, data, path}) ?? "" : defaultValue,
383-
path
384-
)
385-
: null;
376+
if (data[key] !== undefined) return data[key] != null ? String(data[key]) : null;
377+
const value = typeof defaultValue === "function" ? defaultValue({title, data, path}) : defaultValue;
378+
return value != null ? rewriteHtmlPaths(value, path) : null;
386379
}
387380

388381
function getStyle(data: FrontMatter, {path, style = null}: ParseOptions): string | null {

0 commit comments

Comments
 (0)