@mintlify/common 1.0.777 → 1.0.778
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mdx/astUtils.d.ts
CHANGED
|
@@ -5,3 +5,8 @@ import type { Root } from 'mdast';
|
|
|
5
5
|
* @param tree The Root node of the document.
|
|
6
6
|
*/
|
|
7
7
|
export declare const removeFrontmatterFromAST: (tree: Root) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Transforms `const X = ...; export default X;` into `export const X = ...;`
|
|
10
|
+
* so that the content is valid MDX ESM. Modifies the tree in place.
|
|
11
|
+
*/
|
|
12
|
+
export declare const normalizeDefaultExportInTree: (tree: Root) => void;
|
package/dist/mdx/astUtils.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { jsx, toJs } from 'estree-util-to-js';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
import { isMdxJsEsm } from './utils.js';
|
|
1
4
|
/**
|
|
2
5
|
* Removes the YAML frontmatter node from an AST (Root) if it exists as the first child.
|
|
3
6
|
* Modifies the tree in place.
|
|
@@ -9,3 +12,46 @@ export const removeFrontmatterFromAST = (tree) => {
|
|
|
9
12
|
tree.children.shift();
|
|
10
13
|
}
|
|
11
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Transforms `const X = ...; export default X;` into `export const X = ...;`
|
|
17
|
+
* so that the content is valid MDX ESM. Modifies the tree in place.
|
|
18
|
+
*/
|
|
19
|
+
export const normalizeDefaultExportInTree = (tree) => {
|
|
20
|
+
visit(tree, (node) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
if (!isMdxJsEsm(node) || !((_b = (_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) === null || _b === void 0 ? void 0 : _b.body))
|
|
23
|
+
return;
|
|
24
|
+
const body = node.data.estree.body;
|
|
25
|
+
const defaultExportIdx = body.findIndex((n) => n.type === 'ExportDefaultDeclaration' && n.declaration.type === 'Identifier');
|
|
26
|
+
if (defaultExportIdx === -1)
|
|
27
|
+
return;
|
|
28
|
+
const defaultExport = body[defaultExportIdx];
|
|
29
|
+
if ((defaultExport === null || defaultExport === void 0 ? void 0 : defaultExport.type) !== 'ExportDefaultDeclaration')
|
|
30
|
+
return;
|
|
31
|
+
if (defaultExport.declaration.type !== 'Identifier')
|
|
32
|
+
return;
|
|
33
|
+
const identifier = defaultExport.declaration.name;
|
|
34
|
+
const declIdx = body.findIndex((n) => {
|
|
35
|
+
var _a;
|
|
36
|
+
if (n.type === 'VariableDeclaration') {
|
|
37
|
+
return n.declarations.some((d) => d.id.type === 'Identifier' && d.id.name === identifier);
|
|
38
|
+
}
|
|
39
|
+
if (n.type === 'FunctionDeclaration' && ((_a = n.id) === null || _a === void 0 ? void 0 : _a.name) === identifier)
|
|
40
|
+
return true;
|
|
41
|
+
return false;
|
|
42
|
+
});
|
|
43
|
+
if (declIdx === -1)
|
|
44
|
+
return;
|
|
45
|
+
const decl = body[declIdx];
|
|
46
|
+
if (decl && decl.type !== 'VariableDeclaration' && decl.type !== 'FunctionDeclaration')
|
|
47
|
+
return;
|
|
48
|
+
body[declIdx] = {
|
|
49
|
+
type: 'ExportNamedDeclaration',
|
|
50
|
+
declaration: decl,
|
|
51
|
+
specifiers: [],
|
|
52
|
+
source: null,
|
|
53
|
+
};
|
|
54
|
+
body.splice(defaultExportIdx, 1);
|
|
55
|
+
node.value = toJs(node.data.estree, { handlers: jsx }).value;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Root } from 'mdast';
|
|
2
2
|
import type { ImportSpecifier } from '../../../types/mdx/snippets/import.js';
|
|
3
|
+
export { findExport } from './findExport.js';
|
|
4
|
+
export { injectToTopOfFileOfTree } from './injectToTopOfFile.js';
|
|
3
5
|
/**
|
|
4
6
|
*
|
|
5
7
|
* @param importSpecifier The name of the imported component we want to replace
|
|
@@ -12,6 +12,8 @@ import { getAST } from '../../remark.js';
|
|
|
12
12
|
import { findExport } from './findExport.js';
|
|
13
13
|
import { injectToTopOfFileOfTree } from './injectToTopOfFile.js';
|
|
14
14
|
import { resolveComponentWithContent } from './resolveComponentWithContent.js';
|
|
15
|
+
export { findExport } from './findExport.js';
|
|
16
|
+
export { injectToTopOfFileOfTree } from './injectToTopOfFile.js';
|
|
15
17
|
const VALID_SPECIFIERS = [
|
|
16
18
|
MdxImportSpecifier.ImportSpecifier,
|
|
17
19
|
MdxImportSpecifier.RenamedImportSpecifier,
|