@@ -3,6 +3,7 @@ import type {
33 Parent as MdastParent ,
44 Literal as MdastLiteral ,
55 BlockContent ,
6+ DefinitionContent ,
67 PhrasingContent
78} from 'mdast'
89import type { Program } from 'estree-jsx'
@@ -16,52 +17,140 @@ export {mdxJsxFromMarkdown, mdxJsxToMarkdown} from './lib/index.js'
1617export type { ToMarkdownOptions } from './lib/index.js'
1718
1819// Expose node types.
20+ /**
21+ * MDX JSX attribute value set to an expression.
22+ *
23+ * ```markdown
24+ * > | <a b={c} />
25+ * ^^^
26+ * ```
27+ */
1928// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
2029export interface MdxJsxAttributeValueExpression extends MdastLiteral {
30+ /**
31+ * Node type.
32+ */
2133 type : 'mdxJsxAttributeValueExpression'
22- data ?: { estree ?: Program } & MdastLiteral [ 'data' ]
34+ data ?: {
35+ /**
36+ * Program node from estree.
37+ */
38+ // eslint-disable-next-line @typescript-eslint/ban-types
39+ estree ?: Program | null | undefined
40+ } & MdastLiteral [ 'data' ]
2341}
2442
43+ /**
44+ * MDX JSX attribute as an expression.
45+ *
46+ * ```markdown
47+ * > | <a {...b} />
48+ * ^^^^^^
49+ * ```
50+ */
2551// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
2652export interface MdxJsxExpressionAttribute extends MdastLiteral {
53+ /**
54+ * Node type.
55+ */
2756 type : 'mdxJsxExpressionAttribute'
28- data ?: { estree ?: Program } & MdastLiteral [ 'data' ]
57+ data ?: {
58+ /**
59+ * Program node from estree.
60+ */
61+ // eslint-disable-next-line @typescript-eslint/ban-types
62+ estree ?: Program | null | undefined
63+ } & MdastLiteral [ 'data' ]
2964}
3065
66+ /**
67+ * MDX JSX attribute with a key.
68+ *
69+ * ```markdown
70+ * > | <a b="c" />
71+ * ^^^^^
72+ * ```
73+ */
3174// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
3275export interface MdxJsxAttribute extends MdastNode {
76+ /**
77+ * Node type.
78+ */
3379 type : 'mdxJsxAttribute'
80+ /**
81+ * Attribute name.
82+ */
3483 name : string
84+ /**
85+ * Attribute value.
86+ */
87+ // eslint-disable-next-line @typescript-eslint/ban-types
3588 value ?: MdxJsxAttributeValueExpression | string | null | undefined
3689}
3790
91+ /**
92+ * MDX JSX element node, occurring in flow (block).
93+ */
3894// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
39- interface MdxJsxElementFields {
95+ export interface MdxJsxFlowElement extends MdastParent {
96+ /**
97+ * Node type.
98+ */
99+ type : 'mdxJsxFlowElement'
100+ /**
101+ * MDX JSX element name (`null` for fragments).
102+ */
103+ // eslint-disable-next-line @typescript-eslint/ban-types
40104 name : string | null
105+ /**
106+ * MDX JSX element attributes.
107+ */
41108 attributes : Array < MdxJsxAttribute | MdxJsxExpressionAttribute >
109+ /**
110+ * Content.
111+ */
112+ children : Array < BlockContent | DefinitionContent >
42113}
43114
115+ /**
116+ * MDX JSX element node, occurring in text (phrasing).
117+ */
44118// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
45- export interface MdxJsxFlowElement extends MdxJsxElementFields , MdastParent {
46- type : 'mdxJsxFlowElement'
47- children : BlockContent [ ]
48- }
49-
50- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
51- export interface MdxJsxTextElement extends MdxJsxElementFields , MdastParent {
119+ export interface MdxJsxTextElement extends MdastParent {
120+ /**
121+ * Node type.
122+ */
52123 type : 'mdxJsxTextElement'
124+ /**
125+ * MDX JSX element name (`null` for fragments).
126+ */
127+ // eslint-disable-next-line @typescript-eslint/ban-types
128+ name : string | null
129+ /**
130+ * MDX JSX element attributes.
131+ */
132+ attributes : Array < MdxJsxAttribute | MdxJsxExpressionAttribute >
133+ /**
134+ * Content.
135+ */
53136 children : PhrasingContent [ ]
54137}
55138
56139// Add nodes to mdast content.
57140declare module 'mdast' {
58141 // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
59142 interface StaticPhrasingContentMap {
143+ /**
144+ * MDX JSX element node, occurring in text (phrasing).
145+ */
60146 mdxJsxTextElement : MdxJsxTextElement
61147 }
62148
63149 // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
64150 interface BlockContentMap {
151+ /**
152+ * MDX JSX element node, occurring in flow (block).
153+ */
65154 mdxJsxFlowElement : MdxJsxFlowElement
66155 }
67156}
@@ -70,13 +159,25 @@ declare module 'mdast' {
70159declare module 'hast' {
71160 // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
72161 interface RootContentMap {
162+ /**
163+ * MDX JSX element node, occurring in text (phrasing).
164+ */
73165 mdxJsxTextElement : MdxJsxTextElement
166+ /**
167+ * MDX JSX element node, occurring in flow (block).
168+ */
74169 mdxJsxFlowElement : MdxJsxFlowElement
75170 }
76171
77172 // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
78173 interface ElementContentMap {
174+ /**
175+ * MDX JSX element node, occurring in text (phrasing).
176+ */
79177 mdxJsxTextElement : MdxJsxTextElement
178+ /**
179+ * MDX JSX element node, occurring in flow (block).
180+ */
80181 mdxJsxFlowElement : MdxJsxFlowElement
81182 }
82183}
0 commit comments