@mintlify/common 1.0.1338 → 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 &&
|
|
@@ -1062,6 +1077,7 @@ function setKnownProp(props, failed, name, value) {
|
|
|
1062
1077
|
if (name !== FAILED_SPREAD)
|
|
1063
1078
|
failed === null || failed === void 0 ? void 0 : failed.delete(name);
|
|
1064
1079
|
}
|
|
1080
|
+
const JSX_PROP_SLOT_NONCE = `${Math.random().toString(36).slice(2)}${Math.random().toString(36).slice(2)}`;
|
|
1065
1081
|
let nextJsxPropSlot = 0;
|
|
1066
1082
|
function jsxValueExpression(expression) {
|
|
1067
1083
|
let value = expression;
|
|
@@ -1075,7 +1091,7 @@ function jsxValueExpression(expression) {
|
|
|
1075
1091
|
: undefined;
|
|
1076
1092
|
}
|
|
1077
1093
|
function slotJsxProp(props, failed, name, markdown, slots) {
|
|
1078
|
-
const placeholder = `\uE000${nextJsxPropSlot++}\uE000`;
|
|
1094
|
+
const placeholder = `\uE000${JSX_PROP_SLOT_NONCE}:${nextJsxPropSlot++}\uE000`;
|
|
1079
1095
|
slots.set(placeholder, markdown);
|
|
1080
1096
|
setKnownProp(props, failed, name, placeholder);
|
|
1081
1097
|
}
|
|
@@ -1097,6 +1113,8 @@ export function slotJsxUsageProps(node, ctx, props, failed) {
|
|
|
1097
1113
|
return slots;
|
|
1098
1114
|
}
|
|
1099
1115
|
function slotJsxStaticProps(node, ctx, props, failed) {
|
|
1116
|
+
var _a;
|
|
1117
|
+
var _b;
|
|
1100
1118
|
const slots = new Map();
|
|
1101
1119
|
for (const attribute of jsxAttributes(node)) {
|
|
1102
1120
|
if (attribute.type !== 'JSXAttribute')
|
|
@@ -1107,7 +1125,9 @@ function slotJsxStaticProps(node, ctx, props, failed) {
|
|
|
1107
1125
|
if (!failed.has(attrName.name))
|
|
1108
1126
|
continue;
|
|
1109
1127
|
const value = attribute.value;
|
|
1110
|
-
const
|
|
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);
|
|
1111
1131
|
if (expression === undefined)
|
|
1112
1132
|
continue;
|
|
1113
1133
|
const markdown = serializeJsxExpression(expression, ctx).trim();
|
|
@@ -1284,8 +1304,35 @@ function analyzeParams(params) {
|
|
|
1284
1304
|
return { bindings, childrenName, propsObjectName, restName, unknownNames };
|
|
1285
1305
|
}
|
|
1286
1306
|
function bindDeclarator(declarator, env) {
|
|
1307
|
+
var _a, _b;
|
|
1287
1308
|
if (nodeType(declarator) !== 'VariableDeclarator' || !isObject(declarator))
|
|
1288
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
|
+
}
|
|
1289
1336
|
const evaluated = evaluateStatic(declarator.init, env);
|
|
1290
1337
|
if (evaluated.ok)
|
|
1291
1338
|
bindPattern(declarator.id, evaluated.value, env);
|
|
@@ -1346,6 +1393,7 @@ function hoistedVarNames(node, names = new Set()) {
|
|
|
1346
1393
|
return names;
|
|
1347
1394
|
}
|
|
1348
1395
|
function findReturnInBlock(block, env) {
|
|
1396
|
+
var _a, _b, _c, _d;
|
|
1349
1397
|
const statements = Array.isArray(block.body) ? block.body : [];
|
|
1350
1398
|
const shadowed = new Map();
|
|
1351
1399
|
// Block declarations shadow outer bindings from the start of the block: `let` and `const` are
|
|
@@ -1354,11 +1402,17 @@ function findReturnInBlock(block, env) {
|
|
|
1354
1402
|
...blockScopedNames(statements),
|
|
1355
1403
|
...declaredFunctionNames(statements),
|
|
1356
1404
|
]);
|
|
1405
|
+
const shadowedJsx = new Map();
|
|
1357
1406
|
for (const name of localNames) {
|
|
1358
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);
|
|
1359
1411
|
}
|
|
1360
|
-
for (const name of localNames)
|
|
1412
|
+
for (const name of localNames) {
|
|
1361
1413
|
env.scope.delete(name);
|
|
1414
|
+
(_b = env.jsxLocals) === null || _b === void 0 ? void 0 : _b.delete(name);
|
|
1415
|
+
}
|
|
1362
1416
|
const nested = findReturnInStatements(statements, env);
|
|
1363
1417
|
if (nested !== undefined)
|
|
1364
1418
|
return nested;
|
|
@@ -1367,6 +1421,11 @@ function findReturnInBlock(block, env) {
|
|
|
1367
1421
|
env.scope.delete(name);
|
|
1368
1422
|
else
|
|
1369
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);
|
|
1370
1429
|
}
|
|
1371
1430
|
return undefined;
|
|
1372
1431
|
}
|
|
@@ -1380,9 +1439,10 @@ const STRAIGHT_LINE_STATEMENTS = new Set([
|
|
|
1380
1439
|
]);
|
|
1381
1440
|
function findReturnExpression(body, env) {
|
|
1382
1441
|
var _a;
|
|
1442
|
+
var _b;
|
|
1383
1443
|
const type = nodeType(body);
|
|
1384
1444
|
if (type === 'ReturnStatement' && isObject(body))
|
|
1385
|
-
return (
|
|
1445
|
+
return (_b = body.argument) !== null && _b !== void 0 ? _b : null;
|
|
1386
1446
|
if (type === 'IfStatement')
|
|
1387
1447
|
return findReturnInStatements([body], env);
|
|
1388
1448
|
if (type !== undefined && type !== 'BlockStatement')
|
|
@@ -1397,15 +1457,20 @@ function findReturnExpression(body, env) {
|
|
|
1397
1457
|
...blockScopedNames(body.body),
|
|
1398
1458
|
...hoistedVarNames(body.body),
|
|
1399
1459
|
];
|
|
1400
|
-
for (const name of localNames)
|
|
1460
|
+
for (const name of localNames) {
|
|
1401
1461
|
env.scope.delete(name);
|
|
1462
|
+
(_a = env.jsxLocals) === null || _a === void 0 ? void 0 : _a.delete(name);
|
|
1463
|
+
}
|
|
1402
1464
|
return findReturnInStatements(body.body, env);
|
|
1403
1465
|
}
|
|
1404
1466
|
/** Anything a statement assigns or writes through, even inside callbacks, is no longer known. */
|
|
1405
1467
|
function unbindWrites(statement, env) {
|
|
1468
|
+
var _a;
|
|
1406
1469
|
const { reassigned, mutated } = collectModuleWrites(statement);
|
|
1407
|
-
for (const name of reassigned)
|
|
1470
|
+
for (const name of reassigned) {
|
|
1408
1471
|
env.scope.delete(name);
|
|
1472
|
+
(_a = env.jsxLocals) === null || _a === void 0 ? void 0 : _a.delete(name);
|
|
1473
|
+
}
|
|
1409
1474
|
for (const name of mutated)
|
|
1410
1475
|
env.scope.delete(name);
|
|
1411
1476
|
}
|
|
@@ -1501,6 +1566,7 @@ function bindComponentScope(paramInfo, base, props, failedProps, childrenMarkdow
|
|
|
1501
1566
|
declaredNames,
|
|
1502
1567
|
childrenName: paramInfo.childrenName,
|
|
1503
1568
|
markdownChildren,
|
|
1569
|
+
jsxLocals: new Map(),
|
|
1504
1570
|
};
|
|
1505
1571
|
// Supplied children are bound first, so later parameter defaults can read them
|
|
1506
1572
|
if (childrenMarkdown !== '')
|