Skip to content

Commit b9e30b0

Browse files
committed
fix: return result from DOMParser correctly
1 parent 149bcfa commit b9e30b0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/utilities.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ export const truthyStr = (v: any, value?: string): string => v ? ((value !== und
122122
/* ****************************************************************************************************************** */
123123
// region: Parser
124124
/* ****************************************************************************************************************** */
125+
125126
// For esbuild removing code
126-
declare global {const __IS_BROWSER__: boolean}
127+
declare global { let __IS_BROWSER__: boolean; }
127128

128129

129130
function tryParseWithNativeDom(html: string): ElementNode | undefined {
130131
try {
131-
if (!(window?.DOMParser && (new window.DOMParser()).parseFromString('', 'text/html'))) return void 0;
132+
if (DOMParser) {
133+
const doc = new DOMParser().parseFromString(html, 'text/html');
134+
if (doc.documentElement) return doc.documentElement
135+
}
132136
}
133137
catch {
134138
return void 0;

0 commit comments

Comments
 (0)