@formspec/build 0.1.0-alpha.57 → 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 +625 -326
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +586 -279
- 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 +615 -315
- 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 +585 -277
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +589 -289
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +554 -246
- 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,18 +2458,19 @@ 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,
|
|
2470
|
+
getTypedParserLogger,
|
|
2471
|
+
extractEffectiveArgumentText,
|
|
2472
|
+
mapTypedParserDiagnosticCode,
|
|
2473
|
+
parseTagArgument,
|
|
2391
2474
|
describeTypeKind,
|
|
2392
2475
|
elapsedMicros,
|
|
2393
2476
|
nowMicros,
|
|
@@ -2399,7 +2482,7 @@ function sharedTagValueOptions(options) {
|
|
|
2399
2482
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2400
2483
|
};
|
|
2401
2484
|
}
|
|
2402
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
2485
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2403
2486
|
function getExtensionTypeNames(registry) {
|
|
2404
2487
|
if (registry === void 0) {
|
|
2405
2488
|
return /* @__PURE__ */ new Set();
|
|
@@ -2413,23 +2496,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2413
2496
|
function collectImportedNames(sourceFile) {
|
|
2414
2497
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2415
2498
|
for (const statement of sourceFile.statements) {
|
|
2416
|
-
if (
|
|
2499
|
+
if (ts3.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2417
2500
|
const clause = statement.importClause;
|
|
2418
2501
|
if (clause.name !== void 0) {
|
|
2419
2502
|
importedNames.add(clause.name.text);
|
|
2420
2503
|
}
|
|
2421
2504
|
if (clause.namedBindings !== void 0) {
|
|
2422
|
-
if (
|
|
2505
|
+
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
2423
2506
|
for (const specifier of clause.namedBindings.elements) {
|
|
2424
2507
|
importedNames.add(specifier.name.text);
|
|
2425
2508
|
}
|
|
2426
|
-
} else if (
|
|
2509
|
+
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
2427
2510
|
importedNames.add(clause.namedBindings.name.text);
|
|
2428
2511
|
}
|
|
2429
2512
|
}
|
|
2430
2513
|
continue;
|
|
2431
2514
|
}
|
|
2432
|
-
if (
|
|
2515
|
+
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
2433
2516
|
importedNames.add(statement.name.text);
|
|
2434
2517
|
}
|
|
2435
2518
|
}
|
|
@@ -2437,13 +2520,13 @@ function collectImportedNames(sourceFile) {
|
|
|
2437
2520
|
}
|
|
2438
2521
|
function isNonReferenceIdentifier(node) {
|
|
2439
2522
|
const parent = node.parent;
|
|
2440
|
-
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) {
|
|
2441
2524
|
return true;
|
|
2442
2525
|
}
|
|
2443
|
-
if ((
|
|
2526
|
+
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2444
2527
|
return true;
|
|
2445
2528
|
}
|
|
2446
|
-
if (
|
|
2529
|
+
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
2447
2530
|
return true;
|
|
2448
2531
|
}
|
|
2449
2532
|
return false;
|
|
@@ -2455,20 +2538,20 @@ function astReferencesImportedName(root, importedNames) {
|
|
|
2455
2538
|
let found = false;
|
|
2456
2539
|
const visit = (node) => {
|
|
2457
2540
|
if (found) return;
|
|
2458
|
-
if (
|
|
2541
|
+
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2459
2542
|
found = true;
|
|
2460
2543
|
return;
|
|
2461
2544
|
}
|
|
2462
|
-
|
|
2545
|
+
ts3.forEachChild(node, visit);
|
|
2463
2546
|
};
|
|
2464
2547
|
visit(root);
|
|
2465
2548
|
return found;
|
|
2466
2549
|
}
|
|
2467
2550
|
function getObjectMembers(statement) {
|
|
2468
|
-
if (
|
|
2551
|
+
if (ts3.isInterfaceDeclaration(statement)) {
|
|
2469
2552
|
return statement.members;
|
|
2470
2553
|
}
|
|
2471
|
-
if (
|
|
2554
|
+
if (ts3.isTypeLiteralNode(statement.type)) {
|
|
2472
2555
|
return statement.type.members;
|
|
2473
2556
|
}
|
|
2474
2557
|
return void 0;
|
|
@@ -2480,7 +2563,7 @@ function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
|
2480
2563
|
}
|
|
2481
2564
|
const replacements = [];
|
|
2482
2565
|
for (const member of members) {
|
|
2483
|
-
if (!
|
|
2566
|
+
if (!ts3.isPropertySignature(member)) {
|
|
2484
2567
|
if (astReferencesImportedName(member, importedNames)) {
|
|
2485
2568
|
return null;
|
|
2486
2569
|
}
|
|
@@ -2512,14 +2595,14 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
2512
2595
|
);
|
|
2513
2596
|
const result = [];
|
|
2514
2597
|
for (const statement of sourceFile.statements) {
|
|
2515
|
-
if (
|
|
2516
|
-
if (
|
|
2517
|
-
if (
|
|
2598
|
+
if (ts3.isImportDeclaration(statement)) continue;
|
|
2599
|
+
if (ts3.isImportEqualsDeclaration(statement)) continue;
|
|
2600
|
+
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2518
2601
|
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2519
2602
|
result.push(statement.getText(sourceFile));
|
|
2520
2603
|
continue;
|
|
2521
2604
|
}
|
|
2522
|
-
if (
|
|
2605
|
+
if (ts3.isInterfaceDeclaration(statement) || ts3.isTypeAliasDeclaration(statement)) {
|
|
2523
2606
|
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2524
2607
|
if (rewritten !== null) {
|
|
2525
2608
|
result.push(rewritten);
|
|
@@ -2544,6 +2627,7 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
2544
2627
|
sourceFile,
|
|
2545
2628
|
tagName,
|
|
2546
2629
|
parsedTag,
|
|
2630
|
+
text,
|
|
2547
2631
|
provenance,
|
|
2548
2632
|
supportingDeclarations,
|
|
2549
2633
|
options
|
|
@@ -2571,6 +2655,9 @@ function renderSyntheticArgumentExpression(valueKind, argumentText) {
|
|
|
2571
2655
|
case "number":
|
|
2572
2656
|
case "integer":
|
|
2573
2657
|
case "signedInteger":
|
|
2658
|
+
if (trimmed === "Infinity" || trimmed === "-Infinity" || trimmed === "NaN") {
|
|
2659
|
+
return trimmed;
|
|
2660
|
+
}
|
|
2574
2661
|
return Number.isFinite(Number(trimmed)) ? trimmed : JSON.stringify(trimmed);
|
|
2575
2662
|
case "string":
|
|
2576
2663
|
return JSON.stringify(argumentText);
|
|
@@ -2618,7 +2705,7 @@ function stripHintNullishUnion(type) {
|
|
|
2618
2705
|
return type;
|
|
2619
2706
|
}
|
|
2620
2707
|
const nonNullish = type.types.filter(
|
|
2621
|
-
(member) => (member.flags & (
|
|
2708
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
2622
2709
|
);
|
|
2623
2710
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2624
2711
|
return nonNullish[0];
|
|
@@ -2634,10 +2721,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2634
2721
|
}
|
|
2635
2722
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2636
2723
|
const name = declaration.name;
|
|
2637
|
-
if (
|
|
2724
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
2638
2725
|
return false;
|
|
2639
2726
|
}
|
|
2640
|
-
if (!
|
|
2727
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
2641
2728
|
return false;
|
|
2642
2729
|
}
|
|
2643
2730
|
}
|
|
@@ -2782,7 +2869,7 @@ function hasBuiltinConstraintBroadening(tagName, options) {
|
|
|
2782
2869
|
const broadenedTypeId = getBroadenedCustomTypeId(options?.fieldType);
|
|
2783
2870
|
return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
|
|
2784
2871
|
}
|
|
2785
|
-
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, provenance, supportingDeclarations, options) {
|
|
2872
|
+
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance, supportingDeclarations, options) {
|
|
2786
2873
|
if (!isBuiltinConstraintName(tagName)) {
|
|
2787
2874
|
return [];
|
|
2788
2875
|
}
|
|
@@ -2803,8 +2890,10 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2803
2890
|
const log = getBuildLogger();
|
|
2804
2891
|
const broadeningLog = getBroadeningLogger();
|
|
2805
2892
|
const syntheticLog = getSyntheticLogger2();
|
|
2893
|
+
const typedParserLog = getTypedParserLogger();
|
|
2806
2894
|
const logsEnabled = log !== noopLogger3 || broadeningLog !== noopLogger3;
|
|
2807
2895
|
const syntheticTraceEnabled = syntheticLog !== noopLogger3;
|
|
2896
|
+
const typedParserTraceEnabled = typedParserLog !== noopLogger3;
|
|
2808
2897
|
const logStart = logsEnabled ? nowMicros() : 0;
|
|
2809
2898
|
const subjectTypeKind = logsEnabled ? describeTypeKind(subjectType, checker) : "";
|
|
2810
2899
|
function emit(outcome, result2) {
|
|
@@ -2881,7 +2970,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2881
2970
|
}
|
|
2882
2971
|
const hasBroadening = (() => {
|
|
2883
2972
|
if (target === null) {
|
|
2884
|
-
if (
|
|
2973
|
+
if (_isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2885
2974
|
return true;
|
|
2886
2975
|
}
|
|
2887
2976
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
@@ -2912,16 +3001,41 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2912
3001
|
]);
|
|
2913
3002
|
}
|
|
2914
3003
|
}
|
|
2915
|
-
const argumentExpression = renderSyntheticArgumentExpression(
|
|
2916
|
-
definition.valueKind,
|
|
2917
|
-
parsedTag?.argumentText ?? ""
|
|
2918
|
-
);
|
|
2919
|
-
if (definition.requiresArgument && argumentExpression === null) {
|
|
2920
|
-
return emit("A-pass", []);
|
|
2921
|
-
}
|
|
2922
3004
|
if (hasBroadening) {
|
|
2923
3005
|
return emit("bypass", []);
|
|
2924
3006
|
}
|
|
3007
|
+
const effectiveArgumentText = extractEffectiveArgumentText(tagName, rawText, parsedTag);
|
|
3008
|
+
const typedParseResult = parseTagArgument(tagName, effectiveArgumentText, "build");
|
|
3009
|
+
if (!typedParseResult.ok) {
|
|
3010
|
+
if (typedParserTraceEnabled) {
|
|
3011
|
+
typedParserLog.trace("typed-parser C-reject", {
|
|
3012
|
+
consumer: "build",
|
|
3013
|
+
tag: tagName,
|
|
3014
|
+
placement: nonNullPlacement,
|
|
3015
|
+
subjectTypeKind: subjectTypeKind !== "" ? subjectTypeKind : "-",
|
|
3016
|
+
roleOutcome: "C-reject",
|
|
3017
|
+
diagnosticCode: typedParseResult.diagnostic.code
|
|
3018
|
+
});
|
|
3019
|
+
}
|
|
3020
|
+
const mappedCode = mapTypedParserDiagnosticCode(typedParseResult.diagnostic.code, tagName);
|
|
3021
|
+
return emit("C-reject", [
|
|
3022
|
+
makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
|
|
3023
|
+
]);
|
|
3024
|
+
}
|
|
3025
|
+
if (typedParserTraceEnabled) {
|
|
3026
|
+
typedParserLog.trace("typed-parser C-pass", {
|
|
3027
|
+
consumer: "build",
|
|
3028
|
+
tag: tagName,
|
|
3029
|
+
placement: nonNullPlacement,
|
|
3030
|
+
subjectTypeKind: subjectTypeKind !== "" ? subjectTypeKind : "-",
|
|
3031
|
+
roleOutcome: "C-pass",
|
|
3032
|
+
valueKind: typedParseResult.value.kind
|
|
3033
|
+
});
|
|
3034
|
+
}
|
|
3035
|
+
const argumentExpression = renderSyntheticArgumentExpression(
|
|
3036
|
+
definition.valueKind,
|
|
3037
|
+
effectiveArgumentText
|
|
3038
|
+
);
|
|
2925
3039
|
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2926
3040
|
const hostType = options?.hostType ?? subjectType;
|
|
2927
3041
|
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
@@ -2960,13 +3074,13 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2960
3074
|
} : {}
|
|
2961
3075
|
});
|
|
2962
3076
|
if (result.diagnostics.length === 0) {
|
|
2963
|
-
return emit("
|
|
3077
|
+
return emit("D-pass", []);
|
|
2964
3078
|
}
|
|
2965
3079
|
const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
|
|
2966
3080
|
if (setupDiagnostic !== void 0) {
|
|
2967
3081
|
return emit("C-reject", [
|
|
2968
3082
|
makeDiagnostic(
|
|
2969
|
-
setupDiagnostic.kind
|
|
3083
|
+
_mapSetupDiagnosticCode(setupDiagnostic.kind),
|
|
2970
3084
|
setupDiagnostic.message,
|
|
2971
3085
|
provenance
|
|
2972
3086
|
)
|
|
@@ -3034,6 +3148,16 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3034
3148
|
if (cached !== void 0) {
|
|
3035
3149
|
return cached;
|
|
3036
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
|
+
}
|
|
3037
3161
|
const constraints = [];
|
|
3038
3162
|
const annotations = [];
|
|
3039
3163
|
const diagnostics = [];
|
|
@@ -3045,12 +3169,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3045
3169
|
const sourceText = sourceFile.getFullText();
|
|
3046
3170
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
3047
3171
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
3048
|
-
const commentRanges =
|
|
3172
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3049
3173
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
3050
3174
|
const extensionTagNames = getExtensionTagNames(options);
|
|
3051
3175
|
if (commentRanges) {
|
|
3052
3176
|
for (const range of commentRanges) {
|
|
3053
|
-
if (range.kind !==
|
|
3177
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
3054
3178
|
continue;
|
|
3055
3179
|
}
|
|
3056
3180
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3207,10 +3331,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3207
3331
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3208
3332
|
const sourceFile = node.getSourceFile();
|
|
3209
3333
|
const sourceText = sourceFile.getFullText();
|
|
3210
|
-
const commentRanges =
|
|
3334
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3211
3335
|
if (commentRanges) {
|
|
3212
3336
|
for (const range of commentRanges) {
|
|
3213
|
-
if (range.kind !==
|
|
3337
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3214
3338
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3215
3339
|
if (!commentText.startsWith("/**")) continue;
|
|
3216
3340
|
const unified = parseUnifiedComment(commentText);
|
|
@@ -3235,7 +3359,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3235
3359
|
}
|
|
3236
3360
|
function collectRawTextFallbacks(node, file) {
|
|
3237
3361
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3238
|
-
for (const tag of
|
|
3362
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
3239
3363
|
const tagName = normalizeConstraintTagName2(tag.tagName.text);
|
|
3240
3364
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3241
3365
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3290,7 +3414,7 @@ function getTagCommentText(tag) {
|
|
|
3290
3414
|
if (typeof tag.comment === "string") {
|
|
3291
3415
|
return tag.comment;
|
|
3292
3416
|
}
|
|
3293
|
-
return
|
|
3417
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
3294
3418
|
}
|
|
3295
3419
|
|
|
3296
3420
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3308,18 +3432,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3308
3432
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3309
3433
|
if (!initializer) return null;
|
|
3310
3434
|
let value;
|
|
3311
|
-
if (
|
|
3435
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
3312
3436
|
value = initializer.text;
|
|
3313
|
-
} else if (
|
|
3437
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
3314
3438
|
value = Number(initializer.text);
|
|
3315
|
-
} else if (initializer.kind ===
|
|
3439
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
3316
3440
|
value = true;
|
|
3317
|
-
} else if (initializer.kind ===
|
|
3441
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
3318
3442
|
value = false;
|
|
3319
|
-
} else if (initializer.kind ===
|
|
3443
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
3320
3444
|
value = null;
|
|
3321
|
-
} else if (
|
|
3322
|
-
if (initializer.operator ===
|
|
3445
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
3446
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
3323
3447
|
value = -Number(initializer.operand.text);
|
|
3324
3448
|
}
|
|
3325
3449
|
}
|
|
@@ -3341,28 +3465,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3341
3465
|
|
|
3342
3466
|
// src/analyzer/class-analyzer.ts
|
|
3343
3467
|
function isObjectType(type) {
|
|
3344
|
-
return !!(type.flags &
|
|
3468
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
3345
3469
|
}
|
|
3346
3470
|
function isIntersectionType(type) {
|
|
3347
|
-
return !!(type.flags &
|
|
3471
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
3348
3472
|
}
|
|
3349
3473
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3350
|
-
if (
|
|
3474
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3351
3475
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3352
3476
|
}
|
|
3353
|
-
if (
|
|
3477
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
3354
3478
|
return true;
|
|
3355
3479
|
}
|
|
3356
|
-
return
|
|
3480
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3357
3481
|
}
|
|
3358
3482
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3359
3483
|
if (isIntersectionType(type)) {
|
|
3360
3484
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3361
3485
|
}
|
|
3362
|
-
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);
|
|
3363
3487
|
}
|
|
3364
3488
|
function isTypeReference(type) {
|
|
3365
|
-
return !!(type.flags &
|
|
3489
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
3366
3490
|
}
|
|
3367
3491
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3368
3492
|
kind: "object",
|
|
@@ -3388,6 +3512,21 @@ function createAnalyzerMetadataPolicy(input, discriminator) {
|
|
|
3388
3512
|
discriminator
|
|
3389
3513
|
};
|
|
3390
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
|
+
}
|
|
3391
3530
|
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
3392
3531
|
const analysis = analyzeMetadataForNodeWithChecker({
|
|
3393
3532
|
checker,
|
|
@@ -3424,10 +3563,121 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3424
3563
|
}
|
|
3425
3564
|
return resolvedMetadata;
|
|
3426
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
|
+
}
|
|
3427
3677
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3428
3678
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3429
3679
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3430
|
-
const logicalName =
|
|
3680
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3431
3681
|
const docResult = extractJSDocParseResult(
|
|
3432
3682
|
declaration,
|
|
3433
3683
|
file,
|
|
@@ -3469,13 +3719,19 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3469
3719
|
file,
|
|
3470
3720
|
makeParseOptions(extensionRegistry, void 0, checker, classType, classType)
|
|
3471
3721
|
);
|
|
3472
|
-
const
|
|
3722
|
+
const inheritedClassAnnotations = collectInheritedTypeAnnotations(
|
|
3723
|
+
classDecl,
|
|
3724
|
+
classDoc.annotations,
|
|
3725
|
+
checker,
|
|
3726
|
+
extensionRegistry
|
|
3727
|
+
);
|
|
3728
|
+
const annotations = [...classDoc.annotations, ...inheritedClassAnnotations];
|
|
3473
3729
|
diagnostics.push(...classDoc.diagnostics);
|
|
3474
3730
|
const visiting = /* @__PURE__ */ new Set();
|
|
3475
3731
|
const instanceMethods = [];
|
|
3476
3732
|
const staticMethods = [];
|
|
3477
3733
|
for (const member of classDecl.members) {
|
|
3478
|
-
if (
|
|
3734
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
3479
3735
|
const fieldNode = analyzeFieldToIR(
|
|
3480
3736
|
member,
|
|
3481
3737
|
checker,
|
|
@@ -3491,10 +3747,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3491
3747
|
fields.push(fieldNode);
|
|
3492
3748
|
fieldLayouts.push({});
|
|
3493
3749
|
}
|
|
3494
|
-
} else if (
|
|
3750
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
3495
3751
|
const methodInfo = analyzeMethod(member, checker);
|
|
3496
3752
|
if (methodInfo) {
|
|
3497
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3753
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
3498
3754
|
if (isStatic) {
|
|
3499
3755
|
staticMethods.push(methodInfo);
|
|
3500
3756
|
} else {
|
|
@@ -3526,6 +3782,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3526
3782
|
hostType: classType
|
|
3527
3783
|
}
|
|
3528
3784
|
);
|
|
3785
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3529
3786
|
return {
|
|
3530
3787
|
name,
|
|
3531
3788
|
...metadata !== void 0 && { metadata },
|
|
@@ -3533,7 +3790,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3533
3790
|
fieldLayouts,
|
|
3534
3791
|
typeRegistry,
|
|
3535
3792
|
...annotations.length > 0 && { annotations },
|
|
3536
|
-
...
|
|
3793
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3537
3794
|
instanceMethods,
|
|
3538
3795
|
staticMethods
|
|
3539
3796
|
};
|
|
@@ -3553,11 +3810,20 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3553
3810
|
file,
|
|
3554
3811
|
makeParseOptions(extensionRegistry, void 0, checker, interfaceType, interfaceType)
|
|
3555
3812
|
);
|
|
3556
|
-
const
|
|
3813
|
+
const inheritedInterfaceAnnotations = collectInheritedTypeAnnotations(
|
|
3814
|
+
interfaceDecl,
|
|
3815
|
+
interfaceDoc.annotations,
|
|
3816
|
+
checker,
|
|
3817
|
+
extensionRegistry
|
|
3818
|
+
);
|
|
3819
|
+
const annotations = [
|
|
3820
|
+
...interfaceDoc.annotations,
|
|
3821
|
+
...inheritedInterfaceAnnotations
|
|
3822
|
+
];
|
|
3557
3823
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3558
3824
|
const visiting = /* @__PURE__ */ new Set();
|
|
3559
3825
|
for (const member of interfaceDecl.members) {
|
|
3560
|
-
if (
|
|
3826
|
+
if (ts5.isPropertySignature(member)) {
|
|
3561
3827
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3562
3828
|
member,
|
|
3563
3829
|
checker,
|
|
@@ -3598,6 +3864,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3598
3864
|
hostType: interfaceType
|
|
3599
3865
|
}
|
|
3600
3866
|
);
|
|
3867
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3601
3868
|
return {
|
|
3602
3869
|
name,
|
|
3603
3870
|
...metadata !== void 0 && { metadata },
|
|
@@ -3605,7 +3872,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3605
3872
|
fieldLayouts,
|
|
3606
3873
|
typeRegistry,
|
|
3607
3874
|
...annotations.length > 0 && { annotations },
|
|
3608
|
-
...
|
|
3875
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3609
3876
|
instanceMethods: [],
|
|
3610
3877
|
staticMethods: []
|
|
3611
3878
|
};
|
|
@@ -3615,7 +3882,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3615
3882
|
if (members === null) {
|
|
3616
3883
|
const sourceFile = typeAlias.getSourceFile();
|
|
3617
3884
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3618
|
-
const kindDesc =
|
|
3885
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3619
3886
|
return {
|
|
3620
3887
|
ok: false,
|
|
3621
3888
|
kind: "not-object-like",
|
|
@@ -3650,7 +3917,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3650
3917
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3651
3918
|
const visiting = /* @__PURE__ */ new Set();
|
|
3652
3919
|
for (const member of members) {
|
|
3653
|
-
if (
|
|
3920
|
+
if (ts5.isPropertySignature(member)) {
|
|
3654
3921
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3655
3922
|
member,
|
|
3656
3923
|
checker,
|
|
@@ -3690,6 +3957,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3690
3957
|
hostType: aliasType
|
|
3691
3958
|
}
|
|
3692
3959
|
);
|
|
3960
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3693
3961
|
return {
|
|
3694
3962
|
ok: true,
|
|
3695
3963
|
analysis: {
|
|
@@ -3699,7 +3967,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3699
3967
|
fieldLayouts: specializedFields.map(() => ({})),
|
|
3700
3968
|
typeRegistry,
|
|
3701
3969
|
...annotations.length > 0 && { annotations },
|
|
3702
|
-
...
|
|
3970
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3703
3971
|
instanceMethods: [],
|
|
3704
3972
|
staticMethods: []
|
|
3705
3973
|
}
|
|
@@ -3717,13 +3985,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3717
3985
|
function getLeadingParsedTags(node) {
|
|
3718
3986
|
const sourceFile = node.getSourceFile();
|
|
3719
3987
|
const sourceText = sourceFile.getFullText();
|
|
3720
|
-
const commentRanges =
|
|
3988
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3721
3989
|
if (commentRanges === void 0) {
|
|
3722
3990
|
return [];
|
|
3723
3991
|
}
|
|
3724
3992
|
const parsedTags = [];
|
|
3725
3993
|
for (const range of commentRanges) {
|
|
3726
|
-
if (range.kind !==
|
|
3994
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
3727
3995
|
continue;
|
|
3728
3996
|
}
|
|
3729
3997
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3741,19 +4009,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3741
4009
|
return null;
|
|
3742
4010
|
}
|
|
3743
4011
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3744
|
-
(candidate) =>
|
|
4012
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
3745
4013
|
) ?? propertySymbol.declarations?.[0];
|
|
3746
4014
|
return {
|
|
3747
4015
|
declaration,
|
|
3748
4016
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3749
|
-
optional: !!(propertySymbol.flags &
|
|
4017
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3750
4018
|
};
|
|
3751
4019
|
}
|
|
3752
4020
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3753
4021
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3754
4022
|
}
|
|
3755
4023
|
function isNullishSemanticType(type) {
|
|
3756
|
-
if (type.flags & (
|
|
4024
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
3757
4025
|
return true;
|
|
3758
4026
|
}
|
|
3759
4027
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3763,7 +4031,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3763
4031
|
return false;
|
|
3764
4032
|
}
|
|
3765
4033
|
seen.add(type);
|
|
3766
|
-
if (type.flags &
|
|
4034
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
3767
4035
|
return true;
|
|
3768
4036
|
}
|
|
3769
4037
|
if (type.isUnion()) {
|
|
@@ -3776,13 +4044,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3776
4044
|
return false;
|
|
3777
4045
|
}
|
|
3778
4046
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3779
|
-
if (
|
|
4047
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3780
4048
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3781
4049
|
}
|
|
3782
|
-
if (
|
|
4050
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
3783
4051
|
return [...typeNode.members];
|
|
3784
4052
|
}
|
|
3785
|
-
if (
|
|
4053
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
3786
4054
|
const members = [];
|
|
3787
4055
|
for (const intersectionMember of typeNode.types) {
|
|
3788
4056
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3945,7 +4213,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3945
4213
|
}
|
|
3946
4214
|
if (propertyType.isUnion()) {
|
|
3947
4215
|
const nonNullMembers = propertyType.types.filter(
|
|
3948
|
-
(member) => !(member.flags & (
|
|
4216
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3949
4217
|
);
|
|
3950
4218
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3951
4219
|
diagnostics.push(
|
|
@@ -3994,13 +4262,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3994
4262
|
seen.add(type);
|
|
3995
4263
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3996
4264
|
if (symbol !== void 0) {
|
|
3997
|
-
const aliased = symbol.flags &
|
|
4265
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3998
4266
|
const targetSymbol = aliased ?? symbol;
|
|
3999
4267
|
const declaration = targetSymbol.declarations?.find(
|
|
4000
|
-
(candidate) =>
|
|
4268
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
4001
4269
|
);
|
|
4002
4270
|
if (declaration !== void 0) {
|
|
4003
|
-
if (
|
|
4271
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
4004
4272
|
return resolveNamedDiscriminatorDeclaration(
|
|
4005
4273
|
checker.getTypeFromTypeNode(declaration.type),
|
|
4006
4274
|
checker,
|
|
@@ -4028,7 +4296,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4028
4296
|
}
|
|
4029
4297
|
if (boundType.isUnion()) {
|
|
4030
4298
|
const nonNullMembers = boundType.types.filter(
|
|
4031
|
-
(member) => !(member.flags & (
|
|
4299
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4032
4300
|
);
|
|
4033
4301
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4034
4302
|
diagnostics.push(
|
|
@@ -4073,7 +4341,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4073
4341
|
return null;
|
|
4074
4342
|
}
|
|
4075
4343
|
function getDeclarationName(node) {
|
|
4076
|
-
if (
|
|
4344
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
4077
4345
|
return node.name?.text ?? "anonymous";
|
|
4078
4346
|
}
|
|
4079
4347
|
return "anonymous";
|
|
@@ -4128,11 +4396,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4128
4396
|
if (sourceTypeNode === void 0) {
|
|
4129
4397
|
return [];
|
|
4130
4398
|
}
|
|
4131
|
-
const unwrapParentheses = (typeNode) =>
|
|
4399
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4132
4400
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4133
|
-
const referenceTypeNode =
|
|
4401
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4134
4402
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4135
|
-
return
|
|
4403
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4136
4404
|
})();
|
|
4137
4405
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4138
4406
|
return [];
|
|
@@ -4140,7 +4408,7 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4140
4408
|
return referenceTypeNode.typeArguments.map((argumentNode) => {
|
|
4141
4409
|
const argumentType = checker.getTypeFromTypeNode(argumentNode);
|
|
4142
4410
|
const baseSymbol = argumentType.aliasSymbol ?? argumentType.getSymbol();
|
|
4143
|
-
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags &
|
|
4411
|
+
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(baseSymbol) : baseSymbol;
|
|
4144
4412
|
const argumentDecl = argumentSymbol?.declarations?.[0];
|
|
4145
4413
|
if (argumentDecl !== void 0 && argumentDecl.getSourceFile().fileName !== file) {
|
|
4146
4414
|
const argumentName = argumentSymbol?.getName() ?? baseSymbol?.getName();
|
|
@@ -4203,7 +4471,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4203
4471
|
);
|
|
4204
4472
|
}
|
|
4205
4473
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4206
|
-
if (!
|
|
4474
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
4207
4475
|
return null;
|
|
4208
4476
|
}
|
|
4209
4477
|
const name = prop.name.text;
|
|
@@ -4330,7 +4598,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4330
4598
|
const seen = /* @__PURE__ */ new Set();
|
|
4331
4599
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4332
4600
|
for (const member of members) {
|
|
4333
|
-
if (!
|
|
4601
|
+
if (!ts5.isPropertySignature(member)) {
|
|
4334
4602
|
continue;
|
|
4335
4603
|
}
|
|
4336
4604
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4346,7 +4614,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4346
4614
|
return [...duplicates].sort();
|
|
4347
4615
|
}
|
|
4348
4616
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4349
|
-
if (
|
|
4617
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
4350
4618
|
return name.text;
|
|
4351
4619
|
}
|
|
4352
4620
|
return null;
|
|
@@ -4441,28 +4709,28 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4441
4709
|
if (primitiveAlias) {
|
|
4442
4710
|
return primitiveAlias;
|
|
4443
4711
|
}
|
|
4444
|
-
if (
|
|
4712
|
+
if (_isIntegerBrandedType(type)) {
|
|
4445
4713
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4446
4714
|
}
|
|
4447
|
-
if (type.flags &
|
|
4715
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4448
4716
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4449
4717
|
}
|
|
4450
|
-
if (type.flags &
|
|
4718
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4451
4719
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4452
4720
|
}
|
|
4453
|
-
if (type.flags & (
|
|
4721
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4454
4722
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4455
4723
|
}
|
|
4456
|
-
if (type.flags &
|
|
4724
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4457
4725
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4458
4726
|
}
|
|
4459
|
-
if (type.flags &
|
|
4727
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4460
4728
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4461
4729
|
}
|
|
4462
|
-
if (type.flags &
|
|
4730
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
4463
4731
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4464
4732
|
}
|
|
4465
|
-
if (type.flags &
|
|
4733
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
4466
4734
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4467
4735
|
}
|
|
4468
4736
|
if (type.isStringLiteral()) {
|
|
@@ -4549,10 +4817,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4549
4817
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4550
4818
|
}
|
|
4551
4819
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4552
|
-
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)) {
|
|
4553
4821
|
return null;
|
|
4554
4822
|
}
|
|
4555
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4823
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4556
4824
|
if (!aliasDecl) {
|
|
4557
4825
|
return null;
|
|
4558
4826
|
}
|
|
@@ -4563,11 +4831,18 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4563
4831
|
...extractJSDocConstraintNodes(aliasDecl, file, makeParseOptions(extensionRegistry)),
|
|
4564
4832
|
...extractTypeAliasConstraintNodes(aliasDecl.type, checker, file, extensionRegistry)
|
|
4565
4833
|
];
|
|
4566
|
-
const
|
|
4834
|
+
const localAnnotations = extractJSDocAnnotationNodes(
|
|
4567
4835
|
aliasDecl,
|
|
4568
4836
|
file,
|
|
4569
4837
|
makeParseOptions(extensionRegistry)
|
|
4570
4838
|
);
|
|
4839
|
+
const inheritedAnnotations = collectInheritedTypeAnnotations(
|
|
4840
|
+
aliasDecl,
|
|
4841
|
+
localAnnotations,
|
|
4842
|
+
checker,
|
|
4843
|
+
extensionRegistry
|
|
4844
|
+
);
|
|
4845
|
+
const annotations = [...localAnnotations, ...inheritedAnnotations];
|
|
4571
4846
|
const metadata = resolveNodeMetadata(
|
|
4572
4847
|
metadataPolicy,
|
|
4573
4848
|
"type",
|
|
@@ -4602,8 +4877,8 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4602
4877
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4603
4878
|
}
|
|
4604
4879
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4605
|
-
const typeNode = sourceNode && (
|
|
4606
|
-
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)) {
|
|
4607
4882
|
return void 0;
|
|
4608
4883
|
}
|
|
4609
4884
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4624,7 +4899,7 @@ function resolveNamedTypeWithSourceRecovery(type, sourceNode, checker) {
|
|
|
4624
4899
|
return { typeName: refAliasDecl.name.text, namedDecl: refAliasDecl };
|
|
4625
4900
|
}
|
|
4626
4901
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4627
|
-
if (!
|
|
4902
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
4628
4903
|
return false;
|
|
4629
4904
|
}
|
|
4630
4905
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4632,10 +4907,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4632
4907
|
return false;
|
|
4633
4908
|
}
|
|
4634
4909
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4635
|
-
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));
|
|
4636
4911
|
}
|
|
4637
4912
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4638
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4913
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
4639
4914
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4640
4915
|
visitedAliases.add(nestedAliasDecl);
|
|
4641
4916
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4650,22 +4925,22 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4650
4925
|
visitedAliases
|
|
4651
4926
|
);
|
|
4652
4927
|
}
|
|
4653
|
-
if (
|
|
4928
|
+
if (_isIntegerBrandedType(type)) {
|
|
4654
4929
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4655
4930
|
}
|
|
4656
|
-
if (type.flags &
|
|
4931
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4657
4932
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4658
4933
|
}
|
|
4659
|
-
if (type.flags &
|
|
4934
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4660
4935
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4661
4936
|
}
|
|
4662
|
-
if (type.flags & (
|
|
4937
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4663
4938
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4664
4939
|
}
|
|
4665
|
-
if (type.flags &
|
|
4940
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4666
4941
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4667
4942
|
}
|
|
4668
|
-
if (type.flags &
|
|
4943
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4669
4944
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4670
4945
|
}
|
|
4671
4946
|
return resolveTypeNode(
|
|
@@ -4685,7 +4960,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4685
4960
|
let typeName = null;
|
|
4686
4961
|
let namedDecl;
|
|
4687
4962
|
if (recovered !== null) {
|
|
4688
|
-
const recoveredAliasDecl =
|
|
4963
|
+
const recoveredAliasDecl = ts5.isTypeAliasDeclaration(recovered.namedDecl) ? recovered.namedDecl : void 0;
|
|
4689
4964
|
if (recoveredAliasDecl !== void 0) {
|
|
4690
4965
|
const aliasUnderlyingType = checker.getTypeFromTypeNode(recoveredAliasDecl.type);
|
|
4691
4966
|
const isNonGeneric = recoveredAliasDecl.typeParameters === void 0 || recoveredAliasDecl.typeParameters.length === 0;
|
|
@@ -4707,13 +4982,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4707
4982
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4708
4983
|
);
|
|
4709
4984
|
const nonNullTypes = allTypes.filter(
|
|
4710
|
-
(memberType) => !(memberType.flags & (
|
|
4985
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4711
4986
|
);
|
|
4712
4987
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4713
4988
|
memberType,
|
|
4714
4989
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4715
4990
|
}));
|
|
4716
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4991
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
4717
4992
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4718
4993
|
if (namedDecl) {
|
|
4719
4994
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4733,7 +5008,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4733
5008
|
if (existing !== void 0 && existing.type !== RESOLVING_TYPE_PLACEHOLDER) {
|
|
4734
5009
|
return { kind: "reference", name: typeName, typeArguments: [] };
|
|
4735
5010
|
}
|
|
4736
|
-
const annotations = namedDecl ?
|
|
5011
|
+
const annotations = namedDecl ? extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) : void 0;
|
|
4737
5012
|
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4738
5013
|
metadataPolicy,
|
|
4739
5014
|
"type",
|
|
@@ -4760,7 +5035,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4760
5035
|
const displayName = memberDisplayNames.get(String(value));
|
|
4761
5036
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4762
5037
|
});
|
|
4763
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
5038
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
4764
5039
|
if (isBooleanUnion2) {
|
|
4765
5040
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4766
5041
|
const result = hasNull ? {
|
|
@@ -4852,7 +5127,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4852
5127
|
if (type.getProperties().length > 0) {
|
|
4853
5128
|
return null;
|
|
4854
5129
|
}
|
|
4855
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
5130
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
4856
5131
|
if (!indexInfo) {
|
|
4857
5132
|
return null;
|
|
4858
5133
|
}
|
|
@@ -4900,20 +5175,53 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4900
5175
|
}
|
|
4901
5176
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4902
5177
|
const name = declaration.name;
|
|
4903
|
-
if (
|
|
5178
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
4904
5179
|
return false;
|
|
4905
5180
|
}
|
|
4906
|
-
if (!
|
|
5181
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
4907
5182
|
return false;
|
|
4908
5183
|
}
|
|
4909
5184
|
}
|
|
4910
5185
|
return true;
|
|
4911
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
|
+
}
|
|
4912
5212
|
function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4913
5213
|
const collectedDiagnostics = diagnostics ?? [];
|
|
4914
5214
|
const typeName = getNamedTypeName(type);
|
|
4915
5215
|
const namedTypeName = typeName ?? void 0;
|
|
4916
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;
|
|
4917
5225
|
const referenceTypeArguments = extractReferenceTypeArguments(
|
|
4918
5226
|
type,
|
|
4919
5227
|
checker,
|
|
@@ -4925,13 +5233,13 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4925
5233
|
extensionRegistry,
|
|
4926
5234
|
collectedDiagnostics
|
|
4927
5235
|
);
|
|
4928
|
-
const instantiatedTypeName =
|
|
4929
|
-
|
|
5236
|
+
const instantiatedTypeName = effectiveTypeName !== void 0 && referenceTypeArguments.length > 0 ? buildInstantiatedReferenceName(
|
|
5237
|
+
effectiveTypeName,
|
|
4930
5238
|
referenceTypeArguments.map((argument) => argument.tsType),
|
|
4931
5239
|
checker
|
|
4932
5240
|
) : void 0;
|
|
4933
|
-
const registryTypeName = instantiatedTypeName ??
|
|
4934
|
-
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" &&
|
|
5241
|
+
const registryTypeName = instantiatedTypeName ?? effectiveTypeName;
|
|
5242
|
+
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" && effectiveNamedDecl?.getSourceFile().fileName !== file);
|
|
4935
5243
|
const clearNamedTypeRegistration = () => {
|
|
4936
5244
|
if (registryTypeName === void 0 || !shouldRegisterNamedType) {
|
|
4937
5245
|
return;
|
|
@@ -4952,7 +5260,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4952
5260
|
typeRegistry[registryTypeName] = {
|
|
4953
5261
|
name: registryTypeName,
|
|
4954
5262
|
type: RESOLVING_TYPE_PLACEHOLDER,
|
|
4955
|
-
provenance: provenanceForDeclaration(
|
|
5263
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
4956
5264
|
};
|
|
4957
5265
|
}
|
|
4958
5266
|
visiting.add(type);
|
|
@@ -4984,17 +5292,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4984
5292
|
clearNamedTypeRegistration();
|
|
4985
5293
|
return recordNode;
|
|
4986
5294
|
}
|
|
4987
|
-
const annotations =
|
|
4988
|
-
const metadata =
|
|
5295
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5296
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
4989
5297
|
metadataPolicy,
|
|
4990
5298
|
"type",
|
|
4991
5299
|
registryTypeName,
|
|
4992
|
-
|
|
5300
|
+
effectiveNamedDecl,
|
|
4993
5301
|
checker,
|
|
4994
5302
|
extensionRegistry,
|
|
4995
5303
|
{
|
|
4996
5304
|
checker,
|
|
4997
|
-
declaration:
|
|
5305
|
+
declaration: effectiveNamedDecl,
|
|
4998
5306
|
subjectType: type
|
|
4999
5307
|
}
|
|
5000
5308
|
) : void 0;
|
|
@@ -5003,7 +5311,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5003
5311
|
...metadata !== void 0 && { metadata },
|
|
5004
5312
|
type: recordNode,
|
|
5005
5313
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5006
|
-
provenance: provenanceForDeclaration(
|
|
5314
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5007
5315
|
};
|
|
5008
5316
|
return {
|
|
5009
5317
|
kind: "reference",
|
|
@@ -5029,7 +5337,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5029
5337
|
if (!declaration) continue;
|
|
5030
5338
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
5031
5339
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
5032
|
-
const optional = !!(prop.flags &
|
|
5340
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
5033
5341
|
const propTypeNode = resolveTypeNode(
|
|
5034
5342
|
propType,
|
|
5035
5343
|
checker,
|
|
@@ -5042,7 +5350,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5042
5350
|
collectedDiagnostics
|
|
5043
5351
|
);
|
|
5044
5352
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
5045
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
5353
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
5046
5354
|
declaration,
|
|
5047
5355
|
checker,
|
|
5048
5356
|
file,
|
|
@@ -5052,7 +5360,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5052
5360
|
type,
|
|
5053
5361
|
metadataPolicy,
|
|
5054
5362
|
extensionRegistry
|
|
5055
|
-
) :
|
|
5363
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
5056
5364
|
declaration,
|
|
5057
5365
|
checker,
|
|
5058
5366
|
file,
|
|
@@ -5080,9 +5388,9 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5080
5388
|
visiting.delete(type);
|
|
5081
5389
|
const objectNode = {
|
|
5082
5390
|
kind: "object",
|
|
5083
|
-
properties:
|
|
5391
|
+
properties: effectiveNamedDecl !== void 0 && (ts5.isClassDeclaration(effectiveNamedDecl) || ts5.isInterfaceDeclaration(effectiveNamedDecl) || ts5.isTypeAliasDeclaration(effectiveNamedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
5084
5392
|
properties,
|
|
5085
|
-
|
|
5393
|
+
effectiveNamedDecl,
|
|
5086
5394
|
type,
|
|
5087
5395
|
checker,
|
|
5088
5396
|
file,
|
|
@@ -5092,17 +5400,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5092
5400
|
additionalProperties: true
|
|
5093
5401
|
};
|
|
5094
5402
|
if (registryTypeName !== void 0 && shouldRegisterNamedType) {
|
|
5095
|
-
const annotations =
|
|
5096
|
-
const metadata =
|
|
5403
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5404
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
5097
5405
|
metadataPolicy,
|
|
5098
5406
|
"type",
|
|
5099
5407
|
registryTypeName,
|
|
5100
|
-
|
|
5408
|
+
effectiveNamedDecl,
|
|
5101
5409
|
checker,
|
|
5102
5410
|
extensionRegistry,
|
|
5103
5411
|
{
|
|
5104
5412
|
checker,
|
|
5105
|
-
declaration:
|
|
5413
|
+
declaration: effectiveNamedDecl,
|
|
5106
5414
|
subjectType: type
|
|
5107
5415
|
}
|
|
5108
5416
|
) : void 0;
|
|
@@ -5111,7 +5419,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5111
5419
|
...metadata !== void 0 && { metadata },
|
|
5112
5420
|
type: objectNode,
|
|
5113
5421
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5114
|
-
provenance: provenanceForDeclaration(
|
|
5422
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5115
5423
|
};
|
|
5116
5424
|
return {
|
|
5117
5425
|
kind: "reference",
|
|
@@ -5128,12 +5436,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5128
5436
|
for (const symbol of symbols) {
|
|
5129
5437
|
const declarations = symbol.declarations;
|
|
5130
5438
|
if (!declarations) continue;
|
|
5131
|
-
const classDecl = declarations.find(
|
|
5439
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
5132
5440
|
if (classDecl) {
|
|
5133
5441
|
const map = /* @__PURE__ */ new Map();
|
|
5134
5442
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
5135
5443
|
for (const member of classDecl.members) {
|
|
5136
|
-
if (
|
|
5444
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
5137
5445
|
const fieldNode = analyzeFieldToIR(
|
|
5138
5446
|
member,
|
|
5139
5447
|
checker,
|
|
@@ -5157,7 +5465,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5157
5465
|
}
|
|
5158
5466
|
return map;
|
|
5159
5467
|
}
|
|
5160
|
-
const interfaceDecl = declarations.find(
|
|
5468
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
5161
5469
|
if (interfaceDecl) {
|
|
5162
5470
|
return buildFieldNodeInfoMap(
|
|
5163
5471
|
interfaceDecl.members,
|
|
@@ -5171,7 +5479,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5171
5479
|
extensionRegistry
|
|
5172
5480
|
);
|
|
5173
5481
|
}
|
|
5174
|
-
const typeAliasDecl = declarations.find(
|
|
5482
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
5175
5483
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5176
5484
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5177
5485
|
return buildFieldNodeInfoMap(
|
|
@@ -5195,10 +5503,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5195
5503
|
return void 0;
|
|
5196
5504
|
}
|
|
5197
5505
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5198
|
-
if (
|
|
5506
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
5199
5507
|
return resolvedTypeNode.elementType;
|
|
5200
5508
|
}
|
|
5201
|
-
if (
|
|
5509
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5202
5510
|
return resolvedTypeNode.typeArguments[0];
|
|
5203
5511
|
}
|
|
5204
5512
|
return void 0;
|
|
@@ -5209,13 +5517,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5209
5517
|
return [];
|
|
5210
5518
|
}
|
|
5211
5519
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5212
|
-
return
|
|
5520
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5213
5521
|
}
|
|
5214
5522
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5215
|
-
if (
|
|
5523
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
5216
5524
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5217
5525
|
}
|
|
5218
|
-
if (!
|
|
5526
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
5219
5527
|
return typeNode;
|
|
5220
5528
|
}
|
|
5221
5529
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5226,15 +5534,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5226
5534
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5227
5535
|
}
|
|
5228
5536
|
function isNullishTypeNode(typeNode) {
|
|
5229
|
-
if (typeNode.kind ===
|
|
5537
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
5230
5538
|
return true;
|
|
5231
5539
|
}
|
|
5232
|
-
return
|
|
5540
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
5233
5541
|
}
|
|
5234
5542
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5235
5543
|
const map = /* @__PURE__ */ new Map();
|
|
5236
5544
|
for (const member of members) {
|
|
5237
|
-
if (
|
|
5545
|
+
if (ts5.isPropertySignature(member)) {
|
|
5238
5546
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5239
5547
|
member,
|
|
5240
5548
|
checker,
|
|
@@ -5260,7 +5568,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5260
5568
|
}
|
|
5261
5569
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5262
5570
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5263
|
-
if (!
|
|
5571
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
5264
5572
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5265
5573
|
const aliasName = typeNode.typeName.getText();
|
|
5266
5574
|
throw new Error(
|
|
@@ -5269,7 +5577,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5269
5577
|
}
|
|
5270
5578
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5271
5579
|
if (!aliasDecl) return [];
|
|
5272
|
-
if (
|
|
5580
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5273
5581
|
const aliasFieldType = resolveTypeNode(
|
|
5274
5582
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5275
5583
|
checker,
|
|
@@ -5313,14 +5621,14 @@ function getNamedTypeName(type) {
|
|
|
5313
5621
|
const symbol = type.getSymbol();
|
|
5314
5622
|
if (symbol?.declarations) {
|
|
5315
5623
|
const decl = symbol.declarations[0];
|
|
5316
|
-
if (decl && (
|
|
5317
|
-
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;
|
|
5318
5626
|
if (name) return name;
|
|
5319
5627
|
}
|
|
5320
5628
|
}
|
|
5321
5629
|
const aliasSymbol = type.aliasSymbol;
|
|
5322
5630
|
if (aliasSymbol?.declarations) {
|
|
5323
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5631
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5324
5632
|
if (aliasDecl) {
|
|
5325
5633
|
return aliasDecl.name.text;
|
|
5326
5634
|
}
|
|
@@ -5331,24 +5639,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5331
5639
|
const symbol = type.getSymbol();
|
|
5332
5640
|
if (symbol?.declarations) {
|
|
5333
5641
|
const decl = symbol.declarations[0];
|
|
5334
|
-
if (decl && (
|
|
5642
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5335
5643
|
return decl;
|
|
5336
5644
|
}
|
|
5337
5645
|
}
|
|
5338
5646
|
const aliasSymbol = type.aliasSymbol;
|
|
5339
5647
|
if (aliasSymbol?.declarations) {
|
|
5340
|
-
return aliasSymbol.declarations.find(
|
|
5648
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5341
5649
|
}
|
|
5342
5650
|
return void 0;
|
|
5343
5651
|
}
|
|
5344
5652
|
function analyzeMethod(method, checker) {
|
|
5345
|
-
if (!
|
|
5653
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
5346
5654
|
return null;
|
|
5347
5655
|
}
|
|
5348
5656
|
const name = method.name.text;
|
|
5349
5657
|
const parameters = [];
|
|
5350
5658
|
for (const param of method.parameters) {
|
|
5351
|
-
if (
|
|
5659
|
+
if (ts5.isIdentifier(param.name)) {
|
|
5352
5660
|
const paramInfo = analyzeParameter(param, checker);
|
|
5353
5661
|
parameters.push(paramInfo);
|
|
5354
5662
|
}
|
|
@@ -5359,7 +5667,7 @@ function analyzeMethod(method, checker) {
|
|
|
5359
5667
|
return { name, parameters, returnTypeNode, returnType };
|
|
5360
5668
|
}
|
|
5361
5669
|
function analyzeParameter(param, checker) {
|
|
5362
|
-
const name =
|
|
5670
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
5363
5671
|
const typeNode = param.type;
|
|
5364
5672
|
const type = checker.getTypeAtLocation(param);
|
|
5365
5673
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5368,15 +5676,15 @@ function analyzeParameter(param, checker) {
|
|
|
5368
5676
|
}
|
|
5369
5677
|
function detectFormSpecReference(typeNode) {
|
|
5370
5678
|
if (!typeNode) return null;
|
|
5371
|
-
if (!
|
|
5372
|
-
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;
|
|
5373
5681
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5374
5682
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5375
|
-
if (!typeArg || !
|
|
5376
|
-
if (
|
|
5683
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
5684
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
5377
5685
|
return typeArg.exprName.text;
|
|
5378
5686
|
}
|
|
5379
|
-
if (
|
|
5687
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
5380
5688
|
return typeArg.exprName.right.text;
|
|
5381
5689
|
}
|
|
5382
5690
|
return null;
|
|
@@ -5398,23 +5706,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5398
5706
|
function createProgramContext(filePath, additionalFiles) {
|
|
5399
5707
|
const absolutePath = path.resolve(filePath);
|
|
5400
5708
|
const fileDir = path.dirname(absolutePath);
|
|
5401
|
-
const configPath =
|
|
5709
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
5402
5710
|
let compilerOptions;
|
|
5403
5711
|
let fileNames;
|
|
5404
5712
|
if (configPath) {
|
|
5405
|
-
const configFile =
|
|
5713
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
5406
5714
|
if (configFile.error) {
|
|
5407
5715
|
throw new Error(
|
|
5408
|
-
`Error reading tsconfig.json: ${
|
|
5716
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5409
5717
|
);
|
|
5410
5718
|
}
|
|
5411
|
-
const parsed =
|
|
5719
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
5412
5720
|
configFile.config,
|
|
5413
|
-
|
|
5721
|
+
ts6.sys,
|
|
5414
5722
|
path.dirname(configPath)
|
|
5415
5723
|
);
|
|
5416
5724
|
if (parsed.errors.length > 0) {
|
|
5417
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5725
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5418
5726
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5419
5727
|
}
|
|
5420
5728
|
compilerOptions = parsed.options;
|
|
@@ -5422,9 +5730,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5422
5730
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5423
5731
|
} else {
|
|
5424
5732
|
compilerOptions = {
|
|
5425
|
-
target:
|
|
5426
|
-
module:
|
|
5427
|
-
moduleResolution:
|
|
5733
|
+
target: ts6.ScriptTarget.ES2022,
|
|
5734
|
+
module: ts6.ModuleKind.NodeNext,
|
|
5735
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
5428
5736
|
strict: true,
|
|
5429
5737
|
skipLibCheck: true,
|
|
5430
5738
|
declaration: true
|
|
@@ -5432,7 +5740,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5432
5740
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5433
5741
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5434
5742
|
}
|
|
5435
|
-
const program =
|
|
5743
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
5436
5744
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5437
5745
|
if (!sourceFile) {
|
|
5438
5746
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5451,19 +5759,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5451
5759
|
result = node;
|
|
5452
5760
|
return;
|
|
5453
5761
|
}
|
|
5454
|
-
|
|
5762
|
+
ts6.forEachChild(node, visit);
|
|
5455
5763
|
}
|
|
5456
5764
|
visit(sourceFile);
|
|
5457
5765
|
return result;
|
|
5458
5766
|
}
|
|
5459
5767
|
function findClassByName(sourceFile, className) {
|
|
5460
|
-
return findNodeByName(sourceFile, className,
|
|
5768
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
5461
5769
|
}
|
|
5462
5770
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5463
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5771
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
5464
5772
|
}
|
|
5465
5773
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5466
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5774
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5467
5775
|
}
|
|
5468
5776
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5469
5777
|
if (rootType.kind === "object") {
|
|
@@ -5503,22 +5811,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5503
5811
|
};
|
|
5504
5812
|
}
|
|
5505
5813
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5506
|
-
if (
|
|
5814
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5507
5815
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5508
5816
|
}
|
|
5509
|
-
if (
|
|
5817
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5510
5818
|
return true;
|
|
5511
5819
|
}
|
|
5512
|
-
return
|
|
5820
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5513
5821
|
}
|
|
5514
5822
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5515
|
-
if (
|
|
5823
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5516
5824
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5517
5825
|
}
|
|
5518
|
-
if (
|
|
5826
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
5519
5827
|
const propertyNames = [];
|
|
5520
5828
|
for (const member of typeNode.members) {
|
|
5521
|
-
if (!
|
|
5829
|
+
if (!ts6.isPropertySignature(member)) {
|
|
5522
5830
|
continue;
|
|
5523
5831
|
}
|
|
5524
5832
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5528,13 +5836,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5528
5836
|
}
|
|
5529
5837
|
return propertyNames;
|
|
5530
5838
|
}
|
|
5531
|
-
if (
|
|
5839
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5532
5840
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5533
5841
|
}
|
|
5534
5842
|
return null;
|
|
5535
5843
|
}
|
|
5536
5844
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5537
|
-
if (!
|
|
5845
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
5538
5846
|
return [];
|
|
5539
5847
|
}
|
|
5540
5848
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5735,7 +6043,7 @@ function makeFileProvenance(filePath) {
|
|
|
5735
6043
|
}
|
|
5736
6044
|
|
|
5737
6045
|
// src/extensions/symbol-registry.ts
|
|
5738
|
-
import * as
|
|
6046
|
+
import * as ts7 from "typescript";
|
|
5739
6047
|
import * as path2 from "path";
|
|
5740
6048
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5741
6049
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5745,10 +6053,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5745
6053
|
return symbolMap;
|
|
5746
6054
|
}
|
|
5747
6055
|
function visit(node) {
|
|
5748
|
-
if (
|
|
6056
|
+
if (ts7.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5749
6057
|
processDefineCustomTypeCall(node);
|
|
5750
6058
|
}
|
|
5751
|
-
|
|
6059
|
+
ts7.forEachChild(node, visit);
|
|
5752
6060
|
}
|
|
5753
6061
|
function processDefineCustomTypeCall(call) {
|
|
5754
6062
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5785,7 +6093,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5785
6093
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5786
6094
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5787
6095
|
if (callSymbol !== void 0) {
|
|
5788
|
-
const resolved = callSymbol.flags &
|
|
6096
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5789
6097
|
const decl = resolved.declarations?.[0];
|
|
5790
6098
|
if (decl !== void 0) {
|
|
5791
6099
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5793,24 +6101,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5793
6101
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5794
6102
|
}
|
|
5795
6103
|
}
|
|
5796
|
-
return
|
|
6104
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5797
6105
|
}
|
|
5798
6106
|
function extractTypeNameFromCallArg(call) {
|
|
5799
6107
|
const arg = call.arguments[0];
|
|
5800
|
-
if (arg === void 0 || !
|
|
6108
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5801
6109
|
return null;
|
|
5802
6110
|
}
|
|
5803
6111
|
const typeNameProp = arg.properties.find(
|
|
5804
|
-
(p) =>
|
|
6112
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5805
6113
|
);
|
|
5806
|
-
if (typeNameProp === void 0 || !
|
|
6114
|
+
if (typeNameProp === void 0 || !ts7.isStringLiteral(typeNameProp.initializer)) {
|
|
5807
6115
|
return null;
|
|
5808
6116
|
}
|
|
5809
6117
|
return typeNameProp.initializer.text;
|
|
5810
6118
|
}
|
|
5811
6119
|
function extractEnclosingExtensionId(call, checker) {
|
|
5812
|
-
for (let node = call.parent; !
|
|
5813
|
-
if (
|
|
6120
|
+
for (let node = call.parent; !ts7.isSourceFile(node); node = node.parent) {
|
|
6121
|
+
if (ts7.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5814
6122
|
return extractExtensionIdFromCallArg(node);
|
|
5815
6123
|
}
|
|
5816
6124
|
}
|
|
@@ -5819,24 +6127,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5819
6127
|
function isDefineExtensionCall(node, checker) {
|
|
5820
6128
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5821
6129
|
if (callSymbol !== void 0) {
|
|
5822
|
-
const resolved = callSymbol.flags &
|
|
6130
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5823
6131
|
const decl = resolved.declarations?.[0];
|
|
5824
6132
|
if (decl !== void 0) {
|
|
5825
6133
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5826
6134
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5827
6135
|
}
|
|
5828
6136
|
}
|
|
5829
|
-
return
|
|
6137
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5830
6138
|
}
|
|
5831
6139
|
function extractExtensionIdFromCallArg(call) {
|
|
5832
6140
|
const arg = call.arguments[0];
|
|
5833
|
-
if (arg === void 0 || !
|
|
6141
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5834
6142
|
return null;
|
|
5835
6143
|
}
|
|
5836
6144
|
const prop = arg.properties.find(
|
|
5837
|
-
(p) =>
|
|
6145
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5838
6146
|
);
|
|
5839
|
-
if (prop === void 0 || !
|
|
6147
|
+
if (prop === void 0 || !ts7.isStringLiteral(prop.initializer)) {
|
|
5840
6148
|
return null;
|
|
5841
6149
|
}
|
|
5842
6150
|
return prop.initializer.text;
|
|
@@ -6098,7 +6406,7 @@ function generateSchemasBatch(options) {
|
|
|
6098
6406
|
return options.targets.map((target) => {
|
|
6099
6407
|
let ctx;
|
|
6100
6408
|
try {
|
|
6101
|
-
const cacheKey =
|
|
6409
|
+
const cacheKey = ts8.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
6102
6410
|
const cachedContext = contextCache.get(cacheKey);
|
|
6103
6411
|
if (cachedContext === void 0) {
|
|
6104
6412
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6157,7 +6465,7 @@ function isMutableRegistry(reg) {
|
|
|
6157
6465
|
}
|
|
6158
6466
|
function resolveStaticOptions(options) {
|
|
6159
6467
|
const legacyRegistry = options.extensionRegistry;
|
|
6160
|
-
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;
|
|
6161
6469
|
return {
|
|
6162
6470
|
extensionRegistry: legacyRegistry ?? configRegistry,
|
|
6163
6471
|
// eslint-disable-next-line @typescript-eslint/no-deprecated -- migration bridge reads deprecated fields
|
|
@@ -6169,7 +6477,7 @@ function resolveStaticOptions(options) {
|
|
|
6169
6477
|
};
|
|
6170
6478
|
}
|
|
6171
6479
|
function resolveOptions(options) {
|
|
6172
|
-
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;
|
|
6173
6481
|
const legacyRegistry = options.extensionRegistry;
|
|
6174
6482
|
return {
|
|
6175
6483
|
// When the caller provides the deprecated extensionRegistry field directly,
|
|
@@ -6254,7 +6562,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6254
6562
|
}
|
|
6255
6563
|
|
|
6256
6564
|
// src/static-build.ts
|
|
6257
|
-
import * as
|
|
6565
|
+
import * as ts9 from "typescript";
|
|
6258
6566
|
function toStaticBuildContext(context) {
|
|
6259
6567
|
return context;
|
|
6260
6568
|
}
|
|
@@ -6269,7 +6577,7 @@ function getModuleSymbol(context) {
|
|
|
6269
6577
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6270
6578
|
}
|
|
6271
6579
|
function isSchemaSourceDeclaration(declaration) {
|
|
6272
|
-
return
|
|
6580
|
+
return ts9.isClassDeclaration(declaration) || ts9.isInterfaceDeclaration(declaration) || ts9.isTypeAliasDeclaration(declaration);
|
|
6273
6581
|
}
|
|
6274
6582
|
function resolveModuleExport(context, exportName = "default") {
|
|
6275
6583
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6280,14 +6588,14 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6280
6588
|
if (exportSymbol === null) {
|
|
6281
6589
|
return null;
|
|
6282
6590
|
}
|
|
6283
|
-
return exportSymbol.flags &
|
|
6591
|
+
return exportSymbol.flags & ts9.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6284
6592
|
}
|
|
6285
6593
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6286
6594
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6287
6595
|
}
|
|
6288
6596
|
|
|
6289
6597
|
// src/generators/discovered-schema.ts
|
|
6290
|
-
import * as
|
|
6598
|
+
import * as ts10 from "typescript";
|
|
6291
6599
|
import { analyzeMetadataForNodeWithChecker as analyzeMetadataForNodeWithChecker2 } from "@formspec/analysis/internal";
|
|
6292
6600
|
import { IR_VERSION as IR_VERSION3 } from "@formspec/core/internals";
|
|
6293
6601
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
@@ -6297,17 +6605,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6297
6605
|
};
|
|
6298
6606
|
}
|
|
6299
6607
|
function isNamedTypeDeclaration(declaration) {
|
|
6300
|
-
return
|
|
6608
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6301
6609
|
}
|
|
6302
6610
|
function hasConcreteTypeArguments(type, checker) {
|
|
6303
6611
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6304
6612
|
return true;
|
|
6305
6613
|
}
|
|
6306
|
-
if ((type.flags &
|
|
6614
|
+
if ((type.flags & ts10.TypeFlags.Object) === 0) {
|
|
6307
6615
|
return false;
|
|
6308
6616
|
}
|
|
6309
6617
|
const objectType = type;
|
|
6310
|
-
if ((objectType.objectFlags &
|
|
6618
|
+
if ((objectType.objectFlags & ts10.ObjectFlags.Reference) === 0) {
|
|
6311
6619
|
return false;
|
|
6312
6620
|
}
|
|
6313
6621
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6320,13 +6628,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6320
6628
|
return declaration;
|
|
6321
6629
|
}
|
|
6322
6630
|
}
|
|
6323
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6631
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts10.isTypeAliasDeclaration);
|
|
6324
6632
|
return aliasDeclaration;
|
|
6325
6633
|
}
|
|
6326
6634
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6327
6635
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6328
6636
|
const namedNode = sourceNode;
|
|
6329
|
-
if (namedNode.name !== void 0 &&
|
|
6637
|
+
if (namedNode.name !== void 0 && ts10.isIdentifier(namedNode.name)) {
|
|
6330
6638
|
return namedNode.name.text;
|
|
6331
6639
|
}
|
|
6332
6640
|
}
|
|
@@ -6548,7 +6856,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6548
6856
|
function generateSchemasFromDeclaration(options) {
|
|
6549
6857
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6550
6858
|
const resolved = resolveStaticOptions(options);
|
|
6551
|
-
if (
|
|
6859
|
+
if (ts10.isClassDeclaration(options.declaration)) {
|
|
6552
6860
|
return generateSchemasFromAnalysis(
|
|
6553
6861
|
analyzeClassToIR(
|
|
6554
6862
|
options.declaration,
|
|
@@ -6562,7 +6870,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6562
6870
|
resolved
|
|
6563
6871
|
);
|
|
6564
6872
|
}
|
|
6565
|
-
if (
|
|
6873
|
+
if (ts10.isInterfaceDeclaration(options.declaration)) {
|
|
6566
6874
|
return generateSchemasFromAnalysis(
|
|
6567
6875
|
analyzeInterfaceToIR(
|
|
6568
6876
|
options.declaration,
|
|
@@ -6576,7 +6884,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6576
6884
|
resolved
|
|
6577
6885
|
);
|
|
6578
6886
|
}
|
|
6579
|
-
if (
|
|
6887
|
+
if (ts10.isTypeAliasDeclaration(options.declaration)) {
|
|
6580
6888
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6581
6889
|
options.declaration,
|
|
6582
6890
|
options.context.checker,
|
|
@@ -6635,7 +6943,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6635
6943
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6636
6944
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6637
6945
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6638
|
-
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";
|
|
6639
6947
|
return generateSchemasFromResolvedType({
|
|
6640
6948
|
...options,
|
|
6641
6949
|
type,
|
|
@@ -6682,14 +6990,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6682
6990
|
if (typeNode === void 0) {
|
|
6683
6991
|
return void 0;
|
|
6684
6992
|
}
|
|
6685
|
-
if (
|
|
6993
|
+
if (ts10.isParenthesizedTypeNode(typeNode)) {
|
|
6686
6994
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6687
6995
|
return unwrapped ?? typeNode;
|
|
6688
6996
|
}
|
|
6689
6997
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6690
6998
|
}
|
|
6691
6999
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6692
|
-
return
|
|
7000
|
+
return ts10.isTypeReferenceNode(typeNode) && ts10.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6693
7001
|
}
|
|
6694
7002
|
|
|
6695
7003
|
// src/generators/mixed-authoring.ts
|