@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
- export function isUnsafeEsm(estree) {
234
+ function isFunction(estree) {
216
235
  if (!estree.body.length)
217
236
  return false;
218
- let hasUnsafeNode = false;
237
+ let hasFunctionDeclaration = false;
219
238
  walk(estree, {
220
239
  enter(node) {
221
- switch (node.type) {
222
- // Function/class definitions (could be used as executable components)
223
- case 'FunctionDeclaration':
224
- case 'FunctionExpression':
225
- case 'ArrowFunctionExpression':
226
- case 'ClassDeclaration':
227
- case 'ClassExpression':
228
- // Code execution
229
- case 'CallExpression':
230
- case 'NewExpression':
231
- case 'ImportExpression':
232
- case 'TaggedTemplateExpression':
233
- case 'AwaitExpression':
234
- case 'YieldExpression':
235
- // Side effects
236
- case 'AssignmentExpression':
237
- case 'UpdateExpression':
238
- // Property access (could read process.env, globalThis, etc.)
239
- case 'MemberExpression':
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 hasUnsafeNode;
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 (!((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree))
279
+ if (((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) && !isFunction(node.data.estree))
271
280
  return false;
272
- return isUnsafeEsm(node.data.estree);
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))