@mintlify/common 1.0.785 → 1.0.786
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,7 +1,7 @@
|
|
|
1
1
|
import type { Program, Property } from 'estree-jsx';
|
|
2
2
|
import type { Root } from 'mdast';
|
|
3
|
+
export declare const REACT_HOOKS: string[];
|
|
3
4
|
export declare function isStringSafe(value: string): boolean;
|
|
4
5
|
export declare function filterStyleProperties(estree: Program): Program | null;
|
|
5
6
|
export declare function rebuildStyleValue(properties: Property[]): string;
|
|
6
|
-
export declare function isUnsafeEsm(estree: Program): boolean;
|
|
7
7
|
export declare function remarkMdxRemoveJs(): (tree: Root) => void;
|
|
@@ -136,6 +136,25 @@ const DEFAULT_PROP_EXPRESSIONS = {
|
|
|
136
136
|
'x-hidden': { value: '"true"', estree: trueEstree },
|
|
137
137
|
'x-excluded': { value: '"true"', estree: trueEstree },
|
|
138
138
|
};
|
|
139
|
+
export const REACT_HOOKS = [
|
|
140
|
+
'useState',
|
|
141
|
+
'useEffect',
|
|
142
|
+
'useRef',
|
|
143
|
+
'useCallback',
|
|
144
|
+
'useMemo',
|
|
145
|
+
'useReducer',
|
|
146
|
+
'useContext',
|
|
147
|
+
'useLayoutEffect',
|
|
148
|
+
'useImperativeHandle',
|
|
149
|
+
'useDebugValue',
|
|
150
|
+
'useDeferredValue',
|
|
151
|
+
'useTransition',
|
|
152
|
+
'useId',
|
|
153
|
+
'useSyncExternalStore',
|
|
154
|
+
'useInsertionEffect',
|
|
155
|
+
'useOptimistic',
|
|
156
|
+
'useActionState',
|
|
157
|
+
];
|
|
139
158
|
export function isStringSafe(value) {
|
|
140
159
|
switch (true) {
|
|
141
160
|
case value === 'true':
|
|
@@ -212,45 +231,35 @@ export function rebuildStyleValue(properties) {
|
|
|
212
231
|
});
|
|
213
232
|
return `{ ${parts.join(', ')} }`;
|
|
214
233
|
}
|
|
215
|
-
|
|
234
|
+
function isFunction(estree) {
|
|
216
235
|
if (!estree.body.length)
|
|
217
236
|
return false;
|
|
218
|
-
let
|
|
237
|
+
let hasFunctionDeclaration = false;
|
|
219
238
|
walk(estree, {
|
|
220
239
|
enter(node) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
hasUnsafeNode = true;
|
|
241
|
-
return this.skip();
|
|
242
|
-
// Re-exports pull in external modules (e.g. `export { readFileSync } from 'fs'`)
|
|
243
|
-
case 'ExportNamedDeclaration':
|
|
244
|
-
case 'ExportAllDeclaration':
|
|
245
|
-
if ('source' in node && node.source != null) {
|
|
246
|
-
hasUnsafeNode = true;
|
|
247
|
-
return this.skip();
|
|
248
|
-
}
|
|
249
|
-
break;
|
|
240
|
+
if (node.type === 'FunctionDeclaration' ||
|
|
241
|
+
node.type === 'ArrowFunctionExpression' ||
|
|
242
|
+
node.type === 'FunctionExpression') {
|
|
243
|
+
hasFunctionDeclaration = true;
|
|
244
|
+
return this.skip();
|
|
245
|
+
}
|
|
246
|
+
if (node.type === 'ExportDefaultDeclaration' &&
|
|
247
|
+
(node.declaration.type === 'FunctionDeclaration' ||
|
|
248
|
+
node.declaration.type === 'FunctionExpression' ||
|
|
249
|
+
node.declaration.type === 'ArrowFunctionExpression')) {
|
|
250
|
+
hasFunctionDeclaration = true;
|
|
251
|
+
return this.skip();
|
|
252
|
+
}
|
|
253
|
+
if (node.type === 'VariableDeclaration' &&
|
|
254
|
+
node.declarations.some((decl) => decl.init &&
|
|
255
|
+
(decl.init.type === 'ArrowFunctionExpression' ||
|
|
256
|
+
decl.init.type === 'FunctionExpression'))) {
|
|
257
|
+
hasFunctionDeclaration = true;
|
|
258
|
+
return this.skip();
|
|
250
259
|
}
|
|
251
260
|
},
|
|
252
261
|
});
|
|
253
|
-
return
|
|
262
|
+
return hasFunctionDeclaration;
|
|
254
263
|
}
|
|
255
264
|
function isArrayOfStringLiterals(estree) {
|
|
256
265
|
const stmt = estree.body[0];
|
|
@@ -267,9 +276,11 @@ export function remarkMdxRemoveJs() {
|
|
|
267
276
|
var _a;
|
|
268
277
|
if (!isMdxJsEsm(node))
|
|
269
278
|
return false;
|
|
270
|
-
if (
|
|
279
|
+
if (((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) && !isFunction(node.data.estree))
|
|
271
280
|
return false;
|
|
272
|
-
|
|
281
|
+
const value = node.value;
|
|
282
|
+
const containsReact = REACT_HOOKS.some((hook) => value.includes(hook) || value.includes('React.' + hook.toLowerCase()));
|
|
283
|
+
return containsReact;
|
|
273
284
|
});
|
|
274
285
|
visit(tree, (node) => {
|
|
275
286
|
if (!('attributes' in node))
|