@mintlify/common 1.0.1339 → 1.0.1340

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.
@@ -57,6 +57,12 @@ export type EvalEnv = {
57
57
  failedProps?: ReadonlySet<string>;
58
58
  restName?: string;
59
59
  restFailedProps?: ReadonlySet<string>;
60
+ jsxLocals?: Map<string, JsxLocal>;
61
+ };
62
+ export type JsxLocal = {
63
+ node: unknown;
64
+ scope: StaticScope;
65
+ jsxLocals: ReadonlyMap<string, JsxLocal>;
60
66
  };
61
67
  export declare function unbindPattern(pattern: unknown, env: EvalEnv): void;
62
68
  export declare function bindPattern(pattern: unknown, value: StaticValue, env: EvalEnv): void;
@@ -694,11 +694,26 @@ function serializeJsxNode(node, ctx) {
694
694
  return '';
695
695
  }
696
696
  }
697
+ function serializeJsxLocal(name, ctx) {
698
+ var _a;
699
+ const local = (_a = ctx.jsxLocals) === null || _a === void 0 ? void 0 : _a.get(name);
700
+ if (local === undefined)
701
+ return undefined;
702
+ if (ctx.budget.remainingBytes <= 0 || !chargeUnfoldCall(ctx))
703
+ return '';
704
+ const markdown = serializeJsxExpression(local.node, Object.assign(Object.assign({}, ctx), { scope: local.scope, jsxLocals: new Map(local.jsxLocals) }));
705
+ return chargeUnfoldBudget(ctx, markdown.length) ? markdown : '';
706
+ }
697
707
  function serializeJsxExpression(expression, ctx) {
698
708
  if (!isObject(expression))
699
709
  return '';
700
710
  if (expression.type === 'JSXEmptyExpression')
701
711
  return '';
712
+ if (expression.type === 'Identifier' && typeof expression.name === 'string') {
713
+ const local = serializeJsxLocal(expression.name, ctx);
714
+ if (local !== undefined)
715
+ return local;
716
+ }
702
717
  if (expression.type === 'Identifier' &&
703
718
  typeof expression.name === 'string' &&
704
719
  expression.name === ctx.childrenName &&
@@ -1098,6 +1113,8 @@ export function slotJsxUsageProps(node, ctx, props, failed) {
1098
1113
  return slots;
1099
1114
  }
1100
1115
  function slotJsxStaticProps(node, ctx, props, failed) {
1116
+ var _a;
1117
+ var _b;
1101
1118
  const slots = new Map();
1102
1119
  for (const attribute of jsxAttributes(node)) {
1103
1120
  if (attribute.type !== 'JSXAttribute')
@@ -1108,7 +1125,9 @@ function slotJsxStaticProps(node, ctx, props, failed) {
1108
1125
  if (!failed.has(attrName.name))
1109
1126
  continue;
1110
1127
  const value = attribute.value;
1111
- const expression = jsxValueExpression(nodeType(value) === 'JSXExpressionContainer' && isObject(value) ? value.expression : value);
1128
+ const raw = nodeType(value) === 'JSXExpressionContainer' && isObject(value) ? value.expression : value;
1129
+ const local = identifierName(raw);
1130
+ const expression = (_b = jsxValueExpression(raw)) !== null && _b !== void 0 ? _b : (local !== undefined && ((_a = ctx.jsxLocals) === null || _a === void 0 ? void 0 : _a.has(local)) === true ? raw : undefined);
1112
1131
  if (expression === undefined)
1113
1132
  continue;
1114
1133
  const markdown = serializeJsxExpression(expression, ctx).trim();
@@ -1285,8 +1304,35 @@ function analyzeParams(params) {
1285
1304
  return { bindings, childrenName, propsObjectName, restName, unknownNames };
1286
1305
  }
1287
1306
  function bindDeclarator(declarator, env) {
1307
+ var _a, _b;
1288
1308
  if (nodeType(declarator) !== 'VariableDeclarator' || !isObject(declarator))
1289
1309
  return;
1310
+ const declared = new Set();
1311
+ collectPatternNames(declarator.id, declared);
1312
+ for (const name of declared)
1313
+ (_a = env.jsxLocals) === null || _a === void 0 ? void 0 : _a.delete(name);
1314
+ const name = identifierName(declarator.id);
1315
+ const jsx = jsxValueExpression(declarator.init);
1316
+ if (name !== undefined && jsx !== undefined) {
1317
+ env.scope.delete(name);
1318
+ const scope = new Map();
1319
+ const jsxLocals = new Map();
1320
+ visitReferences(jsx, new Set(), {
1321
+ reference: (identifier) => {
1322
+ var _a;
1323
+ const referenced = identifier.name;
1324
+ if (typeof referenced !== 'string')
1325
+ return;
1326
+ if (env.scope.has(referenced))
1327
+ scope.set(referenced, env.scope.get(referenced));
1328
+ const local = (_a = env.jsxLocals) === null || _a === void 0 ? void 0 : _a.get(referenced);
1329
+ if (local !== undefined)
1330
+ jsxLocals.set(referenced, local);
1331
+ },
1332
+ });
1333
+ (_b = env.jsxLocals) === null || _b === void 0 ? void 0 : _b.set(name, { node: jsx, scope, jsxLocals });
1334
+ return;
1335
+ }
1290
1336
  const evaluated = evaluateStatic(declarator.init, env);
1291
1337
  if (evaluated.ok)
1292
1338
  bindPattern(declarator.id, evaluated.value, env);
@@ -1347,6 +1393,7 @@ function hoistedVarNames(node, names = new Set()) {
1347
1393
  return names;
1348
1394
  }
1349
1395
  function findReturnInBlock(block, env) {
1396
+ var _a, _b, _c, _d;
1350
1397
  const statements = Array.isArray(block.body) ? block.body : [];
1351
1398
  const shadowed = new Map();
1352
1399
  // Block declarations shadow outer bindings from the start of the block: `let` and `const` are
@@ -1355,11 +1402,17 @@ function findReturnInBlock(block, env) {
1355
1402
  ...blockScopedNames(statements),
1356
1403
  ...declaredFunctionNames(statements),
1357
1404
  ]);
1405
+ const shadowedJsx = new Map();
1358
1406
  for (const name of localNames) {
1359
1407
  shadowed.set(name, env.scope.has(name) ? { value: env.scope.get(name) } : undefined);
1408
+ const outerJsx = (_a = env.jsxLocals) === null || _a === void 0 ? void 0 : _a.get(name);
1409
+ if (outerJsx !== undefined)
1410
+ shadowedJsx.set(name, outerJsx);
1360
1411
  }
1361
- for (const name of localNames)
1412
+ for (const name of localNames) {
1362
1413
  env.scope.delete(name);
1414
+ (_b = env.jsxLocals) === null || _b === void 0 ? void 0 : _b.delete(name);
1415
+ }
1363
1416
  const nested = findReturnInStatements(statements, env);
1364
1417
  if (nested !== undefined)
1365
1418
  return nested;
@@ -1368,6 +1421,11 @@ function findReturnInBlock(block, env) {
1368
1421
  env.scope.delete(name);
1369
1422
  else
1370
1423
  env.scope.set(name, previous.value);
1424
+ const previousJsx = shadowedJsx.get(name);
1425
+ if (previousJsx === undefined)
1426
+ (_c = env.jsxLocals) === null || _c === void 0 ? void 0 : _c.delete(name);
1427
+ else
1428
+ (_d = env.jsxLocals) === null || _d === void 0 ? void 0 : _d.set(name, previousJsx);
1371
1429
  }
1372
1430
  return undefined;
1373
1431
  }
@@ -1381,9 +1439,10 @@ const STRAIGHT_LINE_STATEMENTS = new Set([
1381
1439
  ]);
1382
1440
  function findReturnExpression(body, env) {
1383
1441
  var _a;
1442
+ var _b;
1384
1443
  const type = nodeType(body);
1385
1444
  if (type === 'ReturnStatement' && isObject(body))
1386
- return (_a = body.argument) !== null && _a !== void 0 ? _a : null;
1445
+ return (_b = body.argument) !== null && _b !== void 0 ? _b : null;
1387
1446
  if (type === 'IfStatement')
1388
1447
  return findReturnInStatements([body], env);
1389
1448
  if (type !== undefined && type !== 'BlockStatement')
@@ -1398,15 +1457,20 @@ function findReturnExpression(body, env) {
1398
1457
  ...blockScopedNames(body.body),
1399
1458
  ...hoistedVarNames(body.body),
1400
1459
  ];
1401
- for (const name of localNames)
1460
+ for (const name of localNames) {
1402
1461
  env.scope.delete(name);
1462
+ (_a = env.jsxLocals) === null || _a === void 0 ? void 0 : _a.delete(name);
1463
+ }
1403
1464
  return findReturnInStatements(body.body, env);
1404
1465
  }
1405
1466
  /** Anything a statement assigns or writes through, even inside callbacks, is no longer known. */
1406
1467
  function unbindWrites(statement, env) {
1468
+ var _a;
1407
1469
  const { reassigned, mutated } = collectModuleWrites(statement);
1408
- for (const name of reassigned)
1470
+ for (const name of reassigned) {
1409
1471
  env.scope.delete(name);
1472
+ (_a = env.jsxLocals) === null || _a === void 0 ? void 0 : _a.delete(name);
1473
+ }
1410
1474
  for (const name of mutated)
1411
1475
  env.scope.delete(name);
1412
1476
  }
@@ -1502,6 +1566,7 @@ function bindComponentScope(paramInfo, base, props, failedProps, childrenMarkdow
1502
1566
  declaredNames,
1503
1567
  childrenName: paramInfo.childrenName,
1504
1568
  markdownChildren,
1569
+ jsxLocals: new Map(),
1505
1570
  };
1506
1571
  // Supplied children are bound first, so later parameter defaults can read them
1507
1572
  if (childrenMarkdown !== '')