@mintlify/common 1.0.359 → 1.0.361
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { walk } from 'estree-walker';
|
|
1
2
|
import { remove } from 'unist-util-remove';
|
|
2
3
|
import { isMdxJsEsm } from '../../utils.js';
|
|
3
4
|
const REACT_HOOKS = [
|
|
@@ -22,12 +23,43 @@ const REACT_HOOKS = [
|
|
|
22
23
|
export const remarkMdxRemoveJs = () => (tree) => {
|
|
23
24
|
remove(tree, ['mdxTextExpression', 'mdxFlowExpression']);
|
|
24
25
|
remove(tree, (node) => {
|
|
26
|
+
var _a;
|
|
25
27
|
if (!isMdxJsEsm(node))
|
|
26
28
|
return false;
|
|
29
|
+
if (((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) && !isFunction(node.data.estree))
|
|
30
|
+
return false;
|
|
27
31
|
const value = node.value;
|
|
28
|
-
const containsReact = value.includes('React')
|
|
29
|
-
value.includes('react') ||
|
|
30
|
-
REACT_HOOKS.some((hook) => value.includes(hook));
|
|
32
|
+
const containsReact = REACT_HOOKS.some((hook) => value.includes(hook) || value.includes('React.' + hook.toLowerCase()));
|
|
31
33
|
return containsReact;
|
|
32
34
|
});
|
|
33
35
|
};
|
|
36
|
+
function isFunction(estree) {
|
|
37
|
+
if (!estree.body.length)
|
|
38
|
+
return false;
|
|
39
|
+
let hasFunctionDeclaration = false;
|
|
40
|
+
walk(estree, {
|
|
41
|
+
enter(node) {
|
|
42
|
+
if (node.type === 'FunctionDeclaration' ||
|
|
43
|
+
node.type === 'ArrowFunctionExpression' ||
|
|
44
|
+
node.type === 'FunctionExpression') {
|
|
45
|
+
hasFunctionDeclaration = true;
|
|
46
|
+
return this.skip();
|
|
47
|
+
}
|
|
48
|
+
if (node.type === 'ExportDefaultDeclaration' &&
|
|
49
|
+
(node.declaration.type === 'FunctionDeclaration' ||
|
|
50
|
+
node.declaration.type === 'FunctionExpression' ||
|
|
51
|
+
node.declaration.type === 'ArrowFunctionExpression')) {
|
|
52
|
+
hasFunctionDeclaration = true;
|
|
53
|
+
return this.skip();
|
|
54
|
+
}
|
|
55
|
+
if (node.type === 'VariableDeclaration' &&
|
|
56
|
+
node.declarations.some((decl) => decl.init &&
|
|
57
|
+
(decl.init.type === 'ArrowFunctionExpression' ||
|
|
58
|
+
decl.init.type === 'FunctionExpression'))) {
|
|
59
|
+
hasFunctionDeclaration = true;
|
|
60
|
+
return this.skip();
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
return hasFunctionDeclaration;
|
|
65
|
+
}
|