@formspec/build 0.1.0-alpha.58 → 0.1.0-alpha.61
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 +30 -1
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/jsdoc-constraints.d.ts +0 -6
- package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts +2 -5
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +127 -32
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +130 -33
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +432 -12
- package/dist/build-beta.d.ts +400 -12
- package/dist/build-internal.d.ts +463 -12
- package/dist/build.d.ts +400 -12
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +2 -1
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -1
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts +2 -1
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -1
- package/dist/cli.cjs +610 -629
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +573 -586
- 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/generators/method-schema.d.ts +3 -2
- package/dist/generators/method-schema.d.ts.map +1 -1
- package/dist/index.cjs +600 -618
- 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 +571 -583
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +573 -591
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +540 -552
- package/dist/internals.js.map +1 -1
- package/dist/metadata/index.d.ts +1 -4
- package/dist/metadata/index.d.ts.map +1 -1
- package/dist/metadata/policy.d.ts +2 -6
- package/dist/metadata/policy.d.ts.map +1 -1
- package/dist/metadata/resolve.d.ts +3 -2
- package/dist/metadata/resolve.d.ts.map +1 -1
- package/dist/ui-schema/schema.d.ts +11 -28
- package/dist/ui-schema/schema.d.ts.map +1 -1
- package/package.json +7 -7
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,16 +2116,32 @@ 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
|
}
|
|
2045
2132
|
function createExtensionRegistry(extensions) {
|
|
2046
|
-
const registryLog = (0, import_internal.
|
|
2133
|
+
const registryLog = (0, import_internal.getRegistryLogger)();
|
|
2047
2134
|
registryLog.debug("createExtensionRegistry: constructing", {
|
|
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,161 +2484,39 @@ 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
|
|
2416
|
-
function sharedTagValueOptions(options) {
|
|
2490
|
+
var import_internal5 = require("@formspec/analysis/internal");
|
|
2491
|
+
function sharedTagValueOptions(options, pathResolvedCustomTypeId) {
|
|
2417
2492
|
return {
|
|
2418
2493
|
...options?.extensionRegistry !== void 0 ? { registry: options.extensionRegistry } : {},
|
|
2419
|
-
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2494
|
+
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {},
|
|
2495
|
+
...pathResolvedCustomTypeId !== void 0 ? { pathResolvedCustomTypeId } : {}
|
|
2420
2496
|
};
|
|
2421
2497
|
}
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
}
|
|
2427
|
-
return new Set(
|
|
2428
|
-
registry.extensions.flatMap(
|
|
2429
|
-
(ext) => (ext.types ?? []).flatMap((t) => t.tsTypeNames ?? [t.typeName])
|
|
2430
|
-
)
|
|
2431
|
-
);
|
|
2498
|
+
function customTypeIdForResolvedType(resolvedType, checker, registry) {
|
|
2499
|
+
if (registry === void 0) return void 0;
|
|
2500
|
+
const lookup = resolveCustomTypeFromTsType(resolvedType, checker, registry);
|
|
2501
|
+
return lookup === null ? void 0 : customTypeIdFromLookup(lookup);
|
|
2432
2502
|
}
|
|
2433
|
-
function
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
if (clause.name !== void 0) {
|
|
2439
|
-
importedNames.add(clause.name.text);
|
|
2440
|
-
}
|
|
2441
|
-
if (clause.namedBindings !== void 0) {
|
|
2442
|
-
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
2443
|
-
for (const specifier of clause.namedBindings.elements) {
|
|
2444
|
-
importedNames.add(specifier.name.text);
|
|
2445
|
-
}
|
|
2446
|
-
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
2447
|
-
importedNames.add(clause.namedBindings.name.text);
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
continue;
|
|
2451
|
-
}
|
|
2452
|
-
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
2453
|
-
importedNames.add(statement.name.text);
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
return importedNames;
|
|
2457
|
-
}
|
|
2458
|
-
function isNonReferenceIdentifier(node) {
|
|
2459
|
-
const parent = node.parent;
|
|
2460
|
-
if ((ts4.isBindingElement(parent) || ts4.isClassDeclaration(parent) || ts4.isEnumDeclaration(parent) || ts4.isEnumMember(parent) || ts4.isFunctionDeclaration(parent) || ts4.isFunctionExpression(parent) || ts4.isImportClause(parent) || ts4.isImportEqualsDeclaration(parent) || ts4.isImportSpecifier(parent) || ts4.isInterfaceDeclaration(parent) || ts4.isMethodDeclaration(parent) || ts4.isMethodSignature(parent) || ts4.isModuleDeclaration(parent) || ts4.isNamespaceExport(parent) || ts4.isNamespaceImport(parent) || ts4.isParameter(parent) || ts4.isPropertyDeclaration(parent) || ts4.isPropertySignature(parent) || ts4.isSetAccessorDeclaration(parent) || ts4.isGetAccessorDeclaration(parent) || ts4.isTypeAliasDeclaration(parent) || ts4.isTypeParameterDeclaration(parent) || ts4.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2461
|
-
return true;
|
|
2462
|
-
}
|
|
2463
|
-
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2464
|
-
return true;
|
|
2465
|
-
}
|
|
2466
|
-
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
2467
|
-
return true;
|
|
2468
|
-
}
|
|
2469
|
-
return false;
|
|
2470
|
-
}
|
|
2471
|
-
function astReferencesImportedName(root, importedNames) {
|
|
2472
|
-
if (importedNames.size === 0) {
|
|
2473
|
-
return false;
|
|
2474
|
-
}
|
|
2475
|
-
let found = false;
|
|
2476
|
-
const visit = (node) => {
|
|
2477
|
-
if (found) return;
|
|
2478
|
-
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2479
|
-
found = true;
|
|
2480
|
-
return;
|
|
2481
|
-
}
|
|
2482
|
-
ts4.forEachChild(node, visit);
|
|
2483
|
-
};
|
|
2484
|
-
visit(root);
|
|
2485
|
-
return found;
|
|
2486
|
-
}
|
|
2487
|
-
function getObjectMembers(statement) {
|
|
2488
|
-
if (ts4.isInterfaceDeclaration(statement)) {
|
|
2489
|
-
return statement.members;
|
|
2490
|
-
}
|
|
2491
|
-
if (ts4.isTypeLiteralNode(statement.type)) {
|
|
2492
|
-
return statement.type.members;
|
|
2493
|
-
}
|
|
2494
|
-
return void 0;
|
|
2495
|
-
}
|
|
2496
|
-
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
2497
|
-
const members = getObjectMembers(statement);
|
|
2498
|
-
if (members === void 0) {
|
|
2499
|
-
return null;
|
|
2500
|
-
}
|
|
2501
|
-
const replacements = [];
|
|
2502
|
-
for (const member of members) {
|
|
2503
|
-
if (!ts4.isPropertySignature(member)) {
|
|
2504
|
-
if (astReferencesImportedName(member, importedNames)) {
|
|
2505
|
-
return null;
|
|
2506
|
-
}
|
|
2507
|
-
continue;
|
|
2508
|
-
}
|
|
2509
|
-
const typeAnnotation = member.type;
|
|
2510
|
-
if (typeAnnotation === void 0) continue;
|
|
2511
|
-
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
2512
|
-
replacements.push({
|
|
2513
|
-
start: typeAnnotation.getStart(sourceFile),
|
|
2514
|
-
end: typeAnnotation.getEnd()
|
|
2515
|
-
});
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
if (replacements.length === 0) {
|
|
2519
|
-
return statement.getText(sourceFile);
|
|
2520
|
-
}
|
|
2521
|
-
const stmtStart = statement.getStart(sourceFile);
|
|
2522
|
-
let result = statement.getText(sourceFile);
|
|
2523
|
-
for (const { start, end } of [...replacements].reverse()) {
|
|
2524
|
-
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
2503
|
+
function resolvePathTargetCustomTypeId(parsedTag, subjectType, checker, registry) {
|
|
2504
|
+
if (parsedTag === null) return void 0;
|
|
2505
|
+
const target = parsedTag.target;
|
|
2506
|
+
if (target?.kind !== "path" || !target.valid || target.path === null) {
|
|
2507
|
+
return void 0;
|
|
2525
2508
|
}
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
2529
|
-
const importedNames = collectImportedNames(sourceFile);
|
|
2530
|
-
const importedNamesToSkip = new Set(
|
|
2531
|
-
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2532
|
-
);
|
|
2533
|
-
const result = [];
|
|
2534
|
-
for (const statement of sourceFile.statements) {
|
|
2535
|
-
if (ts4.isImportDeclaration(statement)) continue;
|
|
2536
|
-
if (ts4.isImportEqualsDeclaration(statement)) continue;
|
|
2537
|
-
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2538
|
-
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2539
|
-
result.push(statement.getText(sourceFile));
|
|
2540
|
-
continue;
|
|
2541
|
-
}
|
|
2542
|
-
if (ts4.isInterfaceDeclaration(statement) || ts4.isTypeAliasDeclaration(statement)) {
|
|
2543
|
-
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2544
|
-
if (rewritten !== null) {
|
|
2545
|
-
result.push(rewritten);
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2509
|
+
if (subjectType === void 0 || checker === void 0) {
|
|
2510
|
+
return void 0;
|
|
2548
2511
|
}
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
for (const diagnostic of additions) {
|
|
2553
|
-
if ((diagnostic.code === "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" || diagnostic.code === "SYNTHETIC_SETUP_FAILURE") && target.some(
|
|
2554
|
-
(existing) => existing.code === diagnostic.code && existing.message === diagnostic.message
|
|
2555
|
-
)) {
|
|
2556
|
-
continue;
|
|
2557
|
-
}
|
|
2558
|
-
target.push(diagnostic);
|
|
2512
|
+
const resolution = (0, import_internal4.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
2513
|
+
if (resolution.kind !== "resolved") {
|
|
2514
|
+
return void 0;
|
|
2559
2515
|
}
|
|
2516
|
+
return customTypeIdForResolvedType(resolution.type, checker, registry);
|
|
2560
2517
|
}
|
|
2561
|
-
|
|
2518
|
+
var TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2519
|
+
function processConstraintTag(tagName, text, parsedTag, provenance, node, sourceFile, options, constraints, diagnostics) {
|
|
2562
2520
|
const compilerDiagnostics = buildCompilerBackedConstraintDiagnostics(
|
|
2563
2521
|
node,
|
|
2564
2522
|
sourceFile,
|
|
@@ -2566,74 +2524,30 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
2566
2524
|
parsedTag,
|
|
2567
2525
|
text,
|
|
2568
2526
|
provenance,
|
|
2569
|
-
supportingDeclarations,
|
|
2570
2527
|
options
|
|
2571
2528
|
);
|
|
2572
2529
|
if (compilerDiagnostics.length > 0) {
|
|
2573
|
-
|
|
2530
|
+
diagnostics.push(...compilerDiagnostics);
|
|
2574
2531
|
return;
|
|
2575
2532
|
}
|
|
2576
|
-
const
|
|
2533
|
+
const pathResolvedCustomTypeId = resolvePathTargetCustomTypeId(
|
|
2534
|
+
parsedTag,
|
|
2535
|
+
options?.subjectType,
|
|
2536
|
+
options?.checker,
|
|
2537
|
+
options?.extensionRegistry
|
|
2538
|
+
);
|
|
2539
|
+
const constraintNode = (0, import_internal4.parseConstraintTagValue)(
|
|
2577
2540
|
tagName,
|
|
2578
2541
|
text,
|
|
2579
2542
|
provenance,
|
|
2580
|
-
sharedTagValueOptions(options)
|
|
2543
|
+
sharedTagValueOptions(options, pathResolvedCustomTypeId)
|
|
2581
2544
|
);
|
|
2582
2545
|
if (constraintNode) {
|
|
2583
2546
|
constraints.push(constraintNode);
|
|
2584
2547
|
}
|
|
2585
2548
|
}
|
|
2586
|
-
function renderSyntheticArgumentExpression(valueKind, argumentText) {
|
|
2587
|
-
const trimmed = argumentText.trim();
|
|
2588
|
-
if (trimmed === "") {
|
|
2589
|
-
return null;
|
|
2590
|
-
}
|
|
2591
|
-
switch (valueKind) {
|
|
2592
|
-
case "number":
|
|
2593
|
-
case "integer":
|
|
2594
|
-
case "signedInteger":
|
|
2595
|
-
if (trimmed === "Infinity" || trimmed === "-Infinity" || trimmed === "NaN") {
|
|
2596
|
-
return trimmed;
|
|
2597
|
-
}
|
|
2598
|
-
return Number.isFinite(Number(trimmed)) ? trimmed : JSON.stringify(trimmed);
|
|
2599
|
-
case "string":
|
|
2600
|
-
return JSON.stringify(argumentText);
|
|
2601
|
-
case "json":
|
|
2602
|
-
try {
|
|
2603
|
-
JSON.parse(trimmed);
|
|
2604
|
-
return `(${trimmed})`;
|
|
2605
|
-
} catch {
|
|
2606
|
-
return JSON.stringify(trimmed);
|
|
2607
|
-
}
|
|
2608
|
-
case "boolean":
|
|
2609
|
-
return trimmed === "true" || trimmed === "false" ? trimmed : JSON.stringify(trimmed);
|
|
2610
|
-
case "condition":
|
|
2611
|
-
return "undefined as unknown as FormSpecCondition";
|
|
2612
|
-
case null:
|
|
2613
|
-
return null;
|
|
2614
|
-
default: {
|
|
2615
|
-
return String(valueKind);
|
|
2616
|
-
}
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
function getArrayElementType(type, checker) {
|
|
2620
|
-
if (!checker.isArrayType(type)) {
|
|
2621
|
-
return null;
|
|
2622
|
-
}
|
|
2623
|
-
return checker.getTypeArguments(type)[0] ?? null;
|
|
2624
|
-
}
|
|
2625
2549
|
function supportsConstraintCapability(type, checker, capability) {
|
|
2626
|
-
|
|
2627
|
-
return true;
|
|
2628
|
-
}
|
|
2629
|
-
if ((0, import_internal3.hasTypeSemanticCapability)(type, checker, capability)) {
|
|
2630
|
-
return true;
|
|
2631
|
-
}
|
|
2632
|
-
if (capability === "string-like") {
|
|
2633
|
-
const itemType = getArrayElementType(type, checker);
|
|
2634
|
-
return itemType !== null && (0, import_internal3.hasTypeSemanticCapability)(itemType, checker, capability);
|
|
2635
|
-
}
|
|
2636
|
-
return false;
|
|
2550
|
+
return (0, import_internal4._supportsConstraintCapability)(capability, type, checker);
|
|
2637
2551
|
}
|
|
2638
2552
|
var MAX_HINT_CANDIDATES = 5;
|
|
2639
2553
|
var MAX_HINT_DEPTH = 3;
|
|
@@ -2642,7 +2556,7 @@ function stripHintNullishUnion(type) {
|
|
|
2642
2556
|
return type;
|
|
2643
2557
|
}
|
|
2644
2558
|
const nonNullish = type.types.filter(
|
|
2645
|
-
(member) => (member.flags & (
|
|
2559
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
2646
2560
|
);
|
|
2647
2561
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2648
2562
|
return nonNullish[0];
|
|
@@ -2658,10 +2572,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2658
2572
|
}
|
|
2659
2573
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2660
2574
|
const name = declaration.name;
|
|
2661
|
-
if (
|
|
2575
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
2662
2576
|
return false;
|
|
2663
2577
|
}
|
|
2664
|
-
if (!
|
|
2578
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
2665
2579
|
return false;
|
|
2666
2580
|
}
|
|
2667
2581
|
}
|
|
@@ -2677,7 +2591,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2677
2591
|
if (isCallableType(stripped)) {
|
|
2678
2592
|
return;
|
|
2679
2593
|
}
|
|
2680
|
-
if (!(0,
|
|
2594
|
+
if (!(0, import_internal4.hasTypeSemanticCapability)(stripped, checker, "object-like")) {
|
|
2681
2595
|
return;
|
|
2682
2596
|
}
|
|
2683
2597
|
for (const property of stripped.getProperties()) {
|
|
@@ -2695,7 +2609,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2695
2609
|
continue;
|
|
2696
2610
|
}
|
|
2697
2611
|
const strippedPropertyType = stripHintNullishUnion(propertyType);
|
|
2698
|
-
if (!isCallableType(strippedPropertyType) && (0,
|
|
2612
|
+
if (!isCallableType(strippedPropertyType) && (0, import_internal4.hasTypeSemanticCapability)(strippedPropertyType, checker, "object-like")) {
|
|
2699
2613
|
visit(strippedPropertyType, path4, depth + 1);
|
|
2700
2614
|
}
|
|
2701
2615
|
}
|
|
@@ -2704,7 +2618,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2704
2618
|
return out;
|
|
2705
2619
|
}
|
|
2706
2620
|
function buildPathTargetHint(subjectType, checker, capability, tagName, argumentText) {
|
|
2707
|
-
if (!(0,
|
|
2621
|
+
if (!(0, import_internal4.hasTypeSemanticCapability)(subjectType, checker, "object-like")) {
|
|
2708
2622
|
return null;
|
|
2709
2623
|
}
|
|
2710
2624
|
const candidates = collectObjectSubfieldCandidates(subjectType, checker, capability);
|
|
@@ -2760,53 +2674,11 @@ function placementLabel(placement) {
|
|
|
2760
2674
|
}
|
|
2761
2675
|
}
|
|
2762
2676
|
}
|
|
2763
|
-
function capabilityLabel(capability) {
|
|
2764
|
-
switch (capability) {
|
|
2765
|
-
case "numeric-comparable":
|
|
2766
|
-
return "number";
|
|
2767
|
-
case "string-like":
|
|
2768
|
-
return "string";
|
|
2769
|
-
case "array-like":
|
|
2770
|
-
return "array";
|
|
2771
|
-
case "enum-member-addressable":
|
|
2772
|
-
return "enum";
|
|
2773
|
-
case "json-like":
|
|
2774
|
-
return "JSON-compatible";
|
|
2775
|
-
case "object-like":
|
|
2776
|
-
return "object";
|
|
2777
|
-
case "condition-like":
|
|
2778
|
-
return "conditional";
|
|
2779
|
-
case void 0:
|
|
2780
|
-
return "compatible";
|
|
2781
|
-
default:
|
|
2782
|
-
return capability;
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
function getBroadenedCustomTypeId(fieldType) {
|
|
2786
|
-
if (fieldType?.kind === "custom") {
|
|
2787
|
-
return fieldType.typeId;
|
|
2788
|
-
}
|
|
2789
|
-
if (fieldType?.kind !== "union") {
|
|
2790
|
-
return void 0;
|
|
2791
|
-
}
|
|
2792
|
-
const customMembers = fieldType.members.filter(
|
|
2793
|
-
(member) => member.kind === "custom"
|
|
2794
|
-
);
|
|
2795
|
-
if (customMembers.length !== 1) {
|
|
2796
|
-
return void 0;
|
|
2797
|
-
}
|
|
2798
|
-
const nonCustomMembers = fieldType.members.filter((member) => member.kind !== "custom");
|
|
2799
|
-
const allOtherMembersAreNull = nonCustomMembers.every(
|
|
2800
|
-
(member) => member.kind === "primitive" && member.primitiveKind === "null"
|
|
2801
|
-
);
|
|
2802
|
-
const customMember = customMembers[0];
|
|
2803
|
-
return allOtherMembersAreNull && customMember !== void 0 ? customMember.typeId : void 0;
|
|
2804
|
-
}
|
|
2805
2677
|
function hasBuiltinConstraintBroadening(tagName, options) {
|
|
2806
|
-
const broadenedTypeId = getBroadenedCustomTypeId(options?.fieldType);
|
|
2678
|
+
const broadenedTypeId = (0, import_internal4.getBroadenedCustomTypeId)(options?.fieldType);
|
|
2807
2679
|
return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
|
|
2808
2680
|
}
|
|
2809
|
-
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance,
|
|
2681
|
+
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance, options) {
|
|
2810
2682
|
if (!(0, import_internals4.isBuiltinConstraintName)(tagName)) {
|
|
2811
2683
|
return [];
|
|
2812
2684
|
}
|
|
@@ -2815,27 +2687,25 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2815
2687
|
if (checker === void 0 || subjectType === void 0) {
|
|
2816
2688
|
return [];
|
|
2817
2689
|
}
|
|
2818
|
-
const placement = (0,
|
|
2690
|
+
const placement = (0, import_internal4.resolveDeclarationPlacement)(node);
|
|
2819
2691
|
if (placement === null) {
|
|
2820
2692
|
return [];
|
|
2821
2693
|
}
|
|
2822
|
-
const definition = (0,
|
|
2694
|
+
const definition = (0, import_internal4.getTagDefinition)(tagName, options?.extensionRegistry?.extensions);
|
|
2823
2695
|
if (definition === null) {
|
|
2824
2696
|
return [];
|
|
2825
2697
|
}
|
|
2826
2698
|
const nonNullPlacement = placement;
|
|
2827
|
-
const log = (0,
|
|
2828
|
-
const broadeningLog = (0,
|
|
2829
|
-
const
|
|
2830
|
-
const typedParserLog = (0, import_internal4.getTypedParserLogger)();
|
|
2699
|
+
const log = (0, import_internal5.getBuildLogger)();
|
|
2700
|
+
const broadeningLog = (0, import_internal5.getBroadeningLogger)();
|
|
2701
|
+
const typedParserLog = (0, import_internal5.getTypedParserLogger)();
|
|
2831
2702
|
const logsEnabled = log !== import_core3.noopLogger || broadeningLog !== import_core3.noopLogger;
|
|
2832
|
-
const syntheticTraceEnabled = syntheticLog !== import_core3.noopLogger;
|
|
2833
2703
|
const typedParserTraceEnabled = typedParserLog !== import_core3.noopLogger;
|
|
2834
|
-
const logStart = logsEnabled ? (0,
|
|
2835
|
-
const subjectTypeKind = logsEnabled ? (0,
|
|
2836
|
-
function emit(outcome,
|
|
2704
|
+
const logStart = logsEnabled ? (0, import_internal5.nowMicros)() : 0;
|
|
2705
|
+
const subjectTypeKind = logsEnabled ? (0, import_internal5.describeTypeKind)(subjectType, checker) : "";
|
|
2706
|
+
function emit(outcome, result) {
|
|
2837
2707
|
if (!logsEnabled) {
|
|
2838
|
-
return
|
|
2708
|
+
return result;
|
|
2839
2709
|
}
|
|
2840
2710
|
const entry = {
|
|
2841
2711
|
consumer: "build",
|
|
@@ -2843,13 +2713,13 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2843
2713
|
placement: nonNullPlacement,
|
|
2844
2714
|
subjectTypeKind,
|
|
2845
2715
|
roleOutcome: outcome,
|
|
2846
|
-
elapsedMicros: (0,
|
|
2716
|
+
elapsedMicros: (0, import_internal5.elapsedMicros)(logStart)
|
|
2847
2717
|
};
|
|
2848
|
-
(0,
|
|
2718
|
+
(0, import_internal5.logTagApplication)(log, entry);
|
|
2849
2719
|
if (outcome === "bypass" || outcome === "D1" || outcome === "D2") {
|
|
2850
|
-
(0,
|
|
2720
|
+
(0, import_internal5.logTagApplication)(broadeningLog, entry);
|
|
2851
2721
|
}
|
|
2852
|
-
return
|
|
2722
|
+
return result;
|
|
2853
2723
|
}
|
|
2854
2724
|
if (!definition.placements.includes(placement)) {
|
|
2855
2725
|
return emit("A-reject", [
|
|
@@ -2882,7 +2752,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2882
2752
|
)
|
|
2883
2753
|
]);
|
|
2884
2754
|
}
|
|
2885
|
-
const resolution = (0,
|
|
2755
|
+
const resolution = (0, import_internal4.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
2886
2756
|
if (resolution.kind === "missing-property") {
|
|
2887
2757
|
return emit("B-reject", [
|
|
2888
2758
|
makeDiagnostic(
|
|
@@ -2893,7 +2763,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2893
2763
|
]);
|
|
2894
2764
|
}
|
|
2895
2765
|
if (resolution.kind === "unresolvable") {
|
|
2896
|
-
const actualType = checker.typeToString(resolution.type, node,
|
|
2766
|
+
const actualType = checker.typeToString(resolution.type, node, TYPE_FORMAT_FLAGS);
|
|
2897
2767
|
return emit("B-reject", [
|
|
2898
2768
|
makeDiagnostic(
|
|
2899
2769
|
"TYPE_MISMATCH",
|
|
@@ -2907,21 +2777,21 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2907
2777
|
}
|
|
2908
2778
|
const hasBroadening = (() => {
|
|
2909
2779
|
if (target === null) {
|
|
2910
|
-
if (
|
|
2780
|
+
if ((0, import_internal3._isIntegerBrandedType)((0, import_internal4.stripNullishUnion)(subjectType)) && definition.capabilities[0] === "numeric-comparable") {
|
|
2911
2781
|
return true;
|
|
2912
2782
|
}
|
|
2913
2783
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2914
2784
|
}
|
|
2915
2785
|
const registry = options?.extensionRegistry;
|
|
2916
2786
|
if (registry === void 0) return false;
|
|
2917
|
-
const
|
|
2918
|
-
return
|
|
2787
|
+
const typeId = customTypeIdForResolvedType(evaluatedType, checker, registry);
|
|
2788
|
+
return typeId !== void 0 && registry.findBuiltinConstraintBroadening(typeId, tagName) !== void 0;
|
|
2919
2789
|
})();
|
|
2920
2790
|
if (!hasBroadening) {
|
|
2921
2791
|
const requiredCapability = definition.capabilities[0];
|
|
2922
2792
|
if (requiredCapability !== void 0 && !supportsConstraintCapability(evaluatedType, checker, requiredCapability)) {
|
|
2923
|
-
const actualType = checker.typeToString(evaluatedType, node,
|
|
2924
|
-
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${
|
|
2793
|
+
const actualType = checker.typeToString(evaluatedType, node, TYPE_FORMAT_FLAGS);
|
|
2794
|
+
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${(0, import_internal4._capabilityLabel)(requiredCapability)} targets, but field type is "${actualType}"`;
|
|
2925
2795
|
const hint = target === null ? buildPathTargetHint(
|
|
2926
2796
|
subjectType,
|
|
2927
2797
|
checker,
|
|
@@ -2938,11 +2808,11 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2938
2808
|
]);
|
|
2939
2809
|
}
|
|
2940
2810
|
}
|
|
2941
|
-
const effectiveArgumentText = parsedTag !== null ? (0, import_internal3.parseTagSyntax)(tagName, rawText).argumentText : rawText;
|
|
2942
2811
|
if (hasBroadening) {
|
|
2943
2812
|
return emit("bypass", []);
|
|
2944
2813
|
}
|
|
2945
|
-
const
|
|
2814
|
+
const effectiveArgumentText = (0, import_internal5.extractEffectiveArgumentText)(tagName, rawText, parsedTag);
|
|
2815
|
+
const typedParseResult = (0, import_internal5.parseTagArgument)(tagName, effectiveArgumentText, "build");
|
|
2946
2816
|
if (!typedParseResult.ok) {
|
|
2947
2817
|
if (typedParserTraceEnabled) {
|
|
2948
2818
|
typedParserLog.trace("typed-parser C-reject", {
|
|
@@ -2954,23 +2824,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2954
2824
|
diagnosticCode: typedParseResult.diagnostic.code
|
|
2955
2825
|
});
|
|
2956
2826
|
}
|
|
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
|
-
}
|
|
2827
|
+
const mappedCode = (0, import_internal5.mapTypedParserDiagnosticCode)(typedParseResult.diagnostic.code, tagName);
|
|
2974
2828
|
return emit("C-reject", [
|
|
2975
2829
|
makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
|
|
2976
2830
|
]);
|
|
@@ -2985,77 +2839,16 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2985
2839
|
valueKind: typedParseResult.value.kind
|
|
2986
2840
|
});
|
|
2987
2841
|
}
|
|
2988
|
-
|
|
2989
|
-
definition.valueKind,
|
|
2990
|
-
effectiveArgumentText
|
|
2991
|
-
);
|
|
2992
|
-
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2993
|
-
const hostType = options?.hostType ?? subjectType;
|
|
2994
|
-
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2995
|
-
if (syntheticTraceEnabled) {
|
|
2996
|
-
syntheticLog.trace("invoking synthetic checker", {
|
|
2997
|
-
consumer: "build",
|
|
2998
|
-
tag: tagName,
|
|
2999
|
-
placement,
|
|
3000
|
-
subjectTypeKind,
|
|
3001
|
-
subjectTypeText
|
|
3002
|
-
});
|
|
3003
|
-
}
|
|
3004
|
-
const result = (0, import_internal3.checkSyntheticTagApplication)({
|
|
3005
|
-
tagName,
|
|
3006
|
-
placement,
|
|
3007
|
-
hostType: hostTypeText,
|
|
3008
|
-
subjectType: subjectTypeText,
|
|
3009
|
-
...target?.kind === "path" ? { target: { kind: "path", text: target.rawText } } : {},
|
|
3010
|
-
...argumentExpression !== null ? { argumentExpression } : {},
|
|
3011
|
-
supportingDeclarations,
|
|
3012
|
-
...options?.extensionRegistry !== void 0 ? {
|
|
3013
|
-
extensions: options.extensionRegistry.extensions.map((extension) => ({
|
|
3014
|
-
extensionId: extension.extensionId,
|
|
3015
|
-
...extension.constraintTags !== void 0 ? {
|
|
3016
|
-
constraintTags: extension.constraintTags.map((tag) => ({ tagName: tag.tagName }))
|
|
3017
|
-
} : {},
|
|
3018
|
-
...extension.metadataSlots !== void 0 ? {
|
|
3019
|
-
metadataSlots: extension.metadataSlots
|
|
3020
|
-
} : {},
|
|
3021
|
-
...extension.types !== void 0 ? {
|
|
3022
|
-
customTypes: extension.types.map((t) => ({
|
|
3023
|
-
tsTypeNames: t.tsTypeNames ?? [t.typeName]
|
|
3024
|
-
}))
|
|
3025
|
-
} : {}
|
|
3026
|
-
}))
|
|
3027
|
-
} : {}
|
|
3028
|
-
});
|
|
3029
|
-
if (result.diagnostics.length === 0) {
|
|
3030
|
-
return emit("C-pass", []);
|
|
3031
|
-
}
|
|
3032
|
-
const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
|
|
3033
|
-
if (setupDiagnostic !== void 0) {
|
|
3034
|
-
return emit("C-reject", [
|
|
3035
|
-
makeDiagnostic(
|
|
3036
|
-
setupDiagnostic.kind === "unsupported-custom-type-override" ? "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" : "SYNTHETIC_SETUP_FAILURE",
|
|
3037
|
-
setupDiagnostic.message,
|
|
3038
|
-
provenance
|
|
3039
|
-
)
|
|
3040
|
-
]);
|
|
3041
|
-
}
|
|
3042
|
-
const expectedLabel = definition.valueKind === null ? "compatible argument" : capabilityLabel(definition.valueKind);
|
|
3043
|
-
return emit("C-reject", [
|
|
3044
|
-
makeDiagnostic(
|
|
3045
|
-
"TYPE_MISMATCH",
|
|
3046
|
-
`Tag "@${tagName}" received an invalid argument for ${expectedLabel}.`,
|
|
3047
|
-
provenance
|
|
3048
|
-
)
|
|
3049
|
-
]);
|
|
2842
|
+
return emit("C-pass", []);
|
|
3050
2843
|
}
|
|
3051
2844
|
var parseResultCache = /* @__PURE__ */ new Map();
|
|
3052
2845
|
function getExtensionTagNames(options) {
|
|
3053
2846
|
return [
|
|
3054
2847
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
3055
|
-
(extension) => (extension.constraintTags ?? []).map((tag) => (0,
|
|
2848
|
+
(extension) => (extension.constraintTags ?? []).map((tag) => (0, import_internal4.normalizeFormSpecTagName)(tag.tagName))
|
|
3056
2849
|
) ?? [],
|
|
3057
2850
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
3058
|
-
(extension) => (extension.metadataSlots ?? []).map((slot) => (0,
|
|
2851
|
+
(extension) => (extension.metadataSlots ?? []).map((slot) => (0, import_internal4.normalizeFormSpecTagName)(slot.tagName))
|
|
3059
2852
|
) ?? []
|
|
3060
2853
|
].sort();
|
|
3061
2854
|
}
|
|
@@ -3067,9 +2860,9 @@ function getExtensionRegistryCacheKey(registry) {
|
|
|
3067
2860
|
(extension) => JSON.stringify({
|
|
3068
2861
|
extensionId: extension.extensionId,
|
|
3069
2862
|
typeNames: extension.types?.map((type) => type.typeName) ?? [],
|
|
3070
|
-
constraintTags: extension.constraintTags?.map((tag) => (0,
|
|
2863
|
+
constraintTags: extension.constraintTags?.map((tag) => (0, import_internal4.normalizeFormSpecTagName)(tag.tagName)) ?? [],
|
|
3071
2864
|
metadataSlots: extension.metadataSlots?.map((slot) => ({
|
|
3072
|
-
tagName: (0,
|
|
2865
|
+
tagName: (0, import_internal4.normalizeFormSpecTagName)(slot.tagName),
|
|
3073
2866
|
declarationKinds: [...slot.declarationKinds].sort(),
|
|
3074
2867
|
allowBare: slot.allowBare !== false,
|
|
3075
2868
|
qualifiers: (slot.qualifiers ?? []).map((qualifier) => ({
|
|
@@ -3090,8 +2883,8 @@ function getParseCacheKey(node, file, options) {
|
|
|
3090
2883
|
start: node.getFullStart(),
|
|
3091
2884
|
end: node.getEnd(),
|
|
3092
2885
|
fieldType: options?.fieldType ?? null,
|
|
3093
|
-
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node,
|
|
3094
|
-
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node,
|
|
2886
|
+
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node, TYPE_FORMAT_FLAGS) : null,
|
|
2887
|
+
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node, TYPE_FORMAT_FLAGS) : null,
|
|
3095
2888
|
extensions: getExtensionRegistryCacheKey(options?.extensionRegistry)
|
|
3096
2889
|
});
|
|
3097
2890
|
}
|
|
@@ -3101,6 +2894,16 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3101
2894
|
if (cached !== void 0) {
|
|
3102
2895
|
return cached;
|
|
3103
2896
|
}
|
|
2897
|
+
const setupDiags = options?.extensionRegistry?.setupDiagnostics;
|
|
2898
|
+
if (setupDiags !== void 0 && setupDiags.length > 0) {
|
|
2899
|
+
const result2 = {
|
|
2900
|
+
constraints: [],
|
|
2901
|
+
annotations: [],
|
|
2902
|
+
diagnostics: (0, import_internal5._emitSetupDiagnostics)(setupDiags, file)
|
|
2903
|
+
};
|
|
2904
|
+
parseResultCache.set(cacheKey, result2);
|
|
2905
|
+
return result2;
|
|
2906
|
+
}
|
|
3104
2907
|
const constraints = [];
|
|
3105
2908
|
const annotations = [];
|
|
3106
2909
|
const diagnostics = [];
|
|
@@ -3110,14 +2913,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3110
2913
|
let placeholderProvenance;
|
|
3111
2914
|
const sourceFile = node.getSourceFile();
|
|
3112
2915
|
const sourceText = sourceFile.getFullText();
|
|
3113
|
-
const
|
|
3114
|
-
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
3115
|
-
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2916
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3116
2917
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
3117
2918
|
const extensionTagNames = getExtensionTagNames(options);
|
|
3118
2919
|
if (commentRanges) {
|
|
3119
2920
|
for (const range of commentRanges) {
|
|
3120
|
-
if (range.kind !==
|
|
2921
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
3121
2922
|
continue;
|
|
3122
2923
|
}
|
|
3123
2924
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3125,7 +2926,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3125
2926
|
continue;
|
|
3126
2927
|
}
|
|
3127
2928
|
const extensions = options?.extensionRegistry?.extensions;
|
|
3128
|
-
const unified = (0,
|
|
2929
|
+
const unified = (0, import_internal4.parseUnifiedComment)(commentText, {
|
|
3129
2930
|
offset: range.pos,
|
|
3130
2931
|
extensionTagNames,
|
|
3131
2932
|
...extensions !== void 0 ? { extensions } : {}
|
|
@@ -3160,13 +2961,13 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3160
2961
|
}
|
|
3161
2962
|
continue;
|
|
3162
2963
|
}
|
|
3163
|
-
if (
|
|
2964
|
+
if (import_internal4.TAGS_REQUIRING_RAW_TEXT.has(tagName)) {
|
|
3164
2965
|
const fallback = rawTextFallbacks.get(tagName)?.shift();
|
|
3165
|
-
const text2 = (0,
|
|
2966
|
+
const text2 = (0, import_internal4.choosePreferredPayloadText)(tag.resolvedPayloadText, fallback?.text ?? "");
|
|
3166
2967
|
if (text2 === "") continue;
|
|
3167
2968
|
const provenance2 = provenanceForParsedTag(tag, sourceFile, file);
|
|
3168
2969
|
if (tagName === "defaultValue") {
|
|
3169
|
-
annotations.push((0,
|
|
2970
|
+
annotations.push((0, import_internal4.parseDefaultValueTagValue)(text2, provenance2));
|
|
3170
2971
|
continue;
|
|
3171
2972
|
}
|
|
3172
2973
|
processConstraintTag(
|
|
@@ -3176,7 +2977,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3176
2977
|
provenance2,
|
|
3177
2978
|
node,
|
|
3178
2979
|
sourceFile,
|
|
3179
|
-
supportingDeclarations,
|
|
3180
2980
|
options,
|
|
3181
2981
|
constraints,
|
|
3182
2982
|
diagnostics
|
|
@@ -3194,7 +2994,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3194
2994
|
provenance,
|
|
3195
2995
|
node,
|
|
3196
2996
|
sourceFile,
|
|
3197
|
-
supportingDeclarations,
|
|
3198
2997
|
options,
|
|
3199
2998
|
constraints,
|
|
3200
2999
|
diagnostics
|
|
@@ -3248,7 +3047,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3248
3047
|
if (text === "") continue;
|
|
3249
3048
|
const provenance = fallback.provenance;
|
|
3250
3049
|
if (tagName === "defaultValue") {
|
|
3251
|
-
annotations.push((0,
|
|
3050
|
+
annotations.push((0, import_internal4.parseDefaultValueTagValue)(text, provenance));
|
|
3252
3051
|
continue;
|
|
3253
3052
|
}
|
|
3254
3053
|
processConstraintTag(
|
|
@@ -3258,7 +3057,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3258
3057
|
provenance,
|
|
3259
3058
|
node,
|
|
3260
3059
|
sourceFile,
|
|
3261
|
-
supportingDeclarations,
|
|
3262
3060
|
options,
|
|
3263
3061
|
constraints,
|
|
3264
3062
|
diagnostics
|
|
@@ -3274,13 +3072,13 @@ function extractDisplayNameMetadata(node) {
|
|
|
3274
3072
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3275
3073
|
const sourceFile = node.getSourceFile();
|
|
3276
3074
|
const sourceText = sourceFile.getFullText();
|
|
3277
|
-
const commentRanges =
|
|
3075
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3278
3076
|
if (commentRanges) {
|
|
3279
3077
|
for (const range of commentRanges) {
|
|
3280
|
-
if (range.kind !==
|
|
3078
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3281
3079
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3282
3080
|
if (!commentText.startsWith("/**")) continue;
|
|
3283
|
-
const unified = (0,
|
|
3081
|
+
const unified = (0, import_internal4.parseUnifiedComment)(commentText);
|
|
3284
3082
|
for (const tag of unified.tags) {
|
|
3285
3083
|
if (tag.normalizedTagName !== "displayName") {
|
|
3286
3084
|
continue;
|
|
@@ -3302,9 +3100,9 @@ function extractDisplayNameMetadata(node) {
|
|
|
3302
3100
|
}
|
|
3303
3101
|
function collectRawTextFallbacks(node, file) {
|
|
3304
3102
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3305
|
-
for (const tag of
|
|
3103
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
3306
3104
|
const tagName = (0, import_internals4.normalizeConstraintTagName)(tag.tagName.text);
|
|
3307
|
-
if (!
|
|
3105
|
+
if (!import_internal4.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3308
3106
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
3309
3107
|
if (commentText === "") continue;
|
|
3310
3108
|
const entries = fallbacks.get(tagName) ?? [];
|
|
@@ -3317,7 +3115,7 @@ function collectRawTextFallbacks(node, file) {
|
|
|
3317
3115
|
return fallbacks;
|
|
3318
3116
|
}
|
|
3319
3117
|
function isMemberTargetDisplayName(text) {
|
|
3320
|
-
return (0,
|
|
3118
|
+
return (0, import_internal4.parseTagSyntax)("displayName", text).target !== null;
|
|
3321
3119
|
}
|
|
3322
3120
|
function provenanceForComment(range, sourceFile, file, tagName) {
|
|
3323
3121
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);
|
|
@@ -3357,7 +3155,7 @@ function getTagCommentText(tag) {
|
|
|
3357
3155
|
if (typeof tag.comment === "string") {
|
|
3358
3156
|
return tag.comment;
|
|
3359
3157
|
}
|
|
3360
|
-
return
|
|
3158
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
3361
3159
|
}
|
|
3362
3160
|
|
|
3363
3161
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3375,18 +3173,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3375
3173
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3376
3174
|
if (!initializer) return null;
|
|
3377
3175
|
let value;
|
|
3378
|
-
if (
|
|
3176
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
3379
3177
|
value = initializer.text;
|
|
3380
|
-
} else if (
|
|
3178
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
3381
3179
|
value = Number(initializer.text);
|
|
3382
|
-
} else if (initializer.kind ===
|
|
3180
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
3383
3181
|
value = true;
|
|
3384
|
-
} else if (initializer.kind ===
|
|
3182
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
3385
3183
|
value = false;
|
|
3386
|
-
} else if (initializer.kind ===
|
|
3184
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
3387
3185
|
value = null;
|
|
3388
|
-
} else if (
|
|
3389
|
-
if (initializer.operator ===
|
|
3186
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
3187
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
3390
3188
|
value = -Number(initializer.operand.text);
|
|
3391
3189
|
}
|
|
3392
3190
|
}
|
|
@@ -3408,28 +3206,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3408
3206
|
|
|
3409
3207
|
// src/analyzer/class-analyzer.ts
|
|
3410
3208
|
function isObjectType(type) {
|
|
3411
|
-
return !!(type.flags &
|
|
3209
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
3412
3210
|
}
|
|
3413
3211
|
function isIntersectionType(type) {
|
|
3414
|
-
return !!(type.flags &
|
|
3212
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
3415
3213
|
}
|
|
3416
3214
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3417
|
-
if (
|
|
3215
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3418
3216
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3419
3217
|
}
|
|
3420
|
-
if (
|
|
3218
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
3421
3219
|
return true;
|
|
3422
3220
|
}
|
|
3423
|
-
return
|
|
3221
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3424
3222
|
}
|
|
3425
3223
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3426
3224
|
if (isIntersectionType(type)) {
|
|
3427
3225
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3428
3226
|
}
|
|
3429
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3227
|
+
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
3228
|
}
|
|
3431
3229
|
function isTypeReference(type) {
|
|
3432
|
-
return !!(type.flags &
|
|
3230
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
3433
3231
|
}
|
|
3434
3232
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3435
3233
|
kind: "object",
|
|
@@ -3455,8 +3253,23 @@ function createAnalyzerMetadataPolicy(input, discriminator) {
|
|
|
3455
3253
|
discriminator
|
|
3456
3254
|
};
|
|
3457
3255
|
}
|
|
3256
|
+
var DEDUPLICATABLE_DIAGNOSTIC_CODES = /* @__PURE__ */ new Set([
|
|
3257
|
+
"SYNTHETIC_SETUP_FAILURE",
|
|
3258
|
+
"UNSUPPORTED_CUSTOM_TYPE_OVERRIDE"
|
|
3259
|
+
]);
|
|
3260
|
+
function deduplicateDiagnostics(diagnostics) {
|
|
3261
|
+
if (diagnostics.length <= 1) return diagnostics;
|
|
3262
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3263
|
+
return diagnostics.filter((d) => {
|
|
3264
|
+
if (!DEDUPLICATABLE_DIAGNOSTIC_CODES.has(d.code)) return true;
|
|
3265
|
+
const key = `${d.code}\0${d.message}`;
|
|
3266
|
+
if (seen.has(key)) return false;
|
|
3267
|
+
seen.add(key);
|
|
3268
|
+
return true;
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3458
3271
|
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
3459
|
-
const analysis = (0,
|
|
3272
|
+
const analysis = (0, import_internal6.analyzeMetadataForNodeWithChecker)({
|
|
3460
3273
|
checker,
|
|
3461
3274
|
node,
|
|
3462
3275
|
logicalName,
|
|
@@ -3491,10 +3304,121 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3491
3304
|
}
|
|
3492
3305
|
return resolvedMetadata;
|
|
3493
3306
|
}
|
|
3307
|
+
var INHERITABLE_TYPE_ANNOTATION_KINDS = /* @__PURE__ */ new Set(["format"]);
|
|
3308
|
+
function getInheritableAnnotationStringValue(annotation) {
|
|
3309
|
+
if (annotation.annotationKind === "format") return annotation.value;
|
|
3310
|
+
return void 0;
|
|
3311
|
+
}
|
|
3312
|
+
function isOverridingInheritableAnnotation(annotation) {
|
|
3313
|
+
const value = getInheritableAnnotationStringValue(annotation);
|
|
3314
|
+
if (value === void 0) return true;
|
|
3315
|
+
return value.trim().length > 0;
|
|
3316
|
+
}
|
|
3317
|
+
function collectInheritedTypeAnnotations(derivedDecl, existingAnnotations, checker, extensionRegistry) {
|
|
3318
|
+
const existingKinds = new Set(
|
|
3319
|
+
existingAnnotations.filter(isOverridingInheritableAnnotation).map((a) => a.annotationKind)
|
|
3320
|
+
);
|
|
3321
|
+
const needed = /* @__PURE__ */ new Set();
|
|
3322
|
+
for (const kind of INHERITABLE_TYPE_ANNOTATION_KINDS) {
|
|
3323
|
+
if (!existingKinds.has(kind)) needed.add(kind);
|
|
3324
|
+
}
|
|
3325
|
+
if (needed.size === 0) return [];
|
|
3326
|
+
const inherited = [];
|
|
3327
|
+
const seen = /* @__PURE__ */ new Set([derivedDecl]);
|
|
3328
|
+
const queue = [];
|
|
3329
|
+
const resolveSymbolTarget = (sym) => {
|
|
3330
|
+
if ((sym.flags & ts5.SymbolFlags.Alias) === 0) return sym;
|
|
3331
|
+
try {
|
|
3332
|
+
return checker.getAliasedSymbol(sym);
|
|
3333
|
+
} catch {
|
|
3334
|
+
return sym;
|
|
3335
|
+
}
|
|
3336
|
+
};
|
|
3337
|
+
const isObjectShapedTypeAlias = (alias) => {
|
|
3338
|
+
const type = checker.getTypeFromTypeNode(alias.type);
|
|
3339
|
+
if ((type.flags & ts5.TypeFlags.Object) !== 0) return true;
|
|
3340
|
+
if (type.isIntersection()) return true;
|
|
3341
|
+
return false;
|
|
3342
|
+
};
|
|
3343
|
+
const enqueueCandidate = (baseDecl, fromTypeAliasRhs) => {
|
|
3344
|
+
if (seen.has(baseDecl)) return;
|
|
3345
|
+
if (ts5.isClassDeclaration(baseDecl) || ts5.isInterfaceDeclaration(baseDecl)) {
|
|
3346
|
+
seen.add(baseDecl);
|
|
3347
|
+
queue.push(baseDecl);
|
|
3348
|
+
return;
|
|
3349
|
+
}
|
|
3350
|
+
if (ts5.isTypeAliasDeclaration(baseDecl)) {
|
|
3351
|
+
if (!fromTypeAliasRhs && !isObjectShapedTypeAlias(baseDecl)) return;
|
|
3352
|
+
seen.add(baseDecl);
|
|
3353
|
+
queue.push(baseDecl);
|
|
3354
|
+
}
|
|
3355
|
+
};
|
|
3356
|
+
const enqueueBasesOf = (decl) => {
|
|
3357
|
+
if (ts5.isTypeAliasDeclaration(decl)) {
|
|
3358
|
+
const rhs = decl.type;
|
|
3359
|
+
if (!ts5.isTypeReferenceNode(rhs)) return;
|
|
3360
|
+
const sym = checker.getSymbolAtLocation(rhs.typeName);
|
|
3361
|
+
if (!sym) return;
|
|
3362
|
+
const target = resolveSymbolTarget(sym);
|
|
3363
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
3364
|
+
enqueueCandidate(
|
|
3365
|
+
baseDecl,
|
|
3366
|
+
/*fromTypeAliasRhs*/
|
|
3367
|
+
true
|
|
3368
|
+
);
|
|
3369
|
+
}
|
|
3370
|
+
return;
|
|
3371
|
+
}
|
|
3372
|
+
const heritageClauses = decl.heritageClauses;
|
|
3373
|
+
if (!heritageClauses) return;
|
|
3374
|
+
for (const clause of heritageClauses) {
|
|
3375
|
+
if (clause.token !== ts5.SyntaxKind.ExtendsKeyword) continue;
|
|
3376
|
+
for (const typeExpr of clause.types) {
|
|
3377
|
+
const sym = checker.getSymbolAtLocation(typeExpr.expression);
|
|
3378
|
+
if (!sym) continue;
|
|
3379
|
+
const target = resolveSymbolTarget(sym);
|
|
3380
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
3381
|
+
enqueueCandidate(
|
|
3382
|
+
baseDecl,
|
|
3383
|
+
/*fromTypeAliasRhs*/
|
|
3384
|
+
false
|
|
3385
|
+
);
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
};
|
|
3390
|
+
enqueueBasesOf(derivedDecl);
|
|
3391
|
+
for (let queueIndex = 0; queueIndex < queue.length && needed.size > 0; queueIndex++) {
|
|
3392
|
+
const baseDecl = queue[queueIndex];
|
|
3393
|
+
if (baseDecl === void 0) continue;
|
|
3394
|
+
const baseFile = baseDecl.getSourceFile().fileName;
|
|
3395
|
+
const baseAnnotations = extractJSDocAnnotationNodes(
|
|
3396
|
+
baseDecl,
|
|
3397
|
+
baseFile,
|
|
3398
|
+
makeParseOptions(extensionRegistry)
|
|
3399
|
+
);
|
|
3400
|
+
for (const annotation of baseAnnotations) {
|
|
3401
|
+
if (!needed.has(annotation.annotationKind)) continue;
|
|
3402
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
3403
|
+
inherited.push(annotation);
|
|
3404
|
+
needed.delete(annotation.annotationKind);
|
|
3405
|
+
}
|
|
3406
|
+
if (needed.size > 0) {
|
|
3407
|
+
enqueueBasesOf(baseDecl);
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
return inherited;
|
|
3411
|
+
}
|
|
3412
|
+
function extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) {
|
|
3413
|
+
const local = extractJSDocAnnotationNodes(namedDecl, file, makeParseOptions(extensionRegistry));
|
|
3414
|
+
const inherited = collectInheritedTypeAnnotations(namedDecl, local, checker, extensionRegistry);
|
|
3415
|
+
if (inherited.length === 0) return [...local];
|
|
3416
|
+
return [...local, ...inherited];
|
|
3417
|
+
}
|
|
3494
3418
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3495
3419
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3496
3420
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3497
|
-
const logicalName =
|
|
3421
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3498
3422
|
const docResult = extractJSDocParseResult(
|
|
3499
3423
|
declaration,
|
|
3500
3424
|
file,
|
|
@@ -3536,13 +3460,19 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3536
3460
|
file,
|
|
3537
3461
|
makeParseOptions(extensionRegistry, void 0, checker, classType, classType)
|
|
3538
3462
|
);
|
|
3539
|
-
const
|
|
3463
|
+
const inheritedClassAnnotations = collectInheritedTypeAnnotations(
|
|
3464
|
+
classDecl,
|
|
3465
|
+
classDoc.annotations,
|
|
3466
|
+
checker,
|
|
3467
|
+
extensionRegistry
|
|
3468
|
+
);
|
|
3469
|
+
const annotations = [...classDoc.annotations, ...inheritedClassAnnotations];
|
|
3540
3470
|
diagnostics.push(...classDoc.diagnostics);
|
|
3541
3471
|
const visiting = /* @__PURE__ */ new Set();
|
|
3542
3472
|
const instanceMethods = [];
|
|
3543
3473
|
const staticMethods = [];
|
|
3544
3474
|
for (const member of classDecl.members) {
|
|
3545
|
-
if (
|
|
3475
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
3546
3476
|
const fieldNode = analyzeFieldToIR(
|
|
3547
3477
|
member,
|
|
3548
3478
|
checker,
|
|
@@ -3558,10 +3488,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3558
3488
|
fields.push(fieldNode);
|
|
3559
3489
|
fieldLayouts.push({});
|
|
3560
3490
|
}
|
|
3561
|
-
} else if (
|
|
3491
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
3562
3492
|
const methodInfo = analyzeMethod(member, checker);
|
|
3563
3493
|
if (methodInfo) {
|
|
3564
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3494
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
3565
3495
|
if (isStatic) {
|
|
3566
3496
|
staticMethods.push(methodInfo);
|
|
3567
3497
|
} else {
|
|
@@ -3593,6 +3523,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3593
3523
|
hostType: classType
|
|
3594
3524
|
}
|
|
3595
3525
|
);
|
|
3526
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3596
3527
|
return {
|
|
3597
3528
|
name,
|
|
3598
3529
|
...metadata !== void 0 && { metadata },
|
|
@@ -3600,7 +3531,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3600
3531
|
fieldLayouts,
|
|
3601
3532
|
typeRegistry,
|
|
3602
3533
|
...annotations.length > 0 && { annotations },
|
|
3603
|
-
...
|
|
3534
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3604
3535
|
instanceMethods,
|
|
3605
3536
|
staticMethods
|
|
3606
3537
|
};
|
|
@@ -3620,11 +3551,20 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3620
3551
|
file,
|
|
3621
3552
|
makeParseOptions(extensionRegistry, void 0, checker, interfaceType, interfaceType)
|
|
3622
3553
|
);
|
|
3623
|
-
const
|
|
3554
|
+
const inheritedInterfaceAnnotations = collectInheritedTypeAnnotations(
|
|
3555
|
+
interfaceDecl,
|
|
3556
|
+
interfaceDoc.annotations,
|
|
3557
|
+
checker,
|
|
3558
|
+
extensionRegistry
|
|
3559
|
+
);
|
|
3560
|
+
const annotations = [
|
|
3561
|
+
...interfaceDoc.annotations,
|
|
3562
|
+
...inheritedInterfaceAnnotations
|
|
3563
|
+
];
|
|
3624
3564
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3625
3565
|
const visiting = /* @__PURE__ */ new Set();
|
|
3626
3566
|
for (const member of interfaceDecl.members) {
|
|
3627
|
-
if (
|
|
3567
|
+
if (ts5.isPropertySignature(member)) {
|
|
3628
3568
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3629
3569
|
member,
|
|
3630
3570
|
checker,
|
|
@@ -3665,6 +3605,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3665
3605
|
hostType: interfaceType
|
|
3666
3606
|
}
|
|
3667
3607
|
);
|
|
3608
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3668
3609
|
return {
|
|
3669
3610
|
name,
|
|
3670
3611
|
...metadata !== void 0 && { metadata },
|
|
@@ -3672,7 +3613,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3672
3613
|
fieldLayouts,
|
|
3673
3614
|
typeRegistry,
|
|
3674
3615
|
...annotations.length > 0 && { annotations },
|
|
3675
|
-
...
|
|
3616
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3676
3617
|
instanceMethods: [],
|
|
3677
3618
|
staticMethods: []
|
|
3678
3619
|
};
|
|
@@ -3682,7 +3623,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3682
3623
|
if (members === null) {
|
|
3683
3624
|
const sourceFile = typeAlias.getSourceFile();
|
|
3684
3625
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3685
|
-
const kindDesc =
|
|
3626
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3686
3627
|
return {
|
|
3687
3628
|
ok: false,
|
|
3688
3629
|
kind: "not-object-like",
|
|
@@ -3717,7 +3658,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3717
3658
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3718
3659
|
const visiting = /* @__PURE__ */ new Set();
|
|
3719
3660
|
for (const member of members) {
|
|
3720
|
-
if (
|
|
3661
|
+
if (ts5.isPropertySignature(member)) {
|
|
3721
3662
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3722
3663
|
member,
|
|
3723
3664
|
checker,
|
|
@@ -3757,6 +3698,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3757
3698
|
hostType: aliasType
|
|
3758
3699
|
}
|
|
3759
3700
|
);
|
|
3701
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3760
3702
|
return {
|
|
3761
3703
|
ok: true,
|
|
3762
3704
|
analysis: {
|
|
@@ -3766,7 +3708,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3766
3708
|
fieldLayouts: specializedFields.map(() => ({})),
|
|
3767
3709
|
typeRegistry,
|
|
3768
3710
|
...annotations.length > 0 && { annotations },
|
|
3769
|
-
...
|
|
3711
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3770
3712
|
instanceMethods: [],
|
|
3771
3713
|
staticMethods: []
|
|
3772
3714
|
}
|
|
@@ -3784,20 +3726,20 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3784
3726
|
function getLeadingParsedTags(node) {
|
|
3785
3727
|
const sourceFile = node.getSourceFile();
|
|
3786
3728
|
const sourceText = sourceFile.getFullText();
|
|
3787
|
-
const commentRanges =
|
|
3729
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3788
3730
|
if (commentRanges === void 0) {
|
|
3789
3731
|
return [];
|
|
3790
3732
|
}
|
|
3791
3733
|
const parsedTags = [];
|
|
3792
3734
|
for (const range of commentRanges) {
|
|
3793
|
-
if (range.kind !==
|
|
3735
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
3794
3736
|
continue;
|
|
3795
3737
|
}
|
|
3796
3738
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
3797
3739
|
if (!commentText.startsWith("/**")) {
|
|
3798
3740
|
continue;
|
|
3799
3741
|
}
|
|
3800
|
-
parsedTags.push(...(0,
|
|
3742
|
+
parsedTags.push(...(0, import_internal6.parseCommentBlock)(commentText, { offset: range.pos }).tags);
|
|
3801
3743
|
}
|
|
3802
3744
|
return parsedTags;
|
|
3803
3745
|
}
|
|
@@ -3808,19 +3750,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3808
3750
|
return null;
|
|
3809
3751
|
}
|
|
3810
3752
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3811
|
-
(candidate) =>
|
|
3753
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
3812
3754
|
) ?? propertySymbol.declarations?.[0];
|
|
3813
3755
|
return {
|
|
3814
3756
|
declaration,
|
|
3815
3757
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3816
|
-
optional: !!(propertySymbol.flags &
|
|
3758
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3817
3759
|
};
|
|
3818
3760
|
}
|
|
3819
3761
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3820
3762
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3821
3763
|
}
|
|
3822
3764
|
function isNullishSemanticType(type) {
|
|
3823
|
-
if (type.flags & (
|
|
3765
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
3824
3766
|
return true;
|
|
3825
3767
|
}
|
|
3826
3768
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3830,7 +3772,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3830
3772
|
return false;
|
|
3831
3773
|
}
|
|
3832
3774
|
seen.add(type);
|
|
3833
|
-
if (type.flags &
|
|
3775
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
3834
3776
|
return true;
|
|
3835
3777
|
}
|
|
3836
3778
|
if (type.isUnion()) {
|
|
@@ -3843,13 +3785,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3843
3785
|
return false;
|
|
3844
3786
|
}
|
|
3845
3787
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3846
|
-
if (
|
|
3788
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3847
3789
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3848
3790
|
}
|
|
3849
|
-
if (
|
|
3791
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
3850
3792
|
return [...typeNode.members];
|
|
3851
3793
|
}
|
|
3852
|
-
if (
|
|
3794
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
3853
3795
|
const members = [];
|
|
3854
3796
|
for (const intersectionMember of typeNode.types) {
|
|
3855
3797
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -4012,7 +3954,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
4012
3954
|
}
|
|
4013
3955
|
if (propertyType.isUnion()) {
|
|
4014
3956
|
const nonNullMembers = propertyType.types.filter(
|
|
4015
|
-
(member) => !(member.flags & (
|
|
3957
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4016
3958
|
);
|
|
4017
3959
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4018
3960
|
diagnostics.push(
|
|
@@ -4061,13 +4003,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
4061
4003
|
seen.add(type);
|
|
4062
4004
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
4063
4005
|
if (symbol !== void 0) {
|
|
4064
|
-
const aliased = symbol.flags &
|
|
4006
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
4065
4007
|
const targetSymbol = aliased ?? symbol;
|
|
4066
4008
|
const declaration = targetSymbol.declarations?.find(
|
|
4067
|
-
(candidate) =>
|
|
4009
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
4068
4010
|
);
|
|
4069
4011
|
if (declaration !== void 0) {
|
|
4070
|
-
if (
|
|
4012
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
4071
4013
|
return resolveNamedDiscriminatorDeclaration(
|
|
4072
4014
|
checker.getTypeFromTypeNode(declaration.type),
|
|
4073
4015
|
checker,
|
|
@@ -4095,7 +4037,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4095
4037
|
}
|
|
4096
4038
|
if (boundType.isUnion()) {
|
|
4097
4039
|
const nonNullMembers = boundType.types.filter(
|
|
4098
|
-
(member) => !(member.flags & (
|
|
4040
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4099
4041
|
);
|
|
4100
4042
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4101
4043
|
diagnostics.push(
|
|
@@ -4140,7 +4082,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4140
4082
|
return null;
|
|
4141
4083
|
}
|
|
4142
4084
|
function getDeclarationName(node) {
|
|
4143
|
-
if (
|
|
4085
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
4144
4086
|
return node.name?.text ?? "anonymous";
|
|
4145
4087
|
}
|
|
4146
4088
|
return "anonymous";
|
|
@@ -4195,11 +4137,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4195
4137
|
if (sourceTypeNode === void 0) {
|
|
4196
4138
|
return [];
|
|
4197
4139
|
}
|
|
4198
|
-
const unwrapParentheses = (typeNode) =>
|
|
4140
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4199
4141
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4200
|
-
const referenceTypeNode =
|
|
4142
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4201
4143
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4202
|
-
return
|
|
4144
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4203
4145
|
})();
|
|
4204
4146
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4205
4147
|
return [];
|
|
@@ -4207,7 +4149,7 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4207
4149
|
return referenceTypeNode.typeArguments.map((argumentNode) => {
|
|
4208
4150
|
const argumentType = checker.getTypeFromTypeNode(argumentNode);
|
|
4209
4151
|
const baseSymbol = argumentType.aliasSymbol ?? argumentType.getSymbol();
|
|
4210
|
-
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags &
|
|
4152
|
+
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(baseSymbol) : baseSymbol;
|
|
4211
4153
|
const argumentDecl = argumentSymbol?.declarations?.[0];
|
|
4212
4154
|
if (argumentDecl !== void 0 && argumentDecl.getSourceFile().fileName !== file) {
|
|
4213
4155
|
const argumentName = argumentSymbol?.getName() ?? baseSymbol?.getName();
|
|
@@ -4270,7 +4212,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4270
4212
|
);
|
|
4271
4213
|
}
|
|
4272
4214
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4273
|
-
if (!
|
|
4215
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
4274
4216
|
return null;
|
|
4275
4217
|
}
|
|
4276
4218
|
const name = prop.name.text;
|
|
@@ -4397,7 +4339,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4397
4339
|
const seen = /* @__PURE__ */ new Set();
|
|
4398
4340
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4399
4341
|
for (const member of members) {
|
|
4400
|
-
if (!
|
|
4342
|
+
if (!ts5.isPropertySignature(member)) {
|
|
4401
4343
|
continue;
|
|
4402
4344
|
}
|
|
4403
4345
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4413,7 +4355,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4413
4355
|
return [...duplicates].sort();
|
|
4414
4356
|
}
|
|
4415
4357
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4416
|
-
if (
|
|
4358
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
4417
4359
|
return name.text;
|
|
4418
4360
|
}
|
|
4419
4361
|
return null;
|
|
@@ -4508,28 +4450,28 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4508
4450
|
if (primitiveAlias) {
|
|
4509
4451
|
return primitiveAlias;
|
|
4510
4452
|
}
|
|
4511
|
-
if (
|
|
4453
|
+
if ((0, import_internal3._isIntegerBrandedType)(type)) {
|
|
4512
4454
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4513
4455
|
}
|
|
4514
|
-
if (type.flags &
|
|
4456
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4515
4457
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4516
4458
|
}
|
|
4517
|
-
if (type.flags &
|
|
4459
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4518
4460
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4519
4461
|
}
|
|
4520
|
-
if (type.flags & (
|
|
4462
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4521
4463
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4522
4464
|
}
|
|
4523
|
-
if (type.flags &
|
|
4465
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4524
4466
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4525
4467
|
}
|
|
4526
|
-
if (type.flags &
|
|
4468
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4527
4469
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4528
4470
|
}
|
|
4529
|
-
if (type.flags &
|
|
4471
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
4530
4472
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4531
4473
|
}
|
|
4532
|
-
if (type.flags &
|
|
4474
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
4533
4475
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4534
4476
|
}
|
|
4535
4477
|
if (type.isStringLiteral()) {
|
|
@@ -4616,10 +4558,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4616
4558
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4617
4559
|
}
|
|
4618
4560
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4619
|
-
if (!(type.flags & (
|
|
4561
|
+
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
4562
|
return null;
|
|
4621
4563
|
}
|
|
4622
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4564
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4623
4565
|
if (!aliasDecl) {
|
|
4624
4566
|
return null;
|
|
4625
4567
|
}
|
|
@@ -4630,11 +4572,18 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4630
4572
|
...extractJSDocConstraintNodes(aliasDecl, file, makeParseOptions(extensionRegistry)),
|
|
4631
4573
|
...extractTypeAliasConstraintNodes(aliasDecl.type, checker, file, extensionRegistry)
|
|
4632
4574
|
];
|
|
4633
|
-
const
|
|
4575
|
+
const localAnnotations = extractJSDocAnnotationNodes(
|
|
4634
4576
|
aliasDecl,
|
|
4635
4577
|
file,
|
|
4636
4578
|
makeParseOptions(extensionRegistry)
|
|
4637
4579
|
);
|
|
4580
|
+
const inheritedAnnotations = collectInheritedTypeAnnotations(
|
|
4581
|
+
aliasDecl,
|
|
4582
|
+
localAnnotations,
|
|
4583
|
+
checker,
|
|
4584
|
+
extensionRegistry
|
|
4585
|
+
);
|
|
4586
|
+
const annotations = [...localAnnotations, ...inheritedAnnotations];
|
|
4638
4587
|
const metadata = resolveNodeMetadata(
|
|
4639
4588
|
metadataPolicy,
|
|
4640
4589
|
"type",
|
|
@@ -4669,8 +4618,8 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4669
4618
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4670
4619
|
}
|
|
4671
4620
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4672
|
-
const typeNode = sourceNode && (
|
|
4673
|
-
if (!typeNode || !
|
|
4621
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4622
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
4674
4623
|
return void 0;
|
|
4675
4624
|
}
|
|
4676
4625
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4691,7 +4640,7 @@ function resolveNamedTypeWithSourceRecovery(type, sourceNode, checker) {
|
|
|
4691
4640
|
return { typeName: refAliasDecl.name.text, namedDecl: refAliasDecl };
|
|
4692
4641
|
}
|
|
4693
4642
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4694
|
-
if (!
|
|
4643
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
4695
4644
|
return false;
|
|
4696
4645
|
}
|
|
4697
4646
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4699,10 +4648,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4699
4648
|
return false;
|
|
4700
4649
|
}
|
|
4701
4650
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4702
|
-
return !!(resolved.flags & (
|
|
4651
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
4703
4652
|
}
|
|
4704
4653
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4705
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4654
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
4706
4655
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4707
4656
|
visitedAliases.add(nestedAliasDecl);
|
|
4708
4657
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4717,22 +4666,22 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4717
4666
|
visitedAliases
|
|
4718
4667
|
);
|
|
4719
4668
|
}
|
|
4720
|
-
if (
|
|
4669
|
+
if ((0, import_internal3._isIntegerBrandedType)(type)) {
|
|
4721
4670
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4722
4671
|
}
|
|
4723
|
-
if (type.flags &
|
|
4672
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4724
4673
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4725
4674
|
}
|
|
4726
|
-
if (type.flags &
|
|
4675
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4727
4676
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4728
4677
|
}
|
|
4729
|
-
if (type.flags & (
|
|
4678
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4730
4679
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4731
4680
|
}
|
|
4732
|
-
if (type.flags &
|
|
4681
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4733
4682
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4734
4683
|
}
|
|
4735
|
-
if (type.flags &
|
|
4684
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4736
4685
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4737
4686
|
}
|
|
4738
4687
|
return resolveTypeNode(
|
|
@@ -4752,7 +4701,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4752
4701
|
let typeName = null;
|
|
4753
4702
|
let namedDecl;
|
|
4754
4703
|
if (recovered !== null) {
|
|
4755
|
-
const recoveredAliasDecl =
|
|
4704
|
+
const recoveredAliasDecl = ts5.isTypeAliasDeclaration(recovered.namedDecl) ? recovered.namedDecl : void 0;
|
|
4756
4705
|
if (recoveredAliasDecl !== void 0) {
|
|
4757
4706
|
const aliasUnderlyingType = checker.getTypeFromTypeNode(recoveredAliasDecl.type);
|
|
4758
4707
|
const isNonGeneric = recoveredAliasDecl.typeParameters === void 0 || recoveredAliasDecl.typeParameters.length === 0;
|
|
@@ -4774,13 +4723,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4774
4723
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4775
4724
|
);
|
|
4776
4725
|
const nonNullTypes = allTypes.filter(
|
|
4777
|
-
(memberType) => !(memberType.flags & (
|
|
4726
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4778
4727
|
);
|
|
4779
4728
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4780
4729
|
memberType,
|
|
4781
4730
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4782
4731
|
}));
|
|
4783
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4732
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
4784
4733
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4785
4734
|
if (namedDecl) {
|
|
4786
4735
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4800,7 +4749,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4800
4749
|
if (existing !== void 0 && existing.type !== RESOLVING_TYPE_PLACEHOLDER) {
|
|
4801
4750
|
return { kind: "reference", name: typeName, typeArguments: [] };
|
|
4802
4751
|
}
|
|
4803
|
-
const annotations = namedDecl ?
|
|
4752
|
+
const annotations = namedDecl ? extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) : void 0;
|
|
4804
4753
|
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4805
4754
|
metadataPolicy,
|
|
4806
4755
|
"type",
|
|
@@ -4827,7 +4776,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4827
4776
|
const displayName = memberDisplayNames.get(String(value));
|
|
4828
4777
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4829
4778
|
});
|
|
4830
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4779
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
4831
4780
|
if (isBooleanUnion2) {
|
|
4832
4781
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4833
4782
|
const result = hasNull ? {
|
|
@@ -4919,7 +4868,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4919
4868
|
if (type.getProperties().length > 0) {
|
|
4920
4869
|
return null;
|
|
4921
4870
|
}
|
|
4922
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4871
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
4923
4872
|
if (!indexInfo) {
|
|
4924
4873
|
return null;
|
|
4925
4874
|
}
|
|
@@ -4967,20 +4916,53 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4967
4916
|
}
|
|
4968
4917
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4969
4918
|
const name = declaration.name;
|
|
4970
|
-
if (
|
|
4919
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
4971
4920
|
return false;
|
|
4972
4921
|
}
|
|
4973
|
-
if (!
|
|
4922
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
4974
4923
|
return false;
|
|
4975
4924
|
}
|
|
4976
4925
|
}
|
|
4977
4926
|
return true;
|
|
4978
4927
|
}
|
|
4928
|
+
function getPassThroughTypeAliasFromSourceNode(sourceNode, checker, extensionRegistry, resolvedTypeName) {
|
|
4929
|
+
const aliasDecl = getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4930
|
+
if (!aliasDecl) return void 0;
|
|
4931
|
+
const aliasName = aliasDecl.name.text;
|
|
4932
|
+
if (aliasName === resolvedTypeName) return void 0;
|
|
4933
|
+
if (!ts5.isTypeReferenceNode(aliasDecl.type)) return void 0;
|
|
4934
|
+
if (!hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry)) {
|
|
4935
|
+
return void 0;
|
|
4936
|
+
}
|
|
4937
|
+
return { aliasName, aliasDecl };
|
|
4938
|
+
}
|
|
4939
|
+
function hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry) {
|
|
4940
|
+
const file = aliasDecl.getSourceFile().fileName;
|
|
4941
|
+
const local = extractJSDocAnnotationNodes(aliasDecl, file, makeParseOptions(extensionRegistry));
|
|
4942
|
+
for (const annotation of local) {
|
|
4943
|
+
if (!INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) continue;
|
|
4944
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
4945
|
+
return true;
|
|
4946
|
+
}
|
|
4947
|
+
const inherited = collectInheritedTypeAnnotations(aliasDecl, local, checker, extensionRegistry);
|
|
4948
|
+
for (const annotation of inherited) {
|
|
4949
|
+
if (INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) return true;
|
|
4950
|
+
}
|
|
4951
|
+
return false;
|
|
4952
|
+
}
|
|
4979
4953
|
function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4980
4954
|
const collectedDiagnostics = diagnostics ?? [];
|
|
4981
4955
|
const typeName = getNamedTypeName(type);
|
|
4982
4956
|
const namedTypeName = typeName ?? void 0;
|
|
4983
4957
|
const namedDecl = getNamedTypeDeclaration(type);
|
|
4958
|
+
const passThroughAlias = getPassThroughTypeAliasFromSourceNode(
|
|
4959
|
+
sourceNode,
|
|
4960
|
+
checker,
|
|
4961
|
+
extensionRegistry,
|
|
4962
|
+
namedTypeName
|
|
4963
|
+
);
|
|
4964
|
+
const effectiveTypeName = passThroughAlias?.aliasName ?? namedTypeName;
|
|
4965
|
+
const effectiveNamedDecl = passThroughAlias?.aliasDecl ?? namedDecl;
|
|
4984
4966
|
const referenceTypeArguments = extractReferenceTypeArguments(
|
|
4985
4967
|
type,
|
|
4986
4968
|
checker,
|
|
@@ -4992,13 +4974,13 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4992
4974
|
extensionRegistry,
|
|
4993
4975
|
collectedDiagnostics
|
|
4994
4976
|
);
|
|
4995
|
-
const instantiatedTypeName =
|
|
4996
|
-
|
|
4977
|
+
const instantiatedTypeName = effectiveTypeName !== void 0 && referenceTypeArguments.length > 0 ? buildInstantiatedReferenceName(
|
|
4978
|
+
effectiveTypeName,
|
|
4997
4979
|
referenceTypeArguments.map((argument) => argument.tsType),
|
|
4998
4980
|
checker
|
|
4999
4981
|
) : void 0;
|
|
5000
|
-
const registryTypeName = instantiatedTypeName ??
|
|
5001
|
-
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" &&
|
|
4982
|
+
const registryTypeName = instantiatedTypeName ?? effectiveTypeName;
|
|
4983
|
+
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" && effectiveNamedDecl?.getSourceFile().fileName !== file);
|
|
5002
4984
|
const clearNamedTypeRegistration = () => {
|
|
5003
4985
|
if (registryTypeName === void 0 || !shouldRegisterNamedType) {
|
|
5004
4986
|
return;
|
|
@@ -5019,7 +5001,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5019
5001
|
typeRegistry[registryTypeName] = {
|
|
5020
5002
|
name: registryTypeName,
|
|
5021
5003
|
type: RESOLVING_TYPE_PLACEHOLDER,
|
|
5022
|
-
provenance: provenanceForDeclaration(
|
|
5004
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5023
5005
|
};
|
|
5024
5006
|
}
|
|
5025
5007
|
visiting.add(type);
|
|
@@ -5051,17 +5033,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5051
5033
|
clearNamedTypeRegistration();
|
|
5052
5034
|
return recordNode;
|
|
5053
5035
|
}
|
|
5054
|
-
const annotations =
|
|
5055
|
-
const metadata =
|
|
5036
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5037
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
5056
5038
|
metadataPolicy,
|
|
5057
5039
|
"type",
|
|
5058
5040
|
registryTypeName,
|
|
5059
|
-
|
|
5041
|
+
effectiveNamedDecl,
|
|
5060
5042
|
checker,
|
|
5061
5043
|
extensionRegistry,
|
|
5062
5044
|
{
|
|
5063
5045
|
checker,
|
|
5064
|
-
declaration:
|
|
5046
|
+
declaration: effectiveNamedDecl,
|
|
5065
5047
|
subjectType: type
|
|
5066
5048
|
}
|
|
5067
5049
|
) : void 0;
|
|
@@ -5070,7 +5052,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5070
5052
|
...metadata !== void 0 && { metadata },
|
|
5071
5053
|
type: recordNode,
|
|
5072
5054
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5073
|
-
provenance: provenanceForDeclaration(
|
|
5055
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5074
5056
|
};
|
|
5075
5057
|
return {
|
|
5076
5058
|
kind: "reference",
|
|
@@ -5096,7 +5078,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5096
5078
|
if (!declaration) continue;
|
|
5097
5079
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
5098
5080
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
5099
|
-
const optional = !!(prop.flags &
|
|
5081
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
5100
5082
|
const propTypeNode = resolveTypeNode(
|
|
5101
5083
|
propType,
|
|
5102
5084
|
checker,
|
|
@@ -5109,7 +5091,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5109
5091
|
collectedDiagnostics
|
|
5110
5092
|
);
|
|
5111
5093
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
5112
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
5094
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
5113
5095
|
declaration,
|
|
5114
5096
|
checker,
|
|
5115
5097
|
file,
|
|
@@ -5119,7 +5101,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5119
5101
|
type,
|
|
5120
5102
|
metadataPolicy,
|
|
5121
5103
|
extensionRegistry
|
|
5122
|
-
) :
|
|
5104
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
5123
5105
|
declaration,
|
|
5124
5106
|
checker,
|
|
5125
5107
|
file,
|
|
@@ -5147,9 +5129,9 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5147
5129
|
visiting.delete(type);
|
|
5148
5130
|
const objectNode = {
|
|
5149
5131
|
kind: "object",
|
|
5150
|
-
properties:
|
|
5132
|
+
properties: effectiveNamedDecl !== void 0 && (ts5.isClassDeclaration(effectiveNamedDecl) || ts5.isInterfaceDeclaration(effectiveNamedDecl) || ts5.isTypeAliasDeclaration(effectiveNamedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
5151
5133
|
properties,
|
|
5152
|
-
|
|
5134
|
+
effectiveNamedDecl,
|
|
5153
5135
|
type,
|
|
5154
5136
|
checker,
|
|
5155
5137
|
file,
|
|
@@ -5159,17 +5141,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5159
5141
|
additionalProperties: true
|
|
5160
5142
|
};
|
|
5161
5143
|
if (registryTypeName !== void 0 && shouldRegisterNamedType) {
|
|
5162
|
-
const annotations =
|
|
5163
|
-
const metadata =
|
|
5144
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5145
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
5164
5146
|
metadataPolicy,
|
|
5165
5147
|
"type",
|
|
5166
5148
|
registryTypeName,
|
|
5167
|
-
|
|
5149
|
+
effectiveNamedDecl,
|
|
5168
5150
|
checker,
|
|
5169
5151
|
extensionRegistry,
|
|
5170
5152
|
{
|
|
5171
5153
|
checker,
|
|
5172
|
-
declaration:
|
|
5154
|
+
declaration: effectiveNamedDecl,
|
|
5173
5155
|
subjectType: type
|
|
5174
5156
|
}
|
|
5175
5157
|
) : void 0;
|
|
@@ -5178,7 +5160,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5178
5160
|
...metadata !== void 0 && { metadata },
|
|
5179
5161
|
type: objectNode,
|
|
5180
5162
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5181
|
-
provenance: provenanceForDeclaration(
|
|
5163
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5182
5164
|
};
|
|
5183
5165
|
return {
|
|
5184
5166
|
kind: "reference",
|
|
@@ -5195,12 +5177,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5195
5177
|
for (const symbol of symbols) {
|
|
5196
5178
|
const declarations = symbol.declarations;
|
|
5197
5179
|
if (!declarations) continue;
|
|
5198
|
-
const classDecl = declarations.find(
|
|
5180
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
5199
5181
|
if (classDecl) {
|
|
5200
5182
|
const map = /* @__PURE__ */ new Map();
|
|
5201
5183
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
5202
5184
|
for (const member of classDecl.members) {
|
|
5203
|
-
if (
|
|
5185
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
5204
5186
|
const fieldNode = analyzeFieldToIR(
|
|
5205
5187
|
member,
|
|
5206
5188
|
checker,
|
|
@@ -5224,7 +5206,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5224
5206
|
}
|
|
5225
5207
|
return map;
|
|
5226
5208
|
}
|
|
5227
|
-
const interfaceDecl = declarations.find(
|
|
5209
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
5228
5210
|
if (interfaceDecl) {
|
|
5229
5211
|
return buildFieldNodeInfoMap(
|
|
5230
5212
|
interfaceDecl.members,
|
|
@@ -5238,7 +5220,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5238
5220
|
extensionRegistry
|
|
5239
5221
|
);
|
|
5240
5222
|
}
|
|
5241
|
-
const typeAliasDecl = declarations.find(
|
|
5223
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
5242
5224
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5243
5225
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5244
5226
|
return buildFieldNodeInfoMap(
|
|
@@ -5262,10 +5244,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5262
5244
|
return void 0;
|
|
5263
5245
|
}
|
|
5264
5246
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5265
|
-
if (
|
|
5247
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
5266
5248
|
return resolvedTypeNode.elementType;
|
|
5267
5249
|
}
|
|
5268
|
-
if (
|
|
5250
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5269
5251
|
return resolvedTypeNode.typeArguments[0];
|
|
5270
5252
|
}
|
|
5271
5253
|
return void 0;
|
|
@@ -5276,13 +5258,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5276
5258
|
return [];
|
|
5277
5259
|
}
|
|
5278
5260
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5279
|
-
return
|
|
5261
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5280
5262
|
}
|
|
5281
5263
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5282
|
-
if (
|
|
5264
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
5283
5265
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5284
5266
|
}
|
|
5285
|
-
if (!
|
|
5267
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
5286
5268
|
return typeNode;
|
|
5287
5269
|
}
|
|
5288
5270
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5293,15 +5275,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5293
5275
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5294
5276
|
}
|
|
5295
5277
|
function isNullishTypeNode(typeNode) {
|
|
5296
|
-
if (typeNode.kind ===
|
|
5278
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
5297
5279
|
return true;
|
|
5298
5280
|
}
|
|
5299
|
-
return
|
|
5281
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
5300
5282
|
}
|
|
5301
5283
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5302
5284
|
const map = /* @__PURE__ */ new Map();
|
|
5303
5285
|
for (const member of members) {
|
|
5304
|
-
if (
|
|
5286
|
+
if (ts5.isPropertySignature(member)) {
|
|
5305
5287
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5306
5288
|
member,
|
|
5307
5289
|
checker,
|
|
@@ -5327,7 +5309,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5327
5309
|
}
|
|
5328
5310
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5329
5311
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5330
|
-
if (!
|
|
5312
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
5331
5313
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5332
5314
|
const aliasName = typeNode.typeName.getText();
|
|
5333
5315
|
throw new Error(
|
|
@@ -5336,7 +5318,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5336
5318
|
}
|
|
5337
5319
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5338
5320
|
if (!aliasDecl) return [];
|
|
5339
|
-
if (
|
|
5321
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5340
5322
|
const aliasFieldType = resolveTypeNode(
|
|
5341
5323
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5342
5324
|
checker,
|
|
@@ -5380,14 +5362,14 @@ function getNamedTypeName(type) {
|
|
|
5380
5362
|
const symbol = type.getSymbol();
|
|
5381
5363
|
if (symbol?.declarations) {
|
|
5382
5364
|
const decl = symbol.declarations[0];
|
|
5383
|
-
if (decl && (
|
|
5384
|
-
const name =
|
|
5365
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5366
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5385
5367
|
if (name) return name;
|
|
5386
5368
|
}
|
|
5387
5369
|
}
|
|
5388
5370
|
const aliasSymbol = type.aliasSymbol;
|
|
5389
5371
|
if (aliasSymbol?.declarations) {
|
|
5390
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5372
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5391
5373
|
if (aliasDecl) {
|
|
5392
5374
|
return aliasDecl.name.text;
|
|
5393
5375
|
}
|
|
@@ -5398,24 +5380,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5398
5380
|
const symbol = type.getSymbol();
|
|
5399
5381
|
if (symbol?.declarations) {
|
|
5400
5382
|
const decl = symbol.declarations[0];
|
|
5401
|
-
if (decl && (
|
|
5383
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5402
5384
|
return decl;
|
|
5403
5385
|
}
|
|
5404
5386
|
}
|
|
5405
5387
|
const aliasSymbol = type.aliasSymbol;
|
|
5406
5388
|
if (aliasSymbol?.declarations) {
|
|
5407
|
-
return aliasSymbol.declarations.find(
|
|
5389
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5408
5390
|
}
|
|
5409
5391
|
return void 0;
|
|
5410
5392
|
}
|
|
5411
5393
|
function analyzeMethod(method, checker) {
|
|
5412
|
-
if (!
|
|
5394
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
5413
5395
|
return null;
|
|
5414
5396
|
}
|
|
5415
5397
|
const name = method.name.text;
|
|
5416
5398
|
const parameters = [];
|
|
5417
5399
|
for (const param of method.parameters) {
|
|
5418
|
-
if (
|
|
5400
|
+
if (ts5.isIdentifier(param.name)) {
|
|
5419
5401
|
const paramInfo = analyzeParameter(param, checker);
|
|
5420
5402
|
parameters.push(paramInfo);
|
|
5421
5403
|
}
|
|
@@ -5426,7 +5408,7 @@ function analyzeMethod(method, checker) {
|
|
|
5426
5408
|
return { name, parameters, returnTypeNode, returnType };
|
|
5427
5409
|
}
|
|
5428
5410
|
function analyzeParameter(param, checker) {
|
|
5429
|
-
const name =
|
|
5411
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
5430
5412
|
const typeNode = param.type;
|
|
5431
5413
|
const type = checker.getTypeAtLocation(param);
|
|
5432
5414
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5435,15 +5417,15 @@ function analyzeParameter(param, checker) {
|
|
|
5435
5417
|
}
|
|
5436
5418
|
function detectFormSpecReference(typeNode) {
|
|
5437
5419
|
if (!typeNode) return null;
|
|
5438
|
-
if (!
|
|
5439
|
-
const typeName =
|
|
5420
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
5421
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5440
5422
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5441
5423
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5442
|
-
if (!typeArg || !
|
|
5443
|
-
if (
|
|
5424
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
5425
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
5444
5426
|
return typeArg.exprName.text;
|
|
5445
5427
|
}
|
|
5446
|
-
if (
|
|
5428
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
5447
5429
|
return typeArg.exprName.right.text;
|
|
5448
5430
|
}
|
|
5449
5431
|
return null;
|
|
@@ -5465,23 +5447,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5465
5447
|
function createProgramContext(filePath, additionalFiles) {
|
|
5466
5448
|
const absolutePath = path.resolve(filePath);
|
|
5467
5449
|
const fileDir = path.dirname(absolutePath);
|
|
5468
|
-
const configPath =
|
|
5450
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
5469
5451
|
let compilerOptions;
|
|
5470
5452
|
let fileNames;
|
|
5471
5453
|
if (configPath) {
|
|
5472
|
-
const configFile =
|
|
5454
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
5473
5455
|
if (configFile.error) {
|
|
5474
5456
|
throw new Error(
|
|
5475
|
-
`Error reading tsconfig.json: ${
|
|
5457
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5476
5458
|
);
|
|
5477
5459
|
}
|
|
5478
|
-
const parsed =
|
|
5460
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
5479
5461
|
configFile.config,
|
|
5480
|
-
|
|
5462
|
+
ts6.sys,
|
|
5481
5463
|
path.dirname(configPath)
|
|
5482
5464
|
);
|
|
5483
5465
|
if (parsed.errors.length > 0) {
|
|
5484
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5466
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5485
5467
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5486
5468
|
}
|
|
5487
5469
|
compilerOptions = parsed.options;
|
|
@@ -5489,9 +5471,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5489
5471
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5490
5472
|
} else {
|
|
5491
5473
|
compilerOptions = {
|
|
5492
|
-
target:
|
|
5493
|
-
module:
|
|
5494
|
-
moduleResolution:
|
|
5474
|
+
target: ts6.ScriptTarget.ES2022,
|
|
5475
|
+
module: ts6.ModuleKind.NodeNext,
|
|
5476
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
5495
5477
|
strict: true,
|
|
5496
5478
|
skipLibCheck: true,
|
|
5497
5479
|
declaration: true
|
|
@@ -5499,7 +5481,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5499
5481
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5500
5482
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5501
5483
|
}
|
|
5502
|
-
const program =
|
|
5484
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
5503
5485
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5504
5486
|
if (!sourceFile) {
|
|
5505
5487
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5518,19 +5500,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5518
5500
|
result = node;
|
|
5519
5501
|
return;
|
|
5520
5502
|
}
|
|
5521
|
-
|
|
5503
|
+
ts6.forEachChild(node, visit);
|
|
5522
5504
|
}
|
|
5523
5505
|
visit(sourceFile);
|
|
5524
5506
|
return result;
|
|
5525
5507
|
}
|
|
5526
5508
|
function findClassByName(sourceFile, className) {
|
|
5527
|
-
return findNodeByName(sourceFile, className,
|
|
5509
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
5528
5510
|
}
|
|
5529
5511
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5530
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5512
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
5531
5513
|
}
|
|
5532
5514
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5533
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5515
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5534
5516
|
}
|
|
5535
5517
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5536
5518
|
if (rootType.kind === "object") {
|
|
@@ -5570,22 +5552,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5570
5552
|
};
|
|
5571
5553
|
}
|
|
5572
5554
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5573
|
-
if (
|
|
5555
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5574
5556
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5575
5557
|
}
|
|
5576
|
-
if (
|
|
5558
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5577
5559
|
return true;
|
|
5578
5560
|
}
|
|
5579
|
-
return
|
|
5561
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5580
5562
|
}
|
|
5581
5563
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5582
|
-
if (
|
|
5564
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5583
5565
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5584
5566
|
}
|
|
5585
|
-
if (
|
|
5567
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
5586
5568
|
const propertyNames = [];
|
|
5587
5569
|
for (const member of typeNode.members) {
|
|
5588
|
-
if (!
|
|
5570
|
+
if (!ts6.isPropertySignature(member)) {
|
|
5589
5571
|
continue;
|
|
5590
5572
|
}
|
|
5591
5573
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5595,13 +5577,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5595
5577
|
}
|
|
5596
5578
|
return propertyNames;
|
|
5597
5579
|
}
|
|
5598
|
-
if (
|
|
5580
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5599
5581
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5600
5582
|
}
|
|
5601
5583
|
return null;
|
|
5602
5584
|
}
|
|
5603
5585
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5604
|
-
if (!
|
|
5586
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
5605
5587
|
return [];
|
|
5606
5588
|
}
|
|
5607
5589
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5802,7 +5784,7 @@ function makeFileProvenance(filePath) {
|
|
|
5802
5784
|
}
|
|
5803
5785
|
|
|
5804
5786
|
// src/extensions/symbol-registry.ts
|
|
5805
|
-
var
|
|
5787
|
+
var ts7 = __toESM(require("typescript"), 1);
|
|
5806
5788
|
var path2 = __toESM(require("path"), 1);
|
|
5807
5789
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5808
5790
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5812,10 +5794,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5812
5794
|
return symbolMap;
|
|
5813
5795
|
}
|
|
5814
5796
|
function visit(node) {
|
|
5815
|
-
if (
|
|
5797
|
+
if (ts7.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5816
5798
|
processDefineCustomTypeCall(node);
|
|
5817
5799
|
}
|
|
5818
|
-
|
|
5800
|
+
ts7.forEachChild(node, visit);
|
|
5819
5801
|
}
|
|
5820
5802
|
function processDefineCustomTypeCall(call) {
|
|
5821
5803
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5852,7 +5834,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5852
5834
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5853
5835
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5854
5836
|
if (callSymbol !== void 0) {
|
|
5855
|
-
const resolved = callSymbol.flags &
|
|
5837
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5856
5838
|
const decl = resolved.declarations?.[0];
|
|
5857
5839
|
if (decl !== void 0) {
|
|
5858
5840
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5860,24 +5842,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5860
5842
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5861
5843
|
}
|
|
5862
5844
|
}
|
|
5863
|
-
return
|
|
5845
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5864
5846
|
}
|
|
5865
5847
|
function extractTypeNameFromCallArg(call) {
|
|
5866
5848
|
const arg = call.arguments[0];
|
|
5867
|
-
if (arg === void 0 || !
|
|
5849
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5868
5850
|
return null;
|
|
5869
5851
|
}
|
|
5870
5852
|
const typeNameProp = arg.properties.find(
|
|
5871
|
-
(p) =>
|
|
5853
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5872
5854
|
);
|
|
5873
|
-
if (typeNameProp === void 0 || !
|
|
5855
|
+
if (typeNameProp === void 0 || !ts7.isStringLiteral(typeNameProp.initializer)) {
|
|
5874
5856
|
return null;
|
|
5875
5857
|
}
|
|
5876
5858
|
return typeNameProp.initializer.text;
|
|
5877
5859
|
}
|
|
5878
5860
|
function extractEnclosingExtensionId(call, checker) {
|
|
5879
|
-
for (let node = call.parent; !
|
|
5880
|
-
if (
|
|
5861
|
+
for (let node = call.parent; !ts7.isSourceFile(node); node = node.parent) {
|
|
5862
|
+
if (ts7.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5881
5863
|
return extractExtensionIdFromCallArg(node);
|
|
5882
5864
|
}
|
|
5883
5865
|
}
|
|
@@ -5886,24 +5868,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5886
5868
|
function isDefineExtensionCall(node, checker) {
|
|
5887
5869
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5888
5870
|
if (callSymbol !== void 0) {
|
|
5889
|
-
const resolved = callSymbol.flags &
|
|
5871
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5890
5872
|
const decl = resolved.declarations?.[0];
|
|
5891
5873
|
if (decl !== void 0) {
|
|
5892
5874
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5893
5875
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5894
5876
|
}
|
|
5895
5877
|
}
|
|
5896
|
-
return
|
|
5878
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5897
5879
|
}
|
|
5898
5880
|
function extractExtensionIdFromCallArg(call) {
|
|
5899
5881
|
const arg = call.arguments[0];
|
|
5900
|
-
if (arg === void 0 || !
|
|
5882
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5901
5883
|
return null;
|
|
5902
5884
|
}
|
|
5903
5885
|
const prop = arg.properties.find(
|
|
5904
|
-
(p) =>
|
|
5886
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5905
5887
|
);
|
|
5906
|
-
if (prop === void 0 || !
|
|
5888
|
+
if (prop === void 0 || !ts7.isStringLiteral(prop.initializer)) {
|
|
5907
5889
|
return null;
|
|
5908
5890
|
}
|
|
5909
5891
|
return prop.initializer.text;
|
|
@@ -5923,9 +5905,9 @@ function findRegistrationByTypeName(registry, typeName) {
|
|
|
5923
5905
|
}
|
|
5924
5906
|
|
|
5925
5907
|
// src/validate/constraint-validator.ts
|
|
5926
|
-
var
|
|
5908
|
+
var import_internal7 = require("@formspec/analysis/internal");
|
|
5927
5909
|
function validateFieldNode(ctx, field) {
|
|
5928
|
-
const analysis = (0,
|
|
5910
|
+
const analysis = (0, import_internal7.analyzeConstraintTargets)(
|
|
5929
5911
|
field.name,
|
|
5930
5912
|
field.type,
|
|
5931
5913
|
field.constraints,
|
|
@@ -5943,7 +5925,7 @@ function validateFieldNode(ctx, field) {
|
|
|
5943
5925
|
}
|
|
5944
5926
|
function validateObjectProperty(ctx, parentName, property) {
|
|
5945
5927
|
const qualifiedName = `${parentName}.${property.name}`;
|
|
5946
|
-
const analysis = (0,
|
|
5928
|
+
const analysis = (0, import_internal7.analyzeConstraintTargets)(
|
|
5947
5929
|
qualifiedName,
|
|
5948
5930
|
property.type,
|
|
5949
5931
|
property.constraints,
|
|
@@ -6165,7 +6147,7 @@ function generateSchemasBatch(options) {
|
|
|
6165
6147
|
return options.targets.map((target) => {
|
|
6166
6148
|
let ctx;
|
|
6167
6149
|
try {
|
|
6168
|
-
const cacheKey =
|
|
6150
|
+
const cacheKey = ts8.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
6169
6151
|
const cachedContext = contextCache.get(cacheKey);
|
|
6170
6152
|
if (cachedContext === void 0) {
|
|
6171
6153
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6224,7 +6206,7 @@ function isMutableRegistry(reg) {
|
|
|
6224
6206
|
}
|
|
6225
6207
|
function resolveStaticOptions(options) {
|
|
6226
6208
|
const legacyRegistry = options.extensionRegistry;
|
|
6227
|
-
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6209
|
+
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6228
6210
|
return {
|
|
6229
6211
|
extensionRegistry: legacyRegistry ?? configRegistry,
|
|
6230
6212
|
// eslint-disable-next-line @typescript-eslint/no-deprecated -- migration bridge reads deprecated fields
|
|
@@ -6236,7 +6218,7 @@ function resolveStaticOptions(options) {
|
|
|
6236
6218
|
};
|
|
6237
6219
|
}
|
|
6238
6220
|
function resolveOptions(options) {
|
|
6239
|
-
const configRegistry = options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6221
|
+
const configRegistry = options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6240
6222
|
const legacyRegistry = options.extensionRegistry;
|
|
6241
6223
|
return {
|
|
6242
6224
|
// When the caller provides the deprecated extensionRegistry field directly,
|
|
@@ -6321,7 +6303,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6321
6303
|
}
|
|
6322
6304
|
|
|
6323
6305
|
// src/static-build.ts
|
|
6324
|
-
var
|
|
6306
|
+
var ts9 = __toESM(require("typescript"), 1);
|
|
6325
6307
|
function toStaticBuildContext(context) {
|
|
6326
6308
|
return context;
|
|
6327
6309
|
}
|
|
@@ -6336,7 +6318,7 @@ function getModuleSymbol(context) {
|
|
|
6336
6318
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6337
6319
|
}
|
|
6338
6320
|
function isSchemaSourceDeclaration(declaration) {
|
|
6339
|
-
return
|
|
6321
|
+
return ts9.isClassDeclaration(declaration) || ts9.isInterfaceDeclaration(declaration) || ts9.isTypeAliasDeclaration(declaration);
|
|
6340
6322
|
}
|
|
6341
6323
|
function resolveModuleExport(context, exportName = "default") {
|
|
6342
6324
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6347,15 +6329,15 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6347
6329
|
if (exportSymbol === null) {
|
|
6348
6330
|
return null;
|
|
6349
6331
|
}
|
|
6350
|
-
return exportSymbol.flags &
|
|
6332
|
+
return exportSymbol.flags & ts9.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6351
6333
|
}
|
|
6352
6334
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6353
6335
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6354
6336
|
}
|
|
6355
6337
|
|
|
6356
6338
|
// src/generators/discovered-schema.ts
|
|
6357
|
-
var
|
|
6358
|
-
var
|
|
6339
|
+
var ts10 = __toESM(require("typescript"), 1);
|
|
6340
|
+
var import_internal8 = require("@formspec/analysis/internal");
|
|
6359
6341
|
var import_internals6 = require("@formspec/core/internals");
|
|
6360
6342
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
6361
6343
|
return {
|
|
@@ -6364,17 +6346,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6364
6346
|
};
|
|
6365
6347
|
}
|
|
6366
6348
|
function isNamedTypeDeclaration(declaration) {
|
|
6367
|
-
return
|
|
6349
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6368
6350
|
}
|
|
6369
6351
|
function hasConcreteTypeArguments(type, checker) {
|
|
6370
6352
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6371
6353
|
return true;
|
|
6372
6354
|
}
|
|
6373
|
-
if ((type.flags &
|
|
6355
|
+
if ((type.flags & ts10.TypeFlags.Object) === 0) {
|
|
6374
6356
|
return false;
|
|
6375
6357
|
}
|
|
6376
6358
|
const objectType = type;
|
|
6377
|
-
if ((objectType.objectFlags &
|
|
6359
|
+
if ((objectType.objectFlags & ts10.ObjectFlags.Reference) === 0) {
|
|
6378
6360
|
return false;
|
|
6379
6361
|
}
|
|
6380
6362
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6387,13 +6369,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6387
6369
|
return declaration;
|
|
6388
6370
|
}
|
|
6389
6371
|
}
|
|
6390
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6372
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts10.isTypeAliasDeclaration);
|
|
6391
6373
|
return aliasDeclaration;
|
|
6392
6374
|
}
|
|
6393
6375
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6394
6376
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6395
6377
|
const namedNode = sourceNode;
|
|
6396
|
-
if (namedNode.name !== void 0 &&
|
|
6378
|
+
if (namedNode.name !== void 0 && ts10.isIdentifier(namedNode.name)) {
|
|
6397
6379
|
return namedNode.name.text;
|
|
6398
6380
|
}
|
|
6399
6381
|
}
|
|
@@ -6615,7 +6597,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6615
6597
|
function generateSchemasFromDeclaration(options) {
|
|
6616
6598
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6617
6599
|
const resolved = resolveStaticOptions(options);
|
|
6618
|
-
if (
|
|
6600
|
+
if (ts10.isClassDeclaration(options.declaration)) {
|
|
6619
6601
|
return generateSchemasFromAnalysis(
|
|
6620
6602
|
analyzeClassToIR(
|
|
6621
6603
|
options.declaration,
|
|
@@ -6629,7 +6611,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6629
6611
|
resolved
|
|
6630
6612
|
);
|
|
6631
6613
|
}
|
|
6632
|
-
if (
|
|
6614
|
+
if (ts10.isInterfaceDeclaration(options.declaration)) {
|
|
6633
6615
|
return generateSchemasFromAnalysis(
|
|
6634
6616
|
analyzeInterfaceToIR(
|
|
6635
6617
|
options.declaration,
|
|
@@ -6643,7 +6625,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6643
6625
|
resolved
|
|
6644
6626
|
);
|
|
6645
6627
|
}
|
|
6646
|
-
if (
|
|
6628
|
+
if (ts10.isTypeAliasDeclaration(options.declaration)) {
|
|
6647
6629
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6648
6630
|
options.declaration,
|
|
6649
6631
|
options.context.checker,
|
|
@@ -6702,7 +6684,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6702
6684
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6703
6685
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6704
6686
|
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 &&
|
|
6687
|
+
const fallbackName = options.declaration.name !== void 0 && ts10.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6706
6688
|
return generateSchemasFromResolvedType({
|
|
6707
6689
|
...options,
|
|
6708
6690
|
type,
|
|
@@ -6712,7 +6694,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6712
6694
|
}
|
|
6713
6695
|
function resolveDeclarationMetadata(options) {
|
|
6714
6696
|
const resolved = resolveStaticOptions(options);
|
|
6715
|
-
const analysis = (0,
|
|
6697
|
+
const analysis = (0, import_internal8.analyzeMetadataForNodeWithChecker)({
|
|
6716
6698
|
checker: options.context.checker,
|
|
6717
6699
|
node: options.declaration,
|
|
6718
6700
|
metadata: resolved.metadata,
|
|
@@ -6749,14 +6731,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6749
6731
|
if (typeNode === void 0) {
|
|
6750
6732
|
return void 0;
|
|
6751
6733
|
}
|
|
6752
|
-
if (
|
|
6734
|
+
if (ts10.isParenthesizedTypeNode(typeNode)) {
|
|
6753
6735
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6754
6736
|
return unwrapped ?? typeNode;
|
|
6755
6737
|
}
|
|
6756
6738
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6757
6739
|
}
|
|
6758
6740
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6759
|
-
return
|
|
6741
|
+
return ts10.isTypeReferenceNode(typeNode) && ts10.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6760
6742
|
}
|
|
6761
6743
|
|
|
6762
6744
|
// src/generators/mixed-authoring.ts
|