Skip to content

Commit 96aeb38

Browse files
committed
Add exports of Mdx{Flow,Text}ExpressionHast types
* while this is practically equivalent to the current node types, this is meant for the hast space, which in the future could start diverging from mdast literals
1 parent b251f32 commit 96aeb38

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

index.d.ts

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type {Literal} from 'mdast'
21
import type {Program} from 'estree-jsx'
2+
import type {Literal as HastLiteral} from 'hast'
3+
import type {Literal as MdastLiteral} from 'mdast'
34

45
export {
56
mdxExpressionFromMarkdown,
@@ -10,7 +11,7 @@ export {
1011
* MDX expression node, occurring in flow (block).
1112
*/
1213
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
13-
export interface MdxFlowExpression extends Literal {
14+
export interface MdxFlowExpression extends MdastLiteral {
1415
/**
1516
* Node type.
1617
*/
@@ -25,14 +26,14 @@ export interface MdxFlowExpression extends Literal {
2526
*/
2627
// eslint-disable-next-line @typescript-eslint/ban-types
2728
estree?: Program | null | undefined
28-
} & Literal['data']
29+
} & MdastLiteral['data']
2930
}
3031

3132
/**
3233
* MDX expression node, occurring in text (phrasing).
3334
*/
3435
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
35-
export interface MdxTextExpression extends Literal {
36+
export interface MdxTextExpression extends MdastLiteral {
3637
/**
3738
* Node type.
3839
*/
@@ -47,7 +48,7 @@ export interface MdxTextExpression extends Literal {
4748
*/
4849
// eslint-disable-next-line @typescript-eslint/ban-types
4950
estree?: Program | null | undefined
50-
} & Literal['data']
51+
} & MdastLiteral['data']
5152
}
5253

5354
/**
@@ -62,6 +63,50 @@ export type MDXFlowExpression = MdxFlowExpression
6263
// eslint-disable-next-line @typescript-eslint/naming-convention
6364
export type MDXTextExpression = MdxTextExpression
6465

66+
/**
67+
* MDX expression node, occurring in flow (block), for hast.
68+
*/
69+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
70+
export interface MdxFlowExpressionHast extends HastLiteral {
71+
/**
72+
* Node type.
73+
*/
74+
type: 'mdxFlowExpression'
75+
76+
/**
77+
* Data.
78+
*/
79+
data?: {
80+
/**
81+
* Program node from estree.
82+
*/
83+
// eslint-disable-next-line @typescript-eslint/ban-types
84+
estree?: Program | null | undefined
85+
} & HastLiteral['data']
86+
}
87+
88+
/**
89+
* MDX expression node, occurring in text (phrasing), for hast.
90+
*/
91+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
92+
export interface MdxTextExpressionHast extends HastLiteral {
93+
/**
94+
* Node type.
95+
*/
96+
type: 'mdxTextExpression'
97+
98+
/**
99+
* Data.
100+
*/
101+
data?: {
102+
/**
103+
* Program node from estree.
104+
*/
105+
// eslint-disable-next-line @typescript-eslint/ban-types
106+
estree?: Program | null | undefined
107+
} & HastLiteral['data']
108+
}
109+
65110
// Add nodes to mdast content.
66111
declare module 'mdast' {
67112
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
@@ -81,28 +126,29 @@ declare module 'mdast' {
81126
}
82127
}
83128

129+
// Add nodes to hast content.
84130
declare module 'hast' {
85131
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
86132
interface RootContentMap {
87133
/**
88134
* MDX expression node, occurring in flow (block).
89135
*/
90-
mdxFlowExpression: MdxFlowExpression
136+
mdxFlowExpression: MdxFlowExpressionHast
91137
/**
92138
* MDX expression node, occurring in text (phrasing).
93139
*/
94-
mdxTextExpression: MdxTextExpression
140+
mdxTextExpression: MdxTextExpressionHast
95141
}
96142

97143
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
98144
interface ElementContentMap {
99145
/**
100146
* MDX expression node, occurring in flow (block).
101147
*/
102-
mdxFlowExpression: MdxFlowExpression
148+
mdxFlowExpression: MdxFlowExpressionHast
103149
/**
104150
* MDX expression node, occurring in text (phrasing).
105151
*/
106-
mdxTextExpression: MdxTextExpression
152+
mdxTextExpression: MdxTextExpressionHast
107153
}
108154
}

0 commit comments

Comments
 (0)