Skip to content

Commit

Permalink
perf(lib): return [] if empty string is passed to server parser
Browse files Browse the repository at this point in the history
Since `htmlparser2` returns the same result, this early return is
an optimization since nothing needs to be instantiated.
  • Loading branch information
remarkablemark committed Nov 4, 2019
1 parent 86c27d2 commit 3a95c89
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/html-to-dom-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ function parseDOM(html, options) {
if (typeof html !== 'string') {
throw new TypeError('First argument must be a string.');
}

if (!html) {
return [];
}

var handler = new DomHandler(options);
new Parser(handler, options).end(html);
return handler.dom;
Expand Down

0 comments on commit 3a95c89

Please sign in to comment.