@formspec/build 0.1.0-alpha.58 → 0.1.0-alpha.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/builtin-brands.d.ts +10 -7
- package/dist/analyzer/builtin-brands.d.ts.map +1 -1
- package/dist/analyzer/class-analyzer.d.ts +29 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +126 -31
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +129 -32
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +431 -12
- package/dist/build-beta.d.ts +399 -12
- package/dist/build-internal.d.ts +460 -12
- package/dist/build.d.ts +399 -12
- package/dist/cli.cjs +590 -338
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +547 -289
- package/dist/cli.js.map +1 -1
- package/dist/extensions/registry.d.ts +19 -1
- package/dist/extensions/registry.d.ts.map +1 -1
- package/dist/extensions/resolve-custom-type.d.ts.map +1 -1
- package/dist/extensions/ts-type-utils.d.ts +0 -11
- package/dist/extensions/ts-type-utils.d.ts.map +1 -1
- package/dist/generators/class-schema.d.ts.map +1 -1
- package/dist/index.cjs +580 -327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +546 -287
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +554 -301
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +515 -256
- package/dist/internals.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -996,7 +996,7 @@ function generateJsonSchemaFromIR(ir, options) {
|
|
|
996
996
|
applyConstraints(ctx.defs[schemaName], typeDef.constraints, ctx);
|
|
997
997
|
}
|
|
998
998
|
if (typeDef.annotations && typeDef.annotations.length > 0) {
|
|
999
|
-
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx);
|
|
999
|
+
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx, typeDef.type);
|
|
1000
1000
|
}
|
|
1001
1001
|
}
|
|
1002
1002
|
const properties = {};
|
|
@@ -1069,7 +1069,7 @@ function generateFieldSchema(field, ctx) {
|
|
|
1069
1069
|
}
|
|
1070
1070
|
}
|
|
1071
1071
|
applyResolvedMetadata(schema, field.metadata);
|
|
1072
|
-
applyAnnotations(schema, rootAnnotations, ctx);
|
|
1072
|
+
applyAnnotations(schema, rootAnnotations, ctx, field.type);
|
|
1073
1073
|
if (itemStringSchema !== void 0) {
|
|
1074
1074
|
applyAnnotations(itemStringSchema, itemAnnotations, ctx);
|
|
1075
1075
|
}
|
|
@@ -1112,32 +1112,36 @@ function applyPathTargetedConstraints(schema, pathConstraints, ctx, typeNode) {
|
|
|
1112
1112
|
return schema;
|
|
1113
1113
|
}
|
|
1114
1114
|
if (schema.$ref) {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
properties: propertyOverrides,
|
|
1119
|
-
...rest
|
|
1115
|
+
return {
|
|
1116
|
+
...schema,
|
|
1117
|
+
properties: propertyOverrides
|
|
1120
1118
|
};
|
|
1121
|
-
return { allOf: [refPart, overridePart] };
|
|
1122
1119
|
}
|
|
1123
1120
|
if (schema.type === "object" && schema.properties) {
|
|
1124
|
-
const missingOverrides = {};
|
|
1125
1121
|
for (const [target, overrideSchema] of Object.entries(propertyOverrides)) {
|
|
1126
|
-
if (schema.properties
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1122
|
+
if (Object.hasOwn(schema.properties, target)) {
|
|
1123
|
+
const existing = schema.properties[target];
|
|
1124
|
+
if (existing) {
|
|
1125
|
+
mergeSchemaOverride(existing, overrideSchema);
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1130
1128
|
}
|
|
1129
|
+
Object.defineProperty(schema.properties, target, {
|
|
1130
|
+
value: overrideSchema,
|
|
1131
|
+
writable: true,
|
|
1132
|
+
enumerable: true,
|
|
1133
|
+
configurable: true
|
|
1134
|
+
});
|
|
1131
1135
|
}
|
|
1132
|
-
|
|
1133
|
-
return schema;
|
|
1134
|
-
}
|
|
1135
|
-
return {
|
|
1136
|
-
allOf: [schema, { properties: missingOverrides }]
|
|
1137
|
-
};
|
|
1136
|
+
return schema;
|
|
1138
1137
|
}
|
|
1139
1138
|
if (schema.allOf) {
|
|
1140
|
-
|
|
1139
|
+
const overrideMember = { properties: propertyOverrides };
|
|
1140
|
+
const flattened = tryFlattenAllOfToSiblings(schema, overrideMember);
|
|
1141
|
+
if (flattened !== void 0) {
|
|
1142
|
+
return flattened;
|
|
1143
|
+
}
|
|
1144
|
+
schema.allOf = [...schema.allOf, overrideMember];
|
|
1141
1145
|
return schema;
|
|
1142
1146
|
}
|
|
1143
1147
|
return schema;
|
|
@@ -1250,7 +1254,7 @@ function generatePropertySchema(prop, ctx) {
|
|
|
1250
1254
|
const schema = generateTypeNode(prop.type, ctx);
|
|
1251
1255
|
applyConstraints(schema, prop.constraints, ctx);
|
|
1252
1256
|
applyResolvedMetadata(schema, prop.metadata);
|
|
1253
|
-
applyAnnotations(schema, prop.annotations, ctx);
|
|
1257
|
+
applyAnnotations(schema, prop.annotations, ctx, prop.type);
|
|
1254
1258
|
return schema;
|
|
1255
1259
|
}
|
|
1256
1260
|
function generateUnionType(type, ctx) {
|
|
@@ -1353,13 +1357,20 @@ function buildPropertyOverrides(pathConstraints, typeNode, ctx) {
|
|
|
1353
1357
|
grouped.push(constraint);
|
|
1354
1358
|
byTarget.set(target, grouped);
|
|
1355
1359
|
}
|
|
1356
|
-
const overrides =
|
|
1360
|
+
const overrides = /* @__PURE__ */ Object.create(null);
|
|
1357
1361
|
for (const [target, constraints] of byTarget) {
|
|
1358
|
-
|
|
1362
|
+
const resolvedName = resolveSerializedPropertyName(target, typeNode, ctx);
|
|
1363
|
+
const schema = buildPathOverrideSchema(
|
|
1359
1364
|
constraints.map(stripLeadingPathSegment),
|
|
1360
1365
|
resolveTargetTypeNode(target, typeNode, ctx),
|
|
1361
1366
|
ctx
|
|
1362
1367
|
);
|
|
1368
|
+
Object.defineProperty(overrides, resolvedName, {
|
|
1369
|
+
value: schema,
|
|
1370
|
+
writable: true,
|
|
1371
|
+
enumerable: true,
|
|
1372
|
+
configurable: true
|
|
1373
|
+
});
|
|
1363
1374
|
}
|
|
1364
1375
|
return overrides;
|
|
1365
1376
|
}
|
|
@@ -1386,6 +1397,34 @@ function buildPathOverrideSchema(constraints, typeNode, ctx) {
|
|
|
1386
1397
|
schema.properties = buildPropertyOverrides(nestedConstraints, effectiveType, ctx);
|
|
1387
1398
|
return schema;
|
|
1388
1399
|
}
|
|
1400
|
+
function tryFlattenAllOfToSiblings(schema, overrideMember) {
|
|
1401
|
+
if (schema.allOf?.length !== 1) {
|
|
1402
|
+
return void 0;
|
|
1403
|
+
}
|
|
1404
|
+
const [soleMember] = schema.allOf;
|
|
1405
|
+
if (soleMember === void 0) {
|
|
1406
|
+
return void 0;
|
|
1407
|
+
}
|
|
1408
|
+
const { allOf: _allOf, ...outerRest } = schema;
|
|
1409
|
+
const outerKeys = new Set(Object.keys(outerRest));
|
|
1410
|
+
const memberKeys = new Set(Object.keys(soleMember));
|
|
1411
|
+
const overrideKeys = new Set(Object.keys(overrideMember));
|
|
1412
|
+
for (const key of memberKeys) {
|
|
1413
|
+
if (outerKeys.has(key) || overrideKeys.has(key)) {
|
|
1414
|
+
return void 0;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
for (const key of overrideKeys) {
|
|
1418
|
+
if (outerKeys.has(key)) {
|
|
1419
|
+
return void 0;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
return {
|
|
1423
|
+
...outerRest,
|
|
1424
|
+
...soleMember,
|
|
1425
|
+
...overrideMember
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1389
1428
|
function mergeSchemaOverride(target, override) {
|
|
1390
1429
|
const nullableValueBranch = getNullableUnionValueSchema(target);
|
|
1391
1430
|
if (nullableValueBranch !== void 0) {
|
|
@@ -1393,11 +1432,16 @@ function mergeSchemaOverride(target, override) {
|
|
|
1393
1432
|
return;
|
|
1394
1433
|
}
|
|
1395
1434
|
if (override.properties !== void 0) {
|
|
1396
|
-
const mergedProperties = target.properties ??
|
|
1435
|
+
const mergedProperties = target.properties ?? /* @__PURE__ */ Object.create(null);
|
|
1397
1436
|
for (const [name, propertyOverride] of Object.entries(override.properties)) {
|
|
1398
|
-
const existing = mergedProperties[name];
|
|
1437
|
+
const existing = Object.hasOwn(mergedProperties, name) ? mergedProperties[name] : void 0;
|
|
1399
1438
|
if (existing === void 0) {
|
|
1400
|
-
mergedProperties
|
|
1439
|
+
Object.defineProperty(mergedProperties, name, {
|
|
1440
|
+
value: propertyOverride,
|
|
1441
|
+
writable: true,
|
|
1442
|
+
enumerable: true,
|
|
1443
|
+
configurable: true
|
|
1444
|
+
});
|
|
1401
1445
|
} else {
|
|
1402
1446
|
mergeSchemaOverride(existing, propertyOverride);
|
|
1403
1447
|
}
|
|
@@ -1415,7 +1459,12 @@ function mergeSchemaOverride(target, override) {
|
|
|
1415
1459
|
if (key === "properties" || key === "items") {
|
|
1416
1460
|
continue;
|
|
1417
1461
|
}
|
|
1418
|
-
target
|
|
1462
|
+
Object.defineProperty(target, key, {
|
|
1463
|
+
value,
|
|
1464
|
+
writable: true,
|
|
1465
|
+
enumerable: true,
|
|
1466
|
+
configurable: true
|
|
1467
|
+
});
|
|
1419
1468
|
}
|
|
1420
1469
|
}
|
|
1421
1470
|
function stripLeadingPathSegment(constraint) {
|
|
@@ -1515,7 +1564,7 @@ function applyConstraints(schema, constraints, ctx) {
|
|
|
1515
1564
|
}
|
|
1516
1565
|
}
|
|
1517
1566
|
}
|
|
1518
|
-
function applyAnnotations(schema, annotations, ctx) {
|
|
1567
|
+
function applyAnnotations(schema, annotations, ctx, typeNode) {
|
|
1519
1568
|
for (const annotation of annotations) {
|
|
1520
1569
|
switch (annotation.annotationKind) {
|
|
1521
1570
|
case "displayName":
|
|
@@ -1528,7 +1577,7 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
1528
1577
|
schema[`${ctx.vendorPrefix}-remarks`] = annotation.value;
|
|
1529
1578
|
break;
|
|
1530
1579
|
case "defaultValue":
|
|
1531
|
-
schema.default = annotation.value;
|
|
1580
|
+
schema.default = coerceDefaultValue(annotation.value, typeNode, schema, ctx);
|
|
1532
1581
|
break;
|
|
1533
1582
|
case "format":
|
|
1534
1583
|
schema.format = annotation.value;
|
|
@@ -1553,6 +1602,34 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
1553
1602
|
}
|
|
1554
1603
|
}
|
|
1555
1604
|
}
|
|
1605
|
+
function coerceDefaultValue(value, typeNode, emittedSchema, ctx) {
|
|
1606
|
+
if (typeNode?.kind !== "custom") {
|
|
1607
|
+
return value;
|
|
1608
|
+
}
|
|
1609
|
+
const registration = ctx.extensionRegistry?.findType(typeNode.typeId);
|
|
1610
|
+
if (registration === void 0) {
|
|
1611
|
+
return value;
|
|
1612
|
+
}
|
|
1613
|
+
if (registration.serializeDefault !== void 0) {
|
|
1614
|
+
return registration.serializeDefault(value, typeNode.payload);
|
|
1615
|
+
}
|
|
1616
|
+
const declaredType = emittedSchema["type"];
|
|
1617
|
+
if (declaredType === "string" && typeof value !== "string") {
|
|
1618
|
+
if (typeof value === "number") {
|
|
1619
|
+
if (!Number.isFinite(value)) {
|
|
1620
|
+
return value;
|
|
1621
|
+
}
|
|
1622
|
+
return String(value);
|
|
1623
|
+
}
|
|
1624
|
+
if (typeof value === "boolean") {
|
|
1625
|
+
return String(value);
|
|
1626
|
+
}
|
|
1627
|
+
if (typeof value === "bigint") {
|
|
1628
|
+
return value.toString();
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
return value;
|
|
1632
|
+
}
|
|
1556
1633
|
function generateCustomType(type, ctx) {
|
|
1557
1634
|
const registration = ctx.extensionRegistry?.findType(type.typeId);
|
|
1558
1635
|
if (registration === void 0) {
|
|
@@ -1979,7 +2056,9 @@ import {
|
|
|
1979
2056
|
import {
|
|
1980
2057
|
getTagDefinition,
|
|
1981
2058
|
normalizeFormSpecTagName,
|
|
1982
|
-
getSyntheticLogger
|
|
2059
|
+
getSyntheticLogger,
|
|
2060
|
+
_validateExtensionSetup,
|
|
2061
|
+
logSetupDiagnostics
|
|
1983
2062
|
} from "@formspec/analysis/internal";
|
|
1984
2063
|
var BUILTIN_METADATA_TAGS = /* @__PURE__ */ new Set(["apiName", "displayName"]);
|
|
1985
2064
|
function buildConstraintTagSources(extensions) {
|
|
@@ -1989,6 +2068,16 @@ function buildConstraintTagSources(extensions) {
|
|
|
1989
2068
|
constraintTags: extension.constraintTags.map((tag) => ({
|
|
1990
2069
|
tagName: normalizeFormSpecTagName(tag.tagName)
|
|
1991
2070
|
}))
|
|
2071
|
+
} : {},
|
|
2072
|
+
// Include customTypes so _validateExtensionSetup can check tsTypeNames for
|
|
2073
|
+
// unsupported built-in overrides and invalid identifier patterns.
|
|
2074
|
+
...extension.types !== void 0 ? {
|
|
2075
|
+
customTypes: extension.types.map((type) => ({
|
|
2076
|
+
// tsTypeNames: deprecated in favour of symbol-based detection, but
|
|
2077
|
+
// still required for name-based validation in _validateExtensionSetup
|
|
2078
|
+
// until the bridge is fully retired (see §synthetic-checker-retirement §4C).
|
|
2079
|
+
tsTypeNames: type.tsTypeNames ?? [type.typeName]
|
|
2080
|
+
}))
|
|
1992
2081
|
} : {}
|
|
1993
2082
|
}));
|
|
1994
2083
|
}
|
|
@@ -1998,7 +2087,13 @@ function createExtensionRegistry(extensions) {
|
|
|
1998
2087
|
extensionCount: extensions.length,
|
|
1999
2088
|
extensionIds: extensions.map((e) => e.extensionId)
|
|
2000
2089
|
});
|
|
2001
|
-
const
|
|
2090
|
+
const extensionTagSources = buildConstraintTagSources(extensions);
|
|
2091
|
+
const setupDiagnostics = _validateExtensionSetup(extensionTagSources);
|
|
2092
|
+
logSetupDiagnostics(registryLog, {
|
|
2093
|
+
diagnosticCount: setupDiagnostics.length,
|
|
2094
|
+
codes: setupDiagnostics.map((d) => d.kind)
|
|
2095
|
+
});
|
|
2096
|
+
const reservedTagSources = extensionTagSources;
|
|
2002
2097
|
let symbolMap = /* @__PURE__ */ new Map();
|
|
2003
2098
|
const typeMap = /* @__PURE__ */ new Map();
|
|
2004
2099
|
const typeNameMap = /* @__PURE__ */ new Map();
|
|
@@ -2135,10 +2230,12 @@ function createExtensionRegistry(extensions) {
|
|
|
2135
2230
|
constraintTagCount: constraintTagMap.size,
|
|
2136
2231
|
broadeningCount: builtinBroadeningMap.size,
|
|
2137
2232
|
annotationCount: annotationMap.size,
|
|
2138
|
-
metadataSlotCount: metadataSlotMap.size
|
|
2233
|
+
metadataSlotCount: metadataSlotMap.size,
|
|
2234
|
+
setupDiagnosticCount: setupDiagnostics.length
|
|
2139
2235
|
});
|
|
2140
2236
|
return {
|
|
2141
2237
|
extensions,
|
|
2238
|
+
setupDiagnostics,
|
|
2142
2239
|
findType: (typeId) => typeMap.get(typeId),
|
|
2143
2240
|
findTypeByName: (typeName) => typeNameMap.get(typeName),
|
|
2144
2241
|
findTypeByBrand: (brand) => brandMap.get(brand),
|
|
@@ -2216,24 +2313,24 @@ var jsonSchema7Schema = z3.lazy(
|
|
|
2216
2313
|
);
|
|
2217
2314
|
|
|
2218
2315
|
// src/generators/class-schema.ts
|
|
2219
|
-
import * as
|
|
2316
|
+
import * as ts8 from "typescript";
|
|
2220
2317
|
|
|
2221
2318
|
// src/analyzer/program.ts
|
|
2222
|
-
import * as
|
|
2319
|
+
import * as ts6 from "typescript";
|
|
2223
2320
|
import * as path from "path";
|
|
2224
2321
|
|
|
2225
2322
|
// src/analyzer/class-analyzer.ts
|
|
2226
|
-
import * as
|
|
2323
|
+
import * as ts5 from "typescript";
|
|
2227
2324
|
import {
|
|
2228
2325
|
analyzeMetadataForNodeWithChecker,
|
|
2229
2326
|
parseCommentBlock
|
|
2230
2327
|
} from "@formspec/analysis/internal";
|
|
2231
2328
|
|
|
2232
2329
|
// src/analyzer/jsdoc-constraints.ts
|
|
2233
|
-
import * as
|
|
2330
|
+
import * as ts4 from "typescript";
|
|
2234
2331
|
|
|
2235
2332
|
// src/analyzer/tsdoc-parser.ts
|
|
2236
|
-
import * as
|
|
2333
|
+
import * as ts3 from "typescript";
|
|
2237
2334
|
import {
|
|
2238
2335
|
checkSyntheticTagApplication,
|
|
2239
2336
|
choosePreferredPayloadText,
|
|
@@ -2260,25 +2357,10 @@ import { noopLogger as noopLogger3 } from "@formspec/core";
|
|
|
2260
2357
|
|
|
2261
2358
|
// src/extensions/resolve-custom-type.ts
|
|
2262
2359
|
import * as ts2 from "typescript";
|
|
2263
|
-
import { stripNullishUnion } from "@formspec/analysis/internal";
|
|
2360
|
+
import { _collectBrandIdentifiers, stripNullishUnion } from "@formspec/analysis/internal";
|
|
2264
2361
|
|
|
2265
2362
|
// src/extensions/ts-type-utils.ts
|
|
2266
2363
|
import * as ts from "typescript";
|
|
2267
|
-
function collectBrandIdentifiers(type) {
|
|
2268
|
-
if (!type.isIntersection()) {
|
|
2269
|
-
return [];
|
|
2270
|
-
}
|
|
2271
|
-
const brands = [];
|
|
2272
|
-
for (const prop of type.getProperties()) {
|
|
2273
|
-
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
2274
|
-
if (decl === void 0) continue;
|
|
2275
|
-
if (!ts.isPropertySignature(decl) && !ts.isPropertyDeclaration(decl)) continue;
|
|
2276
|
-
if (!ts.isComputedPropertyName(decl.name)) continue;
|
|
2277
|
-
if (!ts.isIdentifier(decl.name.expression)) continue;
|
|
2278
|
-
brands.push(decl.name.expression.text);
|
|
2279
|
-
}
|
|
2280
|
-
return brands;
|
|
2281
|
-
}
|
|
2282
2364
|
function resolveCanonicalSymbol(type, checker) {
|
|
2283
2365
|
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
2284
2366
|
if (raw === void 0) return void 0;
|
|
@@ -2363,7 +2445,7 @@ function resolveCustomTypeFromTsType(type, checker, registry, sourceNode) {
|
|
|
2363
2445
|
return bySymbol;
|
|
2364
2446
|
}
|
|
2365
2447
|
}
|
|
2366
|
-
for (const brand of
|
|
2448
|
+
for (const brand of _collectBrandIdentifiers(stripped)) {
|
|
2367
2449
|
const byBrand = registry.findTypeByBrand(brand);
|
|
2368
2450
|
if (byBrand !== void 0) {
|
|
2369
2451
|
return byBrand;
|
|
@@ -2376,19 +2458,18 @@ function customTypeIdFromLookup(result) {
|
|
|
2376
2458
|
}
|
|
2377
2459
|
|
|
2378
2460
|
// src/analyzer/builtin-brands.ts
|
|
2379
|
-
import
|
|
2380
|
-
function isIntegerBrandedType(type) {
|
|
2381
|
-
if (!type.isIntersection()) return false;
|
|
2382
|
-
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2383
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2384
|
-
}
|
|
2461
|
+
import { _isIntegerBrandedType } from "@formspec/analysis/internal";
|
|
2385
2462
|
|
|
2386
2463
|
// src/analyzer/tsdoc-parser.ts
|
|
2387
2464
|
import {
|
|
2465
|
+
_emitSetupDiagnostics,
|
|
2466
|
+
_mapSetupDiagnosticCode,
|
|
2388
2467
|
getBuildLogger,
|
|
2389
2468
|
getBroadeningLogger,
|
|
2390
2469
|
getSyntheticLogger as getSyntheticLogger2,
|
|
2391
2470
|
getTypedParserLogger,
|
|
2471
|
+
extractEffectiveArgumentText,
|
|
2472
|
+
mapTypedParserDiagnosticCode,
|
|
2392
2473
|
parseTagArgument,
|
|
2393
2474
|
describeTypeKind,
|
|
2394
2475
|
elapsedMicros,
|
|
@@ -2401,7 +2482,7 @@ function sharedTagValueOptions(options) {
|
|
|
2401
2482
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2402
2483
|
};
|
|
2403
2484
|
}
|
|
2404
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
2485
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2405
2486
|
function getExtensionTypeNames(registry) {
|
|
2406
2487
|
if (registry === void 0) {
|
|
2407
2488
|
return /* @__PURE__ */ new Set();
|
|
@@ -2415,23 +2496,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2415
2496
|
function collectImportedNames(sourceFile) {
|
|
2416
2497
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2417
2498
|
for (const statement of sourceFile.statements) {
|
|
2418
|
-
if (
|
|
2499
|
+
if (ts3.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2419
2500
|
const clause = statement.importClause;
|
|
2420
2501
|
if (clause.name !== void 0) {
|
|
2421
2502
|
importedNames.add(clause.name.text);
|
|
2422
2503
|
}
|
|
2423
2504
|
if (clause.namedBindings !== void 0) {
|
|
2424
|
-
if (
|
|
2505
|
+
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
2425
2506
|
for (const specifier of clause.namedBindings.elements) {
|
|
2426
2507
|
importedNames.add(specifier.name.text);
|
|
2427
2508
|
}
|
|
2428
|
-
} else if (
|
|
2509
|
+
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
2429
2510
|
importedNames.add(clause.namedBindings.name.text);
|
|
2430
2511
|
}
|
|
2431
2512
|
}
|
|
2432
2513
|
continue;
|
|
2433
2514
|
}
|
|
2434
|
-
if (
|
|
2515
|
+
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
2435
2516
|
importedNames.add(statement.name.text);
|
|
2436
2517
|
}
|
|
2437
2518
|
}
|
|
@@ -2439,13 +2520,13 @@ function collectImportedNames(sourceFile) {
|
|
|
2439
2520
|
}
|
|
2440
2521
|
function isNonReferenceIdentifier(node) {
|
|
2441
2522
|
const parent = node.parent;
|
|
2442
|
-
if ((
|
|
2523
|
+
if ((ts3.isBindingElement(parent) || ts3.isClassDeclaration(parent) || ts3.isEnumDeclaration(parent) || ts3.isEnumMember(parent) || ts3.isFunctionDeclaration(parent) || ts3.isFunctionExpression(parent) || ts3.isImportClause(parent) || ts3.isImportEqualsDeclaration(parent) || ts3.isImportSpecifier(parent) || ts3.isInterfaceDeclaration(parent) || ts3.isMethodDeclaration(parent) || ts3.isMethodSignature(parent) || ts3.isModuleDeclaration(parent) || ts3.isNamespaceExport(parent) || ts3.isNamespaceImport(parent) || ts3.isParameter(parent) || ts3.isPropertyDeclaration(parent) || ts3.isPropertySignature(parent) || ts3.isSetAccessorDeclaration(parent) || ts3.isGetAccessorDeclaration(parent) || ts3.isTypeAliasDeclaration(parent) || ts3.isTypeParameterDeclaration(parent) || ts3.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2443
2524
|
return true;
|
|
2444
2525
|
}
|
|
2445
|
-
if ((
|
|
2526
|
+
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2446
2527
|
return true;
|
|
2447
2528
|
}
|
|
2448
|
-
if (
|
|
2529
|
+
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
2449
2530
|
return true;
|
|
2450
2531
|
}
|
|
2451
2532
|
return false;
|
|
@@ -2457,20 +2538,20 @@ function astReferencesImportedName(root, importedNames) {
|
|
|
2457
2538
|
let found = false;
|
|
2458
2539
|
const visit = (node) => {
|
|
2459
2540
|
if (found) return;
|
|
2460
|
-
if (
|
|
2541
|
+
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2461
2542
|
found = true;
|
|
2462
2543
|
return;
|
|
2463
2544
|
}
|
|
2464
|
-
|
|
2545
|
+
ts3.forEachChild(node, visit);
|
|
2465
2546
|
};
|
|
2466
2547
|
visit(root);
|
|
2467
2548
|
return found;
|
|
2468
2549
|
}
|
|
2469
2550
|
function getObjectMembers(statement) {
|
|
2470
|
-
if (
|
|
2551
|
+
if (ts3.isInterfaceDeclaration(statement)) {
|
|
2471
2552
|
return statement.members;
|
|
2472
2553
|
}
|
|
2473
|
-
if (
|
|
2554
|
+
if (ts3.isTypeLiteralNode(statement.type)) {
|
|
2474
2555
|
return statement.type.members;
|
|
2475
2556
|
}
|
|
2476
2557
|
return void 0;
|
|
@@ -2482,7 +2563,7 @@ function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
|
2482
2563
|
}
|
|
2483
2564
|
const replacements = [];
|
|
2484
2565
|
for (const member of members) {
|
|
2485
|
-
if (!
|
|
2566
|
+
if (!ts3.isPropertySignature(member)) {
|
|
2486
2567
|
if (astReferencesImportedName(member, importedNames)) {
|
|
2487
2568
|
return null;
|
|
2488
2569
|
}
|
|
@@ -2514,14 +2595,14 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
2514
2595
|
);
|
|
2515
2596
|
const result = [];
|
|
2516
2597
|
for (const statement of sourceFile.statements) {
|
|
2517
|
-
if (
|
|
2518
|
-
if (
|
|
2519
|
-
if (
|
|
2598
|
+
if (ts3.isImportDeclaration(statement)) continue;
|
|
2599
|
+
if (ts3.isImportEqualsDeclaration(statement)) continue;
|
|
2600
|
+
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2520
2601
|
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2521
2602
|
result.push(statement.getText(sourceFile));
|
|
2522
2603
|
continue;
|
|
2523
2604
|
}
|
|
2524
|
-
if (
|
|
2605
|
+
if (ts3.isInterfaceDeclaration(statement) || ts3.isTypeAliasDeclaration(statement)) {
|
|
2525
2606
|
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2526
2607
|
if (rewritten !== null) {
|
|
2527
2608
|
result.push(rewritten);
|
|
@@ -2624,7 +2705,7 @@ function stripHintNullishUnion(type) {
|
|
|
2624
2705
|
return type;
|
|
2625
2706
|
}
|
|
2626
2707
|
const nonNullish = type.types.filter(
|
|
2627
|
-
(member) => (member.flags & (
|
|
2708
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
2628
2709
|
);
|
|
2629
2710
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2630
2711
|
return nonNullish[0];
|
|
@@ -2640,10 +2721,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2640
2721
|
}
|
|
2641
2722
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2642
2723
|
const name = declaration.name;
|
|
2643
|
-
if (
|
|
2724
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
2644
2725
|
return false;
|
|
2645
2726
|
}
|
|
2646
|
-
if (!
|
|
2727
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
2647
2728
|
return false;
|
|
2648
2729
|
}
|
|
2649
2730
|
}
|
|
@@ -2889,7 +2970,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2889
2970
|
}
|
|
2890
2971
|
const hasBroadening = (() => {
|
|
2891
2972
|
if (target === null) {
|
|
2892
|
-
if (
|
|
2973
|
+
if (_isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2893
2974
|
return true;
|
|
2894
2975
|
}
|
|
2895
2976
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
@@ -2920,10 +3001,10 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2920
3001
|
]);
|
|
2921
3002
|
}
|
|
2922
3003
|
}
|
|
2923
|
-
const effectiveArgumentText = parsedTag !== null ? parseTagSyntax(tagName, rawText).argumentText : rawText;
|
|
2924
3004
|
if (hasBroadening) {
|
|
2925
3005
|
return emit("bypass", []);
|
|
2926
3006
|
}
|
|
3007
|
+
const effectiveArgumentText = extractEffectiveArgumentText(tagName, rawText, parsedTag);
|
|
2927
3008
|
const typedParseResult = parseTagArgument(tagName, effectiveArgumentText, "build");
|
|
2928
3009
|
if (!typedParseResult.ok) {
|
|
2929
3010
|
if (typedParserTraceEnabled) {
|
|
@@ -2936,23 +3017,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2936
3017
|
diagnosticCode: typedParseResult.diagnostic.code
|
|
2937
3018
|
});
|
|
2938
3019
|
}
|
|
2939
|
-
|
|
2940
|
-
switch (typedParseResult.diagnostic.code) {
|
|
2941
|
-
case "MISSING_TAG_ARGUMENT":
|
|
2942
|
-
mappedCode = "MISSING_TAG_ARGUMENT";
|
|
2943
|
-
break;
|
|
2944
|
-
case "INVALID_TAG_ARGUMENT":
|
|
2945
|
-
mappedCode = "INVALID_TAG_ARGUMENT";
|
|
2946
|
-
break;
|
|
2947
|
-
case "UNKNOWN_TAG":
|
|
2948
|
-
throw new Error(
|
|
2949
|
-
`Unexpected UNKNOWN_TAG from parseTagArgument("${tagName}") \u2014 tag was resolved via getTagDefinition.`
|
|
2950
|
-
);
|
|
2951
|
-
default: {
|
|
2952
|
-
const _exhaustive = typedParseResult.diagnostic.code;
|
|
2953
|
-
throw new Error(`Unknown diagnostic code: ${String(_exhaustive)}`);
|
|
2954
|
-
}
|
|
2955
|
-
}
|
|
3020
|
+
const mappedCode = mapTypedParserDiagnosticCode(typedParseResult.diagnostic.code, tagName);
|
|
2956
3021
|
return emit("C-reject", [
|
|
2957
3022
|
makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
|
|
2958
3023
|
]);
|
|
@@ -3009,13 +3074,13 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3009
3074
|
} : {}
|
|
3010
3075
|
});
|
|
3011
3076
|
if (result.diagnostics.length === 0) {
|
|
3012
|
-
return emit("
|
|
3077
|
+
return emit("D-pass", []);
|
|
3013
3078
|
}
|
|
3014
3079
|
const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
|
|
3015
3080
|
if (setupDiagnostic !== void 0) {
|
|
3016
3081
|
return emit("C-reject", [
|
|
3017
3082
|
makeDiagnostic(
|
|
3018
|
-
setupDiagnostic.kind
|
|
3083
|
+
_mapSetupDiagnosticCode(setupDiagnostic.kind),
|
|
3019
3084
|
setupDiagnostic.message,
|
|
3020
3085
|
provenance
|
|
3021
3086
|
)
|
|
@@ -3083,6 +3148,16 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3083
3148
|
if (cached !== void 0) {
|
|
3084
3149
|
return cached;
|
|
3085
3150
|
}
|
|
3151
|
+
const setupDiags = options?.extensionRegistry?.setupDiagnostics;
|
|
3152
|
+
if (setupDiags !== void 0 && setupDiags.length > 0) {
|
|
3153
|
+
const result2 = {
|
|
3154
|
+
constraints: [],
|
|
3155
|
+
annotations: [],
|
|
3156
|
+
diagnostics: _emitSetupDiagnostics(setupDiags, file)
|
|
3157
|
+
};
|
|
3158
|
+
parseResultCache.set(cacheKey, result2);
|
|
3159
|
+
return result2;
|
|
3160
|
+
}
|
|
3086
3161
|
const constraints = [];
|
|
3087
3162
|
const annotations = [];
|
|
3088
3163
|
const diagnostics = [];
|
|
@@ -3094,12 +3169,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3094
3169
|
const sourceText = sourceFile.getFullText();
|
|
3095
3170
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
3096
3171
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
3097
|
-
const commentRanges =
|
|
3172
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3098
3173
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
3099
3174
|
const extensionTagNames = getExtensionTagNames(options);
|
|
3100
3175
|
if (commentRanges) {
|
|
3101
3176
|
for (const range of commentRanges) {
|
|
3102
|
-
if (range.kind !==
|
|
3177
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
3103
3178
|
continue;
|
|
3104
3179
|
}
|
|
3105
3180
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3256,10 +3331,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3256
3331
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3257
3332
|
const sourceFile = node.getSourceFile();
|
|
3258
3333
|
const sourceText = sourceFile.getFullText();
|
|
3259
|
-
const commentRanges =
|
|
3334
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3260
3335
|
if (commentRanges) {
|
|
3261
3336
|
for (const range of commentRanges) {
|
|
3262
|
-
if (range.kind !==
|
|
3337
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3263
3338
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3264
3339
|
if (!commentText.startsWith("/**")) continue;
|
|
3265
3340
|
const unified = parseUnifiedComment(commentText);
|
|
@@ -3284,7 +3359,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3284
3359
|
}
|
|
3285
3360
|
function collectRawTextFallbacks(node, file) {
|
|
3286
3361
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3287
|
-
for (const tag of
|
|
3362
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
3288
3363
|
const tagName = normalizeConstraintTagName2(tag.tagName.text);
|
|
3289
3364
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3290
3365
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3339,7 +3414,7 @@ function getTagCommentText(tag) {
|
|
|
3339
3414
|
if (typeof tag.comment === "string") {
|
|
3340
3415
|
return tag.comment;
|
|
3341
3416
|
}
|
|
3342
|
-
return
|
|
3417
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
3343
3418
|
}
|
|
3344
3419
|
|
|
3345
3420
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3357,18 +3432,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3357
3432
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3358
3433
|
if (!initializer) return null;
|
|
3359
3434
|
let value;
|
|
3360
|
-
if (
|
|
3435
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
3361
3436
|
value = initializer.text;
|
|
3362
|
-
} else if (
|
|
3437
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
3363
3438
|
value = Number(initializer.text);
|
|
3364
|
-
} else if (initializer.kind ===
|
|
3439
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
3365
3440
|
value = true;
|
|
3366
|
-
} else if (initializer.kind ===
|
|
3441
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
3367
3442
|
value = false;
|
|
3368
|
-
} else if (initializer.kind ===
|
|
3443
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
3369
3444
|
value = null;
|
|
3370
|
-
} else if (
|
|
3371
|
-
if (initializer.operator ===
|
|
3445
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
3446
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
3372
3447
|
value = -Number(initializer.operand.text);
|
|
3373
3448
|
}
|
|
3374
3449
|
}
|
|
@@ -3390,28 +3465,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3390
3465
|
|
|
3391
3466
|
// src/analyzer/class-analyzer.ts
|
|
3392
3467
|
function isObjectType(type) {
|
|
3393
|
-
return !!(type.flags &
|
|
3468
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
3394
3469
|
}
|
|
3395
3470
|
function isIntersectionType(type) {
|
|
3396
|
-
return !!(type.flags &
|
|
3471
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
3397
3472
|
}
|
|
3398
3473
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3399
|
-
if (
|
|
3474
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3400
3475
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3401
3476
|
}
|
|
3402
|
-
if (
|
|
3477
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
3403
3478
|
return true;
|
|
3404
3479
|
}
|
|
3405
|
-
return
|
|
3480
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3406
3481
|
}
|
|
3407
3482
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3408
3483
|
if (isIntersectionType(type)) {
|
|
3409
3484
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3410
3485
|
}
|
|
3411
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3486
|
+
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);
|
|
3412
3487
|
}
|
|
3413
3488
|
function isTypeReference(type) {
|
|
3414
|
-
return !!(type.flags &
|
|
3489
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
3415
3490
|
}
|
|
3416
3491
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3417
3492
|
kind: "object",
|
|
@@ -3437,6 +3512,21 @@ function createAnalyzerMetadataPolicy(input, discriminator) {
|
|
|
3437
3512
|
discriminator
|
|
3438
3513
|
};
|
|
3439
3514
|
}
|
|
3515
|
+
var DEDUPLICATABLE_DIAGNOSTIC_CODES = /* @__PURE__ */ new Set([
|
|
3516
|
+
"SYNTHETIC_SETUP_FAILURE",
|
|
3517
|
+
"UNSUPPORTED_CUSTOM_TYPE_OVERRIDE"
|
|
3518
|
+
]);
|
|
3519
|
+
function deduplicateDiagnostics(diagnostics) {
|
|
3520
|
+
if (diagnostics.length <= 1) return diagnostics;
|
|
3521
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3522
|
+
return diagnostics.filter((d) => {
|
|
3523
|
+
if (!DEDUPLICATABLE_DIAGNOSTIC_CODES.has(d.code)) return true;
|
|
3524
|
+
const key = `${d.code}\0${d.message}`;
|
|
3525
|
+
if (seen.has(key)) return false;
|
|
3526
|
+
seen.add(key);
|
|
3527
|
+
return true;
|
|
3528
|
+
});
|
|
3529
|
+
}
|
|
3440
3530
|
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
3441
3531
|
const analysis = analyzeMetadataForNodeWithChecker({
|
|
3442
3532
|
checker,
|
|
@@ -3473,10 +3563,121 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3473
3563
|
}
|
|
3474
3564
|
return resolvedMetadata;
|
|
3475
3565
|
}
|
|
3566
|
+
var INHERITABLE_TYPE_ANNOTATION_KINDS = /* @__PURE__ */ new Set(["format"]);
|
|
3567
|
+
function getInheritableAnnotationStringValue(annotation) {
|
|
3568
|
+
if (annotation.annotationKind === "format") return annotation.value;
|
|
3569
|
+
return void 0;
|
|
3570
|
+
}
|
|
3571
|
+
function isOverridingInheritableAnnotation(annotation) {
|
|
3572
|
+
const value = getInheritableAnnotationStringValue(annotation);
|
|
3573
|
+
if (value === void 0) return true;
|
|
3574
|
+
return value.trim().length > 0;
|
|
3575
|
+
}
|
|
3576
|
+
function collectInheritedTypeAnnotations(derivedDecl, existingAnnotations, checker, extensionRegistry) {
|
|
3577
|
+
const existingKinds = new Set(
|
|
3578
|
+
existingAnnotations.filter(isOverridingInheritableAnnotation).map((a) => a.annotationKind)
|
|
3579
|
+
);
|
|
3580
|
+
const needed = /* @__PURE__ */ new Set();
|
|
3581
|
+
for (const kind of INHERITABLE_TYPE_ANNOTATION_KINDS) {
|
|
3582
|
+
if (!existingKinds.has(kind)) needed.add(kind);
|
|
3583
|
+
}
|
|
3584
|
+
if (needed.size === 0) return [];
|
|
3585
|
+
const inherited = [];
|
|
3586
|
+
const seen = /* @__PURE__ */ new Set([derivedDecl]);
|
|
3587
|
+
const queue = [];
|
|
3588
|
+
const resolveSymbolTarget = (sym) => {
|
|
3589
|
+
if ((sym.flags & ts5.SymbolFlags.Alias) === 0) return sym;
|
|
3590
|
+
try {
|
|
3591
|
+
return checker.getAliasedSymbol(sym);
|
|
3592
|
+
} catch {
|
|
3593
|
+
return sym;
|
|
3594
|
+
}
|
|
3595
|
+
};
|
|
3596
|
+
const isObjectShapedTypeAlias = (alias) => {
|
|
3597
|
+
const type = checker.getTypeFromTypeNode(alias.type);
|
|
3598
|
+
if ((type.flags & ts5.TypeFlags.Object) !== 0) return true;
|
|
3599
|
+
if (type.isIntersection()) return true;
|
|
3600
|
+
return false;
|
|
3601
|
+
};
|
|
3602
|
+
const enqueueCandidate = (baseDecl, fromTypeAliasRhs) => {
|
|
3603
|
+
if (seen.has(baseDecl)) return;
|
|
3604
|
+
if (ts5.isClassDeclaration(baseDecl) || ts5.isInterfaceDeclaration(baseDecl)) {
|
|
3605
|
+
seen.add(baseDecl);
|
|
3606
|
+
queue.push(baseDecl);
|
|
3607
|
+
return;
|
|
3608
|
+
}
|
|
3609
|
+
if (ts5.isTypeAliasDeclaration(baseDecl)) {
|
|
3610
|
+
if (!fromTypeAliasRhs && !isObjectShapedTypeAlias(baseDecl)) return;
|
|
3611
|
+
seen.add(baseDecl);
|
|
3612
|
+
queue.push(baseDecl);
|
|
3613
|
+
}
|
|
3614
|
+
};
|
|
3615
|
+
const enqueueBasesOf = (decl) => {
|
|
3616
|
+
if (ts5.isTypeAliasDeclaration(decl)) {
|
|
3617
|
+
const rhs = decl.type;
|
|
3618
|
+
if (!ts5.isTypeReferenceNode(rhs)) return;
|
|
3619
|
+
const sym = checker.getSymbolAtLocation(rhs.typeName);
|
|
3620
|
+
if (!sym) return;
|
|
3621
|
+
const target = resolveSymbolTarget(sym);
|
|
3622
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
3623
|
+
enqueueCandidate(
|
|
3624
|
+
baseDecl,
|
|
3625
|
+
/*fromTypeAliasRhs*/
|
|
3626
|
+
true
|
|
3627
|
+
);
|
|
3628
|
+
}
|
|
3629
|
+
return;
|
|
3630
|
+
}
|
|
3631
|
+
const heritageClauses = decl.heritageClauses;
|
|
3632
|
+
if (!heritageClauses) return;
|
|
3633
|
+
for (const clause of heritageClauses) {
|
|
3634
|
+
if (clause.token !== ts5.SyntaxKind.ExtendsKeyword) continue;
|
|
3635
|
+
for (const typeExpr of clause.types) {
|
|
3636
|
+
const sym = checker.getSymbolAtLocation(typeExpr.expression);
|
|
3637
|
+
if (!sym) continue;
|
|
3638
|
+
const target = resolveSymbolTarget(sym);
|
|
3639
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
3640
|
+
enqueueCandidate(
|
|
3641
|
+
baseDecl,
|
|
3642
|
+
/*fromTypeAliasRhs*/
|
|
3643
|
+
false
|
|
3644
|
+
);
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
};
|
|
3649
|
+
enqueueBasesOf(derivedDecl);
|
|
3650
|
+
for (let queueIndex = 0; queueIndex < queue.length && needed.size > 0; queueIndex++) {
|
|
3651
|
+
const baseDecl = queue[queueIndex];
|
|
3652
|
+
if (baseDecl === void 0) continue;
|
|
3653
|
+
const baseFile = baseDecl.getSourceFile().fileName;
|
|
3654
|
+
const baseAnnotations = extractJSDocAnnotationNodes(
|
|
3655
|
+
baseDecl,
|
|
3656
|
+
baseFile,
|
|
3657
|
+
makeParseOptions(extensionRegistry)
|
|
3658
|
+
);
|
|
3659
|
+
for (const annotation of baseAnnotations) {
|
|
3660
|
+
if (!needed.has(annotation.annotationKind)) continue;
|
|
3661
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
3662
|
+
inherited.push(annotation);
|
|
3663
|
+
needed.delete(annotation.annotationKind);
|
|
3664
|
+
}
|
|
3665
|
+
if (needed.size > 0) {
|
|
3666
|
+
enqueueBasesOf(baseDecl);
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3669
|
+
return inherited;
|
|
3670
|
+
}
|
|
3671
|
+
function extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) {
|
|
3672
|
+
const local = extractJSDocAnnotationNodes(namedDecl, file, makeParseOptions(extensionRegistry));
|
|
3673
|
+
const inherited = collectInheritedTypeAnnotations(namedDecl, local, checker, extensionRegistry);
|
|
3674
|
+
if (inherited.length === 0) return [...local];
|
|
3675
|
+
return [...local, ...inherited];
|
|
3676
|
+
}
|
|
3476
3677
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3477
3678
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3478
3679
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3479
|
-
const logicalName =
|
|
3680
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3480
3681
|
const docResult = extractJSDocParseResult(
|
|
3481
3682
|
declaration,
|
|
3482
3683
|
file,
|
|
@@ -3518,13 +3719,19 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3518
3719
|
file,
|
|
3519
3720
|
makeParseOptions(extensionRegistry, void 0, checker, classType, classType)
|
|
3520
3721
|
);
|
|
3521
|
-
const
|
|
3722
|
+
const inheritedClassAnnotations = collectInheritedTypeAnnotations(
|
|
3723
|
+
classDecl,
|
|
3724
|
+
classDoc.annotations,
|
|
3725
|
+
checker,
|
|
3726
|
+
extensionRegistry
|
|
3727
|
+
);
|
|
3728
|
+
const annotations = [...classDoc.annotations, ...inheritedClassAnnotations];
|
|
3522
3729
|
diagnostics.push(...classDoc.diagnostics);
|
|
3523
3730
|
const visiting = /* @__PURE__ */ new Set();
|
|
3524
3731
|
const instanceMethods = [];
|
|
3525
3732
|
const staticMethods = [];
|
|
3526
3733
|
for (const member of classDecl.members) {
|
|
3527
|
-
if (
|
|
3734
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
3528
3735
|
const fieldNode = analyzeFieldToIR(
|
|
3529
3736
|
member,
|
|
3530
3737
|
checker,
|
|
@@ -3540,10 +3747,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3540
3747
|
fields.push(fieldNode);
|
|
3541
3748
|
fieldLayouts.push({});
|
|
3542
3749
|
}
|
|
3543
|
-
} else if (
|
|
3750
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
3544
3751
|
const methodInfo = analyzeMethod(member, checker);
|
|
3545
3752
|
if (methodInfo) {
|
|
3546
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3753
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
3547
3754
|
if (isStatic) {
|
|
3548
3755
|
staticMethods.push(methodInfo);
|
|
3549
3756
|
} else {
|
|
@@ -3575,6 +3782,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3575
3782
|
hostType: classType
|
|
3576
3783
|
}
|
|
3577
3784
|
);
|
|
3785
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3578
3786
|
return {
|
|
3579
3787
|
name,
|
|
3580
3788
|
...metadata !== void 0 && { metadata },
|
|
@@ -3582,7 +3790,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3582
3790
|
fieldLayouts,
|
|
3583
3791
|
typeRegistry,
|
|
3584
3792
|
...annotations.length > 0 && { annotations },
|
|
3585
|
-
...
|
|
3793
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3586
3794
|
instanceMethods,
|
|
3587
3795
|
staticMethods
|
|
3588
3796
|
};
|
|
@@ -3602,11 +3810,20 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3602
3810
|
file,
|
|
3603
3811
|
makeParseOptions(extensionRegistry, void 0, checker, interfaceType, interfaceType)
|
|
3604
3812
|
);
|
|
3605
|
-
const
|
|
3813
|
+
const inheritedInterfaceAnnotations = collectInheritedTypeAnnotations(
|
|
3814
|
+
interfaceDecl,
|
|
3815
|
+
interfaceDoc.annotations,
|
|
3816
|
+
checker,
|
|
3817
|
+
extensionRegistry
|
|
3818
|
+
);
|
|
3819
|
+
const annotations = [
|
|
3820
|
+
...interfaceDoc.annotations,
|
|
3821
|
+
...inheritedInterfaceAnnotations
|
|
3822
|
+
];
|
|
3606
3823
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3607
3824
|
const visiting = /* @__PURE__ */ new Set();
|
|
3608
3825
|
for (const member of interfaceDecl.members) {
|
|
3609
|
-
if (
|
|
3826
|
+
if (ts5.isPropertySignature(member)) {
|
|
3610
3827
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3611
3828
|
member,
|
|
3612
3829
|
checker,
|
|
@@ -3647,6 +3864,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3647
3864
|
hostType: interfaceType
|
|
3648
3865
|
}
|
|
3649
3866
|
);
|
|
3867
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3650
3868
|
return {
|
|
3651
3869
|
name,
|
|
3652
3870
|
...metadata !== void 0 && { metadata },
|
|
@@ -3654,7 +3872,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3654
3872
|
fieldLayouts,
|
|
3655
3873
|
typeRegistry,
|
|
3656
3874
|
...annotations.length > 0 && { annotations },
|
|
3657
|
-
...
|
|
3875
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3658
3876
|
instanceMethods: [],
|
|
3659
3877
|
staticMethods: []
|
|
3660
3878
|
};
|
|
@@ -3664,7 +3882,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3664
3882
|
if (members === null) {
|
|
3665
3883
|
const sourceFile = typeAlias.getSourceFile();
|
|
3666
3884
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3667
|
-
const kindDesc =
|
|
3885
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3668
3886
|
return {
|
|
3669
3887
|
ok: false,
|
|
3670
3888
|
kind: "not-object-like",
|
|
@@ -3699,7 +3917,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3699
3917
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3700
3918
|
const visiting = /* @__PURE__ */ new Set();
|
|
3701
3919
|
for (const member of members) {
|
|
3702
|
-
if (
|
|
3920
|
+
if (ts5.isPropertySignature(member)) {
|
|
3703
3921
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3704
3922
|
member,
|
|
3705
3923
|
checker,
|
|
@@ -3739,6 +3957,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3739
3957
|
hostType: aliasType
|
|
3740
3958
|
}
|
|
3741
3959
|
);
|
|
3960
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3742
3961
|
return {
|
|
3743
3962
|
ok: true,
|
|
3744
3963
|
analysis: {
|
|
@@ -3748,7 +3967,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3748
3967
|
fieldLayouts: specializedFields.map(() => ({})),
|
|
3749
3968
|
typeRegistry,
|
|
3750
3969
|
...annotations.length > 0 && { annotations },
|
|
3751
|
-
...
|
|
3970
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3752
3971
|
instanceMethods: [],
|
|
3753
3972
|
staticMethods: []
|
|
3754
3973
|
}
|
|
@@ -3766,13 +3985,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3766
3985
|
function getLeadingParsedTags(node) {
|
|
3767
3986
|
const sourceFile = node.getSourceFile();
|
|
3768
3987
|
const sourceText = sourceFile.getFullText();
|
|
3769
|
-
const commentRanges =
|
|
3988
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3770
3989
|
if (commentRanges === void 0) {
|
|
3771
3990
|
return [];
|
|
3772
3991
|
}
|
|
3773
3992
|
const parsedTags = [];
|
|
3774
3993
|
for (const range of commentRanges) {
|
|
3775
|
-
if (range.kind !==
|
|
3994
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
3776
3995
|
continue;
|
|
3777
3996
|
}
|
|
3778
3997
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3790,19 +4009,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3790
4009
|
return null;
|
|
3791
4010
|
}
|
|
3792
4011
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3793
|
-
(candidate) =>
|
|
4012
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
3794
4013
|
) ?? propertySymbol.declarations?.[0];
|
|
3795
4014
|
return {
|
|
3796
4015
|
declaration,
|
|
3797
4016
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3798
|
-
optional: !!(propertySymbol.flags &
|
|
4017
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3799
4018
|
};
|
|
3800
4019
|
}
|
|
3801
4020
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3802
4021
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3803
4022
|
}
|
|
3804
4023
|
function isNullishSemanticType(type) {
|
|
3805
|
-
if (type.flags & (
|
|
4024
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
3806
4025
|
return true;
|
|
3807
4026
|
}
|
|
3808
4027
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3812,7 +4031,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3812
4031
|
return false;
|
|
3813
4032
|
}
|
|
3814
4033
|
seen.add(type);
|
|
3815
|
-
if (type.flags &
|
|
4034
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
3816
4035
|
return true;
|
|
3817
4036
|
}
|
|
3818
4037
|
if (type.isUnion()) {
|
|
@@ -3825,13 +4044,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3825
4044
|
return false;
|
|
3826
4045
|
}
|
|
3827
4046
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3828
|
-
if (
|
|
4047
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3829
4048
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3830
4049
|
}
|
|
3831
|
-
if (
|
|
4050
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
3832
4051
|
return [...typeNode.members];
|
|
3833
4052
|
}
|
|
3834
|
-
if (
|
|
4053
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
3835
4054
|
const members = [];
|
|
3836
4055
|
for (const intersectionMember of typeNode.types) {
|
|
3837
4056
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3994,7 +4213,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3994
4213
|
}
|
|
3995
4214
|
if (propertyType.isUnion()) {
|
|
3996
4215
|
const nonNullMembers = propertyType.types.filter(
|
|
3997
|
-
(member) => !(member.flags & (
|
|
4216
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3998
4217
|
);
|
|
3999
4218
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4000
4219
|
diagnostics.push(
|
|
@@ -4043,13 +4262,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
4043
4262
|
seen.add(type);
|
|
4044
4263
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
4045
4264
|
if (symbol !== void 0) {
|
|
4046
|
-
const aliased = symbol.flags &
|
|
4265
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
4047
4266
|
const targetSymbol = aliased ?? symbol;
|
|
4048
4267
|
const declaration = targetSymbol.declarations?.find(
|
|
4049
|
-
(candidate) =>
|
|
4268
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
4050
4269
|
);
|
|
4051
4270
|
if (declaration !== void 0) {
|
|
4052
|
-
if (
|
|
4271
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
4053
4272
|
return resolveNamedDiscriminatorDeclaration(
|
|
4054
4273
|
checker.getTypeFromTypeNode(declaration.type),
|
|
4055
4274
|
checker,
|
|
@@ -4077,7 +4296,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4077
4296
|
}
|
|
4078
4297
|
if (boundType.isUnion()) {
|
|
4079
4298
|
const nonNullMembers = boundType.types.filter(
|
|
4080
|
-
(member) => !(member.flags & (
|
|
4299
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4081
4300
|
);
|
|
4082
4301
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4083
4302
|
diagnostics.push(
|
|
@@ -4122,7 +4341,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4122
4341
|
return null;
|
|
4123
4342
|
}
|
|
4124
4343
|
function getDeclarationName(node) {
|
|
4125
|
-
if (
|
|
4344
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
4126
4345
|
return node.name?.text ?? "anonymous";
|
|
4127
4346
|
}
|
|
4128
4347
|
return "anonymous";
|
|
@@ -4177,11 +4396,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4177
4396
|
if (sourceTypeNode === void 0) {
|
|
4178
4397
|
return [];
|
|
4179
4398
|
}
|
|
4180
|
-
const unwrapParentheses = (typeNode) =>
|
|
4399
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4181
4400
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4182
|
-
const referenceTypeNode =
|
|
4401
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4183
4402
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4184
|
-
return
|
|
4403
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4185
4404
|
})();
|
|
4186
4405
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4187
4406
|
return [];
|
|
@@ -4189,7 +4408,7 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4189
4408
|
return referenceTypeNode.typeArguments.map((argumentNode) => {
|
|
4190
4409
|
const argumentType = checker.getTypeFromTypeNode(argumentNode);
|
|
4191
4410
|
const baseSymbol = argumentType.aliasSymbol ?? argumentType.getSymbol();
|
|
4192
|
-
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags &
|
|
4411
|
+
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(baseSymbol) : baseSymbol;
|
|
4193
4412
|
const argumentDecl = argumentSymbol?.declarations?.[0];
|
|
4194
4413
|
if (argumentDecl !== void 0 && argumentDecl.getSourceFile().fileName !== file) {
|
|
4195
4414
|
const argumentName = argumentSymbol?.getName() ?? baseSymbol?.getName();
|
|
@@ -4252,7 +4471,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4252
4471
|
);
|
|
4253
4472
|
}
|
|
4254
4473
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4255
|
-
if (!
|
|
4474
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
4256
4475
|
return null;
|
|
4257
4476
|
}
|
|
4258
4477
|
const name = prop.name.text;
|
|
@@ -4379,7 +4598,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4379
4598
|
const seen = /* @__PURE__ */ new Set();
|
|
4380
4599
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4381
4600
|
for (const member of members) {
|
|
4382
|
-
if (!
|
|
4601
|
+
if (!ts5.isPropertySignature(member)) {
|
|
4383
4602
|
continue;
|
|
4384
4603
|
}
|
|
4385
4604
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4395,7 +4614,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4395
4614
|
return [...duplicates].sort();
|
|
4396
4615
|
}
|
|
4397
4616
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4398
|
-
if (
|
|
4617
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
4399
4618
|
return name.text;
|
|
4400
4619
|
}
|
|
4401
4620
|
return null;
|
|
@@ -4490,28 +4709,28 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4490
4709
|
if (primitiveAlias) {
|
|
4491
4710
|
return primitiveAlias;
|
|
4492
4711
|
}
|
|
4493
|
-
if (
|
|
4712
|
+
if (_isIntegerBrandedType(type)) {
|
|
4494
4713
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4495
4714
|
}
|
|
4496
|
-
if (type.flags &
|
|
4715
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4497
4716
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4498
4717
|
}
|
|
4499
|
-
if (type.flags &
|
|
4718
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4500
4719
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4501
4720
|
}
|
|
4502
|
-
if (type.flags & (
|
|
4721
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4503
4722
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4504
4723
|
}
|
|
4505
|
-
if (type.flags &
|
|
4724
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4506
4725
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4507
4726
|
}
|
|
4508
|
-
if (type.flags &
|
|
4727
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4509
4728
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4510
4729
|
}
|
|
4511
|
-
if (type.flags &
|
|
4730
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
4512
4731
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4513
4732
|
}
|
|
4514
|
-
if (type.flags &
|
|
4733
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
4515
4734
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4516
4735
|
}
|
|
4517
4736
|
if (type.isStringLiteral()) {
|
|
@@ -4598,10 +4817,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4598
4817
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4599
4818
|
}
|
|
4600
4819
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4601
|
-
if (!(type.flags & (
|
|
4820
|
+
if (!(type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null)) && !_isIntegerBrandedType(type)) {
|
|
4602
4821
|
return null;
|
|
4603
4822
|
}
|
|
4604
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4823
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4605
4824
|
if (!aliasDecl) {
|
|
4606
4825
|
return null;
|
|
4607
4826
|
}
|
|
@@ -4612,11 +4831,18 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4612
4831
|
...extractJSDocConstraintNodes(aliasDecl, file, makeParseOptions(extensionRegistry)),
|
|
4613
4832
|
...extractTypeAliasConstraintNodes(aliasDecl.type, checker, file, extensionRegistry)
|
|
4614
4833
|
];
|
|
4615
|
-
const
|
|
4834
|
+
const localAnnotations = extractJSDocAnnotationNodes(
|
|
4616
4835
|
aliasDecl,
|
|
4617
4836
|
file,
|
|
4618
4837
|
makeParseOptions(extensionRegistry)
|
|
4619
4838
|
);
|
|
4839
|
+
const inheritedAnnotations = collectInheritedTypeAnnotations(
|
|
4840
|
+
aliasDecl,
|
|
4841
|
+
localAnnotations,
|
|
4842
|
+
checker,
|
|
4843
|
+
extensionRegistry
|
|
4844
|
+
);
|
|
4845
|
+
const annotations = [...localAnnotations, ...inheritedAnnotations];
|
|
4620
4846
|
const metadata = resolveNodeMetadata(
|
|
4621
4847
|
metadataPolicy,
|
|
4622
4848
|
"type",
|
|
@@ -4651,8 +4877,8 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4651
4877
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4652
4878
|
}
|
|
4653
4879
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4654
|
-
const typeNode = sourceNode && (
|
|
4655
|
-
if (!typeNode || !
|
|
4880
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4881
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
4656
4882
|
return void 0;
|
|
4657
4883
|
}
|
|
4658
4884
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4673,7 +4899,7 @@ function resolveNamedTypeWithSourceRecovery(type, sourceNode, checker) {
|
|
|
4673
4899
|
return { typeName: refAliasDecl.name.text, namedDecl: refAliasDecl };
|
|
4674
4900
|
}
|
|
4675
4901
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4676
|
-
if (!
|
|
4902
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
4677
4903
|
return false;
|
|
4678
4904
|
}
|
|
4679
4905
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4681,10 +4907,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4681
4907
|
return false;
|
|
4682
4908
|
}
|
|
4683
4909
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4684
|
-
return !!(resolved.flags & (
|
|
4910
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
4685
4911
|
}
|
|
4686
4912
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4687
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4913
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
4688
4914
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4689
4915
|
visitedAliases.add(nestedAliasDecl);
|
|
4690
4916
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4699,22 +4925,22 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4699
4925
|
visitedAliases
|
|
4700
4926
|
);
|
|
4701
4927
|
}
|
|
4702
|
-
if (
|
|
4928
|
+
if (_isIntegerBrandedType(type)) {
|
|
4703
4929
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4704
4930
|
}
|
|
4705
|
-
if (type.flags &
|
|
4931
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4706
4932
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4707
4933
|
}
|
|
4708
|
-
if (type.flags &
|
|
4934
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4709
4935
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4710
4936
|
}
|
|
4711
|
-
if (type.flags & (
|
|
4937
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4712
4938
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4713
4939
|
}
|
|
4714
|
-
if (type.flags &
|
|
4940
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4715
4941
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4716
4942
|
}
|
|
4717
|
-
if (type.flags &
|
|
4943
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4718
4944
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4719
4945
|
}
|
|
4720
4946
|
return resolveTypeNode(
|
|
@@ -4734,7 +4960,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4734
4960
|
let typeName = null;
|
|
4735
4961
|
let namedDecl;
|
|
4736
4962
|
if (recovered !== null) {
|
|
4737
|
-
const recoveredAliasDecl =
|
|
4963
|
+
const recoveredAliasDecl = ts5.isTypeAliasDeclaration(recovered.namedDecl) ? recovered.namedDecl : void 0;
|
|
4738
4964
|
if (recoveredAliasDecl !== void 0) {
|
|
4739
4965
|
const aliasUnderlyingType = checker.getTypeFromTypeNode(recoveredAliasDecl.type);
|
|
4740
4966
|
const isNonGeneric = recoveredAliasDecl.typeParameters === void 0 || recoveredAliasDecl.typeParameters.length === 0;
|
|
@@ -4756,13 +4982,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4756
4982
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4757
4983
|
);
|
|
4758
4984
|
const nonNullTypes = allTypes.filter(
|
|
4759
|
-
(memberType) => !(memberType.flags & (
|
|
4985
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4760
4986
|
);
|
|
4761
4987
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4762
4988
|
memberType,
|
|
4763
4989
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4764
4990
|
}));
|
|
4765
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4991
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
4766
4992
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4767
4993
|
if (namedDecl) {
|
|
4768
4994
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4782,7 +5008,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4782
5008
|
if (existing !== void 0 && existing.type !== RESOLVING_TYPE_PLACEHOLDER) {
|
|
4783
5009
|
return { kind: "reference", name: typeName, typeArguments: [] };
|
|
4784
5010
|
}
|
|
4785
|
-
const annotations = namedDecl ?
|
|
5011
|
+
const annotations = namedDecl ? extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) : void 0;
|
|
4786
5012
|
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4787
5013
|
metadataPolicy,
|
|
4788
5014
|
"type",
|
|
@@ -4809,7 +5035,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4809
5035
|
const displayName = memberDisplayNames.get(String(value));
|
|
4810
5036
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4811
5037
|
});
|
|
4812
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
5038
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
4813
5039
|
if (isBooleanUnion2) {
|
|
4814
5040
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4815
5041
|
const result = hasNull ? {
|
|
@@ -4901,7 +5127,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4901
5127
|
if (type.getProperties().length > 0) {
|
|
4902
5128
|
return null;
|
|
4903
5129
|
}
|
|
4904
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
5130
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
4905
5131
|
if (!indexInfo) {
|
|
4906
5132
|
return null;
|
|
4907
5133
|
}
|
|
@@ -4949,20 +5175,53 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4949
5175
|
}
|
|
4950
5176
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4951
5177
|
const name = declaration.name;
|
|
4952
|
-
if (
|
|
5178
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
4953
5179
|
return false;
|
|
4954
5180
|
}
|
|
4955
|
-
if (!
|
|
5181
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
4956
5182
|
return false;
|
|
4957
5183
|
}
|
|
4958
5184
|
}
|
|
4959
5185
|
return true;
|
|
4960
5186
|
}
|
|
5187
|
+
function getPassThroughTypeAliasFromSourceNode(sourceNode, checker, extensionRegistry, resolvedTypeName) {
|
|
5188
|
+
const aliasDecl = getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
5189
|
+
if (!aliasDecl) return void 0;
|
|
5190
|
+
const aliasName = aliasDecl.name.text;
|
|
5191
|
+
if (aliasName === resolvedTypeName) return void 0;
|
|
5192
|
+
if (!ts5.isTypeReferenceNode(aliasDecl.type)) return void 0;
|
|
5193
|
+
if (!hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry)) {
|
|
5194
|
+
return void 0;
|
|
5195
|
+
}
|
|
5196
|
+
return { aliasName, aliasDecl };
|
|
5197
|
+
}
|
|
5198
|
+
function hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry) {
|
|
5199
|
+
const file = aliasDecl.getSourceFile().fileName;
|
|
5200
|
+
const local = extractJSDocAnnotationNodes(aliasDecl, file, makeParseOptions(extensionRegistry));
|
|
5201
|
+
for (const annotation of local) {
|
|
5202
|
+
if (!INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) continue;
|
|
5203
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
5204
|
+
return true;
|
|
5205
|
+
}
|
|
5206
|
+
const inherited = collectInheritedTypeAnnotations(aliasDecl, local, checker, extensionRegistry);
|
|
5207
|
+
for (const annotation of inherited) {
|
|
5208
|
+
if (INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) return true;
|
|
5209
|
+
}
|
|
5210
|
+
return false;
|
|
5211
|
+
}
|
|
4961
5212
|
function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4962
5213
|
const collectedDiagnostics = diagnostics ?? [];
|
|
4963
5214
|
const typeName = getNamedTypeName(type);
|
|
4964
5215
|
const namedTypeName = typeName ?? void 0;
|
|
4965
5216
|
const namedDecl = getNamedTypeDeclaration(type);
|
|
5217
|
+
const passThroughAlias = getPassThroughTypeAliasFromSourceNode(
|
|
5218
|
+
sourceNode,
|
|
5219
|
+
checker,
|
|
5220
|
+
extensionRegistry,
|
|
5221
|
+
namedTypeName
|
|
5222
|
+
);
|
|
5223
|
+
const effectiveTypeName = passThroughAlias?.aliasName ?? namedTypeName;
|
|
5224
|
+
const effectiveNamedDecl = passThroughAlias?.aliasDecl ?? namedDecl;
|
|
4966
5225
|
const referenceTypeArguments = extractReferenceTypeArguments(
|
|
4967
5226
|
type,
|
|
4968
5227
|
checker,
|
|
@@ -4974,13 +5233,13 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4974
5233
|
extensionRegistry,
|
|
4975
5234
|
collectedDiagnostics
|
|
4976
5235
|
);
|
|
4977
|
-
const instantiatedTypeName =
|
|
4978
|
-
|
|
5236
|
+
const instantiatedTypeName = effectiveTypeName !== void 0 && referenceTypeArguments.length > 0 ? buildInstantiatedReferenceName(
|
|
5237
|
+
effectiveTypeName,
|
|
4979
5238
|
referenceTypeArguments.map((argument) => argument.tsType),
|
|
4980
5239
|
checker
|
|
4981
5240
|
) : void 0;
|
|
4982
|
-
const registryTypeName = instantiatedTypeName ??
|
|
4983
|
-
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" &&
|
|
5241
|
+
const registryTypeName = instantiatedTypeName ?? effectiveTypeName;
|
|
5242
|
+
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" && effectiveNamedDecl?.getSourceFile().fileName !== file);
|
|
4984
5243
|
const clearNamedTypeRegistration = () => {
|
|
4985
5244
|
if (registryTypeName === void 0 || !shouldRegisterNamedType) {
|
|
4986
5245
|
return;
|
|
@@ -5001,7 +5260,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5001
5260
|
typeRegistry[registryTypeName] = {
|
|
5002
5261
|
name: registryTypeName,
|
|
5003
5262
|
type: RESOLVING_TYPE_PLACEHOLDER,
|
|
5004
|
-
provenance: provenanceForDeclaration(
|
|
5263
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5005
5264
|
};
|
|
5006
5265
|
}
|
|
5007
5266
|
visiting.add(type);
|
|
@@ -5033,17 +5292,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5033
5292
|
clearNamedTypeRegistration();
|
|
5034
5293
|
return recordNode;
|
|
5035
5294
|
}
|
|
5036
|
-
const annotations =
|
|
5037
|
-
const metadata =
|
|
5295
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5296
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
5038
5297
|
metadataPolicy,
|
|
5039
5298
|
"type",
|
|
5040
5299
|
registryTypeName,
|
|
5041
|
-
|
|
5300
|
+
effectiveNamedDecl,
|
|
5042
5301
|
checker,
|
|
5043
5302
|
extensionRegistry,
|
|
5044
5303
|
{
|
|
5045
5304
|
checker,
|
|
5046
|
-
declaration:
|
|
5305
|
+
declaration: effectiveNamedDecl,
|
|
5047
5306
|
subjectType: type
|
|
5048
5307
|
}
|
|
5049
5308
|
) : void 0;
|
|
@@ -5052,7 +5311,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5052
5311
|
...metadata !== void 0 && { metadata },
|
|
5053
5312
|
type: recordNode,
|
|
5054
5313
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5055
|
-
provenance: provenanceForDeclaration(
|
|
5314
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5056
5315
|
};
|
|
5057
5316
|
return {
|
|
5058
5317
|
kind: "reference",
|
|
@@ -5078,7 +5337,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5078
5337
|
if (!declaration) continue;
|
|
5079
5338
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
5080
5339
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
5081
|
-
const optional = !!(prop.flags &
|
|
5340
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
5082
5341
|
const propTypeNode = resolveTypeNode(
|
|
5083
5342
|
propType,
|
|
5084
5343
|
checker,
|
|
@@ -5091,7 +5350,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5091
5350
|
collectedDiagnostics
|
|
5092
5351
|
);
|
|
5093
5352
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
5094
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
5353
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
5095
5354
|
declaration,
|
|
5096
5355
|
checker,
|
|
5097
5356
|
file,
|
|
@@ -5101,7 +5360,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5101
5360
|
type,
|
|
5102
5361
|
metadataPolicy,
|
|
5103
5362
|
extensionRegistry
|
|
5104
|
-
) :
|
|
5363
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
5105
5364
|
declaration,
|
|
5106
5365
|
checker,
|
|
5107
5366
|
file,
|
|
@@ -5129,9 +5388,9 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5129
5388
|
visiting.delete(type);
|
|
5130
5389
|
const objectNode = {
|
|
5131
5390
|
kind: "object",
|
|
5132
|
-
properties:
|
|
5391
|
+
properties: effectiveNamedDecl !== void 0 && (ts5.isClassDeclaration(effectiveNamedDecl) || ts5.isInterfaceDeclaration(effectiveNamedDecl) || ts5.isTypeAliasDeclaration(effectiveNamedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
5133
5392
|
properties,
|
|
5134
|
-
|
|
5393
|
+
effectiveNamedDecl,
|
|
5135
5394
|
type,
|
|
5136
5395
|
checker,
|
|
5137
5396
|
file,
|
|
@@ -5141,17 +5400,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5141
5400
|
additionalProperties: true
|
|
5142
5401
|
};
|
|
5143
5402
|
if (registryTypeName !== void 0 && shouldRegisterNamedType) {
|
|
5144
|
-
const annotations =
|
|
5145
|
-
const metadata =
|
|
5403
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5404
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
5146
5405
|
metadataPolicy,
|
|
5147
5406
|
"type",
|
|
5148
5407
|
registryTypeName,
|
|
5149
|
-
|
|
5408
|
+
effectiveNamedDecl,
|
|
5150
5409
|
checker,
|
|
5151
5410
|
extensionRegistry,
|
|
5152
5411
|
{
|
|
5153
5412
|
checker,
|
|
5154
|
-
declaration:
|
|
5413
|
+
declaration: effectiveNamedDecl,
|
|
5155
5414
|
subjectType: type
|
|
5156
5415
|
}
|
|
5157
5416
|
) : void 0;
|
|
@@ -5160,7 +5419,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5160
5419
|
...metadata !== void 0 && { metadata },
|
|
5161
5420
|
type: objectNode,
|
|
5162
5421
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5163
|
-
provenance: provenanceForDeclaration(
|
|
5422
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5164
5423
|
};
|
|
5165
5424
|
return {
|
|
5166
5425
|
kind: "reference",
|
|
@@ -5177,12 +5436,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5177
5436
|
for (const symbol of symbols) {
|
|
5178
5437
|
const declarations = symbol.declarations;
|
|
5179
5438
|
if (!declarations) continue;
|
|
5180
|
-
const classDecl = declarations.find(
|
|
5439
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
5181
5440
|
if (classDecl) {
|
|
5182
5441
|
const map = /* @__PURE__ */ new Map();
|
|
5183
5442
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
5184
5443
|
for (const member of classDecl.members) {
|
|
5185
|
-
if (
|
|
5444
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
5186
5445
|
const fieldNode = analyzeFieldToIR(
|
|
5187
5446
|
member,
|
|
5188
5447
|
checker,
|
|
@@ -5206,7 +5465,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5206
5465
|
}
|
|
5207
5466
|
return map;
|
|
5208
5467
|
}
|
|
5209
|
-
const interfaceDecl = declarations.find(
|
|
5468
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
5210
5469
|
if (interfaceDecl) {
|
|
5211
5470
|
return buildFieldNodeInfoMap(
|
|
5212
5471
|
interfaceDecl.members,
|
|
@@ -5220,7 +5479,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5220
5479
|
extensionRegistry
|
|
5221
5480
|
);
|
|
5222
5481
|
}
|
|
5223
|
-
const typeAliasDecl = declarations.find(
|
|
5482
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
5224
5483
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5225
5484
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5226
5485
|
return buildFieldNodeInfoMap(
|
|
@@ -5244,10 +5503,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5244
5503
|
return void 0;
|
|
5245
5504
|
}
|
|
5246
5505
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5247
|
-
if (
|
|
5506
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
5248
5507
|
return resolvedTypeNode.elementType;
|
|
5249
5508
|
}
|
|
5250
|
-
if (
|
|
5509
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5251
5510
|
return resolvedTypeNode.typeArguments[0];
|
|
5252
5511
|
}
|
|
5253
5512
|
return void 0;
|
|
@@ -5258,13 +5517,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5258
5517
|
return [];
|
|
5259
5518
|
}
|
|
5260
5519
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5261
|
-
return
|
|
5520
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5262
5521
|
}
|
|
5263
5522
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5264
|
-
if (
|
|
5523
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
5265
5524
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5266
5525
|
}
|
|
5267
|
-
if (!
|
|
5526
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
5268
5527
|
return typeNode;
|
|
5269
5528
|
}
|
|
5270
5529
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5275,15 +5534,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5275
5534
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5276
5535
|
}
|
|
5277
5536
|
function isNullishTypeNode(typeNode) {
|
|
5278
|
-
if (typeNode.kind ===
|
|
5537
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
5279
5538
|
return true;
|
|
5280
5539
|
}
|
|
5281
|
-
return
|
|
5540
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
5282
5541
|
}
|
|
5283
5542
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5284
5543
|
const map = /* @__PURE__ */ new Map();
|
|
5285
5544
|
for (const member of members) {
|
|
5286
|
-
if (
|
|
5545
|
+
if (ts5.isPropertySignature(member)) {
|
|
5287
5546
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5288
5547
|
member,
|
|
5289
5548
|
checker,
|
|
@@ -5309,7 +5568,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5309
5568
|
}
|
|
5310
5569
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5311
5570
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5312
|
-
if (!
|
|
5571
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
5313
5572
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5314
5573
|
const aliasName = typeNode.typeName.getText();
|
|
5315
5574
|
throw new Error(
|
|
@@ -5318,7 +5577,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5318
5577
|
}
|
|
5319
5578
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5320
5579
|
if (!aliasDecl) return [];
|
|
5321
|
-
if (
|
|
5580
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5322
5581
|
const aliasFieldType = resolveTypeNode(
|
|
5323
5582
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5324
5583
|
checker,
|
|
@@ -5362,14 +5621,14 @@ function getNamedTypeName(type) {
|
|
|
5362
5621
|
const symbol = type.getSymbol();
|
|
5363
5622
|
if (symbol?.declarations) {
|
|
5364
5623
|
const decl = symbol.declarations[0];
|
|
5365
|
-
if (decl && (
|
|
5366
|
-
const name =
|
|
5624
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5625
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5367
5626
|
if (name) return name;
|
|
5368
5627
|
}
|
|
5369
5628
|
}
|
|
5370
5629
|
const aliasSymbol = type.aliasSymbol;
|
|
5371
5630
|
if (aliasSymbol?.declarations) {
|
|
5372
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5631
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5373
5632
|
if (aliasDecl) {
|
|
5374
5633
|
return aliasDecl.name.text;
|
|
5375
5634
|
}
|
|
@@ -5380,24 +5639,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5380
5639
|
const symbol = type.getSymbol();
|
|
5381
5640
|
if (symbol?.declarations) {
|
|
5382
5641
|
const decl = symbol.declarations[0];
|
|
5383
|
-
if (decl && (
|
|
5642
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5384
5643
|
return decl;
|
|
5385
5644
|
}
|
|
5386
5645
|
}
|
|
5387
5646
|
const aliasSymbol = type.aliasSymbol;
|
|
5388
5647
|
if (aliasSymbol?.declarations) {
|
|
5389
|
-
return aliasSymbol.declarations.find(
|
|
5648
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5390
5649
|
}
|
|
5391
5650
|
return void 0;
|
|
5392
5651
|
}
|
|
5393
5652
|
function analyzeMethod(method, checker) {
|
|
5394
|
-
if (!
|
|
5653
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
5395
5654
|
return null;
|
|
5396
5655
|
}
|
|
5397
5656
|
const name = method.name.text;
|
|
5398
5657
|
const parameters = [];
|
|
5399
5658
|
for (const param of method.parameters) {
|
|
5400
|
-
if (
|
|
5659
|
+
if (ts5.isIdentifier(param.name)) {
|
|
5401
5660
|
const paramInfo = analyzeParameter(param, checker);
|
|
5402
5661
|
parameters.push(paramInfo);
|
|
5403
5662
|
}
|
|
@@ -5408,7 +5667,7 @@ function analyzeMethod(method, checker) {
|
|
|
5408
5667
|
return { name, parameters, returnTypeNode, returnType };
|
|
5409
5668
|
}
|
|
5410
5669
|
function analyzeParameter(param, checker) {
|
|
5411
|
-
const name =
|
|
5670
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
5412
5671
|
const typeNode = param.type;
|
|
5413
5672
|
const type = checker.getTypeAtLocation(param);
|
|
5414
5673
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5417,15 +5676,15 @@ function analyzeParameter(param, checker) {
|
|
|
5417
5676
|
}
|
|
5418
5677
|
function detectFormSpecReference(typeNode) {
|
|
5419
5678
|
if (!typeNode) return null;
|
|
5420
|
-
if (!
|
|
5421
|
-
const typeName =
|
|
5679
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
5680
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5422
5681
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5423
5682
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5424
|
-
if (!typeArg || !
|
|
5425
|
-
if (
|
|
5683
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
5684
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
5426
5685
|
return typeArg.exprName.text;
|
|
5427
5686
|
}
|
|
5428
|
-
if (
|
|
5687
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
5429
5688
|
return typeArg.exprName.right.text;
|
|
5430
5689
|
}
|
|
5431
5690
|
return null;
|
|
@@ -5447,23 +5706,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5447
5706
|
function createProgramContext(filePath, additionalFiles) {
|
|
5448
5707
|
const absolutePath = path.resolve(filePath);
|
|
5449
5708
|
const fileDir = path.dirname(absolutePath);
|
|
5450
|
-
const configPath =
|
|
5709
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
5451
5710
|
let compilerOptions;
|
|
5452
5711
|
let fileNames;
|
|
5453
5712
|
if (configPath) {
|
|
5454
|
-
const configFile =
|
|
5713
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
5455
5714
|
if (configFile.error) {
|
|
5456
5715
|
throw new Error(
|
|
5457
|
-
`Error reading tsconfig.json: ${
|
|
5716
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5458
5717
|
);
|
|
5459
5718
|
}
|
|
5460
|
-
const parsed =
|
|
5719
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
5461
5720
|
configFile.config,
|
|
5462
|
-
|
|
5721
|
+
ts6.sys,
|
|
5463
5722
|
path.dirname(configPath)
|
|
5464
5723
|
);
|
|
5465
5724
|
if (parsed.errors.length > 0) {
|
|
5466
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5725
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5467
5726
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5468
5727
|
}
|
|
5469
5728
|
compilerOptions = parsed.options;
|
|
@@ -5471,9 +5730,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5471
5730
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5472
5731
|
} else {
|
|
5473
5732
|
compilerOptions = {
|
|
5474
|
-
target:
|
|
5475
|
-
module:
|
|
5476
|
-
moduleResolution:
|
|
5733
|
+
target: ts6.ScriptTarget.ES2022,
|
|
5734
|
+
module: ts6.ModuleKind.NodeNext,
|
|
5735
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
5477
5736
|
strict: true,
|
|
5478
5737
|
skipLibCheck: true,
|
|
5479
5738
|
declaration: true
|
|
@@ -5481,7 +5740,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5481
5740
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5482
5741
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5483
5742
|
}
|
|
5484
|
-
const program =
|
|
5743
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
5485
5744
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5486
5745
|
if (!sourceFile) {
|
|
5487
5746
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5500,19 +5759,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5500
5759
|
result = node;
|
|
5501
5760
|
return;
|
|
5502
5761
|
}
|
|
5503
|
-
|
|
5762
|
+
ts6.forEachChild(node, visit);
|
|
5504
5763
|
}
|
|
5505
5764
|
visit(sourceFile);
|
|
5506
5765
|
return result;
|
|
5507
5766
|
}
|
|
5508
5767
|
function findClassByName(sourceFile, className) {
|
|
5509
|
-
return findNodeByName(sourceFile, className,
|
|
5768
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
5510
5769
|
}
|
|
5511
5770
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5512
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5771
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
5513
5772
|
}
|
|
5514
5773
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5515
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5774
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5516
5775
|
}
|
|
5517
5776
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5518
5777
|
if (rootType.kind === "object") {
|
|
@@ -5552,22 +5811,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5552
5811
|
};
|
|
5553
5812
|
}
|
|
5554
5813
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5555
|
-
if (
|
|
5814
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5556
5815
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5557
5816
|
}
|
|
5558
|
-
if (
|
|
5817
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5559
5818
|
return true;
|
|
5560
5819
|
}
|
|
5561
|
-
return
|
|
5820
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5562
5821
|
}
|
|
5563
5822
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5564
|
-
if (
|
|
5823
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5565
5824
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5566
5825
|
}
|
|
5567
|
-
if (
|
|
5826
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
5568
5827
|
const propertyNames = [];
|
|
5569
5828
|
for (const member of typeNode.members) {
|
|
5570
|
-
if (!
|
|
5829
|
+
if (!ts6.isPropertySignature(member)) {
|
|
5571
5830
|
continue;
|
|
5572
5831
|
}
|
|
5573
5832
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5577,13 +5836,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5577
5836
|
}
|
|
5578
5837
|
return propertyNames;
|
|
5579
5838
|
}
|
|
5580
|
-
if (
|
|
5839
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5581
5840
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5582
5841
|
}
|
|
5583
5842
|
return null;
|
|
5584
5843
|
}
|
|
5585
5844
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5586
|
-
if (!
|
|
5845
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
5587
5846
|
return [];
|
|
5588
5847
|
}
|
|
5589
5848
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5784,7 +6043,7 @@ function makeFileProvenance(filePath) {
|
|
|
5784
6043
|
}
|
|
5785
6044
|
|
|
5786
6045
|
// src/extensions/symbol-registry.ts
|
|
5787
|
-
import * as
|
|
6046
|
+
import * as ts7 from "typescript";
|
|
5788
6047
|
import * as path2 from "path";
|
|
5789
6048
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5790
6049
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5794,10 +6053,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5794
6053
|
return symbolMap;
|
|
5795
6054
|
}
|
|
5796
6055
|
function visit(node) {
|
|
5797
|
-
if (
|
|
6056
|
+
if (ts7.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5798
6057
|
processDefineCustomTypeCall(node);
|
|
5799
6058
|
}
|
|
5800
|
-
|
|
6059
|
+
ts7.forEachChild(node, visit);
|
|
5801
6060
|
}
|
|
5802
6061
|
function processDefineCustomTypeCall(call) {
|
|
5803
6062
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5834,7 +6093,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5834
6093
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5835
6094
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5836
6095
|
if (callSymbol !== void 0) {
|
|
5837
|
-
const resolved = callSymbol.flags &
|
|
6096
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5838
6097
|
const decl = resolved.declarations?.[0];
|
|
5839
6098
|
if (decl !== void 0) {
|
|
5840
6099
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5842,24 +6101,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5842
6101
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5843
6102
|
}
|
|
5844
6103
|
}
|
|
5845
|
-
return
|
|
6104
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5846
6105
|
}
|
|
5847
6106
|
function extractTypeNameFromCallArg(call) {
|
|
5848
6107
|
const arg = call.arguments[0];
|
|
5849
|
-
if (arg === void 0 || !
|
|
6108
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5850
6109
|
return null;
|
|
5851
6110
|
}
|
|
5852
6111
|
const typeNameProp = arg.properties.find(
|
|
5853
|
-
(p) =>
|
|
6112
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5854
6113
|
);
|
|
5855
|
-
if (typeNameProp === void 0 || !
|
|
6114
|
+
if (typeNameProp === void 0 || !ts7.isStringLiteral(typeNameProp.initializer)) {
|
|
5856
6115
|
return null;
|
|
5857
6116
|
}
|
|
5858
6117
|
return typeNameProp.initializer.text;
|
|
5859
6118
|
}
|
|
5860
6119
|
function extractEnclosingExtensionId(call, checker) {
|
|
5861
|
-
for (let node = call.parent; !
|
|
5862
|
-
if (
|
|
6120
|
+
for (let node = call.parent; !ts7.isSourceFile(node); node = node.parent) {
|
|
6121
|
+
if (ts7.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5863
6122
|
return extractExtensionIdFromCallArg(node);
|
|
5864
6123
|
}
|
|
5865
6124
|
}
|
|
@@ -5868,24 +6127,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5868
6127
|
function isDefineExtensionCall(node, checker) {
|
|
5869
6128
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5870
6129
|
if (callSymbol !== void 0) {
|
|
5871
|
-
const resolved = callSymbol.flags &
|
|
6130
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5872
6131
|
const decl = resolved.declarations?.[0];
|
|
5873
6132
|
if (decl !== void 0) {
|
|
5874
6133
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5875
6134
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5876
6135
|
}
|
|
5877
6136
|
}
|
|
5878
|
-
return
|
|
6137
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5879
6138
|
}
|
|
5880
6139
|
function extractExtensionIdFromCallArg(call) {
|
|
5881
6140
|
const arg = call.arguments[0];
|
|
5882
|
-
if (arg === void 0 || !
|
|
6141
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5883
6142
|
return null;
|
|
5884
6143
|
}
|
|
5885
6144
|
const prop = arg.properties.find(
|
|
5886
|
-
(p) =>
|
|
6145
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5887
6146
|
);
|
|
5888
|
-
if (prop === void 0 || !
|
|
6147
|
+
if (prop === void 0 || !ts7.isStringLiteral(prop.initializer)) {
|
|
5889
6148
|
return null;
|
|
5890
6149
|
}
|
|
5891
6150
|
return prop.initializer.text;
|
|
@@ -6147,7 +6406,7 @@ function generateSchemasBatch(options) {
|
|
|
6147
6406
|
return options.targets.map((target) => {
|
|
6148
6407
|
let ctx;
|
|
6149
6408
|
try {
|
|
6150
|
-
const cacheKey =
|
|
6409
|
+
const cacheKey = ts8.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
6151
6410
|
const cachedContext = contextCache.get(cacheKey);
|
|
6152
6411
|
if (cachedContext === void 0) {
|
|
6153
6412
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6206,7 +6465,7 @@ function isMutableRegistry(reg) {
|
|
|
6206
6465
|
}
|
|
6207
6466
|
function resolveStaticOptions(options) {
|
|
6208
6467
|
const legacyRegistry = options.extensionRegistry;
|
|
6209
|
-
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6468
|
+
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6210
6469
|
return {
|
|
6211
6470
|
extensionRegistry: legacyRegistry ?? configRegistry,
|
|
6212
6471
|
// eslint-disable-next-line @typescript-eslint/no-deprecated -- migration bridge reads deprecated fields
|
|
@@ -6218,7 +6477,7 @@ function resolveStaticOptions(options) {
|
|
|
6218
6477
|
};
|
|
6219
6478
|
}
|
|
6220
6479
|
function resolveOptions(options) {
|
|
6221
|
-
const configRegistry = options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6480
|
+
const configRegistry = options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6222
6481
|
const legacyRegistry = options.extensionRegistry;
|
|
6223
6482
|
return {
|
|
6224
6483
|
// When the caller provides the deprecated extensionRegistry field directly,
|
|
@@ -6303,7 +6562,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6303
6562
|
}
|
|
6304
6563
|
|
|
6305
6564
|
// src/static-build.ts
|
|
6306
|
-
import * as
|
|
6565
|
+
import * as ts9 from "typescript";
|
|
6307
6566
|
function toStaticBuildContext(context) {
|
|
6308
6567
|
return context;
|
|
6309
6568
|
}
|
|
@@ -6318,7 +6577,7 @@ function getModuleSymbol(context) {
|
|
|
6318
6577
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6319
6578
|
}
|
|
6320
6579
|
function isSchemaSourceDeclaration(declaration) {
|
|
6321
|
-
return
|
|
6580
|
+
return ts9.isClassDeclaration(declaration) || ts9.isInterfaceDeclaration(declaration) || ts9.isTypeAliasDeclaration(declaration);
|
|
6322
6581
|
}
|
|
6323
6582
|
function resolveModuleExport(context, exportName = "default") {
|
|
6324
6583
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6329,14 +6588,14 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6329
6588
|
if (exportSymbol === null) {
|
|
6330
6589
|
return null;
|
|
6331
6590
|
}
|
|
6332
|
-
return exportSymbol.flags &
|
|
6591
|
+
return exportSymbol.flags & ts9.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6333
6592
|
}
|
|
6334
6593
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6335
6594
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6336
6595
|
}
|
|
6337
6596
|
|
|
6338
6597
|
// src/generators/discovered-schema.ts
|
|
6339
|
-
import * as
|
|
6598
|
+
import * as ts10 from "typescript";
|
|
6340
6599
|
import { analyzeMetadataForNodeWithChecker as analyzeMetadataForNodeWithChecker2 } from "@formspec/analysis/internal";
|
|
6341
6600
|
import { IR_VERSION as IR_VERSION3 } from "@formspec/core/internals";
|
|
6342
6601
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
@@ -6346,17 +6605,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6346
6605
|
};
|
|
6347
6606
|
}
|
|
6348
6607
|
function isNamedTypeDeclaration(declaration) {
|
|
6349
|
-
return
|
|
6608
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6350
6609
|
}
|
|
6351
6610
|
function hasConcreteTypeArguments(type, checker) {
|
|
6352
6611
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6353
6612
|
return true;
|
|
6354
6613
|
}
|
|
6355
|
-
if ((type.flags &
|
|
6614
|
+
if ((type.flags & ts10.TypeFlags.Object) === 0) {
|
|
6356
6615
|
return false;
|
|
6357
6616
|
}
|
|
6358
6617
|
const objectType = type;
|
|
6359
|
-
if ((objectType.objectFlags &
|
|
6618
|
+
if ((objectType.objectFlags & ts10.ObjectFlags.Reference) === 0) {
|
|
6360
6619
|
return false;
|
|
6361
6620
|
}
|
|
6362
6621
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6369,13 +6628,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6369
6628
|
return declaration;
|
|
6370
6629
|
}
|
|
6371
6630
|
}
|
|
6372
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6631
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts10.isTypeAliasDeclaration);
|
|
6373
6632
|
return aliasDeclaration;
|
|
6374
6633
|
}
|
|
6375
6634
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6376
6635
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6377
6636
|
const namedNode = sourceNode;
|
|
6378
|
-
if (namedNode.name !== void 0 &&
|
|
6637
|
+
if (namedNode.name !== void 0 && ts10.isIdentifier(namedNode.name)) {
|
|
6379
6638
|
return namedNode.name.text;
|
|
6380
6639
|
}
|
|
6381
6640
|
}
|
|
@@ -6597,7 +6856,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6597
6856
|
function generateSchemasFromDeclaration(options) {
|
|
6598
6857
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6599
6858
|
const resolved = resolveStaticOptions(options);
|
|
6600
|
-
if (
|
|
6859
|
+
if (ts10.isClassDeclaration(options.declaration)) {
|
|
6601
6860
|
return generateSchemasFromAnalysis(
|
|
6602
6861
|
analyzeClassToIR(
|
|
6603
6862
|
options.declaration,
|
|
@@ -6611,7 +6870,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6611
6870
|
resolved
|
|
6612
6871
|
);
|
|
6613
6872
|
}
|
|
6614
|
-
if (
|
|
6873
|
+
if (ts10.isInterfaceDeclaration(options.declaration)) {
|
|
6615
6874
|
return generateSchemasFromAnalysis(
|
|
6616
6875
|
analyzeInterfaceToIR(
|
|
6617
6876
|
options.declaration,
|
|
@@ -6625,7 +6884,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6625
6884
|
resolved
|
|
6626
6885
|
);
|
|
6627
6886
|
}
|
|
6628
|
-
if (
|
|
6887
|
+
if (ts10.isTypeAliasDeclaration(options.declaration)) {
|
|
6629
6888
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6630
6889
|
options.declaration,
|
|
6631
6890
|
options.context.checker,
|
|
@@ -6684,7 +6943,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6684
6943
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6685
6944
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6686
6945
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6687
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6946
|
+
const fallbackName = options.declaration.name !== void 0 && ts10.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6688
6947
|
return generateSchemasFromResolvedType({
|
|
6689
6948
|
...options,
|
|
6690
6949
|
type,
|
|
@@ -6731,14 +6990,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6731
6990
|
if (typeNode === void 0) {
|
|
6732
6991
|
return void 0;
|
|
6733
6992
|
}
|
|
6734
|
-
if (
|
|
6993
|
+
if (ts10.isParenthesizedTypeNode(typeNode)) {
|
|
6735
6994
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6736
6995
|
return unwrapped ?? typeNode;
|
|
6737
6996
|
}
|
|
6738
6997
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6739
6998
|
}
|
|
6740
6999
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6741
|
-
return
|
|
7000
|
+
return ts10.isTypeReferenceNode(typeNode) && ts10.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6742
7001
|
}
|
|
6743
7002
|
|
|
6744
7003
|
// src/generators/mixed-authoring.ts
|