@formspec/build 0.1.0-alpha.58 → 0.1.0-alpha.59
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.
- package/dist/analyzer/builtin-brands.d.ts +10 -7
- package/dist/analyzer/builtin-brands.d.ts.map +1 -1
- package/dist/analyzer/class-analyzer.d.ts +29 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +126 -31
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +129 -32
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +431 -12
- package/dist/build-beta.d.ts +399 -12
- package/dist/build-internal.d.ts +460 -12
- package/dist/build.d.ts +399 -12
- package/dist/cli.cjs +590 -338
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +547 -289
- package/dist/cli.js.map +1 -1
- package/dist/extensions/registry.d.ts +19 -1
- package/dist/extensions/registry.d.ts.map +1 -1
- package/dist/extensions/resolve-custom-type.d.ts.map +1 -1
- package/dist/extensions/ts-type-utils.d.ts +0 -11
- package/dist/extensions/ts-type-utils.d.ts.map +1 -1
- package/dist/generators/class-schema.d.ts.map +1 -1
- package/dist/index.cjs +580 -327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +546 -287
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +554 -301
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +515 -256
- package/dist/internals.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1053,7 +1053,7 @@ function generateJsonSchemaFromIR(ir, options) {
|
|
|
1053
1053
|
applyConstraints(ctx.defs[schemaName], typeDef.constraints, ctx);
|
|
1054
1054
|
}
|
|
1055
1055
|
if (typeDef.annotations && typeDef.annotations.length > 0) {
|
|
1056
|
-
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx);
|
|
1056
|
+
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx, typeDef.type);
|
|
1057
1057
|
}
|
|
1058
1058
|
}
|
|
1059
1059
|
const properties = {};
|
|
@@ -1126,7 +1126,7 @@ function generateFieldSchema(field, ctx) {
|
|
|
1126
1126
|
}
|
|
1127
1127
|
}
|
|
1128
1128
|
applyResolvedMetadata(schema, field.metadata);
|
|
1129
|
-
applyAnnotations(schema, rootAnnotations, ctx);
|
|
1129
|
+
applyAnnotations(schema, rootAnnotations, ctx, field.type);
|
|
1130
1130
|
if (itemStringSchema !== void 0) {
|
|
1131
1131
|
applyAnnotations(itemStringSchema, itemAnnotations, ctx);
|
|
1132
1132
|
}
|
|
@@ -1169,32 +1169,36 @@ function applyPathTargetedConstraints(schema, pathConstraints, ctx, typeNode) {
|
|
|
1169
1169
|
return schema;
|
|
1170
1170
|
}
|
|
1171
1171
|
if (schema.$ref) {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
properties: propertyOverrides,
|
|
1176
|
-
...rest
|
|
1172
|
+
return {
|
|
1173
|
+
...schema,
|
|
1174
|
+
properties: propertyOverrides
|
|
1177
1175
|
};
|
|
1178
|
-
return { allOf: [refPart, overridePart] };
|
|
1179
1176
|
}
|
|
1180
1177
|
if (schema.type === "object" && schema.properties) {
|
|
1181
|
-
const missingOverrides = {};
|
|
1182
1178
|
for (const [target, overrideSchema] of Object.entries(propertyOverrides)) {
|
|
1183
|
-
if (schema.properties
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1179
|
+
if (Object.hasOwn(schema.properties, target)) {
|
|
1180
|
+
const existing = schema.properties[target];
|
|
1181
|
+
if (existing) {
|
|
1182
|
+
mergeSchemaOverride(existing, overrideSchema);
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1187
1185
|
}
|
|
1186
|
+
Object.defineProperty(schema.properties, target, {
|
|
1187
|
+
value: overrideSchema,
|
|
1188
|
+
writable: true,
|
|
1189
|
+
enumerable: true,
|
|
1190
|
+
configurable: true
|
|
1191
|
+
});
|
|
1188
1192
|
}
|
|
1189
|
-
|
|
1190
|
-
return schema;
|
|
1191
|
-
}
|
|
1192
|
-
return {
|
|
1193
|
-
allOf: [schema, { properties: missingOverrides }]
|
|
1194
|
-
};
|
|
1193
|
+
return schema;
|
|
1195
1194
|
}
|
|
1196
1195
|
if (schema.allOf) {
|
|
1197
|
-
|
|
1196
|
+
const overrideMember = { properties: propertyOverrides };
|
|
1197
|
+
const flattened = tryFlattenAllOfToSiblings(schema, overrideMember);
|
|
1198
|
+
if (flattened !== void 0) {
|
|
1199
|
+
return flattened;
|
|
1200
|
+
}
|
|
1201
|
+
schema.allOf = [...schema.allOf, overrideMember];
|
|
1198
1202
|
return schema;
|
|
1199
1203
|
}
|
|
1200
1204
|
return schema;
|
|
@@ -1307,7 +1311,7 @@ function generatePropertySchema(prop, ctx) {
|
|
|
1307
1311
|
const schema = generateTypeNode(prop.type, ctx);
|
|
1308
1312
|
applyConstraints(schema, prop.constraints, ctx);
|
|
1309
1313
|
applyResolvedMetadata(schema, prop.metadata);
|
|
1310
|
-
applyAnnotations(schema, prop.annotations, ctx);
|
|
1314
|
+
applyAnnotations(schema, prop.annotations, ctx, prop.type);
|
|
1311
1315
|
return schema;
|
|
1312
1316
|
}
|
|
1313
1317
|
function generateUnionType(type, ctx) {
|
|
@@ -1410,13 +1414,20 @@ function buildPropertyOverrides(pathConstraints, typeNode, ctx) {
|
|
|
1410
1414
|
grouped.push(constraint);
|
|
1411
1415
|
byTarget.set(target, grouped);
|
|
1412
1416
|
}
|
|
1413
|
-
const overrides =
|
|
1417
|
+
const overrides = /* @__PURE__ */ Object.create(null);
|
|
1414
1418
|
for (const [target, constraints] of byTarget) {
|
|
1415
|
-
|
|
1419
|
+
const resolvedName = resolveSerializedPropertyName(target, typeNode, ctx);
|
|
1420
|
+
const schema = buildPathOverrideSchema(
|
|
1416
1421
|
constraints.map(stripLeadingPathSegment),
|
|
1417
1422
|
resolveTargetTypeNode(target, typeNode, ctx),
|
|
1418
1423
|
ctx
|
|
1419
1424
|
);
|
|
1425
|
+
Object.defineProperty(overrides, resolvedName, {
|
|
1426
|
+
value: schema,
|
|
1427
|
+
writable: true,
|
|
1428
|
+
enumerable: true,
|
|
1429
|
+
configurable: true
|
|
1430
|
+
});
|
|
1420
1431
|
}
|
|
1421
1432
|
return overrides;
|
|
1422
1433
|
}
|
|
@@ -1443,6 +1454,34 @@ function buildPathOverrideSchema(constraints, typeNode, ctx) {
|
|
|
1443
1454
|
schema.properties = buildPropertyOverrides(nestedConstraints, effectiveType, ctx);
|
|
1444
1455
|
return schema;
|
|
1445
1456
|
}
|
|
1457
|
+
function tryFlattenAllOfToSiblings(schema, overrideMember) {
|
|
1458
|
+
if (schema.allOf?.length !== 1) {
|
|
1459
|
+
return void 0;
|
|
1460
|
+
}
|
|
1461
|
+
const [soleMember] = schema.allOf;
|
|
1462
|
+
if (soleMember === void 0) {
|
|
1463
|
+
return void 0;
|
|
1464
|
+
}
|
|
1465
|
+
const { allOf: _allOf, ...outerRest } = schema;
|
|
1466
|
+
const outerKeys = new Set(Object.keys(outerRest));
|
|
1467
|
+
const memberKeys = new Set(Object.keys(soleMember));
|
|
1468
|
+
const overrideKeys = new Set(Object.keys(overrideMember));
|
|
1469
|
+
for (const key of memberKeys) {
|
|
1470
|
+
if (outerKeys.has(key) || overrideKeys.has(key)) {
|
|
1471
|
+
return void 0;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
for (const key of overrideKeys) {
|
|
1475
|
+
if (outerKeys.has(key)) {
|
|
1476
|
+
return void 0;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
return {
|
|
1480
|
+
...outerRest,
|
|
1481
|
+
...soleMember,
|
|
1482
|
+
...overrideMember
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1446
1485
|
function mergeSchemaOverride(target, override) {
|
|
1447
1486
|
const nullableValueBranch = getNullableUnionValueSchema(target);
|
|
1448
1487
|
if (nullableValueBranch !== void 0) {
|
|
@@ -1450,11 +1489,16 @@ function mergeSchemaOverride(target, override) {
|
|
|
1450
1489
|
return;
|
|
1451
1490
|
}
|
|
1452
1491
|
if (override.properties !== void 0) {
|
|
1453
|
-
const mergedProperties = target.properties ??
|
|
1492
|
+
const mergedProperties = target.properties ?? /* @__PURE__ */ Object.create(null);
|
|
1454
1493
|
for (const [name, propertyOverride] of Object.entries(override.properties)) {
|
|
1455
|
-
const existing = mergedProperties[name];
|
|
1494
|
+
const existing = Object.hasOwn(mergedProperties, name) ? mergedProperties[name] : void 0;
|
|
1456
1495
|
if (existing === void 0) {
|
|
1457
|
-
mergedProperties
|
|
1496
|
+
Object.defineProperty(mergedProperties, name, {
|
|
1497
|
+
value: propertyOverride,
|
|
1498
|
+
writable: true,
|
|
1499
|
+
enumerable: true,
|
|
1500
|
+
configurable: true
|
|
1501
|
+
});
|
|
1458
1502
|
} else {
|
|
1459
1503
|
mergeSchemaOverride(existing, propertyOverride);
|
|
1460
1504
|
}
|
|
@@ -1472,7 +1516,12 @@ function mergeSchemaOverride(target, override) {
|
|
|
1472
1516
|
if (key === "properties" || key === "items") {
|
|
1473
1517
|
continue;
|
|
1474
1518
|
}
|
|
1475
|
-
target
|
|
1519
|
+
Object.defineProperty(target, key, {
|
|
1520
|
+
value,
|
|
1521
|
+
writable: true,
|
|
1522
|
+
enumerable: true,
|
|
1523
|
+
configurable: true
|
|
1524
|
+
});
|
|
1476
1525
|
}
|
|
1477
1526
|
}
|
|
1478
1527
|
function stripLeadingPathSegment(constraint) {
|
|
@@ -1572,7 +1621,7 @@ function applyConstraints(schema, constraints, ctx) {
|
|
|
1572
1621
|
}
|
|
1573
1622
|
}
|
|
1574
1623
|
}
|
|
1575
|
-
function applyAnnotations(schema, annotations, ctx) {
|
|
1624
|
+
function applyAnnotations(schema, annotations, ctx, typeNode) {
|
|
1576
1625
|
for (const annotation of annotations) {
|
|
1577
1626
|
switch (annotation.annotationKind) {
|
|
1578
1627
|
case "displayName":
|
|
@@ -1585,7 +1634,7 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
1585
1634
|
schema[`${ctx.vendorPrefix}-remarks`] = annotation.value;
|
|
1586
1635
|
break;
|
|
1587
1636
|
case "defaultValue":
|
|
1588
|
-
schema.default = annotation.value;
|
|
1637
|
+
schema.default = coerceDefaultValue(annotation.value, typeNode, schema, ctx);
|
|
1589
1638
|
break;
|
|
1590
1639
|
case "format":
|
|
1591
1640
|
schema.format = annotation.value;
|
|
@@ -1610,6 +1659,34 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
1610
1659
|
}
|
|
1611
1660
|
}
|
|
1612
1661
|
}
|
|
1662
|
+
function coerceDefaultValue(value, typeNode, emittedSchema, ctx) {
|
|
1663
|
+
if (typeNode?.kind !== "custom") {
|
|
1664
|
+
return value;
|
|
1665
|
+
}
|
|
1666
|
+
const registration = ctx.extensionRegistry?.findType(typeNode.typeId);
|
|
1667
|
+
if (registration === void 0) {
|
|
1668
|
+
return value;
|
|
1669
|
+
}
|
|
1670
|
+
if (registration.serializeDefault !== void 0) {
|
|
1671
|
+
return registration.serializeDefault(value, typeNode.payload);
|
|
1672
|
+
}
|
|
1673
|
+
const declaredType = emittedSchema["type"];
|
|
1674
|
+
if (declaredType === "string" && typeof value !== "string") {
|
|
1675
|
+
if (typeof value === "number") {
|
|
1676
|
+
if (!Number.isFinite(value)) {
|
|
1677
|
+
return value;
|
|
1678
|
+
}
|
|
1679
|
+
return String(value);
|
|
1680
|
+
}
|
|
1681
|
+
if (typeof value === "boolean") {
|
|
1682
|
+
return String(value);
|
|
1683
|
+
}
|
|
1684
|
+
if (typeof value === "bigint") {
|
|
1685
|
+
return value.toString();
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
return value;
|
|
1689
|
+
}
|
|
1613
1690
|
function generateCustomType(type, ctx) {
|
|
1614
1691
|
const registration = ctx.extensionRegistry?.findType(type.typeId);
|
|
1615
1692
|
if (registration === void 0) {
|
|
@@ -2039,6 +2116,16 @@ function buildConstraintTagSources(extensions) {
|
|
|
2039
2116
|
constraintTags: extension.constraintTags.map((tag) => ({
|
|
2040
2117
|
tagName: (0, import_internal.normalizeFormSpecTagName)(tag.tagName)
|
|
2041
2118
|
}))
|
|
2119
|
+
} : {},
|
|
2120
|
+
// Include customTypes so _validateExtensionSetup can check tsTypeNames for
|
|
2121
|
+
// unsupported built-in overrides and invalid identifier patterns.
|
|
2122
|
+
...extension.types !== void 0 ? {
|
|
2123
|
+
customTypes: extension.types.map((type) => ({
|
|
2124
|
+
// tsTypeNames: deprecated in favour of symbol-based detection, but
|
|
2125
|
+
// still required for name-based validation in _validateExtensionSetup
|
|
2126
|
+
// until the bridge is fully retired (see §synthetic-checker-retirement §4C).
|
|
2127
|
+
tsTypeNames: type.tsTypeNames ?? [type.typeName]
|
|
2128
|
+
}))
|
|
2042
2129
|
} : {}
|
|
2043
2130
|
}));
|
|
2044
2131
|
}
|
|
@@ -2048,7 +2135,13 @@ function createExtensionRegistry(extensions) {
|
|
|
2048
2135
|
extensionCount: extensions.length,
|
|
2049
2136
|
extensionIds: extensions.map((e) => e.extensionId)
|
|
2050
2137
|
});
|
|
2051
|
-
const
|
|
2138
|
+
const extensionTagSources = buildConstraintTagSources(extensions);
|
|
2139
|
+
const setupDiagnostics = (0, import_internal._validateExtensionSetup)(extensionTagSources);
|
|
2140
|
+
(0, import_internal.logSetupDiagnostics)(registryLog, {
|
|
2141
|
+
diagnosticCount: setupDiagnostics.length,
|
|
2142
|
+
codes: setupDiagnostics.map((d) => d.kind)
|
|
2143
|
+
});
|
|
2144
|
+
const reservedTagSources = extensionTagSources;
|
|
2052
2145
|
let symbolMap = /* @__PURE__ */ new Map();
|
|
2053
2146
|
const typeMap = /* @__PURE__ */ new Map();
|
|
2054
2147
|
const typeNameMap = /* @__PURE__ */ new Map();
|
|
@@ -2185,10 +2278,12 @@ function createExtensionRegistry(extensions) {
|
|
|
2185
2278
|
constraintTagCount: constraintTagMap.size,
|
|
2186
2279
|
broadeningCount: builtinBroadeningMap.size,
|
|
2187
2280
|
annotationCount: annotationMap.size,
|
|
2188
|
-
metadataSlotCount: metadataSlotMap.size
|
|
2281
|
+
metadataSlotCount: metadataSlotMap.size,
|
|
2282
|
+
setupDiagnosticCount: setupDiagnostics.length
|
|
2189
2283
|
});
|
|
2190
2284
|
return {
|
|
2191
2285
|
extensions,
|
|
2286
|
+
setupDiagnostics,
|
|
2192
2287
|
findType: (typeId) => typeMap.get(typeId),
|
|
2193
2288
|
findTypeByName: (typeName) => typeNameMap.get(typeName),
|
|
2194
2289
|
findTypeByBrand: (brand) => brandMap.get(brand),
|
|
@@ -2266,22 +2361,22 @@ var jsonSchema7Schema = import_zod3.z.lazy(
|
|
|
2266
2361
|
);
|
|
2267
2362
|
|
|
2268
2363
|
// src/generators/class-schema.ts
|
|
2269
|
-
var
|
|
2364
|
+
var ts8 = __toESM(require("typescript"), 1);
|
|
2270
2365
|
|
|
2271
2366
|
// src/analyzer/program.ts
|
|
2272
|
-
var
|
|
2367
|
+
var ts6 = __toESM(require("typescript"), 1);
|
|
2273
2368
|
var path = __toESM(require("path"), 1);
|
|
2274
2369
|
|
|
2275
2370
|
// src/analyzer/class-analyzer.ts
|
|
2276
|
-
var
|
|
2277
|
-
var
|
|
2371
|
+
var ts5 = __toESM(require("typescript"), 1);
|
|
2372
|
+
var import_internal6 = require("@formspec/analysis/internal");
|
|
2278
2373
|
|
|
2279
2374
|
// src/analyzer/jsdoc-constraints.ts
|
|
2280
|
-
var
|
|
2375
|
+
var ts4 = __toESM(require("typescript"), 1);
|
|
2281
2376
|
|
|
2282
2377
|
// src/analyzer/tsdoc-parser.ts
|
|
2283
|
-
var
|
|
2284
|
-
var
|
|
2378
|
+
var ts3 = __toESM(require("typescript"), 1);
|
|
2379
|
+
var import_internal4 = require("@formspec/analysis/internal");
|
|
2285
2380
|
var import_internals4 = require("@formspec/core/internals");
|
|
2286
2381
|
var import_internals5 = require("@formspec/core/internals");
|
|
2287
2382
|
var import_core3 = require("@formspec/core");
|
|
@@ -2292,21 +2387,6 @@ var import_internal2 = require("@formspec/analysis/internal");
|
|
|
2292
2387
|
|
|
2293
2388
|
// src/extensions/ts-type-utils.ts
|
|
2294
2389
|
var ts = __toESM(require("typescript"), 1);
|
|
2295
|
-
function collectBrandIdentifiers(type) {
|
|
2296
|
-
if (!type.isIntersection()) {
|
|
2297
|
-
return [];
|
|
2298
|
-
}
|
|
2299
|
-
const brands = [];
|
|
2300
|
-
for (const prop of type.getProperties()) {
|
|
2301
|
-
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
2302
|
-
if (decl === void 0) continue;
|
|
2303
|
-
if (!ts.isPropertySignature(decl) && !ts.isPropertyDeclaration(decl)) continue;
|
|
2304
|
-
if (!ts.isComputedPropertyName(decl.name)) continue;
|
|
2305
|
-
if (!ts.isIdentifier(decl.name.expression)) continue;
|
|
2306
|
-
brands.push(decl.name.expression.text);
|
|
2307
|
-
}
|
|
2308
|
-
return brands;
|
|
2309
|
-
}
|
|
2310
2390
|
function resolveCanonicalSymbol(type, checker) {
|
|
2311
2391
|
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
2312
2392
|
if (raw === void 0) return void 0;
|
|
@@ -2391,7 +2471,7 @@ function resolveCustomTypeFromTsType(type, checker, registry, sourceNode) {
|
|
|
2391
2471
|
return bySymbol;
|
|
2392
2472
|
}
|
|
2393
2473
|
}
|
|
2394
|
-
for (const brand of
|
|
2474
|
+
for (const brand of (0, import_internal2._collectBrandIdentifiers)(stripped)) {
|
|
2395
2475
|
const byBrand = registry.findTypeByBrand(brand);
|
|
2396
2476
|
if (byBrand !== void 0) {
|
|
2397
2477
|
return byBrand;
|
|
@@ -2404,22 +2484,17 @@ function customTypeIdFromLookup(result) {
|
|
|
2404
2484
|
}
|
|
2405
2485
|
|
|
2406
2486
|
// src/analyzer/builtin-brands.ts
|
|
2407
|
-
var
|
|
2408
|
-
function isIntegerBrandedType(type) {
|
|
2409
|
-
if (!type.isIntersection()) return false;
|
|
2410
|
-
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2411
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2412
|
-
}
|
|
2487
|
+
var import_internal3 = require("@formspec/analysis/internal");
|
|
2413
2488
|
|
|
2414
2489
|
// src/analyzer/tsdoc-parser.ts
|
|
2415
|
-
var
|
|
2490
|
+
var import_internal5 = require("@formspec/analysis/internal");
|
|
2416
2491
|
function sharedTagValueOptions(options) {
|
|
2417
2492
|
return {
|
|
2418
2493
|
...options?.extensionRegistry !== void 0 ? { registry: options.extensionRegistry } : {},
|
|
2419
2494
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2420
2495
|
};
|
|
2421
2496
|
}
|
|
2422
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
2497
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2423
2498
|
function getExtensionTypeNames(registry) {
|
|
2424
2499
|
if (registry === void 0) {
|
|
2425
2500
|
return /* @__PURE__ */ new Set();
|
|
@@ -2433,23 +2508,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2433
2508
|
function collectImportedNames(sourceFile) {
|
|
2434
2509
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2435
2510
|
for (const statement of sourceFile.statements) {
|
|
2436
|
-
if (
|
|
2511
|
+
if (ts3.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2437
2512
|
const clause = statement.importClause;
|
|
2438
2513
|
if (clause.name !== void 0) {
|
|
2439
2514
|
importedNames.add(clause.name.text);
|
|
2440
2515
|
}
|
|
2441
2516
|
if (clause.namedBindings !== void 0) {
|
|
2442
|
-
if (
|
|
2517
|
+
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
2443
2518
|
for (const specifier of clause.namedBindings.elements) {
|
|
2444
2519
|
importedNames.add(specifier.name.text);
|
|
2445
2520
|
}
|
|
2446
|
-
} else if (
|
|
2521
|
+
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
2447
2522
|
importedNames.add(clause.namedBindings.name.text);
|
|
2448
2523
|
}
|
|
2449
2524
|
}
|
|
2450
2525
|
continue;
|
|
2451
2526
|
}
|
|
2452
|
-
if (
|
|
2527
|
+
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
2453
2528
|
importedNames.add(statement.name.text);
|
|
2454
2529
|
}
|
|
2455
2530
|
}
|
|
@@ -2457,13 +2532,13 @@ function collectImportedNames(sourceFile) {
|
|
|
2457
2532
|
}
|
|
2458
2533
|
function isNonReferenceIdentifier(node) {
|
|
2459
2534
|
const parent = node.parent;
|
|
2460
|
-
if ((
|
|
2535
|
+
if ((ts3.isBindingElement(parent) || ts3.isClassDeclaration(parent) || ts3.isEnumDeclaration(parent) || ts3.isEnumMember(parent) || ts3.isFunctionDeclaration(parent) || ts3.isFunctionExpression(parent) || ts3.isImportClause(parent) || ts3.isImportEqualsDeclaration(parent) || ts3.isImportSpecifier(parent) || ts3.isInterfaceDeclaration(parent) || ts3.isMethodDeclaration(parent) || ts3.isMethodSignature(parent) || ts3.isModuleDeclaration(parent) || ts3.isNamespaceExport(parent) || ts3.isNamespaceImport(parent) || ts3.isParameter(parent) || ts3.isPropertyDeclaration(parent) || ts3.isPropertySignature(parent) || ts3.isSetAccessorDeclaration(parent) || ts3.isGetAccessorDeclaration(parent) || ts3.isTypeAliasDeclaration(parent) || ts3.isTypeParameterDeclaration(parent) || ts3.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2461
2536
|
return true;
|
|
2462
2537
|
}
|
|
2463
|
-
if ((
|
|
2538
|
+
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2464
2539
|
return true;
|
|
2465
2540
|
}
|
|
2466
|
-
if (
|
|
2541
|
+
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
2467
2542
|
return true;
|
|
2468
2543
|
}
|
|
2469
2544
|
return false;
|
|
@@ -2475,20 +2550,20 @@ function astReferencesImportedName(root, importedNames) {
|
|
|
2475
2550
|
let found = false;
|
|
2476
2551
|
const visit = (node) => {
|
|
2477
2552
|
if (found) return;
|
|
2478
|
-
if (
|
|
2553
|
+
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2479
2554
|
found = true;
|
|
2480
2555
|
return;
|
|
2481
2556
|
}
|
|
2482
|
-
|
|
2557
|
+
ts3.forEachChild(node, visit);
|
|
2483
2558
|
};
|
|
2484
2559
|
visit(root);
|
|
2485
2560
|
return found;
|
|
2486
2561
|
}
|
|
2487
2562
|
function getObjectMembers(statement) {
|
|
2488
|
-
if (
|
|
2563
|
+
if (ts3.isInterfaceDeclaration(statement)) {
|
|
2489
2564
|
return statement.members;
|
|
2490
2565
|
}
|
|
2491
|
-
if (
|
|
2566
|
+
if (ts3.isTypeLiteralNode(statement.type)) {
|
|
2492
2567
|
return statement.type.members;
|
|
2493
2568
|
}
|
|
2494
2569
|
return void 0;
|
|
@@ -2500,7 +2575,7 @@ function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
|
2500
2575
|
}
|
|
2501
2576
|
const replacements = [];
|
|
2502
2577
|
for (const member of members) {
|
|
2503
|
-
if (!
|
|
2578
|
+
if (!ts3.isPropertySignature(member)) {
|
|
2504
2579
|
if (astReferencesImportedName(member, importedNames)) {
|
|
2505
2580
|
return null;
|
|
2506
2581
|
}
|
|
@@ -2532,14 +2607,14 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
2532
2607
|
);
|
|
2533
2608
|
const result = [];
|
|
2534
2609
|
for (const statement of sourceFile.statements) {
|
|
2535
|
-
if (
|
|
2536
|
-
if (
|
|
2537
|
-
if (
|
|
2610
|
+
if (ts3.isImportDeclaration(statement)) continue;
|
|
2611
|
+
if (ts3.isImportEqualsDeclaration(statement)) continue;
|
|
2612
|
+
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2538
2613
|
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2539
2614
|
result.push(statement.getText(sourceFile));
|
|
2540
2615
|
continue;
|
|
2541
2616
|
}
|
|
2542
|
-
if (
|
|
2617
|
+
if (ts3.isInterfaceDeclaration(statement) || ts3.isTypeAliasDeclaration(statement)) {
|
|
2543
2618
|
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2544
2619
|
if (rewritten !== null) {
|
|
2545
2620
|
result.push(rewritten);
|
|
@@ -2573,7 +2648,7 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
2573
2648
|
pushUniqueCompilerDiagnostics(diagnostics, compilerDiagnostics);
|
|
2574
2649
|
return;
|
|
2575
2650
|
}
|
|
2576
|
-
const constraintNode = (0,
|
|
2651
|
+
const constraintNode = (0, import_internal4.parseConstraintTagValue)(
|
|
2577
2652
|
tagName,
|
|
2578
2653
|
text,
|
|
2579
2654
|
provenance,
|
|
@@ -2626,12 +2701,12 @@ function supportsConstraintCapability(type, checker, capability) {
|
|
|
2626
2701
|
if (capability === void 0) {
|
|
2627
2702
|
return true;
|
|
2628
2703
|
}
|
|
2629
|
-
if ((0,
|
|
2704
|
+
if ((0, import_internal4.hasTypeSemanticCapability)(type, checker, capability)) {
|
|
2630
2705
|
return true;
|
|
2631
2706
|
}
|
|
2632
2707
|
if (capability === "string-like") {
|
|
2633
2708
|
const itemType = getArrayElementType(type, checker);
|
|
2634
|
-
return itemType !== null && (0,
|
|
2709
|
+
return itemType !== null && (0, import_internal4.hasTypeSemanticCapability)(itemType, checker, capability);
|
|
2635
2710
|
}
|
|
2636
2711
|
return false;
|
|
2637
2712
|
}
|
|
@@ -2642,7 +2717,7 @@ function stripHintNullishUnion(type) {
|
|
|
2642
2717
|
return type;
|
|
2643
2718
|
}
|
|
2644
2719
|
const nonNullish = type.types.filter(
|
|
2645
|
-
(member) => (member.flags & (
|
|
2720
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
2646
2721
|
);
|
|
2647
2722
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2648
2723
|
return nonNullish[0];
|
|
@@ -2658,10 +2733,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2658
2733
|
}
|
|
2659
2734
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2660
2735
|
const name = declaration.name;
|
|
2661
|
-
if (
|
|
2736
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
2662
2737
|
return false;
|
|
2663
2738
|
}
|
|
2664
|
-
if (!
|
|
2739
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
2665
2740
|
return false;
|
|
2666
2741
|
}
|
|
2667
2742
|
}
|
|
@@ -2677,7 +2752,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2677
2752
|
if (isCallableType(stripped)) {
|
|
2678
2753
|
return;
|
|
2679
2754
|
}
|
|
2680
|
-
if (!(0,
|
|
2755
|
+
if (!(0, import_internal4.hasTypeSemanticCapability)(stripped, checker, "object-like")) {
|
|
2681
2756
|
return;
|
|
2682
2757
|
}
|
|
2683
2758
|
for (const property of stripped.getProperties()) {
|
|
@@ -2695,7 +2770,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2695
2770
|
continue;
|
|
2696
2771
|
}
|
|
2697
2772
|
const strippedPropertyType = stripHintNullishUnion(propertyType);
|
|
2698
|
-
if (!isCallableType(strippedPropertyType) && (0,
|
|
2773
|
+
if (!isCallableType(strippedPropertyType) && (0, import_internal4.hasTypeSemanticCapability)(strippedPropertyType, checker, "object-like")) {
|
|
2699
2774
|
visit(strippedPropertyType, path4, depth + 1);
|
|
2700
2775
|
}
|
|
2701
2776
|
}
|
|
@@ -2704,7 +2779,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2704
2779
|
return out;
|
|
2705
2780
|
}
|
|
2706
2781
|
function buildPathTargetHint(subjectType, checker, capability, tagName, argumentText) {
|
|
2707
|
-
if (!(0,
|
|
2782
|
+
if (!(0, import_internal4.hasTypeSemanticCapability)(subjectType, checker, "object-like")) {
|
|
2708
2783
|
return null;
|
|
2709
2784
|
}
|
|
2710
2785
|
const candidates = collectObjectSubfieldCandidates(subjectType, checker, capability);
|
|
@@ -2815,24 +2890,24 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2815
2890
|
if (checker === void 0 || subjectType === void 0) {
|
|
2816
2891
|
return [];
|
|
2817
2892
|
}
|
|
2818
|
-
const placement = (0,
|
|
2893
|
+
const placement = (0, import_internal4.resolveDeclarationPlacement)(node);
|
|
2819
2894
|
if (placement === null) {
|
|
2820
2895
|
return [];
|
|
2821
2896
|
}
|
|
2822
|
-
const definition = (0,
|
|
2897
|
+
const definition = (0, import_internal4.getTagDefinition)(tagName, options?.extensionRegistry?.extensions);
|
|
2823
2898
|
if (definition === null) {
|
|
2824
2899
|
return [];
|
|
2825
2900
|
}
|
|
2826
2901
|
const nonNullPlacement = placement;
|
|
2827
|
-
const log = (0,
|
|
2828
|
-
const broadeningLog = (0,
|
|
2829
|
-
const syntheticLog = (0,
|
|
2830
|
-
const typedParserLog = (0,
|
|
2902
|
+
const log = (0, import_internal5.getBuildLogger)();
|
|
2903
|
+
const broadeningLog = (0, import_internal5.getBroadeningLogger)();
|
|
2904
|
+
const syntheticLog = (0, import_internal5.getSyntheticLogger)();
|
|
2905
|
+
const typedParserLog = (0, import_internal5.getTypedParserLogger)();
|
|
2831
2906
|
const logsEnabled = log !== import_core3.noopLogger || broadeningLog !== import_core3.noopLogger;
|
|
2832
2907
|
const syntheticTraceEnabled = syntheticLog !== import_core3.noopLogger;
|
|
2833
2908
|
const typedParserTraceEnabled = typedParserLog !== import_core3.noopLogger;
|
|
2834
|
-
const logStart = logsEnabled ? (0,
|
|
2835
|
-
const subjectTypeKind = logsEnabled ? (0,
|
|
2909
|
+
const logStart = logsEnabled ? (0, import_internal5.nowMicros)() : 0;
|
|
2910
|
+
const subjectTypeKind = logsEnabled ? (0, import_internal5.describeTypeKind)(subjectType, checker) : "";
|
|
2836
2911
|
function emit(outcome, result2) {
|
|
2837
2912
|
if (!logsEnabled) {
|
|
2838
2913
|
return result2;
|
|
@@ -2843,11 +2918,11 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2843
2918
|
placement: nonNullPlacement,
|
|
2844
2919
|
subjectTypeKind,
|
|
2845
2920
|
roleOutcome: outcome,
|
|
2846
|
-
elapsedMicros: (0,
|
|
2921
|
+
elapsedMicros: (0, import_internal5.elapsedMicros)(logStart)
|
|
2847
2922
|
};
|
|
2848
|
-
(0,
|
|
2923
|
+
(0, import_internal5.logTagApplication)(log, entry);
|
|
2849
2924
|
if (outcome === "bypass" || outcome === "D1" || outcome === "D2") {
|
|
2850
|
-
(0,
|
|
2925
|
+
(0, import_internal5.logTagApplication)(broadeningLog, entry);
|
|
2851
2926
|
}
|
|
2852
2927
|
return result2;
|
|
2853
2928
|
}
|
|
@@ -2882,7 +2957,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2882
2957
|
)
|
|
2883
2958
|
]);
|
|
2884
2959
|
}
|
|
2885
|
-
const resolution = (0,
|
|
2960
|
+
const resolution = (0, import_internal4.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
2886
2961
|
if (resolution.kind === "missing-property") {
|
|
2887
2962
|
return emit("B-reject", [
|
|
2888
2963
|
makeDiagnostic(
|
|
@@ -2907,7 +2982,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2907
2982
|
}
|
|
2908
2983
|
const hasBroadening = (() => {
|
|
2909
2984
|
if (target === null) {
|
|
2910
|
-
if (
|
|
2985
|
+
if ((0, import_internal3._isIntegerBrandedType)((0, import_internal4.stripNullishUnion)(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2911
2986
|
return true;
|
|
2912
2987
|
}
|
|
2913
2988
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
@@ -2938,11 +3013,11 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2938
3013
|
]);
|
|
2939
3014
|
}
|
|
2940
3015
|
}
|
|
2941
|
-
const effectiveArgumentText = parsedTag !== null ? (0, import_internal3.parseTagSyntax)(tagName, rawText).argumentText : rawText;
|
|
2942
3016
|
if (hasBroadening) {
|
|
2943
3017
|
return emit("bypass", []);
|
|
2944
3018
|
}
|
|
2945
|
-
const
|
|
3019
|
+
const effectiveArgumentText = (0, import_internal5.extractEffectiveArgumentText)(tagName, rawText, parsedTag);
|
|
3020
|
+
const typedParseResult = (0, import_internal5.parseTagArgument)(tagName, effectiveArgumentText, "build");
|
|
2946
3021
|
if (!typedParseResult.ok) {
|
|
2947
3022
|
if (typedParserTraceEnabled) {
|
|
2948
3023
|
typedParserLog.trace("typed-parser C-reject", {
|
|
@@ -2954,23 +3029,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2954
3029
|
diagnosticCode: typedParseResult.diagnostic.code
|
|
2955
3030
|
});
|
|
2956
3031
|
}
|
|
2957
|
-
|
|
2958
|
-
switch (typedParseResult.diagnostic.code) {
|
|
2959
|
-
case "MISSING_TAG_ARGUMENT":
|
|
2960
|
-
mappedCode = "MISSING_TAG_ARGUMENT";
|
|
2961
|
-
break;
|
|
2962
|
-
case "INVALID_TAG_ARGUMENT":
|
|
2963
|
-
mappedCode = "INVALID_TAG_ARGUMENT";
|
|
2964
|
-
break;
|
|
2965
|
-
case "UNKNOWN_TAG":
|
|
2966
|
-
throw new Error(
|
|
2967
|
-
`Unexpected UNKNOWN_TAG from parseTagArgument("${tagName}") \u2014 tag was resolved via getTagDefinition.`
|
|
2968
|
-
);
|
|
2969
|
-
default: {
|
|
2970
|
-
const _exhaustive = typedParseResult.diagnostic.code;
|
|
2971
|
-
throw new Error(`Unknown diagnostic code: ${String(_exhaustive)}`);
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
3032
|
+
const mappedCode = (0, import_internal5.mapTypedParserDiagnosticCode)(typedParseResult.diagnostic.code, tagName);
|
|
2974
3033
|
return emit("C-reject", [
|
|
2975
3034
|
makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
|
|
2976
3035
|
]);
|
|
@@ -3001,7 +3060,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3001
3060
|
subjectTypeText
|
|
3002
3061
|
});
|
|
3003
3062
|
}
|
|
3004
|
-
const result = (0,
|
|
3063
|
+
const result = (0, import_internal4.checkSyntheticTagApplication)({
|
|
3005
3064
|
tagName,
|
|
3006
3065
|
placement,
|
|
3007
3066
|
hostType: hostTypeText,
|
|
@@ -3027,13 +3086,13 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3027
3086
|
} : {}
|
|
3028
3087
|
});
|
|
3029
3088
|
if (result.diagnostics.length === 0) {
|
|
3030
|
-
return emit("
|
|
3089
|
+
return emit("D-pass", []);
|
|
3031
3090
|
}
|
|
3032
3091
|
const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
|
|
3033
3092
|
if (setupDiagnostic !== void 0) {
|
|
3034
3093
|
return emit("C-reject", [
|
|
3035
3094
|
makeDiagnostic(
|
|
3036
|
-
setupDiagnostic.kind
|
|
3095
|
+
(0, import_internal5._mapSetupDiagnosticCode)(setupDiagnostic.kind),
|
|
3037
3096
|
setupDiagnostic.message,
|
|
3038
3097
|
provenance
|
|
3039
3098
|
)
|
|
@@ -3052,10 +3111,10 @@ var parseResultCache = /* @__PURE__ */ new Map();
|
|
|
3052
3111
|
function getExtensionTagNames(options) {
|
|
3053
3112
|
return [
|
|
3054
3113
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
3055
|
-
(extension) => (extension.constraintTags ?? []).map((tag) => (0,
|
|
3114
|
+
(extension) => (extension.constraintTags ?? []).map((tag) => (0, import_internal4.normalizeFormSpecTagName)(tag.tagName))
|
|
3056
3115
|
) ?? [],
|
|
3057
3116
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
3058
|
-
(extension) => (extension.metadataSlots ?? []).map((slot) => (0,
|
|
3117
|
+
(extension) => (extension.metadataSlots ?? []).map((slot) => (0, import_internal4.normalizeFormSpecTagName)(slot.tagName))
|
|
3059
3118
|
) ?? []
|
|
3060
3119
|
].sort();
|
|
3061
3120
|
}
|
|
@@ -3067,9 +3126,9 @@ function getExtensionRegistryCacheKey(registry) {
|
|
|
3067
3126
|
(extension) => JSON.stringify({
|
|
3068
3127
|
extensionId: extension.extensionId,
|
|
3069
3128
|
typeNames: extension.types?.map((type) => type.typeName) ?? [],
|
|
3070
|
-
constraintTags: extension.constraintTags?.map((tag) => (0,
|
|
3129
|
+
constraintTags: extension.constraintTags?.map((tag) => (0, import_internal4.normalizeFormSpecTagName)(tag.tagName)) ?? [],
|
|
3071
3130
|
metadataSlots: extension.metadataSlots?.map((slot) => ({
|
|
3072
|
-
tagName: (0,
|
|
3131
|
+
tagName: (0, import_internal4.normalizeFormSpecTagName)(slot.tagName),
|
|
3073
3132
|
declarationKinds: [...slot.declarationKinds].sort(),
|
|
3074
3133
|
allowBare: slot.allowBare !== false,
|
|
3075
3134
|
qualifiers: (slot.qualifiers ?? []).map((qualifier) => ({
|
|
@@ -3101,6 +3160,16 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3101
3160
|
if (cached !== void 0) {
|
|
3102
3161
|
return cached;
|
|
3103
3162
|
}
|
|
3163
|
+
const setupDiags = options?.extensionRegistry?.setupDiagnostics;
|
|
3164
|
+
if (setupDiags !== void 0 && setupDiags.length > 0) {
|
|
3165
|
+
const result2 = {
|
|
3166
|
+
constraints: [],
|
|
3167
|
+
annotations: [],
|
|
3168
|
+
diagnostics: (0, import_internal5._emitSetupDiagnostics)(setupDiags, file)
|
|
3169
|
+
};
|
|
3170
|
+
parseResultCache.set(cacheKey, result2);
|
|
3171
|
+
return result2;
|
|
3172
|
+
}
|
|
3104
3173
|
const constraints = [];
|
|
3105
3174
|
const annotations = [];
|
|
3106
3175
|
const diagnostics = [];
|
|
@@ -3112,12 +3181,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3112
3181
|
const sourceText = sourceFile.getFullText();
|
|
3113
3182
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
3114
3183
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
3115
|
-
const commentRanges =
|
|
3184
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3116
3185
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
3117
3186
|
const extensionTagNames = getExtensionTagNames(options);
|
|
3118
3187
|
if (commentRanges) {
|
|
3119
3188
|
for (const range of commentRanges) {
|
|
3120
|
-
if (range.kind !==
|
|
3189
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
3121
3190
|
continue;
|
|
3122
3191
|
}
|
|
3123
3192
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3125,7 +3194,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3125
3194
|
continue;
|
|
3126
3195
|
}
|
|
3127
3196
|
const extensions = options?.extensionRegistry?.extensions;
|
|
3128
|
-
const unified = (0,
|
|
3197
|
+
const unified = (0, import_internal4.parseUnifiedComment)(commentText, {
|
|
3129
3198
|
offset: range.pos,
|
|
3130
3199
|
extensionTagNames,
|
|
3131
3200
|
...extensions !== void 0 ? { extensions } : {}
|
|
@@ -3160,13 +3229,13 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3160
3229
|
}
|
|
3161
3230
|
continue;
|
|
3162
3231
|
}
|
|
3163
|
-
if (
|
|
3232
|
+
if (import_internal4.TAGS_REQUIRING_RAW_TEXT.has(tagName)) {
|
|
3164
3233
|
const fallback = rawTextFallbacks.get(tagName)?.shift();
|
|
3165
|
-
const text2 = (0,
|
|
3234
|
+
const text2 = (0, import_internal4.choosePreferredPayloadText)(tag.resolvedPayloadText, fallback?.text ?? "");
|
|
3166
3235
|
if (text2 === "") continue;
|
|
3167
3236
|
const provenance2 = provenanceForParsedTag(tag, sourceFile, file);
|
|
3168
3237
|
if (tagName === "defaultValue") {
|
|
3169
|
-
annotations.push((0,
|
|
3238
|
+
annotations.push((0, import_internal4.parseDefaultValueTagValue)(text2, provenance2));
|
|
3170
3239
|
continue;
|
|
3171
3240
|
}
|
|
3172
3241
|
processConstraintTag(
|
|
@@ -3248,7 +3317,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3248
3317
|
if (text === "") continue;
|
|
3249
3318
|
const provenance = fallback.provenance;
|
|
3250
3319
|
if (tagName === "defaultValue") {
|
|
3251
|
-
annotations.push((0,
|
|
3320
|
+
annotations.push((0, import_internal4.parseDefaultValueTagValue)(text, provenance));
|
|
3252
3321
|
continue;
|
|
3253
3322
|
}
|
|
3254
3323
|
processConstraintTag(
|
|
@@ -3274,13 +3343,13 @@ function extractDisplayNameMetadata(node) {
|
|
|
3274
3343
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3275
3344
|
const sourceFile = node.getSourceFile();
|
|
3276
3345
|
const sourceText = sourceFile.getFullText();
|
|
3277
|
-
const commentRanges =
|
|
3346
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3278
3347
|
if (commentRanges) {
|
|
3279
3348
|
for (const range of commentRanges) {
|
|
3280
|
-
if (range.kind !==
|
|
3349
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3281
3350
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3282
3351
|
if (!commentText.startsWith("/**")) continue;
|
|
3283
|
-
const unified = (0,
|
|
3352
|
+
const unified = (0, import_internal4.parseUnifiedComment)(commentText);
|
|
3284
3353
|
for (const tag of unified.tags) {
|
|
3285
3354
|
if (tag.normalizedTagName !== "displayName") {
|
|
3286
3355
|
continue;
|
|
@@ -3302,9 +3371,9 @@ function extractDisplayNameMetadata(node) {
|
|
|
3302
3371
|
}
|
|
3303
3372
|
function collectRawTextFallbacks(node, file) {
|
|
3304
3373
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3305
|
-
for (const tag of
|
|
3374
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
3306
3375
|
const tagName = (0, import_internals4.normalizeConstraintTagName)(tag.tagName.text);
|
|
3307
|
-
if (!
|
|
3376
|
+
if (!import_internal4.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3308
3377
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
3309
3378
|
if (commentText === "") continue;
|
|
3310
3379
|
const entries = fallbacks.get(tagName) ?? [];
|
|
@@ -3317,7 +3386,7 @@ function collectRawTextFallbacks(node, file) {
|
|
|
3317
3386
|
return fallbacks;
|
|
3318
3387
|
}
|
|
3319
3388
|
function isMemberTargetDisplayName(text) {
|
|
3320
|
-
return (0,
|
|
3389
|
+
return (0, import_internal4.parseTagSyntax)("displayName", text).target !== null;
|
|
3321
3390
|
}
|
|
3322
3391
|
function provenanceForComment(range, sourceFile, file, tagName) {
|
|
3323
3392
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);
|
|
@@ -3357,7 +3426,7 @@ function getTagCommentText(tag) {
|
|
|
3357
3426
|
if (typeof tag.comment === "string") {
|
|
3358
3427
|
return tag.comment;
|
|
3359
3428
|
}
|
|
3360
|
-
return
|
|
3429
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
3361
3430
|
}
|
|
3362
3431
|
|
|
3363
3432
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3375,18 +3444,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3375
3444
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3376
3445
|
if (!initializer) return null;
|
|
3377
3446
|
let value;
|
|
3378
|
-
if (
|
|
3447
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
3379
3448
|
value = initializer.text;
|
|
3380
|
-
} else if (
|
|
3449
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
3381
3450
|
value = Number(initializer.text);
|
|
3382
|
-
} else if (initializer.kind ===
|
|
3451
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
3383
3452
|
value = true;
|
|
3384
|
-
} else if (initializer.kind ===
|
|
3453
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
3385
3454
|
value = false;
|
|
3386
|
-
} else if (initializer.kind ===
|
|
3455
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
3387
3456
|
value = null;
|
|
3388
|
-
} else if (
|
|
3389
|
-
if (initializer.operator ===
|
|
3457
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
3458
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
3390
3459
|
value = -Number(initializer.operand.text);
|
|
3391
3460
|
}
|
|
3392
3461
|
}
|
|
@@ -3408,28 +3477,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3408
3477
|
|
|
3409
3478
|
// src/analyzer/class-analyzer.ts
|
|
3410
3479
|
function isObjectType(type) {
|
|
3411
|
-
return !!(type.flags &
|
|
3480
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
3412
3481
|
}
|
|
3413
3482
|
function isIntersectionType(type) {
|
|
3414
|
-
return !!(type.flags &
|
|
3483
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
3415
3484
|
}
|
|
3416
3485
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3417
|
-
if (
|
|
3486
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3418
3487
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3419
3488
|
}
|
|
3420
|
-
if (
|
|
3489
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
3421
3490
|
return true;
|
|
3422
3491
|
}
|
|
3423
|
-
return
|
|
3492
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3424
3493
|
}
|
|
3425
3494
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3426
3495
|
if (isIntersectionType(type)) {
|
|
3427
3496
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3428
3497
|
}
|
|
3429
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3498
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts5.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts5.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
3430
3499
|
}
|
|
3431
3500
|
function isTypeReference(type) {
|
|
3432
|
-
return !!(type.flags &
|
|
3501
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
3433
3502
|
}
|
|
3434
3503
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3435
3504
|
kind: "object",
|
|
@@ -3455,8 +3524,23 @@ function createAnalyzerMetadataPolicy(input, discriminator) {
|
|
|
3455
3524
|
discriminator
|
|
3456
3525
|
};
|
|
3457
3526
|
}
|
|
3527
|
+
var DEDUPLICATABLE_DIAGNOSTIC_CODES = /* @__PURE__ */ new Set([
|
|
3528
|
+
"SYNTHETIC_SETUP_FAILURE",
|
|
3529
|
+
"UNSUPPORTED_CUSTOM_TYPE_OVERRIDE"
|
|
3530
|
+
]);
|
|
3531
|
+
function deduplicateDiagnostics(diagnostics) {
|
|
3532
|
+
if (diagnostics.length <= 1) return diagnostics;
|
|
3533
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3534
|
+
return diagnostics.filter((d) => {
|
|
3535
|
+
if (!DEDUPLICATABLE_DIAGNOSTIC_CODES.has(d.code)) return true;
|
|
3536
|
+
const key = `${d.code}\0${d.message}`;
|
|
3537
|
+
if (seen.has(key)) return false;
|
|
3538
|
+
seen.add(key);
|
|
3539
|
+
return true;
|
|
3540
|
+
});
|
|
3541
|
+
}
|
|
3458
3542
|
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
3459
|
-
const analysis = (0,
|
|
3543
|
+
const analysis = (0, import_internal6.analyzeMetadataForNodeWithChecker)({
|
|
3460
3544
|
checker,
|
|
3461
3545
|
node,
|
|
3462
3546
|
logicalName,
|
|
@@ -3491,10 +3575,121 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3491
3575
|
}
|
|
3492
3576
|
return resolvedMetadata;
|
|
3493
3577
|
}
|
|
3578
|
+
var INHERITABLE_TYPE_ANNOTATION_KINDS = /* @__PURE__ */ new Set(["format"]);
|
|
3579
|
+
function getInheritableAnnotationStringValue(annotation) {
|
|
3580
|
+
if (annotation.annotationKind === "format") return annotation.value;
|
|
3581
|
+
return void 0;
|
|
3582
|
+
}
|
|
3583
|
+
function isOverridingInheritableAnnotation(annotation) {
|
|
3584
|
+
const value = getInheritableAnnotationStringValue(annotation);
|
|
3585
|
+
if (value === void 0) return true;
|
|
3586
|
+
return value.trim().length > 0;
|
|
3587
|
+
}
|
|
3588
|
+
function collectInheritedTypeAnnotations(derivedDecl, existingAnnotations, checker, extensionRegistry) {
|
|
3589
|
+
const existingKinds = new Set(
|
|
3590
|
+
existingAnnotations.filter(isOverridingInheritableAnnotation).map((a) => a.annotationKind)
|
|
3591
|
+
);
|
|
3592
|
+
const needed = /* @__PURE__ */ new Set();
|
|
3593
|
+
for (const kind of INHERITABLE_TYPE_ANNOTATION_KINDS) {
|
|
3594
|
+
if (!existingKinds.has(kind)) needed.add(kind);
|
|
3595
|
+
}
|
|
3596
|
+
if (needed.size === 0) return [];
|
|
3597
|
+
const inherited = [];
|
|
3598
|
+
const seen = /* @__PURE__ */ new Set([derivedDecl]);
|
|
3599
|
+
const queue = [];
|
|
3600
|
+
const resolveSymbolTarget = (sym) => {
|
|
3601
|
+
if ((sym.flags & ts5.SymbolFlags.Alias) === 0) return sym;
|
|
3602
|
+
try {
|
|
3603
|
+
return checker.getAliasedSymbol(sym);
|
|
3604
|
+
} catch {
|
|
3605
|
+
return sym;
|
|
3606
|
+
}
|
|
3607
|
+
};
|
|
3608
|
+
const isObjectShapedTypeAlias = (alias) => {
|
|
3609
|
+
const type = checker.getTypeFromTypeNode(alias.type);
|
|
3610
|
+
if ((type.flags & ts5.TypeFlags.Object) !== 0) return true;
|
|
3611
|
+
if (type.isIntersection()) return true;
|
|
3612
|
+
return false;
|
|
3613
|
+
};
|
|
3614
|
+
const enqueueCandidate = (baseDecl, fromTypeAliasRhs) => {
|
|
3615
|
+
if (seen.has(baseDecl)) return;
|
|
3616
|
+
if (ts5.isClassDeclaration(baseDecl) || ts5.isInterfaceDeclaration(baseDecl)) {
|
|
3617
|
+
seen.add(baseDecl);
|
|
3618
|
+
queue.push(baseDecl);
|
|
3619
|
+
return;
|
|
3620
|
+
}
|
|
3621
|
+
if (ts5.isTypeAliasDeclaration(baseDecl)) {
|
|
3622
|
+
if (!fromTypeAliasRhs && !isObjectShapedTypeAlias(baseDecl)) return;
|
|
3623
|
+
seen.add(baseDecl);
|
|
3624
|
+
queue.push(baseDecl);
|
|
3625
|
+
}
|
|
3626
|
+
};
|
|
3627
|
+
const enqueueBasesOf = (decl) => {
|
|
3628
|
+
if (ts5.isTypeAliasDeclaration(decl)) {
|
|
3629
|
+
const rhs = decl.type;
|
|
3630
|
+
if (!ts5.isTypeReferenceNode(rhs)) return;
|
|
3631
|
+
const sym = checker.getSymbolAtLocation(rhs.typeName);
|
|
3632
|
+
if (!sym) return;
|
|
3633
|
+
const target = resolveSymbolTarget(sym);
|
|
3634
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
3635
|
+
enqueueCandidate(
|
|
3636
|
+
baseDecl,
|
|
3637
|
+
/*fromTypeAliasRhs*/
|
|
3638
|
+
true
|
|
3639
|
+
);
|
|
3640
|
+
}
|
|
3641
|
+
return;
|
|
3642
|
+
}
|
|
3643
|
+
const heritageClauses = decl.heritageClauses;
|
|
3644
|
+
if (!heritageClauses) return;
|
|
3645
|
+
for (const clause of heritageClauses) {
|
|
3646
|
+
if (clause.token !== ts5.SyntaxKind.ExtendsKeyword) continue;
|
|
3647
|
+
for (const typeExpr of clause.types) {
|
|
3648
|
+
const sym = checker.getSymbolAtLocation(typeExpr.expression);
|
|
3649
|
+
if (!sym) continue;
|
|
3650
|
+
const target = resolveSymbolTarget(sym);
|
|
3651
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
3652
|
+
enqueueCandidate(
|
|
3653
|
+
baseDecl,
|
|
3654
|
+
/*fromTypeAliasRhs*/
|
|
3655
|
+
false
|
|
3656
|
+
);
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
};
|
|
3661
|
+
enqueueBasesOf(derivedDecl);
|
|
3662
|
+
for (let queueIndex = 0; queueIndex < queue.length && needed.size > 0; queueIndex++) {
|
|
3663
|
+
const baseDecl = queue[queueIndex];
|
|
3664
|
+
if (baseDecl === void 0) continue;
|
|
3665
|
+
const baseFile = baseDecl.getSourceFile().fileName;
|
|
3666
|
+
const baseAnnotations = extractJSDocAnnotationNodes(
|
|
3667
|
+
baseDecl,
|
|
3668
|
+
baseFile,
|
|
3669
|
+
makeParseOptions(extensionRegistry)
|
|
3670
|
+
);
|
|
3671
|
+
for (const annotation of baseAnnotations) {
|
|
3672
|
+
if (!needed.has(annotation.annotationKind)) continue;
|
|
3673
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
3674
|
+
inherited.push(annotation);
|
|
3675
|
+
needed.delete(annotation.annotationKind);
|
|
3676
|
+
}
|
|
3677
|
+
if (needed.size > 0) {
|
|
3678
|
+
enqueueBasesOf(baseDecl);
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
return inherited;
|
|
3682
|
+
}
|
|
3683
|
+
function extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) {
|
|
3684
|
+
const local = extractJSDocAnnotationNodes(namedDecl, file, makeParseOptions(extensionRegistry));
|
|
3685
|
+
const inherited = collectInheritedTypeAnnotations(namedDecl, local, checker, extensionRegistry);
|
|
3686
|
+
if (inherited.length === 0) return [...local];
|
|
3687
|
+
return [...local, ...inherited];
|
|
3688
|
+
}
|
|
3494
3689
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3495
3690
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3496
3691
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3497
|
-
const logicalName =
|
|
3692
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3498
3693
|
const docResult = extractJSDocParseResult(
|
|
3499
3694
|
declaration,
|
|
3500
3695
|
file,
|
|
@@ -3536,13 +3731,19 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3536
3731
|
file,
|
|
3537
3732
|
makeParseOptions(extensionRegistry, void 0, checker, classType, classType)
|
|
3538
3733
|
);
|
|
3539
|
-
const
|
|
3734
|
+
const inheritedClassAnnotations = collectInheritedTypeAnnotations(
|
|
3735
|
+
classDecl,
|
|
3736
|
+
classDoc.annotations,
|
|
3737
|
+
checker,
|
|
3738
|
+
extensionRegistry
|
|
3739
|
+
);
|
|
3740
|
+
const annotations = [...classDoc.annotations, ...inheritedClassAnnotations];
|
|
3540
3741
|
diagnostics.push(...classDoc.diagnostics);
|
|
3541
3742
|
const visiting = /* @__PURE__ */ new Set();
|
|
3542
3743
|
const instanceMethods = [];
|
|
3543
3744
|
const staticMethods = [];
|
|
3544
3745
|
for (const member of classDecl.members) {
|
|
3545
|
-
if (
|
|
3746
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
3546
3747
|
const fieldNode = analyzeFieldToIR(
|
|
3547
3748
|
member,
|
|
3548
3749
|
checker,
|
|
@@ -3558,10 +3759,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3558
3759
|
fields.push(fieldNode);
|
|
3559
3760
|
fieldLayouts.push({});
|
|
3560
3761
|
}
|
|
3561
|
-
} else if (
|
|
3762
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
3562
3763
|
const methodInfo = analyzeMethod(member, checker);
|
|
3563
3764
|
if (methodInfo) {
|
|
3564
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3765
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
3565
3766
|
if (isStatic) {
|
|
3566
3767
|
staticMethods.push(methodInfo);
|
|
3567
3768
|
} else {
|
|
@@ -3593,6 +3794,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3593
3794
|
hostType: classType
|
|
3594
3795
|
}
|
|
3595
3796
|
);
|
|
3797
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3596
3798
|
return {
|
|
3597
3799
|
name,
|
|
3598
3800
|
...metadata !== void 0 && { metadata },
|
|
@@ -3600,7 +3802,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3600
3802
|
fieldLayouts,
|
|
3601
3803
|
typeRegistry,
|
|
3602
3804
|
...annotations.length > 0 && { annotations },
|
|
3603
|
-
...
|
|
3805
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3604
3806
|
instanceMethods,
|
|
3605
3807
|
staticMethods
|
|
3606
3808
|
};
|
|
@@ -3620,11 +3822,20 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3620
3822
|
file,
|
|
3621
3823
|
makeParseOptions(extensionRegistry, void 0, checker, interfaceType, interfaceType)
|
|
3622
3824
|
);
|
|
3623
|
-
const
|
|
3825
|
+
const inheritedInterfaceAnnotations = collectInheritedTypeAnnotations(
|
|
3826
|
+
interfaceDecl,
|
|
3827
|
+
interfaceDoc.annotations,
|
|
3828
|
+
checker,
|
|
3829
|
+
extensionRegistry
|
|
3830
|
+
);
|
|
3831
|
+
const annotations = [
|
|
3832
|
+
...interfaceDoc.annotations,
|
|
3833
|
+
...inheritedInterfaceAnnotations
|
|
3834
|
+
];
|
|
3624
3835
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3625
3836
|
const visiting = /* @__PURE__ */ new Set();
|
|
3626
3837
|
for (const member of interfaceDecl.members) {
|
|
3627
|
-
if (
|
|
3838
|
+
if (ts5.isPropertySignature(member)) {
|
|
3628
3839
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3629
3840
|
member,
|
|
3630
3841
|
checker,
|
|
@@ -3665,6 +3876,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3665
3876
|
hostType: interfaceType
|
|
3666
3877
|
}
|
|
3667
3878
|
);
|
|
3879
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3668
3880
|
return {
|
|
3669
3881
|
name,
|
|
3670
3882
|
...metadata !== void 0 && { metadata },
|
|
@@ -3672,7 +3884,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3672
3884
|
fieldLayouts,
|
|
3673
3885
|
typeRegistry,
|
|
3674
3886
|
...annotations.length > 0 && { annotations },
|
|
3675
|
-
...
|
|
3887
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3676
3888
|
instanceMethods: [],
|
|
3677
3889
|
staticMethods: []
|
|
3678
3890
|
};
|
|
@@ -3682,7 +3894,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3682
3894
|
if (members === null) {
|
|
3683
3895
|
const sourceFile = typeAlias.getSourceFile();
|
|
3684
3896
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3685
|
-
const kindDesc =
|
|
3897
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3686
3898
|
return {
|
|
3687
3899
|
ok: false,
|
|
3688
3900
|
kind: "not-object-like",
|
|
@@ -3717,7 +3929,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3717
3929
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3718
3930
|
const visiting = /* @__PURE__ */ new Set();
|
|
3719
3931
|
for (const member of members) {
|
|
3720
|
-
if (
|
|
3932
|
+
if (ts5.isPropertySignature(member)) {
|
|
3721
3933
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3722
3934
|
member,
|
|
3723
3935
|
checker,
|
|
@@ -3757,6 +3969,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3757
3969
|
hostType: aliasType
|
|
3758
3970
|
}
|
|
3759
3971
|
);
|
|
3972
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3760
3973
|
return {
|
|
3761
3974
|
ok: true,
|
|
3762
3975
|
analysis: {
|
|
@@ -3766,7 +3979,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3766
3979
|
fieldLayouts: specializedFields.map(() => ({})),
|
|
3767
3980
|
typeRegistry,
|
|
3768
3981
|
...annotations.length > 0 && { annotations },
|
|
3769
|
-
...
|
|
3982
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3770
3983
|
instanceMethods: [],
|
|
3771
3984
|
staticMethods: []
|
|
3772
3985
|
}
|
|
@@ -3784,20 +3997,20 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3784
3997
|
function getLeadingParsedTags(node) {
|
|
3785
3998
|
const sourceFile = node.getSourceFile();
|
|
3786
3999
|
const sourceText = sourceFile.getFullText();
|
|
3787
|
-
const commentRanges =
|
|
4000
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3788
4001
|
if (commentRanges === void 0) {
|
|
3789
4002
|
return [];
|
|
3790
4003
|
}
|
|
3791
4004
|
const parsedTags = [];
|
|
3792
4005
|
for (const range of commentRanges) {
|
|
3793
|
-
if (range.kind !==
|
|
4006
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
3794
4007
|
continue;
|
|
3795
4008
|
}
|
|
3796
4009
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
3797
4010
|
if (!commentText.startsWith("/**")) {
|
|
3798
4011
|
continue;
|
|
3799
4012
|
}
|
|
3800
|
-
parsedTags.push(...(0,
|
|
4013
|
+
parsedTags.push(...(0, import_internal6.parseCommentBlock)(commentText, { offset: range.pos }).tags);
|
|
3801
4014
|
}
|
|
3802
4015
|
return parsedTags;
|
|
3803
4016
|
}
|
|
@@ -3808,19 +4021,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3808
4021
|
return null;
|
|
3809
4022
|
}
|
|
3810
4023
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3811
|
-
(candidate) =>
|
|
4024
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
3812
4025
|
) ?? propertySymbol.declarations?.[0];
|
|
3813
4026
|
return {
|
|
3814
4027
|
declaration,
|
|
3815
4028
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3816
|
-
optional: !!(propertySymbol.flags &
|
|
4029
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3817
4030
|
};
|
|
3818
4031
|
}
|
|
3819
4032
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3820
4033
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3821
4034
|
}
|
|
3822
4035
|
function isNullishSemanticType(type) {
|
|
3823
|
-
if (type.flags & (
|
|
4036
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
3824
4037
|
return true;
|
|
3825
4038
|
}
|
|
3826
4039
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3830,7 +4043,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3830
4043
|
return false;
|
|
3831
4044
|
}
|
|
3832
4045
|
seen.add(type);
|
|
3833
|
-
if (type.flags &
|
|
4046
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
3834
4047
|
return true;
|
|
3835
4048
|
}
|
|
3836
4049
|
if (type.isUnion()) {
|
|
@@ -3843,13 +4056,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3843
4056
|
return false;
|
|
3844
4057
|
}
|
|
3845
4058
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3846
|
-
if (
|
|
4059
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3847
4060
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3848
4061
|
}
|
|
3849
|
-
if (
|
|
4062
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
3850
4063
|
return [...typeNode.members];
|
|
3851
4064
|
}
|
|
3852
|
-
if (
|
|
4065
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
3853
4066
|
const members = [];
|
|
3854
4067
|
for (const intersectionMember of typeNode.types) {
|
|
3855
4068
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -4012,7 +4225,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
4012
4225
|
}
|
|
4013
4226
|
if (propertyType.isUnion()) {
|
|
4014
4227
|
const nonNullMembers = propertyType.types.filter(
|
|
4015
|
-
(member) => !(member.flags & (
|
|
4228
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4016
4229
|
);
|
|
4017
4230
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4018
4231
|
diagnostics.push(
|
|
@@ -4061,13 +4274,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
4061
4274
|
seen.add(type);
|
|
4062
4275
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
4063
4276
|
if (symbol !== void 0) {
|
|
4064
|
-
const aliased = symbol.flags &
|
|
4277
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
4065
4278
|
const targetSymbol = aliased ?? symbol;
|
|
4066
4279
|
const declaration = targetSymbol.declarations?.find(
|
|
4067
|
-
(candidate) =>
|
|
4280
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
4068
4281
|
);
|
|
4069
4282
|
if (declaration !== void 0) {
|
|
4070
|
-
if (
|
|
4283
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
4071
4284
|
return resolveNamedDiscriminatorDeclaration(
|
|
4072
4285
|
checker.getTypeFromTypeNode(declaration.type),
|
|
4073
4286
|
checker,
|
|
@@ -4095,7 +4308,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4095
4308
|
}
|
|
4096
4309
|
if (boundType.isUnion()) {
|
|
4097
4310
|
const nonNullMembers = boundType.types.filter(
|
|
4098
|
-
(member) => !(member.flags & (
|
|
4311
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4099
4312
|
);
|
|
4100
4313
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4101
4314
|
diagnostics.push(
|
|
@@ -4140,7 +4353,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4140
4353
|
return null;
|
|
4141
4354
|
}
|
|
4142
4355
|
function getDeclarationName(node) {
|
|
4143
|
-
if (
|
|
4356
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
4144
4357
|
return node.name?.text ?? "anonymous";
|
|
4145
4358
|
}
|
|
4146
4359
|
return "anonymous";
|
|
@@ -4195,11 +4408,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4195
4408
|
if (sourceTypeNode === void 0) {
|
|
4196
4409
|
return [];
|
|
4197
4410
|
}
|
|
4198
|
-
const unwrapParentheses = (typeNode) =>
|
|
4411
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4199
4412
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4200
|
-
const referenceTypeNode =
|
|
4413
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4201
4414
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4202
|
-
return
|
|
4415
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4203
4416
|
})();
|
|
4204
4417
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4205
4418
|
return [];
|
|
@@ -4207,7 +4420,7 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4207
4420
|
return referenceTypeNode.typeArguments.map((argumentNode) => {
|
|
4208
4421
|
const argumentType = checker.getTypeFromTypeNode(argumentNode);
|
|
4209
4422
|
const baseSymbol = argumentType.aliasSymbol ?? argumentType.getSymbol();
|
|
4210
|
-
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags &
|
|
4423
|
+
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(baseSymbol) : baseSymbol;
|
|
4211
4424
|
const argumentDecl = argumentSymbol?.declarations?.[0];
|
|
4212
4425
|
if (argumentDecl !== void 0 && argumentDecl.getSourceFile().fileName !== file) {
|
|
4213
4426
|
const argumentName = argumentSymbol?.getName() ?? baseSymbol?.getName();
|
|
@@ -4270,7 +4483,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4270
4483
|
);
|
|
4271
4484
|
}
|
|
4272
4485
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4273
|
-
if (!
|
|
4486
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
4274
4487
|
return null;
|
|
4275
4488
|
}
|
|
4276
4489
|
const name = prop.name.text;
|
|
@@ -4397,7 +4610,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4397
4610
|
const seen = /* @__PURE__ */ new Set();
|
|
4398
4611
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4399
4612
|
for (const member of members) {
|
|
4400
|
-
if (!
|
|
4613
|
+
if (!ts5.isPropertySignature(member)) {
|
|
4401
4614
|
continue;
|
|
4402
4615
|
}
|
|
4403
4616
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4413,7 +4626,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4413
4626
|
return [...duplicates].sort();
|
|
4414
4627
|
}
|
|
4415
4628
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4416
|
-
if (
|
|
4629
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
4417
4630
|
return name.text;
|
|
4418
4631
|
}
|
|
4419
4632
|
return null;
|
|
@@ -4508,28 +4721,28 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4508
4721
|
if (primitiveAlias) {
|
|
4509
4722
|
return primitiveAlias;
|
|
4510
4723
|
}
|
|
4511
|
-
if (
|
|
4724
|
+
if ((0, import_internal3._isIntegerBrandedType)(type)) {
|
|
4512
4725
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4513
4726
|
}
|
|
4514
|
-
if (type.flags &
|
|
4727
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4515
4728
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4516
4729
|
}
|
|
4517
|
-
if (type.flags &
|
|
4730
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4518
4731
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4519
4732
|
}
|
|
4520
|
-
if (type.flags & (
|
|
4733
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4521
4734
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4522
4735
|
}
|
|
4523
|
-
if (type.flags &
|
|
4736
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4524
4737
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4525
4738
|
}
|
|
4526
|
-
if (type.flags &
|
|
4739
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4527
4740
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4528
4741
|
}
|
|
4529
|
-
if (type.flags &
|
|
4742
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
4530
4743
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4531
4744
|
}
|
|
4532
|
-
if (type.flags &
|
|
4745
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
4533
4746
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4534
4747
|
}
|
|
4535
4748
|
if (type.isStringLiteral()) {
|
|
@@ -4616,10 +4829,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4616
4829
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4617
4830
|
}
|
|
4618
4831
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4619
|
-
if (!(type.flags & (
|
|
4832
|
+
if (!(type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null)) && !(0, import_internal3._isIntegerBrandedType)(type)) {
|
|
4620
4833
|
return null;
|
|
4621
4834
|
}
|
|
4622
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4835
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4623
4836
|
if (!aliasDecl) {
|
|
4624
4837
|
return null;
|
|
4625
4838
|
}
|
|
@@ -4630,11 +4843,18 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4630
4843
|
...extractJSDocConstraintNodes(aliasDecl, file, makeParseOptions(extensionRegistry)),
|
|
4631
4844
|
...extractTypeAliasConstraintNodes(aliasDecl.type, checker, file, extensionRegistry)
|
|
4632
4845
|
];
|
|
4633
|
-
const
|
|
4846
|
+
const localAnnotations = extractJSDocAnnotationNodes(
|
|
4634
4847
|
aliasDecl,
|
|
4635
4848
|
file,
|
|
4636
4849
|
makeParseOptions(extensionRegistry)
|
|
4637
4850
|
);
|
|
4851
|
+
const inheritedAnnotations = collectInheritedTypeAnnotations(
|
|
4852
|
+
aliasDecl,
|
|
4853
|
+
localAnnotations,
|
|
4854
|
+
checker,
|
|
4855
|
+
extensionRegistry
|
|
4856
|
+
);
|
|
4857
|
+
const annotations = [...localAnnotations, ...inheritedAnnotations];
|
|
4638
4858
|
const metadata = resolveNodeMetadata(
|
|
4639
4859
|
metadataPolicy,
|
|
4640
4860
|
"type",
|
|
@@ -4669,8 +4889,8 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4669
4889
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4670
4890
|
}
|
|
4671
4891
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4672
|
-
const typeNode = sourceNode && (
|
|
4673
|
-
if (!typeNode || !
|
|
4892
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4893
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
4674
4894
|
return void 0;
|
|
4675
4895
|
}
|
|
4676
4896
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4691,7 +4911,7 @@ function resolveNamedTypeWithSourceRecovery(type, sourceNode, checker) {
|
|
|
4691
4911
|
return { typeName: refAliasDecl.name.text, namedDecl: refAliasDecl };
|
|
4692
4912
|
}
|
|
4693
4913
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4694
|
-
if (!
|
|
4914
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
4695
4915
|
return false;
|
|
4696
4916
|
}
|
|
4697
4917
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4699,10 +4919,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4699
4919
|
return false;
|
|
4700
4920
|
}
|
|
4701
4921
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4702
|
-
return !!(resolved.flags & (
|
|
4922
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
4703
4923
|
}
|
|
4704
4924
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4705
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4925
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
4706
4926
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4707
4927
|
visitedAliases.add(nestedAliasDecl);
|
|
4708
4928
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4717,22 +4937,22 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4717
4937
|
visitedAliases
|
|
4718
4938
|
);
|
|
4719
4939
|
}
|
|
4720
|
-
if (
|
|
4940
|
+
if ((0, import_internal3._isIntegerBrandedType)(type)) {
|
|
4721
4941
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4722
4942
|
}
|
|
4723
|
-
if (type.flags &
|
|
4943
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4724
4944
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4725
4945
|
}
|
|
4726
|
-
if (type.flags &
|
|
4946
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4727
4947
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4728
4948
|
}
|
|
4729
|
-
if (type.flags & (
|
|
4949
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4730
4950
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4731
4951
|
}
|
|
4732
|
-
if (type.flags &
|
|
4952
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4733
4953
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4734
4954
|
}
|
|
4735
|
-
if (type.flags &
|
|
4955
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4736
4956
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4737
4957
|
}
|
|
4738
4958
|
return resolveTypeNode(
|
|
@@ -4752,7 +4972,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4752
4972
|
let typeName = null;
|
|
4753
4973
|
let namedDecl;
|
|
4754
4974
|
if (recovered !== null) {
|
|
4755
|
-
const recoveredAliasDecl =
|
|
4975
|
+
const recoveredAliasDecl = ts5.isTypeAliasDeclaration(recovered.namedDecl) ? recovered.namedDecl : void 0;
|
|
4756
4976
|
if (recoveredAliasDecl !== void 0) {
|
|
4757
4977
|
const aliasUnderlyingType = checker.getTypeFromTypeNode(recoveredAliasDecl.type);
|
|
4758
4978
|
const isNonGeneric = recoveredAliasDecl.typeParameters === void 0 || recoveredAliasDecl.typeParameters.length === 0;
|
|
@@ -4774,13 +4994,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4774
4994
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4775
4995
|
);
|
|
4776
4996
|
const nonNullTypes = allTypes.filter(
|
|
4777
|
-
(memberType) => !(memberType.flags & (
|
|
4997
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4778
4998
|
);
|
|
4779
4999
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4780
5000
|
memberType,
|
|
4781
5001
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4782
5002
|
}));
|
|
4783
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
5003
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
4784
5004
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4785
5005
|
if (namedDecl) {
|
|
4786
5006
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4800,7 +5020,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4800
5020
|
if (existing !== void 0 && existing.type !== RESOLVING_TYPE_PLACEHOLDER) {
|
|
4801
5021
|
return { kind: "reference", name: typeName, typeArguments: [] };
|
|
4802
5022
|
}
|
|
4803
|
-
const annotations = namedDecl ?
|
|
5023
|
+
const annotations = namedDecl ? extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) : void 0;
|
|
4804
5024
|
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4805
5025
|
metadataPolicy,
|
|
4806
5026
|
"type",
|
|
@@ -4827,7 +5047,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4827
5047
|
const displayName = memberDisplayNames.get(String(value));
|
|
4828
5048
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4829
5049
|
});
|
|
4830
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
5050
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
4831
5051
|
if (isBooleanUnion2) {
|
|
4832
5052
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4833
5053
|
const result = hasNull ? {
|
|
@@ -4919,7 +5139,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4919
5139
|
if (type.getProperties().length > 0) {
|
|
4920
5140
|
return null;
|
|
4921
5141
|
}
|
|
4922
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
5142
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
4923
5143
|
if (!indexInfo) {
|
|
4924
5144
|
return null;
|
|
4925
5145
|
}
|
|
@@ -4967,20 +5187,53 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4967
5187
|
}
|
|
4968
5188
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4969
5189
|
const name = declaration.name;
|
|
4970
|
-
if (
|
|
5190
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
4971
5191
|
return false;
|
|
4972
5192
|
}
|
|
4973
|
-
if (!
|
|
5193
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
4974
5194
|
return false;
|
|
4975
5195
|
}
|
|
4976
5196
|
}
|
|
4977
5197
|
return true;
|
|
4978
5198
|
}
|
|
5199
|
+
function getPassThroughTypeAliasFromSourceNode(sourceNode, checker, extensionRegistry, resolvedTypeName) {
|
|
5200
|
+
const aliasDecl = getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
5201
|
+
if (!aliasDecl) return void 0;
|
|
5202
|
+
const aliasName = aliasDecl.name.text;
|
|
5203
|
+
if (aliasName === resolvedTypeName) return void 0;
|
|
5204
|
+
if (!ts5.isTypeReferenceNode(aliasDecl.type)) return void 0;
|
|
5205
|
+
if (!hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry)) {
|
|
5206
|
+
return void 0;
|
|
5207
|
+
}
|
|
5208
|
+
return { aliasName, aliasDecl };
|
|
5209
|
+
}
|
|
5210
|
+
function hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry) {
|
|
5211
|
+
const file = aliasDecl.getSourceFile().fileName;
|
|
5212
|
+
const local = extractJSDocAnnotationNodes(aliasDecl, file, makeParseOptions(extensionRegistry));
|
|
5213
|
+
for (const annotation of local) {
|
|
5214
|
+
if (!INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) continue;
|
|
5215
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
5216
|
+
return true;
|
|
5217
|
+
}
|
|
5218
|
+
const inherited = collectInheritedTypeAnnotations(aliasDecl, local, checker, extensionRegistry);
|
|
5219
|
+
for (const annotation of inherited) {
|
|
5220
|
+
if (INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) return true;
|
|
5221
|
+
}
|
|
5222
|
+
return false;
|
|
5223
|
+
}
|
|
4979
5224
|
function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4980
5225
|
const collectedDiagnostics = diagnostics ?? [];
|
|
4981
5226
|
const typeName = getNamedTypeName(type);
|
|
4982
5227
|
const namedTypeName = typeName ?? void 0;
|
|
4983
5228
|
const namedDecl = getNamedTypeDeclaration(type);
|
|
5229
|
+
const passThroughAlias = getPassThroughTypeAliasFromSourceNode(
|
|
5230
|
+
sourceNode,
|
|
5231
|
+
checker,
|
|
5232
|
+
extensionRegistry,
|
|
5233
|
+
namedTypeName
|
|
5234
|
+
);
|
|
5235
|
+
const effectiveTypeName = passThroughAlias?.aliasName ?? namedTypeName;
|
|
5236
|
+
const effectiveNamedDecl = passThroughAlias?.aliasDecl ?? namedDecl;
|
|
4984
5237
|
const referenceTypeArguments = extractReferenceTypeArguments(
|
|
4985
5238
|
type,
|
|
4986
5239
|
checker,
|
|
@@ -4992,13 +5245,13 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4992
5245
|
extensionRegistry,
|
|
4993
5246
|
collectedDiagnostics
|
|
4994
5247
|
);
|
|
4995
|
-
const instantiatedTypeName =
|
|
4996
|
-
|
|
5248
|
+
const instantiatedTypeName = effectiveTypeName !== void 0 && referenceTypeArguments.length > 0 ? buildInstantiatedReferenceName(
|
|
5249
|
+
effectiveTypeName,
|
|
4997
5250
|
referenceTypeArguments.map((argument) => argument.tsType),
|
|
4998
5251
|
checker
|
|
4999
5252
|
) : void 0;
|
|
5000
|
-
const registryTypeName = instantiatedTypeName ??
|
|
5001
|
-
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" &&
|
|
5253
|
+
const registryTypeName = instantiatedTypeName ?? effectiveTypeName;
|
|
5254
|
+
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" && effectiveNamedDecl?.getSourceFile().fileName !== file);
|
|
5002
5255
|
const clearNamedTypeRegistration = () => {
|
|
5003
5256
|
if (registryTypeName === void 0 || !shouldRegisterNamedType) {
|
|
5004
5257
|
return;
|
|
@@ -5019,7 +5272,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5019
5272
|
typeRegistry[registryTypeName] = {
|
|
5020
5273
|
name: registryTypeName,
|
|
5021
5274
|
type: RESOLVING_TYPE_PLACEHOLDER,
|
|
5022
|
-
provenance: provenanceForDeclaration(
|
|
5275
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5023
5276
|
};
|
|
5024
5277
|
}
|
|
5025
5278
|
visiting.add(type);
|
|
@@ -5051,17 +5304,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5051
5304
|
clearNamedTypeRegistration();
|
|
5052
5305
|
return recordNode;
|
|
5053
5306
|
}
|
|
5054
|
-
const annotations =
|
|
5055
|
-
const metadata =
|
|
5307
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5308
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
5056
5309
|
metadataPolicy,
|
|
5057
5310
|
"type",
|
|
5058
5311
|
registryTypeName,
|
|
5059
|
-
|
|
5312
|
+
effectiveNamedDecl,
|
|
5060
5313
|
checker,
|
|
5061
5314
|
extensionRegistry,
|
|
5062
5315
|
{
|
|
5063
5316
|
checker,
|
|
5064
|
-
declaration:
|
|
5317
|
+
declaration: effectiveNamedDecl,
|
|
5065
5318
|
subjectType: type
|
|
5066
5319
|
}
|
|
5067
5320
|
) : void 0;
|
|
@@ -5070,7 +5323,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5070
5323
|
...metadata !== void 0 && { metadata },
|
|
5071
5324
|
type: recordNode,
|
|
5072
5325
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5073
|
-
provenance: provenanceForDeclaration(
|
|
5326
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5074
5327
|
};
|
|
5075
5328
|
return {
|
|
5076
5329
|
kind: "reference",
|
|
@@ -5096,7 +5349,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5096
5349
|
if (!declaration) continue;
|
|
5097
5350
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
5098
5351
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
5099
|
-
const optional = !!(prop.flags &
|
|
5352
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
5100
5353
|
const propTypeNode = resolveTypeNode(
|
|
5101
5354
|
propType,
|
|
5102
5355
|
checker,
|
|
@@ -5109,7 +5362,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5109
5362
|
collectedDiagnostics
|
|
5110
5363
|
);
|
|
5111
5364
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
5112
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
5365
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
5113
5366
|
declaration,
|
|
5114
5367
|
checker,
|
|
5115
5368
|
file,
|
|
@@ -5119,7 +5372,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5119
5372
|
type,
|
|
5120
5373
|
metadataPolicy,
|
|
5121
5374
|
extensionRegistry
|
|
5122
|
-
) :
|
|
5375
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
5123
5376
|
declaration,
|
|
5124
5377
|
checker,
|
|
5125
5378
|
file,
|
|
@@ -5147,9 +5400,9 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5147
5400
|
visiting.delete(type);
|
|
5148
5401
|
const objectNode = {
|
|
5149
5402
|
kind: "object",
|
|
5150
|
-
properties:
|
|
5403
|
+
properties: effectiveNamedDecl !== void 0 && (ts5.isClassDeclaration(effectiveNamedDecl) || ts5.isInterfaceDeclaration(effectiveNamedDecl) || ts5.isTypeAliasDeclaration(effectiveNamedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
5151
5404
|
properties,
|
|
5152
|
-
|
|
5405
|
+
effectiveNamedDecl,
|
|
5153
5406
|
type,
|
|
5154
5407
|
checker,
|
|
5155
5408
|
file,
|
|
@@ -5159,17 +5412,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5159
5412
|
additionalProperties: true
|
|
5160
5413
|
};
|
|
5161
5414
|
if (registryTypeName !== void 0 && shouldRegisterNamedType) {
|
|
5162
|
-
const annotations =
|
|
5163
|
-
const metadata =
|
|
5415
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5416
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
5164
5417
|
metadataPolicy,
|
|
5165
5418
|
"type",
|
|
5166
5419
|
registryTypeName,
|
|
5167
|
-
|
|
5420
|
+
effectiveNamedDecl,
|
|
5168
5421
|
checker,
|
|
5169
5422
|
extensionRegistry,
|
|
5170
5423
|
{
|
|
5171
5424
|
checker,
|
|
5172
|
-
declaration:
|
|
5425
|
+
declaration: effectiveNamedDecl,
|
|
5173
5426
|
subjectType: type
|
|
5174
5427
|
}
|
|
5175
5428
|
) : void 0;
|
|
@@ -5178,7 +5431,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5178
5431
|
...metadata !== void 0 && { metadata },
|
|
5179
5432
|
type: objectNode,
|
|
5180
5433
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5181
|
-
provenance: provenanceForDeclaration(
|
|
5434
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5182
5435
|
};
|
|
5183
5436
|
return {
|
|
5184
5437
|
kind: "reference",
|
|
@@ -5195,12 +5448,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5195
5448
|
for (const symbol of symbols) {
|
|
5196
5449
|
const declarations = symbol.declarations;
|
|
5197
5450
|
if (!declarations) continue;
|
|
5198
|
-
const classDecl = declarations.find(
|
|
5451
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
5199
5452
|
if (classDecl) {
|
|
5200
5453
|
const map = /* @__PURE__ */ new Map();
|
|
5201
5454
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
5202
5455
|
for (const member of classDecl.members) {
|
|
5203
|
-
if (
|
|
5456
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
5204
5457
|
const fieldNode = analyzeFieldToIR(
|
|
5205
5458
|
member,
|
|
5206
5459
|
checker,
|
|
@@ -5224,7 +5477,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5224
5477
|
}
|
|
5225
5478
|
return map;
|
|
5226
5479
|
}
|
|
5227
|
-
const interfaceDecl = declarations.find(
|
|
5480
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
5228
5481
|
if (interfaceDecl) {
|
|
5229
5482
|
return buildFieldNodeInfoMap(
|
|
5230
5483
|
interfaceDecl.members,
|
|
@@ -5238,7 +5491,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5238
5491
|
extensionRegistry
|
|
5239
5492
|
);
|
|
5240
5493
|
}
|
|
5241
|
-
const typeAliasDecl = declarations.find(
|
|
5494
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
5242
5495
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5243
5496
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5244
5497
|
return buildFieldNodeInfoMap(
|
|
@@ -5262,10 +5515,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5262
5515
|
return void 0;
|
|
5263
5516
|
}
|
|
5264
5517
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5265
|
-
if (
|
|
5518
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
5266
5519
|
return resolvedTypeNode.elementType;
|
|
5267
5520
|
}
|
|
5268
|
-
if (
|
|
5521
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5269
5522
|
return resolvedTypeNode.typeArguments[0];
|
|
5270
5523
|
}
|
|
5271
5524
|
return void 0;
|
|
@@ -5276,13 +5529,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5276
5529
|
return [];
|
|
5277
5530
|
}
|
|
5278
5531
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5279
|
-
return
|
|
5532
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5280
5533
|
}
|
|
5281
5534
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5282
|
-
if (
|
|
5535
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
5283
5536
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5284
5537
|
}
|
|
5285
|
-
if (!
|
|
5538
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
5286
5539
|
return typeNode;
|
|
5287
5540
|
}
|
|
5288
5541
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5293,15 +5546,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5293
5546
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5294
5547
|
}
|
|
5295
5548
|
function isNullishTypeNode(typeNode) {
|
|
5296
|
-
if (typeNode.kind ===
|
|
5549
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
5297
5550
|
return true;
|
|
5298
5551
|
}
|
|
5299
|
-
return
|
|
5552
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
5300
5553
|
}
|
|
5301
5554
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5302
5555
|
const map = /* @__PURE__ */ new Map();
|
|
5303
5556
|
for (const member of members) {
|
|
5304
|
-
if (
|
|
5557
|
+
if (ts5.isPropertySignature(member)) {
|
|
5305
5558
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5306
5559
|
member,
|
|
5307
5560
|
checker,
|
|
@@ -5327,7 +5580,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5327
5580
|
}
|
|
5328
5581
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5329
5582
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5330
|
-
if (!
|
|
5583
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
5331
5584
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5332
5585
|
const aliasName = typeNode.typeName.getText();
|
|
5333
5586
|
throw new Error(
|
|
@@ -5336,7 +5589,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5336
5589
|
}
|
|
5337
5590
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5338
5591
|
if (!aliasDecl) return [];
|
|
5339
|
-
if (
|
|
5592
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5340
5593
|
const aliasFieldType = resolveTypeNode(
|
|
5341
5594
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5342
5595
|
checker,
|
|
@@ -5380,14 +5633,14 @@ function getNamedTypeName(type) {
|
|
|
5380
5633
|
const symbol = type.getSymbol();
|
|
5381
5634
|
if (symbol?.declarations) {
|
|
5382
5635
|
const decl = symbol.declarations[0];
|
|
5383
|
-
if (decl && (
|
|
5384
|
-
const name =
|
|
5636
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5637
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5385
5638
|
if (name) return name;
|
|
5386
5639
|
}
|
|
5387
5640
|
}
|
|
5388
5641
|
const aliasSymbol = type.aliasSymbol;
|
|
5389
5642
|
if (aliasSymbol?.declarations) {
|
|
5390
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5643
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5391
5644
|
if (aliasDecl) {
|
|
5392
5645
|
return aliasDecl.name.text;
|
|
5393
5646
|
}
|
|
@@ -5398,24 +5651,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5398
5651
|
const symbol = type.getSymbol();
|
|
5399
5652
|
if (symbol?.declarations) {
|
|
5400
5653
|
const decl = symbol.declarations[0];
|
|
5401
|
-
if (decl && (
|
|
5654
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5402
5655
|
return decl;
|
|
5403
5656
|
}
|
|
5404
5657
|
}
|
|
5405
5658
|
const aliasSymbol = type.aliasSymbol;
|
|
5406
5659
|
if (aliasSymbol?.declarations) {
|
|
5407
|
-
return aliasSymbol.declarations.find(
|
|
5660
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5408
5661
|
}
|
|
5409
5662
|
return void 0;
|
|
5410
5663
|
}
|
|
5411
5664
|
function analyzeMethod(method, checker) {
|
|
5412
|
-
if (!
|
|
5665
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
5413
5666
|
return null;
|
|
5414
5667
|
}
|
|
5415
5668
|
const name = method.name.text;
|
|
5416
5669
|
const parameters = [];
|
|
5417
5670
|
for (const param of method.parameters) {
|
|
5418
|
-
if (
|
|
5671
|
+
if (ts5.isIdentifier(param.name)) {
|
|
5419
5672
|
const paramInfo = analyzeParameter(param, checker);
|
|
5420
5673
|
parameters.push(paramInfo);
|
|
5421
5674
|
}
|
|
@@ -5426,7 +5679,7 @@ function analyzeMethod(method, checker) {
|
|
|
5426
5679
|
return { name, parameters, returnTypeNode, returnType };
|
|
5427
5680
|
}
|
|
5428
5681
|
function analyzeParameter(param, checker) {
|
|
5429
|
-
const name =
|
|
5682
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
5430
5683
|
const typeNode = param.type;
|
|
5431
5684
|
const type = checker.getTypeAtLocation(param);
|
|
5432
5685
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5435,15 +5688,15 @@ function analyzeParameter(param, checker) {
|
|
|
5435
5688
|
}
|
|
5436
5689
|
function detectFormSpecReference(typeNode) {
|
|
5437
5690
|
if (!typeNode) return null;
|
|
5438
|
-
if (!
|
|
5439
|
-
const typeName =
|
|
5691
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
5692
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5440
5693
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5441
5694
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5442
|
-
if (!typeArg || !
|
|
5443
|
-
if (
|
|
5695
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
5696
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
5444
5697
|
return typeArg.exprName.text;
|
|
5445
5698
|
}
|
|
5446
|
-
if (
|
|
5699
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
5447
5700
|
return typeArg.exprName.right.text;
|
|
5448
5701
|
}
|
|
5449
5702
|
return null;
|
|
@@ -5465,23 +5718,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5465
5718
|
function createProgramContext(filePath, additionalFiles) {
|
|
5466
5719
|
const absolutePath = path.resolve(filePath);
|
|
5467
5720
|
const fileDir = path.dirname(absolutePath);
|
|
5468
|
-
const configPath =
|
|
5721
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
5469
5722
|
let compilerOptions;
|
|
5470
5723
|
let fileNames;
|
|
5471
5724
|
if (configPath) {
|
|
5472
|
-
const configFile =
|
|
5725
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
5473
5726
|
if (configFile.error) {
|
|
5474
5727
|
throw new Error(
|
|
5475
|
-
`Error reading tsconfig.json: ${
|
|
5728
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5476
5729
|
);
|
|
5477
5730
|
}
|
|
5478
|
-
const parsed =
|
|
5731
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
5479
5732
|
configFile.config,
|
|
5480
|
-
|
|
5733
|
+
ts6.sys,
|
|
5481
5734
|
path.dirname(configPath)
|
|
5482
5735
|
);
|
|
5483
5736
|
if (parsed.errors.length > 0) {
|
|
5484
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5737
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5485
5738
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5486
5739
|
}
|
|
5487
5740
|
compilerOptions = parsed.options;
|
|
@@ -5489,9 +5742,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5489
5742
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5490
5743
|
} else {
|
|
5491
5744
|
compilerOptions = {
|
|
5492
|
-
target:
|
|
5493
|
-
module:
|
|
5494
|
-
moduleResolution:
|
|
5745
|
+
target: ts6.ScriptTarget.ES2022,
|
|
5746
|
+
module: ts6.ModuleKind.NodeNext,
|
|
5747
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
5495
5748
|
strict: true,
|
|
5496
5749
|
skipLibCheck: true,
|
|
5497
5750
|
declaration: true
|
|
@@ -5499,7 +5752,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5499
5752
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5500
5753
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5501
5754
|
}
|
|
5502
|
-
const program =
|
|
5755
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
5503
5756
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5504
5757
|
if (!sourceFile) {
|
|
5505
5758
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5518,19 +5771,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5518
5771
|
result = node;
|
|
5519
5772
|
return;
|
|
5520
5773
|
}
|
|
5521
|
-
|
|
5774
|
+
ts6.forEachChild(node, visit);
|
|
5522
5775
|
}
|
|
5523
5776
|
visit(sourceFile);
|
|
5524
5777
|
return result;
|
|
5525
5778
|
}
|
|
5526
5779
|
function findClassByName(sourceFile, className) {
|
|
5527
|
-
return findNodeByName(sourceFile, className,
|
|
5780
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
5528
5781
|
}
|
|
5529
5782
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5530
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5783
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
5531
5784
|
}
|
|
5532
5785
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5533
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5786
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5534
5787
|
}
|
|
5535
5788
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5536
5789
|
if (rootType.kind === "object") {
|
|
@@ -5570,22 +5823,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5570
5823
|
};
|
|
5571
5824
|
}
|
|
5572
5825
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5573
|
-
if (
|
|
5826
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5574
5827
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5575
5828
|
}
|
|
5576
|
-
if (
|
|
5829
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5577
5830
|
return true;
|
|
5578
5831
|
}
|
|
5579
|
-
return
|
|
5832
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5580
5833
|
}
|
|
5581
5834
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5582
|
-
if (
|
|
5835
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5583
5836
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5584
5837
|
}
|
|
5585
|
-
if (
|
|
5838
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
5586
5839
|
const propertyNames = [];
|
|
5587
5840
|
for (const member of typeNode.members) {
|
|
5588
|
-
if (!
|
|
5841
|
+
if (!ts6.isPropertySignature(member)) {
|
|
5589
5842
|
continue;
|
|
5590
5843
|
}
|
|
5591
5844
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5595,13 +5848,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5595
5848
|
}
|
|
5596
5849
|
return propertyNames;
|
|
5597
5850
|
}
|
|
5598
|
-
if (
|
|
5851
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5599
5852
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5600
5853
|
}
|
|
5601
5854
|
return null;
|
|
5602
5855
|
}
|
|
5603
5856
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5604
|
-
if (!
|
|
5857
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
5605
5858
|
return [];
|
|
5606
5859
|
}
|
|
5607
5860
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5802,7 +6055,7 @@ function makeFileProvenance(filePath) {
|
|
|
5802
6055
|
}
|
|
5803
6056
|
|
|
5804
6057
|
// src/extensions/symbol-registry.ts
|
|
5805
|
-
var
|
|
6058
|
+
var ts7 = __toESM(require("typescript"), 1);
|
|
5806
6059
|
var path2 = __toESM(require("path"), 1);
|
|
5807
6060
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5808
6061
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5812,10 +6065,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5812
6065
|
return symbolMap;
|
|
5813
6066
|
}
|
|
5814
6067
|
function visit(node) {
|
|
5815
|
-
if (
|
|
6068
|
+
if (ts7.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5816
6069
|
processDefineCustomTypeCall(node);
|
|
5817
6070
|
}
|
|
5818
|
-
|
|
6071
|
+
ts7.forEachChild(node, visit);
|
|
5819
6072
|
}
|
|
5820
6073
|
function processDefineCustomTypeCall(call) {
|
|
5821
6074
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5852,7 +6105,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5852
6105
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5853
6106
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5854
6107
|
if (callSymbol !== void 0) {
|
|
5855
|
-
const resolved = callSymbol.flags &
|
|
6108
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5856
6109
|
const decl = resolved.declarations?.[0];
|
|
5857
6110
|
if (decl !== void 0) {
|
|
5858
6111
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5860,24 +6113,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5860
6113
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5861
6114
|
}
|
|
5862
6115
|
}
|
|
5863
|
-
return
|
|
6116
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5864
6117
|
}
|
|
5865
6118
|
function extractTypeNameFromCallArg(call) {
|
|
5866
6119
|
const arg = call.arguments[0];
|
|
5867
|
-
if (arg === void 0 || !
|
|
6120
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5868
6121
|
return null;
|
|
5869
6122
|
}
|
|
5870
6123
|
const typeNameProp = arg.properties.find(
|
|
5871
|
-
(p) =>
|
|
6124
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5872
6125
|
);
|
|
5873
|
-
if (typeNameProp === void 0 || !
|
|
6126
|
+
if (typeNameProp === void 0 || !ts7.isStringLiteral(typeNameProp.initializer)) {
|
|
5874
6127
|
return null;
|
|
5875
6128
|
}
|
|
5876
6129
|
return typeNameProp.initializer.text;
|
|
5877
6130
|
}
|
|
5878
6131
|
function extractEnclosingExtensionId(call, checker) {
|
|
5879
|
-
for (let node = call.parent; !
|
|
5880
|
-
if (
|
|
6132
|
+
for (let node = call.parent; !ts7.isSourceFile(node); node = node.parent) {
|
|
6133
|
+
if (ts7.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5881
6134
|
return extractExtensionIdFromCallArg(node);
|
|
5882
6135
|
}
|
|
5883
6136
|
}
|
|
@@ -5886,24 +6139,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5886
6139
|
function isDefineExtensionCall(node, checker) {
|
|
5887
6140
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5888
6141
|
if (callSymbol !== void 0) {
|
|
5889
|
-
const resolved = callSymbol.flags &
|
|
6142
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5890
6143
|
const decl = resolved.declarations?.[0];
|
|
5891
6144
|
if (decl !== void 0) {
|
|
5892
6145
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5893
6146
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5894
6147
|
}
|
|
5895
6148
|
}
|
|
5896
|
-
return
|
|
6149
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5897
6150
|
}
|
|
5898
6151
|
function extractExtensionIdFromCallArg(call) {
|
|
5899
6152
|
const arg = call.arguments[0];
|
|
5900
|
-
if (arg === void 0 || !
|
|
6153
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5901
6154
|
return null;
|
|
5902
6155
|
}
|
|
5903
6156
|
const prop = arg.properties.find(
|
|
5904
|
-
(p) =>
|
|
6157
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5905
6158
|
);
|
|
5906
|
-
if (prop === void 0 || !
|
|
6159
|
+
if (prop === void 0 || !ts7.isStringLiteral(prop.initializer)) {
|
|
5907
6160
|
return null;
|
|
5908
6161
|
}
|
|
5909
6162
|
return prop.initializer.text;
|
|
@@ -5923,9 +6176,9 @@ function findRegistrationByTypeName(registry, typeName) {
|
|
|
5923
6176
|
}
|
|
5924
6177
|
|
|
5925
6178
|
// src/validate/constraint-validator.ts
|
|
5926
|
-
var
|
|
6179
|
+
var import_internal7 = require("@formspec/analysis/internal");
|
|
5927
6180
|
function validateFieldNode(ctx, field) {
|
|
5928
|
-
const analysis = (0,
|
|
6181
|
+
const analysis = (0, import_internal7.analyzeConstraintTargets)(
|
|
5929
6182
|
field.name,
|
|
5930
6183
|
field.type,
|
|
5931
6184
|
field.constraints,
|
|
@@ -5943,7 +6196,7 @@ function validateFieldNode(ctx, field) {
|
|
|
5943
6196
|
}
|
|
5944
6197
|
function validateObjectProperty(ctx, parentName, property) {
|
|
5945
6198
|
const qualifiedName = `${parentName}.${property.name}`;
|
|
5946
|
-
const analysis = (0,
|
|
6199
|
+
const analysis = (0, import_internal7.analyzeConstraintTargets)(
|
|
5947
6200
|
qualifiedName,
|
|
5948
6201
|
property.type,
|
|
5949
6202
|
property.constraints,
|
|
@@ -6165,7 +6418,7 @@ function generateSchemasBatch(options) {
|
|
|
6165
6418
|
return options.targets.map((target) => {
|
|
6166
6419
|
let ctx;
|
|
6167
6420
|
try {
|
|
6168
|
-
const cacheKey =
|
|
6421
|
+
const cacheKey = ts8.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
6169
6422
|
const cachedContext = contextCache.get(cacheKey);
|
|
6170
6423
|
if (cachedContext === void 0) {
|
|
6171
6424
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6224,7 +6477,7 @@ function isMutableRegistry(reg) {
|
|
|
6224
6477
|
}
|
|
6225
6478
|
function resolveStaticOptions(options) {
|
|
6226
6479
|
const legacyRegistry = options.extensionRegistry;
|
|
6227
|
-
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6480
|
+
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6228
6481
|
return {
|
|
6229
6482
|
extensionRegistry: legacyRegistry ?? configRegistry,
|
|
6230
6483
|
// eslint-disable-next-line @typescript-eslint/no-deprecated -- migration bridge reads deprecated fields
|
|
@@ -6236,7 +6489,7 @@ function resolveStaticOptions(options) {
|
|
|
6236
6489
|
};
|
|
6237
6490
|
}
|
|
6238
6491
|
function resolveOptions(options) {
|
|
6239
|
-
const configRegistry = options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6492
|
+
const configRegistry = options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6240
6493
|
const legacyRegistry = options.extensionRegistry;
|
|
6241
6494
|
return {
|
|
6242
6495
|
// When the caller provides the deprecated extensionRegistry field directly,
|
|
@@ -6321,7 +6574,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6321
6574
|
}
|
|
6322
6575
|
|
|
6323
6576
|
// src/static-build.ts
|
|
6324
|
-
var
|
|
6577
|
+
var ts9 = __toESM(require("typescript"), 1);
|
|
6325
6578
|
function toStaticBuildContext(context) {
|
|
6326
6579
|
return context;
|
|
6327
6580
|
}
|
|
@@ -6336,7 +6589,7 @@ function getModuleSymbol(context) {
|
|
|
6336
6589
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6337
6590
|
}
|
|
6338
6591
|
function isSchemaSourceDeclaration(declaration) {
|
|
6339
|
-
return
|
|
6592
|
+
return ts9.isClassDeclaration(declaration) || ts9.isInterfaceDeclaration(declaration) || ts9.isTypeAliasDeclaration(declaration);
|
|
6340
6593
|
}
|
|
6341
6594
|
function resolveModuleExport(context, exportName = "default") {
|
|
6342
6595
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6347,15 +6600,15 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6347
6600
|
if (exportSymbol === null) {
|
|
6348
6601
|
return null;
|
|
6349
6602
|
}
|
|
6350
|
-
return exportSymbol.flags &
|
|
6603
|
+
return exportSymbol.flags & ts9.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6351
6604
|
}
|
|
6352
6605
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6353
6606
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6354
6607
|
}
|
|
6355
6608
|
|
|
6356
6609
|
// src/generators/discovered-schema.ts
|
|
6357
|
-
var
|
|
6358
|
-
var
|
|
6610
|
+
var ts10 = __toESM(require("typescript"), 1);
|
|
6611
|
+
var import_internal8 = require("@formspec/analysis/internal");
|
|
6359
6612
|
var import_internals6 = require("@formspec/core/internals");
|
|
6360
6613
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
6361
6614
|
return {
|
|
@@ -6364,17 +6617,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6364
6617
|
};
|
|
6365
6618
|
}
|
|
6366
6619
|
function isNamedTypeDeclaration(declaration) {
|
|
6367
|
-
return
|
|
6620
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6368
6621
|
}
|
|
6369
6622
|
function hasConcreteTypeArguments(type, checker) {
|
|
6370
6623
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6371
6624
|
return true;
|
|
6372
6625
|
}
|
|
6373
|
-
if ((type.flags &
|
|
6626
|
+
if ((type.flags & ts10.TypeFlags.Object) === 0) {
|
|
6374
6627
|
return false;
|
|
6375
6628
|
}
|
|
6376
6629
|
const objectType = type;
|
|
6377
|
-
if ((objectType.objectFlags &
|
|
6630
|
+
if ((objectType.objectFlags & ts10.ObjectFlags.Reference) === 0) {
|
|
6378
6631
|
return false;
|
|
6379
6632
|
}
|
|
6380
6633
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6387,13 +6640,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6387
6640
|
return declaration;
|
|
6388
6641
|
}
|
|
6389
6642
|
}
|
|
6390
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6643
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts10.isTypeAliasDeclaration);
|
|
6391
6644
|
return aliasDeclaration;
|
|
6392
6645
|
}
|
|
6393
6646
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6394
6647
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6395
6648
|
const namedNode = sourceNode;
|
|
6396
|
-
if (namedNode.name !== void 0 &&
|
|
6649
|
+
if (namedNode.name !== void 0 && ts10.isIdentifier(namedNode.name)) {
|
|
6397
6650
|
return namedNode.name.text;
|
|
6398
6651
|
}
|
|
6399
6652
|
}
|
|
@@ -6615,7 +6868,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6615
6868
|
function generateSchemasFromDeclaration(options) {
|
|
6616
6869
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6617
6870
|
const resolved = resolveStaticOptions(options);
|
|
6618
|
-
if (
|
|
6871
|
+
if (ts10.isClassDeclaration(options.declaration)) {
|
|
6619
6872
|
return generateSchemasFromAnalysis(
|
|
6620
6873
|
analyzeClassToIR(
|
|
6621
6874
|
options.declaration,
|
|
@@ -6629,7 +6882,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6629
6882
|
resolved
|
|
6630
6883
|
);
|
|
6631
6884
|
}
|
|
6632
|
-
if (
|
|
6885
|
+
if (ts10.isInterfaceDeclaration(options.declaration)) {
|
|
6633
6886
|
return generateSchemasFromAnalysis(
|
|
6634
6887
|
analyzeInterfaceToIR(
|
|
6635
6888
|
options.declaration,
|
|
@@ -6643,7 +6896,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6643
6896
|
resolved
|
|
6644
6897
|
);
|
|
6645
6898
|
}
|
|
6646
|
-
if (
|
|
6899
|
+
if (ts10.isTypeAliasDeclaration(options.declaration)) {
|
|
6647
6900
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6648
6901
|
options.declaration,
|
|
6649
6902
|
options.context.checker,
|
|
@@ -6702,7 +6955,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6702
6955
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6703
6956
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6704
6957
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6705
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6958
|
+
const fallbackName = options.declaration.name !== void 0 && ts10.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6706
6959
|
return generateSchemasFromResolvedType({
|
|
6707
6960
|
...options,
|
|
6708
6961
|
type,
|
|
@@ -6712,7 +6965,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6712
6965
|
}
|
|
6713
6966
|
function resolveDeclarationMetadata(options) {
|
|
6714
6967
|
const resolved = resolveStaticOptions(options);
|
|
6715
|
-
const analysis = (0,
|
|
6968
|
+
const analysis = (0, import_internal8.analyzeMetadataForNodeWithChecker)({
|
|
6716
6969
|
checker: options.context.checker,
|
|
6717
6970
|
node: options.declaration,
|
|
6718
6971
|
metadata: resolved.metadata,
|
|
@@ -6749,14 +7002,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6749
7002
|
if (typeNode === void 0) {
|
|
6750
7003
|
return void 0;
|
|
6751
7004
|
}
|
|
6752
|
-
if (
|
|
7005
|
+
if (ts10.isParenthesizedTypeNode(typeNode)) {
|
|
6753
7006
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6754
7007
|
return unwrapped ?? typeNode;
|
|
6755
7008
|
}
|
|
6756
7009
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6757
7010
|
}
|
|
6758
7011
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6759
|
-
return
|
|
7012
|
+
return ts10.isTypeReferenceNode(typeNode) && ts10.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6760
7013
|
}
|
|
6761
7014
|
|
|
6762
7015
|
// src/generators/mixed-authoring.ts
|