Skip to content

Commit

Permalink
perf(core): reduce the use of spread operators
Browse files Browse the repository at this point in the history
  • Loading branch information
cycleccc committed Nov 9, 2024
1 parent 258e365 commit ebf048e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/core/src/parse-html/parse-elem-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,23 @@ function parseElemHtml($elem: Dom7Array, editor: IDomEditor): Descendant | Desce
if (isDOMElement(childNode)) {
const elem = parseElemHtml($childElem, editor)

return Array.isArray(elem) ? [...descendants, ...elem] : [...descendants, elem]
if (Array.isArray(elem)) {
descendants.push(...elem)
} else {
descendants.push(elem)
}
} else {
const text = isDOMText(childNode)
? { text: (childNode as Text).textContent || '' }
: parseTextElemHtml($childElem, editor)

descendants.push(text)
}
const text = isDOMText(childNode) ? { text: (childNode as Text).textContent || '' } : parseTextElemHtml($childElem, editor)

return [...descendants, text]
return descendants
}, [] as Descendant[])
}

return parseTextElemHtml($elem, editor)

}
Expand Down

0 comments on commit ebf048e

Please sign in to comment.