@mintlify/common 1.0.785 → 1.0.787

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;
@@ -1,4 +1,3 @@
1
- import { walk } from 'estree-walker';
2
1
  import { remove } from 'unist-util-remove';
3
2
  import { CONTINUE, visit } from 'unist-util-visit';
4
3
  import { isMdxJsEsm } from '../../utils.js';
@@ -136,6 +135,25 @@ const DEFAULT_PROP_EXPRESSIONS = {
136
135
  'x-hidden': { value: '"true"', estree: trueEstree },
137
136
  'x-excluded': { value: '"true"', estree: trueEstree },
138
137
  };
138
+ export const REACT_HOOKS = [
139
+ 'useState',
140
+ 'useEffect',
141
+ 'useRef',
142
+ 'useCallback',
143
+ 'useMemo',
144
+ 'useReducer',
145
+ 'useContext',
146
+ 'useLayoutEffect',
147
+ 'useImperativeHandle',
148
+ 'useDebugValue',
149
+ 'useDeferredValue',
150
+ 'useTransition',
151
+ 'useId',
152
+ 'useSyncExternalStore',
153
+ 'useInsertionEffect',
154
+ 'useOptimistic',
155
+ 'useActionState',
156
+ ];
139
157
  export function isStringSafe(value) {
140
158
  switch (true) {
141
159
  case value === 'true':
@@ -212,45 +230,92 @@ export function rebuildStyleValue(properties) {
212
230
  });
213
231
  return `{ ${parts.join(', ')} }`;
214
232
  }
215
- export function isUnsafeEsm(estree) {
216
- if (!estree.body.length)
217
- return false;
218
- let hasUnsafeNode = false;
219
- walk(estree, {
220
- 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;
233
+ function collectExportedNames(estree) {
234
+ var _a, _b;
235
+ const names = [];
236
+ for (const node of estree.body) {
237
+ if (node.type !== 'ExportNamedDeclaration')
238
+ continue;
239
+ const decl = node.declaration;
240
+ if (!decl)
241
+ continue;
242
+ if (decl.type === 'FunctionDeclaration' && decl.id) {
243
+ names.push({ name: decl.id.name, isFunction: true });
244
+ }
245
+ else if (decl.type === 'VariableDeclaration') {
246
+ for (const declarator of decl.declarations) {
247
+ if (declarator.id.type !== 'Identifier')
248
+ continue;
249
+ const isFn = ((_a = declarator.init) === null || _a === void 0 ? void 0 : _a.type) === 'ArrowFunctionExpression' ||
250
+ ((_b = declarator.init) === null || _b === void 0 ? void 0 : _b.type) === 'FunctionExpression';
251
+ names.push({ name: declarator.id.name, isFunction: isFn });
250
252
  }
253
+ }
254
+ }
255
+ return names;
256
+ }
257
+ function buildStubEsmNode(names) {
258
+ const sourceLines = [];
259
+ const body = [];
260
+ for (const { name, isFunction } of names) {
261
+ if (isFunction) {
262
+ sourceLines.push(`export const ${name} = () => null;`);
263
+ body.push({
264
+ type: 'ExportNamedDeclaration',
265
+ declaration: {
266
+ type: 'VariableDeclaration',
267
+ declarations: [
268
+ {
269
+ type: 'VariableDeclarator',
270
+ id: { type: 'Identifier', name },
271
+ init: {
272
+ type: 'ArrowFunctionExpression',
273
+ params: [],
274
+ body: { type: 'Literal', value: null, raw: 'null' },
275
+ expression: true,
276
+ async: false,
277
+ generator: false,
278
+ },
279
+ },
280
+ ],
281
+ kind: 'const',
282
+ },
283
+ specifiers: [],
284
+ source: null,
285
+ });
286
+ }
287
+ else {
288
+ sourceLines.push(`export const ${name} = undefined;`);
289
+ body.push({
290
+ type: 'ExportNamedDeclaration',
291
+ declaration: {
292
+ type: 'VariableDeclaration',
293
+ declarations: [
294
+ {
295
+ type: 'VariableDeclarator',
296
+ id: { type: 'Identifier', name },
297
+ init: { type: 'Identifier', name: 'undefined' },
298
+ },
299
+ ],
300
+ kind: 'const',
301
+ },
302
+ specifiers: [],
303
+ source: null,
304
+ });
305
+ }
306
+ }
307
+ return {
308
+ type: 'mdxjsEsm',
309
+ value: sourceLines.join('\n'),
310
+ data: {
311
+ estree: {
312
+ type: 'Program',
313
+ body,
314
+ sourceType: 'module',
315
+ comments: [],
316
+ },
251
317
  },
252
- });
253
- return hasUnsafeNode;
318
+ };
254
319
  }
255
320
  function isArrayOfStringLiterals(estree) {
256
321
  const stmt = estree.body[0];
@@ -263,14 +328,19 @@ function isArrayOfStringLiterals(estree) {
263
328
  export function remarkMdxRemoveJs() {
264
329
  return (tree) => {
265
330
  remove(tree, ['mdxTextExpression', 'mdxFlowExpression']);
266
- remove(tree, (node) => {
331
+ // Collect exported names before stripping ESM so we can inject stubs
332
+ const exportedNames = [];
333
+ visit(tree, (node) => {
267
334
  var _a;
268
- if (!isMdxJsEsm(node))
269
- return false;
270
- if (!((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree))
271
- return false;
272
- return isUnsafeEsm(node.data.estree);
335
+ if (isMdxJsEsm(node) && ((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree)) {
336
+ exportedNames.push(...collectExportedNames(node.data.estree));
337
+ }
273
338
  });
339
+ remove(tree, (node) => isMdxJsEsm(node));
340
+ // Inject stub declarations for stripped exports to prevent ReferenceErrors
341
+ if (exportedNames.length > 0) {
342
+ tree.children.unshift(buildStubEsmNode(exportedNames));
343
+ }
274
344
  visit(tree, (node) => {
275
345
  if (!('attributes' in node))
276
346
  return CONTINUE;