Skip to content

Commit 3f980d1

Browse files
committed
Add comments to node types
1 parent ebe8a5a commit 3f980d1

File tree

6 files changed

+62
-27
lines changed

6 files changed

+62
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ node_modules/
55
.DS_Store
66
yarn.lock
77
!/complex-types.d.ts
8+
!/index.d.ts

complex-types.d.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
1-
import type {Literal} from 'mdast'
2-
import type {Program} from 'estree-jsx'
1+
// To do: next major: remove this file.
2+
export type {MdxjsEsm} from './index.js'
33

4-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
5-
export interface MdxjsEsm extends Literal {
6-
type: 'mdxjsEsm'
7-
data?: {estree?: Program}
8-
}
9-
10-
declare module 'mdast' {
11-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
12-
interface BlockContentMap {
13-
mdxjsEsm: MdxjsEsm
14-
}
15-
}
16-
17-
declare module 'hast' {
18-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
19-
interface RootContentMap {
20-
mdxjsEsm: MdxjsEsm
21-
}
22-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
23-
interface ElementContentMap {
24-
mdxjsEsm: MdxjsEsm
25-
}
26-
}
4+
/// <reference types="./index.js" />

index.d.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import type {Literal} from 'mdast'
2+
import type {Program} from 'estree-jsx'
3+
4+
export {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from './lib/index.js'
5+
6+
/**
7+
* MDX ESM (import/export) node.
8+
*/
9+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
10+
export interface MdxjsEsm extends Literal {
11+
/**
12+
* Node type.
13+
*/
14+
type: 'mdxjsEsm'
15+
16+
/**
17+
* Data.
18+
*/
19+
data?: {
20+
/**
21+
* Program node from estree.
22+
*/
23+
// eslint-disable-next-line @typescript-eslint/ban-types
24+
estree?: Program | null | undefined
25+
}
26+
}
27+
28+
// Add nodes to content.
29+
declare module 'mdast' {
30+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
31+
interface BlockContentMap {
32+
/**
33+
* MDX ESM.
34+
*/
35+
mdxjsEsm: MdxjsEsm
36+
}
37+
}
38+
39+
declare module 'hast' {
40+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
41+
interface RootContentMap {
42+
/**
43+
* MDX ESM.
44+
*/
45+
mdxjsEsm: MdxjsEsm
46+
}
47+
48+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
49+
interface ElementContentMap {
50+
/**
51+
* MDX ESM.
52+
*/
53+
mdxjsEsm: MdxjsEsm
54+
}
55+
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Note: types exposed from `index.d.ts`.
12
export {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from './lib/index.js'

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
66
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
77
* @typedef {import('estree-jsx').Program} Program
8-
* @typedef {import('../complex-types.js').MdxjsEsm} MdxjsEsm
8+
* @typedef {import('../index.js').MdxjsEsm} MdxjsEsm
99
*
1010
* @typedef {MdxjsEsm} MDXJSEsm
1111
* Deprecated name, prefer `MdxjsEsm`.

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["**/*.js"],
2+
"include": ["**/*.js", "complex-types.d.ts", "index.d.ts"],
33
"exclude": ["coverage/", "node_modules/"],
44
"compilerOptions": {
55
"checkJs": true,

0 commit comments

Comments
 (0)