Skip to content

Commit db50bb6

Browse files
authored
chore: use @types/mdast (#150)
1 parent 8f40d5c commit db50bb6

File tree

8 files changed

+25
-33
lines changed

8 files changed

+25
-33
lines changed

package-lock.json

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
},
1919
"devDependencies": {
2020
"@eslint/js": "^9.13.0",
21+
"@types/mdast": "^4.0.4",
2122
"@types/node": "^22.9.0",
2223
"eslint": "^9.13.0",
2324
"eslint-config-prettier": "^9.1.0",
2425
"eslint-plugin-jsdoc": "^50.5.0",
2526
"globals": "^15.11.0",
2627
"husky": "^9.1.6",
2728
"lint-staged": "^15.2.10",
28-
"mdast": "^3.0.0",
2929
"prettier": "3.3.3"
3030
},
3131
"dependencies": {

src/generators/legacy-html/utils/buildContent.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const buildHeading = ({ data, children }, index, parent) => {
4646
/**
4747
* Builds an HTML Stability element
4848
*
49-
* @param {import('mdast').Blockquote} node The HTML AST tree of the Stability Index content
49+
* @param {import('@types/mdast').Blockquote} node The HTML AST tree of the Stability Index content
5050
* @param {number} index The index of the current node
5151
* @param {import('unist').Parent} parent The parent node of the current node
5252
*/
@@ -69,7 +69,7 @@ const buildStability = ({ children, data }, index, parent) => {
6969
/**
7070
* Transforms the node Markdown link into an HTML link
7171
*
72-
* @param {import('mdast').Html} node The node containing the HTML content
72+
* @param {import('@types/mdast').Html} node The node containing the HTML content
7373
*/
7474
const buildHtmlTypeLink = node => {
7575
node.value = node.value.replace(

src/generators/legacy-json/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ListItem } from 'mdast';
1+
import { ListItem } from '@types/mdast';
22

33
/**
44
* Represents an entry in a hierarchical structure, extending from ApiDocMetadataEntry.

src/generators/legacy-json/utils/parseList.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const extractPattern = (text, pattern, key, current) => {
4040
/**
4141
* Parses an individual list item node to extract its properties
4242
*
43-
* @param {import('mdast').ListItem} child
43+
* @param {import('@types/mdast').ListItem} child
4444
* @returns {import('../types').ParameterList}
4545
*/
4646
function parseListItem(child) {
@@ -82,7 +82,7 @@ function parseListItem(child) {
8282
* Parses a list of nodes and updates the corresponding section object with the extracted information.
8383
* Handles different section types such as methods, properties, and events differently.
8484
* @param {import('../types').Section} section
85-
* @param {import('mdast').RootContent[]} nodes
85+
* @param {import('@types/mdast').RootContent[]} nodes
8686
*/
8787
export function parseList(section, nodes) {
8888
const list = nodes[0]?.type === 'list' ? nodes.shift() : null;

src/generators/man-page/utils/converter.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* This function processes the node recursively, converting each supported node type
44
* to its corresponding Mandoc markup representation. Unsupported node types will be ignored.
55
*
6-
* @param {import("mdast").Node} node - The AST node to be converted to Mandoc format.
6+
* @param {import('@types/mdast').Node} node - The AST node to be converted to Mandoc format.
77
* @param {boolean} [isListItem=false] - Indicates if the current node is a list item.
88
* This parameter is used to correctly format list elements in Mandoc.
99
* @returns {string} The Mandoc formatted string representing the given node and its children.

src/queries.mjs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const createQueries = () => {
2424
* Sanitizes the YAML source by returning the inner YAML content
2525
* and then parsing it into an API Metadata object and updating the current Metadata
2626
*
27-
* @param {import('mdast').Html} node A HTML node containing the YAML content
27+
* @param {import('@types/mdast').Html} node A HTML node containing the YAML content
2828
* @param {ReturnType<import('./metadata.mjs').default>} apiEntryMetadata The API entry Metadata
2929
*/
3030
const addYAMLMetadata = (node, apiEntryMetadata) => {
@@ -42,7 +42,7 @@ const createQueries = () => {
4242
/**
4343
* Parse a Heading node into metadata and updates the current metadata
4444
*
45-
* @param {import('mdast').Heading} node A Markdown heading node
45+
* @param {import('@types/mdast').Heading} node A Markdown heading node
4646
* @param {ReturnType<import('./metadata.mjs').default>} apiEntryMetadata The API entry Metadata
4747
*/
4848
const setHeadingMetadata = (node, apiEntryMetadata) => {
@@ -57,7 +57,7 @@ const createQueries = () => {
5757
/**
5858
* Updates a Markdown link into a HTML link for API docs
5959
*
60-
* @param {import('mdast').Link} node A Markdown link node
60+
* @param {import('@types/mdast').Link} node A Markdown link node
6161
*/
6262
const updateMarkdownLink = node => {
6363
node.url = node.url.replace(
@@ -72,8 +72,8 @@ const createQueries = () => {
7272
* Updates a Markdown text containing an API type reference
7373
* into a Markdown link referencing to the correct API docs
7474
*
75-
* @param {import('mdast').Text} node A Markdown link node
76-
* @param {import('mdast').Parent} parent The parent node
75+
* @param {import('@types/mdast').Text} node A Markdown link node
76+
* @param {import('@types/mdast').Parent} parent The parent node
7777
*/
7878
const updateTypeReference = (node, parent) => {
7979
const replacedTypes = node.value
@@ -104,8 +104,8 @@ const createQueries = () => {
104104
/**
105105
* Updates a Markdown Link Reference into an actual Link to the Definition
106106
*
107-
* @param {import('mdast').LinkReference} node A link reference node
108-
* @param {Array<import('mdast').Definition>} definitions The Definitions of the API Doc
107+
* @param {import('@types/mdast').LinkReference} node A link reference node
108+
* @param {Array<import('@types/mdast').Definition>} definitions The Definitions of the API Doc
109109
*/
110110
const updateLinkReference = (node, definitions) => {
111111
const definition = definitions.find(
@@ -121,7 +121,7 @@ const createQueries = () => {
121121
/**
122122
* Parses a Stability Index Entry and updates the current Metadata
123123
*
124-
* @param {import('mdast').Blockquote} node Thead Link Reference Node
124+
* @param {import('@types/mdast').Blockquote} node Thead Link Reference Node
125125
* @param {ReturnType<import('./metadata.mjs').default>} apiEntryMetadata The API entry Metadata
126126
*/
127127
const addStabilityMetadata = (node, apiEntryMetadata) => {
@@ -204,44 +204,44 @@ createQueries.QUERIES = {
204204

205205
createQueries.UNIST = {
206206
/**
207-
* @param {import('mdast').Blockquote} blockquote
207+
* @param {import('@types/mdast').Blockquote} blockquote
208208
* @returns {boolean}
209209
*/
210210
isStabilityNode: ({ type, children }) =>
211211
type === 'blockquote' &&
212212
createQueries.QUERIES.stabilityIndex.test(transformNodesToString(children)),
213213
/**
214-
* @param {import('mdast').Html} html
214+
* @param {import('@types/mdast').Html} html
215215
* @returns {boolean}
216216
*/
217217
isYamlNode: ({ type, value }) =>
218218
type === 'html' && createQueries.QUERIES.yamlInnerContent.test(value),
219219
/**
220-
* @param {import('mdast').Text} text
220+
* @param {import('@types/mdast').Text} text
221221
* @returns {boolean}
222222
*/
223223
isTextWithType: ({ type, value }) =>
224224
type === 'text' && createQueries.QUERIES.normalizeTypes.test(value),
225225
/**
226-
* @param {import('mdast').Html} html
226+
* @param {import('@types/mdast').Html} html
227227
* @returns {boolean}
228228
*/
229229
isHtmlWithType: ({ type, value }) =>
230230
type === 'html' && createQueries.QUERIES.linksWithTypes.test(value),
231231
/**
232-
* @param {import('mdast').Link} link
232+
* @param {import('@types/mdast').Link} link
233233
* @returns {boolean}
234234
*/
235235
isMarkdownUrl: ({ type, url }) =>
236236
type === 'link' && createQueries.QUERIES.markdownUrl.test(url),
237237
/**
238-
* @param {import('mdast').Heading} heading
238+
* @param {import('@types/mdast').Heading} heading
239239
* @returns {boolean}
240240
*/
241241
isHeading: ({ type, depth }) =>
242242
type === 'heading' && depth >= 1 && depth <= 5,
243243
/**
244-
* @param {import('mdast').LinkReference} linkReference
244+
* @param {import('@types/mdast').LinkReference} linkReference
245245
* @returns {boolean}
246246
*/
247247
isLinkReference: ({ type, identifier }) =>

src/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Heading, Root } from 'mdast';
1+
import type { Heading, Root } from '@types/mdast';
22
import type { SemVer } from 'semver';
3-
import type { Parent, Node, Data } from 'unist';
3+
import type { Data, Node, Parent } from 'unist';
44

55
// String serialization of the AST tree
66
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior

0 commit comments

Comments
 (0)