Skip to content

Commit

Permalink
refactor: use default value instead of
Browse files Browse the repository at this point in the history
optional chaining
  • Loading branch information
bacebu4 committed Nov 20, 2023
1 parent 5596f3b commit b3f6454
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ function treeToXML(tree) {
return `${escapeContent(tree)}\n`;
}

const { tag, attrs = {}, nesting, children } = tree;
const { tag, attrs = {}, nesting, children = [] } = tree;
const indent = '\t'.repeat(nesting + 1);

const attrsString = Object.entries(attrs)
.map(([key, value]) => `${key}="${escapeAttribute(String(value))}"`)
.join(' ');

if (!children?.length) {
if (!children.length) {
return `${indent}<${tag} ${attrsString}/>\n`;
}

const childrenString = (children ?? []).map(treeToXML).join('');
const childrenString = children.map(treeToXML).join('');

return `${indent}<${tag} ${attrsString}>\n${childrenString}${indent}</${tag}>\n`;
}
Expand Down

0 comments on commit b3f6454

Please sign in to comment.