Skip to content

Commit 8432faf

Browse files
Merge pull request #1310 from remarkablemark/fix/esm
fix(esm): fix exported types
2 parents 8a1abba + a25f41c commit 8432faf

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

__tests__/dom-to-react.test.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ describe('domToReact', () => {
3030
});
3131

3232
it('converts multiple DOM nodes to React', () => {
33-
const reactElements = domToReact(htmlToDOM(html.multiple)) as JSX.Element[];
33+
const reactElements = domToReact(
34+
htmlToDOM(html.multiple),
35+
) as React.JSX.Element[];
3436
reactElements.forEach((reactElement, index) => {
3537
expect(reactElement.key).toBe(String(index));
3638
});
@@ -83,7 +85,7 @@ describe('domToReact', () => {
8385
});
8486

8587
it('does not have `children` for void elements', () => {
86-
const reactElement = domToReact(htmlToDOM(html.img)) as JSX.Element;
88+
const reactElement = domToReact(htmlToDOM(html.img)) as React.JSX.Element;
8789
expect(reactElement.props.children).toBe(undefined);
8890
});
8991

@@ -97,7 +99,7 @@ describe('domToReact', () => {
9799
it('skips doctype and comments', () => {
98100
const reactElements = domToReact(
99101
htmlToDOM(html.doctype + html.single + html.comment + html.single),
100-
) as JSX.Element[];
102+
) as React.JSX.Element[];
101103
expect(reactElements).toHaveLength(2);
102104
expect(reactElements[0].key).toBe('1');
103105
expect(reactElements[1].key).toBe('3');
@@ -177,15 +179,15 @@ describe('replace option', () => {
177179
(value) => {
178180
const reactElement = domToReact(htmlToDOM('<br>'), {
179181
replace: () => value,
180-
}) as JSX.Element;
182+
}) as React.JSX.Element;
181183
expect(reactElement).toEqual(<br />);
182184
},
183185
);
184186

185187
it('does not set key for a single node', () => {
186188
const reactElement = domToReact(htmlToDOM(html.single), {
187189
replace: () => <div />,
188-
}) as JSX.Element;
190+
}) as React.JSX.Element;
189191
expect(reactElement.key).toBe(null);
190192
});
191193

@@ -213,7 +215,7 @@ describe('replace option', () => {
213215
}
214216
},
215217
},
216-
) as JSX.Element[];
218+
) as React.JSX.Element[];
217219

218220
expect(reactElements[0].key).toBe('0');
219221
expect(reactElements[1].key).toBe('myKey');
@@ -247,7 +249,7 @@ describe('transform option', () => {
247249
transform: (reactNode, domNode, index) => {
248250
return <div key={index}>{reactNode}</div>;
249251
},
250-
}) as JSX.Element;
252+
}) as React.JSX.Element;
251253

252254
expect(reactElement.key).toBe('0');
253255
expect(reactElement.props.children.props.children[0].key).toBe('0');

esm/index.d.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
export * from '../lib/index';
2-
export { default } from '../lib/index';
1+
import HTMLReactParser from '../lib/index.js';
2+
3+
export * from '../lib/index.js';
4+
5+
// @ts-expect-error Property 'default' exists on type
6+
export default HTMLReactParser.default || HTMLReactParser;

src/dom-to-react.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { cloneElement, createElement, isValidElement } from 'react';
2+
import type { JSX } from 'react';
23
import type { Element, DOMNode, Text } from 'html-dom-parser';
34

45
import attributesToProps from './attributes-to-props';

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import type { HTMLReactParserOptions } from './types';
77
export { Comment, Element, ProcessingInstruction, Text } from 'domhandler';
88
export type { DOMNode } from 'html-dom-parser';
99

10-
export { HTMLReactParserOptions, attributesToProps, domToReact, htmlToDOM };
10+
export type { HTMLReactParserOptions };
11+
export { attributesToProps, domToReact, htmlToDOM };
1112

1213
const domParserOptions = { lowerCaseAttributeNames: false } as const;
1314

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DomHandlerOptions } from 'domhandler';
22
import type { DOMNode } from 'html-dom-parser';
33
import type { ParserOptions } from 'htmlparser2';
4-
import type { ReactNode } from 'react';
4+
import type { JSX, ReactNode } from 'react';
55

66
export interface HTMLReactParserOptions {
77
htmlparser2?: ParserOptions & DomHandlerOptions;

0 commit comments

Comments
 (0)