@mintlify/common 1.0.775 → 1.0.776
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/getFileCategory.js +1 -1
- package/dist/mdx/remark.js +3 -3
- package/dist/mdx/snippets/constants.d.ts +2 -1
- package/dist/mdx/snippets/constants.js +2 -1
- package/dist/mdx/snippets/getJsxEsmTree.d.ts +5 -4
- package/dist/mdx/snippets/getJsxEsmTree.js +13 -8
- package/dist/mdx/snippets/index.d.ts +2 -0
- package/dist/mdx/snippets/index.js +2 -0
- package/dist/mdx/snippets/isJsxOrTsx.d.ts +2 -0
- package/dist/mdx/snippets/isJsxOrTsx.js +11 -0
- package/dist/mdx/snippets/stripTsxTypes.d.ts +1 -0
- package/dist/mdx/snippets/stripTsxTypes.js +9 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/dist/mdx/snippets/isJsxFile.d.ts +0 -1
- package/dist/mdx/snippets/isJsxFile.js +0 -4
package/dist/getFileCategory.js
CHANGED
|
@@ -117,7 +117,7 @@ export const getFileCategory = (filePath, options) => {
|
|
|
117
117
|
}
|
|
118
118
|
return 'page';
|
|
119
119
|
}
|
|
120
|
-
else if (extension === '.jsx') {
|
|
120
|
+
else if (extension === '.jsx' || extension === '.tsx') {
|
|
121
121
|
return 'snippet-v2';
|
|
122
122
|
}
|
|
123
123
|
else if (extension === '.yaml' || extension === '.yml') {
|
package/dist/mdx/remark.js
CHANGED
|
@@ -5,7 +5,7 @@ import remarkMath from 'remark-math';
|
|
|
5
5
|
import remarkMdx from 'remark-mdx';
|
|
6
6
|
import remarkStringify from 'remark-stringify';
|
|
7
7
|
import { getJsxEsmTree } from './snippets/getJsxEsmTree.js';
|
|
8
|
-
import {
|
|
8
|
+
import { isJsxOrTsx } from './snippets/isJsxOrTsx.js';
|
|
9
9
|
export const coreRemarkMdxPlugins = [
|
|
10
10
|
remarkMdx,
|
|
11
11
|
remarkGfm,
|
|
@@ -14,8 +14,8 @@ export const coreRemarkMdxPlugins = [
|
|
|
14
14
|
];
|
|
15
15
|
export const coreRemark = remark().use(coreRemarkMdxPlugins).freeze();
|
|
16
16
|
export const getAST = (str, filePath) => {
|
|
17
|
-
if (
|
|
18
|
-
return getJsxEsmTree(str);
|
|
17
|
+
if (isJsxOrTsx(filePath)) {
|
|
18
|
+
return getJsxEsmTree(str, filePath);
|
|
19
19
|
}
|
|
20
20
|
return coreRemark().parse(str);
|
|
21
21
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const JSX_EXTENSIONS: readonly [".jsx", ".tsx"];
|
|
2
|
+
export declare const SNIPPET_EXTENSIONS: readonly [".mdx", ".jsx", ".tsx", ".md"];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const JSX_EXTENSIONS = ['.jsx', '.tsx'];
|
|
2
|
+
export const SNIPPET_EXTENSIONS = ['.mdx', ...JSX_EXTENSIONS, '.md'];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Root } from 'mdast';
|
|
2
2
|
/**
|
|
3
|
-
* Get the AST for a JSX snippet
|
|
4
|
-
* @param jsxContent the content of the JSX snippet
|
|
5
|
-
* @
|
|
3
|
+
* Get the AST for a JSX/TSX snippet
|
|
4
|
+
* @param jsxContent the content of the JSX/TSX snippet
|
|
5
|
+
* @param filePath optional file path, used to determine if TypeScript stripping is needed
|
|
6
|
+
* @returns the AST for the snippet
|
|
6
7
|
*/
|
|
7
|
-
export declare const getJsxEsmTree: (jsxContent: string) => Root;
|
|
8
|
+
export declare const getJsxEsmTree: (jsxContent: string, filePath?: string) => Root;
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { Parser } from 'acorn';
|
|
2
2
|
import jsx from 'acorn-jsx';
|
|
3
|
+
import { isTsxFile } from './isJsxOrTsx.js';
|
|
4
|
+
import { stripTsxTypes } from './stripTsxTypes.js';
|
|
3
5
|
const JSXParser = Parser.extend(jsx());
|
|
4
6
|
/**
|
|
5
|
-
* Get the AST for a JSX snippet
|
|
6
|
-
* @param jsxContent the content of the JSX snippet
|
|
7
|
-
* @
|
|
7
|
+
* Get the AST for a JSX/TSX snippet
|
|
8
|
+
* @param jsxContent the content of the JSX/TSX snippet
|
|
9
|
+
* @param filePath optional file path, used to determine if TypeScript stripping is needed
|
|
10
|
+
* @returns the AST for the snippet
|
|
8
11
|
*/
|
|
9
|
-
export const getJsxEsmTree = (jsxContent) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
export const getJsxEsmTree = (jsxContent, filePath) => {
|
|
13
|
+
let content = jsxContent.trim();
|
|
14
|
+
if (filePath && isTsxFile(filePath)) {
|
|
15
|
+
content = stripTsxTypes(content).trim();
|
|
16
|
+
}
|
|
17
|
+
const estree = JSXParser.parse(content, {
|
|
12
18
|
ecmaVersion: 'latest',
|
|
13
19
|
sourceType: 'module',
|
|
14
20
|
allowReturnOutsideFunction: true,
|
|
15
21
|
});
|
|
16
|
-
const finalContent = trimmedContent;
|
|
17
22
|
const mdxJsEsmNode = {
|
|
18
23
|
type: 'mdxjsEsm',
|
|
19
|
-
value:
|
|
24
|
+
value: content,
|
|
20
25
|
data: {
|
|
21
26
|
estree,
|
|
22
27
|
},
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const isJsxOrTsx = (filePath) => {
|
|
2
|
+
if (!filePath)
|
|
3
|
+
return false;
|
|
4
|
+
const lower = filePath.toLowerCase();
|
|
5
|
+
return lower.endsWith('.jsx') || lower.endsWith('.tsx');
|
|
6
|
+
};
|
|
7
|
+
export const isTsxFile = (filePath) => {
|
|
8
|
+
if (!filePath)
|
|
9
|
+
return false;
|
|
10
|
+
return filePath.toLowerCase().endsWith('.tsx');
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stripTsxTypes: (code: string) => string;
|