@formspec/build 0.1.0-alpha.58 → 0.1.0-alpha.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/builtin-brands.d.ts +10 -7
- package/dist/analyzer/builtin-brands.d.ts.map +1 -1
- package/dist/analyzer/class-analyzer.d.ts +30 -1
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/jsdoc-constraints.d.ts +0 -6
- package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts +2 -5
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +127 -32
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +130 -33
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +432 -12
- package/dist/build-beta.d.ts +400 -12
- package/dist/build-internal.d.ts +463 -12
- package/dist/build.d.ts +400 -12
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +2 -1
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -1
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts +2 -1
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -1
- package/dist/cli.cjs +610 -629
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +573 -586
- package/dist/cli.js.map +1 -1
- package/dist/extensions/registry.d.ts +19 -1
- package/dist/extensions/registry.d.ts.map +1 -1
- package/dist/extensions/resolve-custom-type.d.ts.map +1 -1
- package/dist/extensions/ts-type-utils.d.ts +0 -11
- package/dist/extensions/ts-type-utils.d.ts.map +1 -1
- package/dist/generators/class-schema.d.ts.map +1 -1
- package/dist/generators/method-schema.d.ts +3 -2
- package/dist/generators/method-schema.d.ts.map +1 -1
- package/dist/index.cjs +600 -618
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +571 -583
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +573 -591
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +540 -552
- package/dist/internals.js.map +1 -1
- package/dist/metadata/index.d.ts +1 -4
- package/dist/metadata/index.d.ts.map +1 -1
- package/dist/metadata/policy.d.ts +2 -6
- package/dist/metadata/policy.d.ts.map +1 -1
- package/dist/metadata/resolve.d.ts +3 -2
- package/dist/metadata/resolve.d.ts.map +1 -1
- package/dist/ui-schema/schema.d.ts +11 -28
- package/dist/ui-schema/schema.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/cli.cjs
CHANGED
|
@@ -1070,7 +1070,7 @@ function generateJsonSchemaFromIR(ir, options) {
|
|
|
1070
1070
|
applyConstraints(ctx.defs[schemaName], typeDef.constraints, ctx);
|
|
1071
1071
|
}
|
|
1072
1072
|
if (typeDef.annotations && typeDef.annotations.length > 0) {
|
|
1073
|
-
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx);
|
|
1073
|
+
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx, typeDef.type);
|
|
1074
1074
|
}
|
|
1075
1075
|
}
|
|
1076
1076
|
const properties = {};
|
|
@@ -1143,7 +1143,7 @@ function generateFieldSchema(field, ctx) {
|
|
|
1143
1143
|
}
|
|
1144
1144
|
}
|
|
1145
1145
|
applyResolvedMetadata(schema, field.metadata);
|
|
1146
|
-
applyAnnotations(schema, rootAnnotations, ctx);
|
|
1146
|
+
applyAnnotations(schema, rootAnnotations, ctx, field.type);
|
|
1147
1147
|
if (itemStringSchema !== void 0) {
|
|
1148
1148
|
applyAnnotations(itemStringSchema, itemAnnotations, ctx);
|
|
1149
1149
|
}
|
|
@@ -1186,32 +1186,36 @@ function applyPathTargetedConstraints(schema, pathConstraints, ctx, typeNode) {
|
|
|
1186
1186
|
return schema;
|
|
1187
1187
|
}
|
|
1188
1188
|
if (schema.$ref) {
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
properties: propertyOverrides,
|
|
1193
|
-
...rest
|
|
1189
|
+
return {
|
|
1190
|
+
...schema,
|
|
1191
|
+
properties: propertyOverrides
|
|
1194
1192
|
};
|
|
1195
|
-
return { allOf: [refPart, overridePart] };
|
|
1196
1193
|
}
|
|
1197
1194
|
if (schema.type === "object" && schema.properties) {
|
|
1198
|
-
const missingOverrides = {};
|
|
1199
1195
|
for (const [target, overrideSchema] of Object.entries(propertyOverrides)) {
|
|
1200
|
-
if (schema.properties
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1196
|
+
if (Object.hasOwn(schema.properties, target)) {
|
|
1197
|
+
const existing = schema.properties[target];
|
|
1198
|
+
if (existing) {
|
|
1199
|
+
mergeSchemaOverride(existing, overrideSchema);
|
|
1200
|
+
continue;
|
|
1201
|
+
}
|
|
1204
1202
|
}
|
|
1203
|
+
Object.defineProperty(schema.properties, target, {
|
|
1204
|
+
value: overrideSchema,
|
|
1205
|
+
writable: true,
|
|
1206
|
+
enumerable: true,
|
|
1207
|
+
configurable: true
|
|
1208
|
+
});
|
|
1205
1209
|
}
|
|
1206
|
-
|
|
1207
|
-
return schema;
|
|
1208
|
-
}
|
|
1209
|
-
return {
|
|
1210
|
-
allOf: [schema, { properties: missingOverrides }]
|
|
1211
|
-
};
|
|
1210
|
+
return schema;
|
|
1212
1211
|
}
|
|
1213
1212
|
if (schema.allOf) {
|
|
1214
|
-
|
|
1213
|
+
const overrideMember = { properties: propertyOverrides };
|
|
1214
|
+
const flattened = tryFlattenAllOfToSiblings(schema, overrideMember);
|
|
1215
|
+
if (flattened !== void 0) {
|
|
1216
|
+
return flattened;
|
|
1217
|
+
}
|
|
1218
|
+
schema.allOf = [...schema.allOf, overrideMember];
|
|
1215
1219
|
return schema;
|
|
1216
1220
|
}
|
|
1217
1221
|
return schema;
|
|
@@ -1324,7 +1328,7 @@ function generatePropertySchema(prop, ctx) {
|
|
|
1324
1328
|
const schema = generateTypeNode(prop.type, ctx);
|
|
1325
1329
|
applyConstraints(schema, prop.constraints, ctx);
|
|
1326
1330
|
applyResolvedMetadata(schema, prop.metadata);
|
|
1327
|
-
applyAnnotations(schema, prop.annotations, ctx);
|
|
1331
|
+
applyAnnotations(schema, prop.annotations, ctx, prop.type);
|
|
1328
1332
|
return schema;
|
|
1329
1333
|
}
|
|
1330
1334
|
function generateUnionType(type, ctx) {
|
|
@@ -1427,13 +1431,20 @@ function buildPropertyOverrides(pathConstraints, typeNode, ctx) {
|
|
|
1427
1431
|
grouped.push(constraint);
|
|
1428
1432
|
byTarget.set(target, grouped);
|
|
1429
1433
|
}
|
|
1430
|
-
const overrides =
|
|
1434
|
+
const overrides = /* @__PURE__ */ Object.create(null);
|
|
1431
1435
|
for (const [target, constraints] of byTarget) {
|
|
1432
|
-
|
|
1436
|
+
const resolvedName = resolveSerializedPropertyName(target, typeNode, ctx);
|
|
1437
|
+
const schema = buildPathOverrideSchema(
|
|
1433
1438
|
constraints.map(stripLeadingPathSegment),
|
|
1434
1439
|
resolveTargetTypeNode(target, typeNode, ctx),
|
|
1435
1440
|
ctx
|
|
1436
1441
|
);
|
|
1442
|
+
Object.defineProperty(overrides, resolvedName, {
|
|
1443
|
+
value: schema,
|
|
1444
|
+
writable: true,
|
|
1445
|
+
enumerable: true,
|
|
1446
|
+
configurable: true
|
|
1447
|
+
});
|
|
1437
1448
|
}
|
|
1438
1449
|
return overrides;
|
|
1439
1450
|
}
|
|
@@ -1460,6 +1471,34 @@ function buildPathOverrideSchema(constraints, typeNode, ctx) {
|
|
|
1460
1471
|
schema.properties = buildPropertyOverrides(nestedConstraints, effectiveType, ctx);
|
|
1461
1472
|
return schema;
|
|
1462
1473
|
}
|
|
1474
|
+
function tryFlattenAllOfToSiblings(schema, overrideMember) {
|
|
1475
|
+
if (schema.allOf?.length !== 1) {
|
|
1476
|
+
return void 0;
|
|
1477
|
+
}
|
|
1478
|
+
const [soleMember] = schema.allOf;
|
|
1479
|
+
if (soleMember === void 0) {
|
|
1480
|
+
return void 0;
|
|
1481
|
+
}
|
|
1482
|
+
const { allOf: _allOf, ...outerRest } = schema;
|
|
1483
|
+
const outerKeys = new Set(Object.keys(outerRest));
|
|
1484
|
+
const memberKeys = new Set(Object.keys(soleMember));
|
|
1485
|
+
const overrideKeys = new Set(Object.keys(overrideMember));
|
|
1486
|
+
for (const key of memberKeys) {
|
|
1487
|
+
if (outerKeys.has(key) || overrideKeys.has(key)) {
|
|
1488
|
+
return void 0;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
for (const key of overrideKeys) {
|
|
1492
|
+
if (outerKeys.has(key)) {
|
|
1493
|
+
return void 0;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
return {
|
|
1497
|
+
...outerRest,
|
|
1498
|
+
...soleMember,
|
|
1499
|
+
...overrideMember
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1463
1502
|
function mergeSchemaOverride(target, override) {
|
|
1464
1503
|
const nullableValueBranch = getNullableUnionValueSchema(target);
|
|
1465
1504
|
if (nullableValueBranch !== void 0) {
|
|
@@ -1467,11 +1506,16 @@ function mergeSchemaOverride(target, override) {
|
|
|
1467
1506
|
return;
|
|
1468
1507
|
}
|
|
1469
1508
|
if (override.properties !== void 0) {
|
|
1470
|
-
const mergedProperties = target.properties ??
|
|
1509
|
+
const mergedProperties = target.properties ?? /* @__PURE__ */ Object.create(null);
|
|
1471
1510
|
for (const [name, propertyOverride] of Object.entries(override.properties)) {
|
|
1472
|
-
const existing = mergedProperties[name];
|
|
1511
|
+
const existing = Object.hasOwn(mergedProperties, name) ? mergedProperties[name] : void 0;
|
|
1473
1512
|
if (existing === void 0) {
|
|
1474
|
-
mergedProperties
|
|
1513
|
+
Object.defineProperty(mergedProperties, name, {
|
|
1514
|
+
value: propertyOverride,
|
|
1515
|
+
writable: true,
|
|
1516
|
+
enumerable: true,
|
|
1517
|
+
configurable: true
|
|
1518
|
+
});
|
|
1475
1519
|
} else {
|
|
1476
1520
|
mergeSchemaOverride(existing, propertyOverride);
|
|
1477
1521
|
}
|
|
@@ -1489,7 +1533,12 @@ function mergeSchemaOverride(target, override) {
|
|
|
1489
1533
|
if (key === "properties" || key === "items") {
|
|
1490
1534
|
continue;
|
|
1491
1535
|
}
|
|
1492
|
-
target
|
|
1536
|
+
Object.defineProperty(target, key, {
|
|
1537
|
+
value,
|
|
1538
|
+
writable: true,
|
|
1539
|
+
enumerable: true,
|
|
1540
|
+
configurable: true
|
|
1541
|
+
});
|
|
1493
1542
|
}
|
|
1494
1543
|
}
|
|
1495
1544
|
function stripLeadingPathSegment(constraint) {
|
|
@@ -1589,7 +1638,7 @@ function applyConstraints(schema, constraints, ctx) {
|
|
|
1589
1638
|
}
|
|
1590
1639
|
}
|
|
1591
1640
|
}
|
|
1592
|
-
function applyAnnotations(schema, annotations, ctx) {
|
|
1641
|
+
function applyAnnotations(schema, annotations, ctx, typeNode) {
|
|
1593
1642
|
for (const annotation of annotations) {
|
|
1594
1643
|
switch (annotation.annotationKind) {
|
|
1595
1644
|
case "displayName":
|
|
@@ -1602,7 +1651,7 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
1602
1651
|
schema[`${ctx.vendorPrefix}-remarks`] = annotation.value;
|
|
1603
1652
|
break;
|
|
1604
1653
|
case "defaultValue":
|
|
1605
|
-
schema.default = annotation.value;
|
|
1654
|
+
schema.default = coerceDefaultValue(annotation.value, typeNode, schema, ctx);
|
|
1606
1655
|
break;
|
|
1607
1656
|
case "format":
|
|
1608
1657
|
schema.format = annotation.value;
|
|
@@ -1627,6 +1676,34 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
1627
1676
|
}
|
|
1628
1677
|
}
|
|
1629
1678
|
}
|
|
1679
|
+
function coerceDefaultValue(value, typeNode, emittedSchema, ctx) {
|
|
1680
|
+
if (typeNode?.kind !== "custom") {
|
|
1681
|
+
return value;
|
|
1682
|
+
}
|
|
1683
|
+
const registration = ctx.extensionRegistry?.findType(typeNode.typeId);
|
|
1684
|
+
if (registration === void 0) {
|
|
1685
|
+
return value;
|
|
1686
|
+
}
|
|
1687
|
+
if (registration.serializeDefault !== void 0) {
|
|
1688
|
+
return registration.serializeDefault(value, typeNode.payload);
|
|
1689
|
+
}
|
|
1690
|
+
const declaredType = emittedSchema["type"];
|
|
1691
|
+
if (declaredType === "string" && typeof value !== "string") {
|
|
1692
|
+
if (typeof value === "number") {
|
|
1693
|
+
if (!Number.isFinite(value)) {
|
|
1694
|
+
return value;
|
|
1695
|
+
}
|
|
1696
|
+
return String(value);
|
|
1697
|
+
}
|
|
1698
|
+
if (typeof value === "boolean") {
|
|
1699
|
+
return String(value);
|
|
1700
|
+
}
|
|
1701
|
+
if (typeof value === "bigint") {
|
|
1702
|
+
return value.toString();
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
return value;
|
|
1706
|
+
}
|
|
1630
1707
|
function generateCustomType(type, ctx) {
|
|
1631
1708
|
const registration = ctx.extensionRegistry?.findType(type.typeId);
|
|
1632
1709
|
if (registration === void 0) {
|
|
@@ -2087,16 +2164,32 @@ function buildConstraintTagSources(extensions) {
|
|
|
2087
2164
|
constraintTags: extension.constraintTags.map((tag) => ({
|
|
2088
2165
|
tagName: (0, import_internal.normalizeFormSpecTagName)(tag.tagName)
|
|
2089
2166
|
}))
|
|
2167
|
+
} : {},
|
|
2168
|
+
// Include customTypes so _validateExtensionSetup can check tsTypeNames for
|
|
2169
|
+
// unsupported built-in overrides and invalid identifier patterns.
|
|
2170
|
+
...extension.types !== void 0 ? {
|
|
2171
|
+
customTypes: extension.types.map((type) => ({
|
|
2172
|
+
// tsTypeNames: deprecated in favour of symbol-based detection, but
|
|
2173
|
+
// still required for name-based validation in _validateExtensionSetup
|
|
2174
|
+
// until the bridge is fully retired (see §synthetic-checker-retirement §4C).
|
|
2175
|
+
tsTypeNames: type.tsTypeNames ?? [type.typeName]
|
|
2176
|
+
}))
|
|
2090
2177
|
} : {}
|
|
2091
2178
|
}));
|
|
2092
2179
|
}
|
|
2093
2180
|
function createExtensionRegistry(extensions) {
|
|
2094
|
-
const registryLog = (0, import_internal.
|
|
2181
|
+
const registryLog = (0, import_internal.getRegistryLogger)();
|
|
2095
2182
|
registryLog.debug("createExtensionRegistry: constructing", {
|
|
2096
2183
|
extensionCount: extensions.length,
|
|
2097
2184
|
extensionIds: extensions.map((e) => e.extensionId)
|
|
2098
2185
|
});
|
|
2099
|
-
const
|
|
2186
|
+
const extensionTagSources = buildConstraintTagSources(extensions);
|
|
2187
|
+
const setupDiagnostics = (0, import_internal._validateExtensionSetup)(extensionTagSources);
|
|
2188
|
+
(0, import_internal.logSetupDiagnostics)(registryLog, {
|
|
2189
|
+
diagnosticCount: setupDiagnostics.length,
|
|
2190
|
+
codes: setupDiagnostics.map((d) => d.kind)
|
|
2191
|
+
});
|
|
2192
|
+
const reservedTagSources = extensionTagSources;
|
|
2100
2193
|
let symbolMap = /* @__PURE__ */ new Map();
|
|
2101
2194
|
const typeMap = /* @__PURE__ */ new Map();
|
|
2102
2195
|
const typeNameMap = /* @__PURE__ */ new Map();
|
|
@@ -2233,10 +2326,12 @@ function createExtensionRegistry(extensions) {
|
|
|
2233
2326
|
constraintTagCount: constraintTagMap.size,
|
|
2234
2327
|
broadeningCount: builtinBroadeningMap.size,
|
|
2235
2328
|
annotationCount: annotationMap.size,
|
|
2236
|
-
metadataSlotCount: metadataSlotMap.size
|
|
2329
|
+
metadataSlotCount: metadataSlotMap.size,
|
|
2330
|
+
setupDiagnosticCount: setupDiagnostics.length
|
|
2237
2331
|
});
|
|
2238
2332
|
return {
|
|
2239
2333
|
extensions,
|
|
2334
|
+
setupDiagnostics,
|
|
2240
2335
|
findType: (typeId) => typeMap.get(typeId),
|
|
2241
2336
|
findTypeByName: (typeName) => typeNameMap.get(typeName),
|
|
2242
2337
|
findTypeByBrand: (brand) => brandMap.get(brand),
|
|
@@ -2337,21 +2432,6 @@ var init_schema2 = __esm({
|
|
|
2337
2432
|
});
|
|
2338
2433
|
|
|
2339
2434
|
// src/extensions/ts-type-utils.ts
|
|
2340
|
-
function collectBrandIdentifiers(type) {
|
|
2341
|
-
if (!type.isIntersection()) {
|
|
2342
|
-
return [];
|
|
2343
|
-
}
|
|
2344
|
-
const brands = [];
|
|
2345
|
-
for (const prop of type.getProperties()) {
|
|
2346
|
-
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
2347
|
-
if (decl === void 0) continue;
|
|
2348
|
-
if (!ts.isPropertySignature(decl) && !ts.isPropertyDeclaration(decl)) continue;
|
|
2349
|
-
if (!ts.isComputedPropertyName(decl.name)) continue;
|
|
2350
|
-
if (!ts.isIdentifier(decl.name.expression)) continue;
|
|
2351
|
-
brands.push(decl.name.expression.text);
|
|
2352
|
-
}
|
|
2353
|
-
return brands;
|
|
2354
|
-
}
|
|
2355
2435
|
function resolveCanonicalSymbol(type, checker) {
|
|
2356
2436
|
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
2357
2437
|
if (raw === void 0) return void 0;
|
|
@@ -2443,7 +2523,7 @@ function resolveCustomTypeFromTsType(type, checker, registry, sourceNode) {
|
|
|
2443
2523
|
return bySymbol;
|
|
2444
2524
|
}
|
|
2445
2525
|
}
|
|
2446
|
-
for (const brand of
|
|
2526
|
+
for (const brand of (0, import_internal2._collectBrandIdentifiers)(stripped)) {
|
|
2447
2527
|
const byBrand = registry.findTypeByBrand(brand);
|
|
2448
2528
|
if (byBrand !== void 0) {
|
|
2449
2529
|
return byBrand;
|
|
@@ -2465,166 +2545,43 @@ var init_resolve_custom_type = __esm({
|
|
|
2465
2545
|
});
|
|
2466
2546
|
|
|
2467
2547
|
// src/analyzer/builtin-brands.ts
|
|
2468
|
-
|
|
2469
|
-
if (!type.isIntersection()) return false;
|
|
2470
|
-
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2471
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2472
|
-
}
|
|
2473
|
-
var ts3;
|
|
2548
|
+
var import_internal3;
|
|
2474
2549
|
var init_builtin_brands = __esm({
|
|
2475
2550
|
"src/analyzer/builtin-brands.ts"() {
|
|
2476
2551
|
"use strict";
|
|
2477
|
-
|
|
2478
|
-
init_ts_type_utils();
|
|
2552
|
+
import_internal3 = require("@formspec/analysis/internal");
|
|
2479
2553
|
}
|
|
2480
2554
|
});
|
|
2481
2555
|
|
|
2482
2556
|
// src/analyzer/tsdoc-parser.ts
|
|
2483
|
-
function sharedTagValueOptions(options) {
|
|
2557
|
+
function sharedTagValueOptions(options, pathResolvedCustomTypeId) {
|
|
2484
2558
|
return {
|
|
2485
2559
|
...options?.extensionRegistry !== void 0 ? { registry: options.extensionRegistry } : {},
|
|
2486
|
-
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2560
|
+
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {},
|
|
2561
|
+
...pathResolvedCustomTypeId !== void 0 ? { pathResolvedCustomTypeId } : {}
|
|
2487
2562
|
};
|
|
2488
2563
|
}
|
|
2489
|
-
function
|
|
2490
|
-
if (registry === void 0)
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
return new Set(
|
|
2494
|
-
registry.extensions.flatMap(
|
|
2495
|
-
(ext) => (ext.types ?? []).flatMap((t) => t.tsTypeNames ?? [t.typeName])
|
|
2496
|
-
)
|
|
2497
|
-
);
|
|
2498
|
-
}
|
|
2499
|
-
function collectImportedNames(sourceFile) {
|
|
2500
|
-
const importedNames = /* @__PURE__ */ new Set();
|
|
2501
|
-
for (const statement of sourceFile.statements) {
|
|
2502
|
-
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2503
|
-
const clause = statement.importClause;
|
|
2504
|
-
if (clause.name !== void 0) {
|
|
2505
|
-
importedNames.add(clause.name.text);
|
|
2506
|
-
}
|
|
2507
|
-
if (clause.namedBindings !== void 0) {
|
|
2508
|
-
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
2509
|
-
for (const specifier of clause.namedBindings.elements) {
|
|
2510
|
-
importedNames.add(specifier.name.text);
|
|
2511
|
-
}
|
|
2512
|
-
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
2513
|
-
importedNames.add(clause.namedBindings.name.text);
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
continue;
|
|
2517
|
-
}
|
|
2518
|
-
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
2519
|
-
importedNames.add(statement.name.text);
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
return importedNames;
|
|
2523
|
-
}
|
|
2524
|
-
function isNonReferenceIdentifier(node) {
|
|
2525
|
-
const parent = node.parent;
|
|
2526
|
-
if ((ts4.isBindingElement(parent) || ts4.isClassDeclaration(parent) || ts4.isEnumDeclaration(parent) || ts4.isEnumMember(parent) || ts4.isFunctionDeclaration(parent) || ts4.isFunctionExpression(parent) || ts4.isImportClause(parent) || ts4.isImportEqualsDeclaration(parent) || ts4.isImportSpecifier(parent) || ts4.isInterfaceDeclaration(parent) || ts4.isMethodDeclaration(parent) || ts4.isMethodSignature(parent) || ts4.isModuleDeclaration(parent) || ts4.isNamespaceExport(parent) || ts4.isNamespaceImport(parent) || ts4.isParameter(parent) || ts4.isPropertyDeclaration(parent) || ts4.isPropertySignature(parent) || ts4.isSetAccessorDeclaration(parent) || ts4.isGetAccessorDeclaration(parent) || ts4.isTypeAliasDeclaration(parent) || ts4.isTypeParameterDeclaration(parent) || ts4.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2527
|
-
return true;
|
|
2528
|
-
}
|
|
2529
|
-
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2530
|
-
return true;
|
|
2531
|
-
}
|
|
2532
|
-
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
2533
|
-
return true;
|
|
2534
|
-
}
|
|
2535
|
-
return false;
|
|
2564
|
+
function customTypeIdForResolvedType(resolvedType, checker, registry) {
|
|
2565
|
+
if (registry === void 0) return void 0;
|
|
2566
|
+
const lookup = resolveCustomTypeFromTsType(resolvedType, checker, registry);
|
|
2567
|
+
return lookup === null ? void 0 : customTypeIdFromLookup(lookup);
|
|
2536
2568
|
}
|
|
2537
|
-
function
|
|
2538
|
-
if (
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
const visit = (node) => {
|
|
2543
|
-
if (found) return;
|
|
2544
|
-
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2545
|
-
found = true;
|
|
2546
|
-
return;
|
|
2547
|
-
}
|
|
2548
|
-
ts4.forEachChild(node, visit);
|
|
2549
|
-
};
|
|
2550
|
-
visit(root);
|
|
2551
|
-
return found;
|
|
2552
|
-
}
|
|
2553
|
-
function getObjectMembers(statement) {
|
|
2554
|
-
if (ts4.isInterfaceDeclaration(statement)) {
|
|
2555
|
-
return statement.members;
|
|
2556
|
-
}
|
|
2557
|
-
if (ts4.isTypeLiteralNode(statement.type)) {
|
|
2558
|
-
return statement.type.members;
|
|
2559
|
-
}
|
|
2560
|
-
return void 0;
|
|
2561
|
-
}
|
|
2562
|
-
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
2563
|
-
const members = getObjectMembers(statement);
|
|
2564
|
-
if (members === void 0) {
|
|
2565
|
-
return null;
|
|
2566
|
-
}
|
|
2567
|
-
const replacements = [];
|
|
2568
|
-
for (const member of members) {
|
|
2569
|
-
if (!ts4.isPropertySignature(member)) {
|
|
2570
|
-
if (astReferencesImportedName(member, importedNames)) {
|
|
2571
|
-
return null;
|
|
2572
|
-
}
|
|
2573
|
-
continue;
|
|
2574
|
-
}
|
|
2575
|
-
const typeAnnotation = member.type;
|
|
2576
|
-
if (typeAnnotation === void 0) continue;
|
|
2577
|
-
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
2578
|
-
replacements.push({
|
|
2579
|
-
start: typeAnnotation.getStart(sourceFile),
|
|
2580
|
-
end: typeAnnotation.getEnd()
|
|
2581
|
-
});
|
|
2582
|
-
}
|
|
2583
|
-
}
|
|
2584
|
-
if (replacements.length === 0) {
|
|
2585
|
-
return statement.getText(sourceFile);
|
|
2586
|
-
}
|
|
2587
|
-
const stmtStart = statement.getStart(sourceFile);
|
|
2588
|
-
let result = statement.getText(sourceFile);
|
|
2589
|
-
for (const { start, end } of [...replacements].reverse()) {
|
|
2590
|
-
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
2569
|
+
function resolvePathTargetCustomTypeId(parsedTag, subjectType, checker, registry) {
|
|
2570
|
+
if (parsedTag === null) return void 0;
|
|
2571
|
+
const target = parsedTag.target;
|
|
2572
|
+
if (target?.kind !== "path" || !target.valid || target.path === null) {
|
|
2573
|
+
return void 0;
|
|
2591
2574
|
}
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
2595
|
-
const importedNames = collectImportedNames(sourceFile);
|
|
2596
|
-
const importedNamesToSkip = new Set(
|
|
2597
|
-
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2598
|
-
);
|
|
2599
|
-
const result = [];
|
|
2600
|
-
for (const statement of sourceFile.statements) {
|
|
2601
|
-
if (ts4.isImportDeclaration(statement)) continue;
|
|
2602
|
-
if (ts4.isImportEqualsDeclaration(statement)) continue;
|
|
2603
|
-
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2604
|
-
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2605
|
-
result.push(statement.getText(sourceFile));
|
|
2606
|
-
continue;
|
|
2607
|
-
}
|
|
2608
|
-
if (ts4.isInterfaceDeclaration(statement) || ts4.isTypeAliasDeclaration(statement)) {
|
|
2609
|
-
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2610
|
-
if (rewritten !== null) {
|
|
2611
|
-
result.push(rewritten);
|
|
2612
|
-
}
|
|
2613
|
-
}
|
|
2575
|
+
if (subjectType === void 0 || checker === void 0) {
|
|
2576
|
+
return void 0;
|
|
2614
2577
|
}
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
for (const diagnostic of additions) {
|
|
2619
|
-
if ((diagnostic.code === "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" || diagnostic.code === "SYNTHETIC_SETUP_FAILURE") && target.some(
|
|
2620
|
-
(existing) => existing.code === diagnostic.code && existing.message === diagnostic.message
|
|
2621
|
-
)) {
|
|
2622
|
-
continue;
|
|
2623
|
-
}
|
|
2624
|
-
target.push(diagnostic);
|
|
2578
|
+
const resolution = (0, import_internal4.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
2579
|
+
if (resolution.kind !== "resolved") {
|
|
2580
|
+
return void 0;
|
|
2625
2581
|
}
|
|
2582
|
+
return customTypeIdForResolvedType(resolution.type, checker, registry);
|
|
2626
2583
|
}
|
|
2627
|
-
function processConstraintTag(tagName, text, parsedTag, provenance, node, sourceFile,
|
|
2584
|
+
function processConstraintTag(tagName, text, parsedTag, provenance, node, sourceFile, options, constraints, diagnostics) {
|
|
2628
2585
|
const compilerDiagnostics = buildCompilerBackedConstraintDiagnostics(
|
|
2629
2586
|
node,
|
|
2630
2587
|
sourceFile,
|
|
@@ -2632,81 +2589,37 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
2632
2589
|
parsedTag,
|
|
2633
2590
|
text,
|
|
2634
2591
|
provenance,
|
|
2635
|
-
supportingDeclarations,
|
|
2636
2592
|
options
|
|
2637
2593
|
);
|
|
2638
2594
|
if (compilerDiagnostics.length > 0) {
|
|
2639
|
-
|
|
2595
|
+
diagnostics.push(...compilerDiagnostics);
|
|
2640
2596
|
return;
|
|
2641
2597
|
}
|
|
2642
|
-
const
|
|
2598
|
+
const pathResolvedCustomTypeId = resolvePathTargetCustomTypeId(
|
|
2599
|
+
parsedTag,
|
|
2600
|
+
options?.subjectType,
|
|
2601
|
+
options?.checker,
|
|
2602
|
+
options?.extensionRegistry
|
|
2603
|
+
);
|
|
2604
|
+
const constraintNode = (0, import_internal4.parseConstraintTagValue)(
|
|
2643
2605
|
tagName,
|
|
2644
2606
|
text,
|
|
2645
2607
|
provenance,
|
|
2646
|
-
sharedTagValueOptions(options)
|
|
2608
|
+
sharedTagValueOptions(options, pathResolvedCustomTypeId)
|
|
2647
2609
|
);
|
|
2648
2610
|
if (constraintNode) {
|
|
2649
2611
|
constraints.push(constraintNode);
|
|
2650
2612
|
}
|
|
2651
2613
|
}
|
|
2652
|
-
function renderSyntheticArgumentExpression(valueKind, argumentText) {
|
|
2653
|
-
const trimmed = argumentText.trim();
|
|
2654
|
-
if (trimmed === "") {
|
|
2655
|
-
return null;
|
|
2656
|
-
}
|
|
2657
|
-
switch (valueKind) {
|
|
2658
|
-
case "number":
|
|
2659
|
-
case "integer":
|
|
2660
|
-
case "signedInteger":
|
|
2661
|
-
if (trimmed === "Infinity" || trimmed === "-Infinity" || trimmed === "NaN") {
|
|
2662
|
-
return trimmed;
|
|
2663
|
-
}
|
|
2664
|
-
return Number.isFinite(Number(trimmed)) ? trimmed : JSON.stringify(trimmed);
|
|
2665
|
-
case "string":
|
|
2666
|
-
return JSON.stringify(argumentText);
|
|
2667
|
-
case "json":
|
|
2668
|
-
try {
|
|
2669
|
-
JSON.parse(trimmed);
|
|
2670
|
-
return `(${trimmed})`;
|
|
2671
|
-
} catch {
|
|
2672
|
-
return JSON.stringify(trimmed);
|
|
2673
|
-
}
|
|
2674
|
-
case "boolean":
|
|
2675
|
-
return trimmed === "true" || trimmed === "false" ? trimmed : JSON.stringify(trimmed);
|
|
2676
|
-
case "condition":
|
|
2677
|
-
return "undefined as unknown as FormSpecCondition";
|
|
2678
|
-
case null:
|
|
2679
|
-
return null;
|
|
2680
|
-
default: {
|
|
2681
|
-
return String(valueKind);
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
|
-
}
|
|
2685
|
-
function getArrayElementType(type, checker) {
|
|
2686
|
-
if (!checker.isArrayType(type)) {
|
|
2687
|
-
return null;
|
|
2688
|
-
}
|
|
2689
|
-
return checker.getTypeArguments(type)[0] ?? null;
|
|
2690
|
-
}
|
|
2691
2614
|
function supportsConstraintCapability(type, checker, capability) {
|
|
2692
|
-
|
|
2693
|
-
return true;
|
|
2694
|
-
}
|
|
2695
|
-
if ((0, import_internal3.hasTypeSemanticCapability)(type, checker, capability)) {
|
|
2696
|
-
return true;
|
|
2697
|
-
}
|
|
2698
|
-
if (capability === "string-like") {
|
|
2699
|
-
const itemType = getArrayElementType(type, checker);
|
|
2700
|
-
return itemType !== null && (0, import_internal3.hasTypeSemanticCapability)(itemType, checker, capability);
|
|
2701
|
-
}
|
|
2702
|
-
return false;
|
|
2615
|
+
return (0, import_internal4._supportsConstraintCapability)(capability, type, checker);
|
|
2703
2616
|
}
|
|
2704
2617
|
function stripHintNullishUnion(type) {
|
|
2705
2618
|
if (!type.isUnion()) {
|
|
2706
2619
|
return type;
|
|
2707
2620
|
}
|
|
2708
2621
|
const nonNullish = type.types.filter(
|
|
2709
|
-
(member) => (member.flags & (
|
|
2622
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
2710
2623
|
);
|
|
2711
2624
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2712
2625
|
return nonNullish[0];
|
|
@@ -2722,10 +2635,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2722
2635
|
}
|
|
2723
2636
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2724
2637
|
const name = declaration.name;
|
|
2725
|
-
if (
|
|
2638
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
2726
2639
|
return false;
|
|
2727
2640
|
}
|
|
2728
|
-
if (!
|
|
2641
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
2729
2642
|
return false;
|
|
2730
2643
|
}
|
|
2731
2644
|
}
|
|
@@ -2741,7 +2654,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2741
2654
|
if (isCallableType(stripped)) {
|
|
2742
2655
|
return;
|
|
2743
2656
|
}
|
|
2744
|
-
if (!(0,
|
|
2657
|
+
if (!(0, import_internal4.hasTypeSemanticCapability)(stripped, checker, "object-like")) {
|
|
2745
2658
|
return;
|
|
2746
2659
|
}
|
|
2747
2660
|
for (const property of stripped.getProperties()) {
|
|
@@ -2759,7 +2672,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2759
2672
|
continue;
|
|
2760
2673
|
}
|
|
2761
2674
|
const strippedPropertyType = stripHintNullishUnion(propertyType);
|
|
2762
|
-
if (!isCallableType(strippedPropertyType) && (0,
|
|
2675
|
+
if (!isCallableType(strippedPropertyType) && (0, import_internal4.hasTypeSemanticCapability)(strippedPropertyType, checker, "object-like")) {
|
|
2763
2676
|
visit(strippedPropertyType, path5, depth + 1);
|
|
2764
2677
|
}
|
|
2765
2678
|
}
|
|
@@ -2768,7 +2681,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2768
2681
|
return out;
|
|
2769
2682
|
}
|
|
2770
2683
|
function buildPathTargetHint(subjectType, checker, capability, tagName, argumentText) {
|
|
2771
|
-
if (!(0,
|
|
2684
|
+
if (!(0, import_internal4.hasTypeSemanticCapability)(subjectType, checker, "object-like")) {
|
|
2772
2685
|
return null;
|
|
2773
2686
|
}
|
|
2774
2687
|
const candidates = collectObjectSubfieldCandidates(subjectType, checker, capability);
|
|
@@ -2824,53 +2737,11 @@ function placementLabel(placement) {
|
|
|
2824
2737
|
}
|
|
2825
2738
|
}
|
|
2826
2739
|
}
|
|
2827
|
-
function capabilityLabel(capability) {
|
|
2828
|
-
switch (capability) {
|
|
2829
|
-
case "numeric-comparable":
|
|
2830
|
-
return "number";
|
|
2831
|
-
case "string-like":
|
|
2832
|
-
return "string";
|
|
2833
|
-
case "array-like":
|
|
2834
|
-
return "array";
|
|
2835
|
-
case "enum-member-addressable":
|
|
2836
|
-
return "enum";
|
|
2837
|
-
case "json-like":
|
|
2838
|
-
return "JSON-compatible";
|
|
2839
|
-
case "object-like":
|
|
2840
|
-
return "object";
|
|
2841
|
-
case "condition-like":
|
|
2842
|
-
return "conditional";
|
|
2843
|
-
case void 0:
|
|
2844
|
-
return "compatible";
|
|
2845
|
-
default:
|
|
2846
|
-
return capability;
|
|
2847
|
-
}
|
|
2848
|
-
}
|
|
2849
|
-
function getBroadenedCustomTypeId(fieldType) {
|
|
2850
|
-
if (fieldType?.kind === "custom") {
|
|
2851
|
-
return fieldType.typeId;
|
|
2852
|
-
}
|
|
2853
|
-
if (fieldType?.kind !== "union") {
|
|
2854
|
-
return void 0;
|
|
2855
|
-
}
|
|
2856
|
-
const customMembers = fieldType.members.filter(
|
|
2857
|
-
(member) => member.kind === "custom"
|
|
2858
|
-
);
|
|
2859
|
-
if (customMembers.length !== 1) {
|
|
2860
|
-
return void 0;
|
|
2861
|
-
}
|
|
2862
|
-
const nonCustomMembers = fieldType.members.filter((member) => member.kind !== "custom");
|
|
2863
|
-
const allOtherMembersAreNull = nonCustomMembers.every(
|
|
2864
|
-
(member) => member.kind === "primitive" && member.primitiveKind === "null"
|
|
2865
|
-
);
|
|
2866
|
-
const customMember = customMembers[0];
|
|
2867
|
-
return allOtherMembersAreNull && customMember !== void 0 ? customMember.typeId : void 0;
|
|
2868
|
-
}
|
|
2869
2740
|
function hasBuiltinConstraintBroadening(tagName, options) {
|
|
2870
|
-
const broadenedTypeId = getBroadenedCustomTypeId(options?.fieldType);
|
|
2741
|
+
const broadenedTypeId = (0, import_internal4.getBroadenedCustomTypeId)(options?.fieldType);
|
|
2871
2742
|
return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
|
|
2872
2743
|
}
|
|
2873
|
-
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance,
|
|
2744
|
+
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance, options) {
|
|
2874
2745
|
if (!(0, import_internals4.isBuiltinConstraintName)(tagName)) {
|
|
2875
2746
|
return [];
|
|
2876
2747
|
}
|
|
@@ -2879,27 +2750,25 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2879
2750
|
if (checker === void 0 || subjectType === void 0) {
|
|
2880
2751
|
return [];
|
|
2881
2752
|
}
|
|
2882
|
-
const placement = (0,
|
|
2753
|
+
const placement = (0, import_internal4.resolveDeclarationPlacement)(node);
|
|
2883
2754
|
if (placement === null) {
|
|
2884
2755
|
return [];
|
|
2885
2756
|
}
|
|
2886
|
-
const definition = (0,
|
|
2757
|
+
const definition = (0, import_internal4.getTagDefinition)(tagName, options?.extensionRegistry?.extensions);
|
|
2887
2758
|
if (definition === null) {
|
|
2888
2759
|
return [];
|
|
2889
2760
|
}
|
|
2890
2761
|
const nonNullPlacement = placement;
|
|
2891
|
-
const log2 = (0,
|
|
2892
|
-
const broadeningLog = (0,
|
|
2893
|
-
const
|
|
2894
|
-
const typedParserLog = (0, import_internal4.getTypedParserLogger)();
|
|
2762
|
+
const log2 = (0, import_internal5.getBuildLogger)();
|
|
2763
|
+
const broadeningLog = (0, import_internal5.getBroadeningLogger)();
|
|
2764
|
+
const typedParserLog = (0, import_internal5.getTypedParserLogger)();
|
|
2895
2765
|
const logsEnabled = log2 !== import_core4.noopLogger || broadeningLog !== import_core4.noopLogger;
|
|
2896
|
-
const syntheticTraceEnabled = syntheticLog !== import_core4.noopLogger;
|
|
2897
2766
|
const typedParserTraceEnabled = typedParserLog !== import_core4.noopLogger;
|
|
2898
|
-
const logStart = logsEnabled ? (0,
|
|
2899
|
-
const subjectTypeKind = logsEnabled ? (0,
|
|
2900
|
-
function emit(outcome,
|
|
2767
|
+
const logStart = logsEnabled ? (0, import_internal5.nowMicros)() : 0;
|
|
2768
|
+
const subjectTypeKind = logsEnabled ? (0, import_internal5.describeTypeKind)(subjectType, checker) : "";
|
|
2769
|
+
function emit(outcome, result) {
|
|
2901
2770
|
if (!logsEnabled) {
|
|
2902
|
-
return
|
|
2771
|
+
return result;
|
|
2903
2772
|
}
|
|
2904
2773
|
const entry = {
|
|
2905
2774
|
consumer: "build",
|
|
@@ -2907,13 +2776,13 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2907
2776
|
placement: nonNullPlacement,
|
|
2908
2777
|
subjectTypeKind,
|
|
2909
2778
|
roleOutcome: outcome,
|
|
2910
|
-
elapsedMicros: (0,
|
|
2779
|
+
elapsedMicros: (0, import_internal5.elapsedMicros)(logStart)
|
|
2911
2780
|
};
|
|
2912
|
-
(0,
|
|
2781
|
+
(0, import_internal5.logTagApplication)(log2, entry);
|
|
2913
2782
|
if (outcome === "bypass" || outcome === "D1" || outcome === "D2") {
|
|
2914
|
-
(0,
|
|
2783
|
+
(0, import_internal5.logTagApplication)(broadeningLog, entry);
|
|
2915
2784
|
}
|
|
2916
|
-
return
|
|
2785
|
+
return result;
|
|
2917
2786
|
}
|
|
2918
2787
|
if (!definition.placements.includes(placement)) {
|
|
2919
2788
|
return emit("A-reject", [
|
|
@@ -2946,7 +2815,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2946
2815
|
)
|
|
2947
2816
|
]);
|
|
2948
2817
|
}
|
|
2949
|
-
const resolution = (0,
|
|
2818
|
+
const resolution = (0, import_internal4.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
2950
2819
|
if (resolution.kind === "missing-property") {
|
|
2951
2820
|
return emit("B-reject", [
|
|
2952
2821
|
makeDiagnostic(
|
|
@@ -2957,7 +2826,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2957
2826
|
]);
|
|
2958
2827
|
}
|
|
2959
2828
|
if (resolution.kind === "unresolvable") {
|
|
2960
|
-
const actualType = checker.typeToString(resolution.type, node,
|
|
2829
|
+
const actualType = checker.typeToString(resolution.type, node, TYPE_FORMAT_FLAGS);
|
|
2961
2830
|
return emit("B-reject", [
|
|
2962
2831
|
makeDiagnostic(
|
|
2963
2832
|
"TYPE_MISMATCH",
|
|
@@ -2971,21 +2840,21 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2971
2840
|
}
|
|
2972
2841
|
const hasBroadening = (() => {
|
|
2973
2842
|
if (target === null) {
|
|
2974
|
-
if (
|
|
2843
|
+
if ((0, import_internal3._isIntegerBrandedType)((0, import_internal4.stripNullishUnion)(subjectType)) && definition.capabilities[0] === "numeric-comparable") {
|
|
2975
2844
|
return true;
|
|
2976
2845
|
}
|
|
2977
2846
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2978
2847
|
}
|
|
2979
2848
|
const registry = options?.extensionRegistry;
|
|
2980
2849
|
if (registry === void 0) return false;
|
|
2981
|
-
const
|
|
2982
|
-
return
|
|
2850
|
+
const typeId = customTypeIdForResolvedType(evaluatedType, checker, registry);
|
|
2851
|
+
return typeId !== void 0 && registry.findBuiltinConstraintBroadening(typeId, tagName) !== void 0;
|
|
2983
2852
|
})();
|
|
2984
2853
|
if (!hasBroadening) {
|
|
2985
2854
|
const requiredCapability = definition.capabilities[0];
|
|
2986
2855
|
if (requiredCapability !== void 0 && !supportsConstraintCapability(evaluatedType, checker, requiredCapability)) {
|
|
2987
|
-
const actualType = checker.typeToString(evaluatedType, node,
|
|
2988
|
-
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${
|
|
2856
|
+
const actualType = checker.typeToString(evaluatedType, node, TYPE_FORMAT_FLAGS);
|
|
2857
|
+
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${(0, import_internal4._capabilityLabel)(requiredCapability)} targets, but field type is "${actualType}"`;
|
|
2989
2858
|
const hint = target === null ? buildPathTargetHint(
|
|
2990
2859
|
subjectType,
|
|
2991
2860
|
checker,
|
|
@@ -3002,11 +2871,11 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3002
2871
|
]);
|
|
3003
2872
|
}
|
|
3004
2873
|
}
|
|
3005
|
-
const effectiveArgumentText = parsedTag !== null ? (0, import_internal3.parseTagSyntax)(tagName, rawText).argumentText : rawText;
|
|
3006
2874
|
if (hasBroadening) {
|
|
3007
2875
|
return emit("bypass", []);
|
|
3008
2876
|
}
|
|
3009
|
-
const
|
|
2877
|
+
const effectiveArgumentText = (0, import_internal5.extractEffectiveArgumentText)(tagName, rawText, parsedTag);
|
|
2878
|
+
const typedParseResult = (0, import_internal5.parseTagArgument)(tagName, effectiveArgumentText, "build");
|
|
3010
2879
|
if (!typedParseResult.ok) {
|
|
3011
2880
|
if (typedParserTraceEnabled) {
|
|
3012
2881
|
typedParserLog.trace("typed-parser C-reject", {
|
|
@@ -3018,23 +2887,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3018
2887
|
diagnosticCode: typedParseResult.diagnostic.code
|
|
3019
2888
|
});
|
|
3020
2889
|
}
|
|
3021
|
-
|
|
3022
|
-
switch (typedParseResult.diagnostic.code) {
|
|
3023
|
-
case "MISSING_TAG_ARGUMENT":
|
|
3024
|
-
mappedCode = "MISSING_TAG_ARGUMENT";
|
|
3025
|
-
break;
|
|
3026
|
-
case "INVALID_TAG_ARGUMENT":
|
|
3027
|
-
mappedCode = "INVALID_TAG_ARGUMENT";
|
|
3028
|
-
break;
|
|
3029
|
-
case "UNKNOWN_TAG":
|
|
3030
|
-
throw new Error(
|
|
3031
|
-
`Unexpected UNKNOWN_TAG from parseTagArgument("${tagName}") \u2014 tag was resolved via getTagDefinition.`
|
|
3032
|
-
);
|
|
3033
|
-
default: {
|
|
3034
|
-
const _exhaustive = typedParseResult.diagnostic.code;
|
|
3035
|
-
throw new Error(`Unknown diagnostic code: ${String(_exhaustive)}`);
|
|
3036
|
-
}
|
|
3037
|
-
}
|
|
2890
|
+
const mappedCode = (0, import_internal5.mapTypedParserDiagnosticCode)(typedParseResult.diagnostic.code, tagName);
|
|
3038
2891
|
return emit("C-reject", [
|
|
3039
2892
|
makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
|
|
3040
2893
|
]);
|
|
@@ -3049,76 +2902,15 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3049
2902
|
valueKind: typedParseResult.value.kind
|
|
3050
2903
|
});
|
|
3051
2904
|
}
|
|
3052
|
-
|
|
3053
|
-
definition.valueKind,
|
|
3054
|
-
effectiveArgumentText
|
|
3055
|
-
);
|
|
3056
|
-
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
3057
|
-
const hostType = options?.hostType ?? subjectType;
|
|
3058
|
-
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
3059
|
-
if (syntheticTraceEnabled) {
|
|
3060
|
-
syntheticLog.trace("invoking synthetic checker", {
|
|
3061
|
-
consumer: "build",
|
|
3062
|
-
tag: tagName,
|
|
3063
|
-
placement,
|
|
3064
|
-
subjectTypeKind,
|
|
3065
|
-
subjectTypeText
|
|
3066
|
-
});
|
|
3067
|
-
}
|
|
3068
|
-
const result = (0, import_internal3.checkSyntheticTagApplication)({
|
|
3069
|
-
tagName,
|
|
3070
|
-
placement,
|
|
3071
|
-
hostType: hostTypeText,
|
|
3072
|
-
subjectType: subjectTypeText,
|
|
3073
|
-
...target?.kind === "path" ? { target: { kind: "path", text: target.rawText } } : {},
|
|
3074
|
-
...argumentExpression !== null ? { argumentExpression } : {},
|
|
3075
|
-
supportingDeclarations,
|
|
3076
|
-
...options?.extensionRegistry !== void 0 ? {
|
|
3077
|
-
extensions: options.extensionRegistry.extensions.map((extension) => ({
|
|
3078
|
-
extensionId: extension.extensionId,
|
|
3079
|
-
...extension.constraintTags !== void 0 ? {
|
|
3080
|
-
constraintTags: extension.constraintTags.map((tag) => ({ tagName: tag.tagName }))
|
|
3081
|
-
} : {},
|
|
3082
|
-
...extension.metadataSlots !== void 0 ? {
|
|
3083
|
-
metadataSlots: extension.metadataSlots
|
|
3084
|
-
} : {},
|
|
3085
|
-
...extension.types !== void 0 ? {
|
|
3086
|
-
customTypes: extension.types.map((t) => ({
|
|
3087
|
-
tsTypeNames: t.tsTypeNames ?? [t.typeName]
|
|
3088
|
-
}))
|
|
3089
|
-
} : {}
|
|
3090
|
-
}))
|
|
3091
|
-
} : {}
|
|
3092
|
-
});
|
|
3093
|
-
if (result.diagnostics.length === 0) {
|
|
3094
|
-
return emit("C-pass", []);
|
|
3095
|
-
}
|
|
3096
|
-
const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
|
|
3097
|
-
if (setupDiagnostic !== void 0) {
|
|
3098
|
-
return emit("C-reject", [
|
|
3099
|
-
makeDiagnostic(
|
|
3100
|
-
setupDiagnostic.kind === "unsupported-custom-type-override" ? "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" : "SYNTHETIC_SETUP_FAILURE",
|
|
3101
|
-
setupDiagnostic.message,
|
|
3102
|
-
provenance
|
|
3103
|
-
)
|
|
3104
|
-
]);
|
|
3105
|
-
}
|
|
3106
|
-
const expectedLabel = definition.valueKind === null ? "compatible argument" : capabilityLabel(definition.valueKind);
|
|
3107
|
-
return emit("C-reject", [
|
|
3108
|
-
makeDiagnostic(
|
|
3109
|
-
"TYPE_MISMATCH",
|
|
3110
|
-
`Tag "@${tagName}" received an invalid argument for ${expectedLabel}.`,
|
|
3111
|
-
provenance
|
|
3112
|
-
)
|
|
3113
|
-
]);
|
|
2905
|
+
return emit("C-pass", []);
|
|
3114
2906
|
}
|
|
3115
2907
|
function getExtensionTagNames(options) {
|
|
3116
2908
|
return [
|
|
3117
2909
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
3118
|
-
(extension) => (extension.constraintTags ?? []).map((tag) => (0,
|
|
2910
|
+
(extension) => (extension.constraintTags ?? []).map((tag) => (0, import_internal4.normalizeFormSpecTagName)(tag.tagName))
|
|
3119
2911
|
) ?? [],
|
|
3120
2912
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
3121
|
-
(extension) => (extension.metadataSlots ?? []).map((slot) => (0,
|
|
2913
|
+
(extension) => (extension.metadataSlots ?? []).map((slot) => (0, import_internal4.normalizeFormSpecTagName)(slot.tagName))
|
|
3122
2914
|
) ?? []
|
|
3123
2915
|
].sort();
|
|
3124
2916
|
}
|
|
@@ -3130,9 +2922,9 @@ function getExtensionRegistryCacheKey(registry) {
|
|
|
3130
2922
|
(extension) => JSON.stringify({
|
|
3131
2923
|
extensionId: extension.extensionId,
|
|
3132
2924
|
typeNames: extension.types?.map((type) => type.typeName) ?? [],
|
|
3133
|
-
constraintTags: extension.constraintTags?.map((tag) => (0,
|
|
2925
|
+
constraintTags: extension.constraintTags?.map((tag) => (0, import_internal4.normalizeFormSpecTagName)(tag.tagName)) ?? [],
|
|
3134
2926
|
metadataSlots: extension.metadataSlots?.map((slot) => ({
|
|
3135
|
-
tagName: (0,
|
|
2927
|
+
tagName: (0, import_internal4.normalizeFormSpecTagName)(slot.tagName),
|
|
3136
2928
|
declarationKinds: [...slot.declarationKinds].sort(),
|
|
3137
2929
|
allowBare: slot.allowBare !== false,
|
|
3138
2930
|
qualifiers: (slot.qualifiers ?? []).map((qualifier) => ({
|
|
@@ -3153,8 +2945,8 @@ function getParseCacheKey(node, file, options) {
|
|
|
3153
2945
|
start: node.getFullStart(),
|
|
3154
2946
|
end: node.getEnd(),
|
|
3155
2947
|
fieldType: options?.fieldType ?? null,
|
|
3156
|
-
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node,
|
|
3157
|
-
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node,
|
|
2948
|
+
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node, TYPE_FORMAT_FLAGS) : null,
|
|
2949
|
+
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node, TYPE_FORMAT_FLAGS) : null,
|
|
3158
2950
|
extensions: getExtensionRegistryCacheKey(options?.extensionRegistry)
|
|
3159
2951
|
});
|
|
3160
2952
|
}
|
|
@@ -3164,6 +2956,16 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3164
2956
|
if (cached !== void 0) {
|
|
3165
2957
|
return cached;
|
|
3166
2958
|
}
|
|
2959
|
+
const setupDiags = options?.extensionRegistry?.setupDiagnostics;
|
|
2960
|
+
if (setupDiags !== void 0 && setupDiags.length > 0) {
|
|
2961
|
+
const result2 = {
|
|
2962
|
+
constraints: [],
|
|
2963
|
+
annotations: [],
|
|
2964
|
+
diagnostics: (0, import_internal5._emitSetupDiagnostics)(setupDiags, file)
|
|
2965
|
+
};
|
|
2966
|
+
parseResultCache.set(cacheKey, result2);
|
|
2967
|
+
return result2;
|
|
2968
|
+
}
|
|
3167
2969
|
const constraints = [];
|
|
3168
2970
|
const annotations = [];
|
|
3169
2971
|
const diagnostics = [];
|
|
@@ -3173,14 +2975,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3173
2975
|
let placeholderProvenance;
|
|
3174
2976
|
const sourceFile = node.getSourceFile();
|
|
3175
2977
|
const sourceText = sourceFile.getFullText();
|
|
3176
|
-
const
|
|
3177
|
-
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
3178
|
-
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2978
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3179
2979
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
3180
2980
|
const extensionTagNames = getExtensionTagNames(options);
|
|
3181
2981
|
if (commentRanges) {
|
|
3182
2982
|
for (const range of commentRanges) {
|
|
3183
|
-
if (range.kind !==
|
|
2983
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
3184
2984
|
continue;
|
|
3185
2985
|
}
|
|
3186
2986
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3188,7 +2988,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3188
2988
|
continue;
|
|
3189
2989
|
}
|
|
3190
2990
|
const extensions = options?.extensionRegistry?.extensions;
|
|
3191
|
-
const unified = (0,
|
|
2991
|
+
const unified = (0, import_internal4.parseUnifiedComment)(commentText, {
|
|
3192
2992
|
offset: range.pos,
|
|
3193
2993
|
extensionTagNames,
|
|
3194
2994
|
...extensions !== void 0 ? { extensions } : {}
|
|
@@ -3223,13 +3023,13 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3223
3023
|
}
|
|
3224
3024
|
continue;
|
|
3225
3025
|
}
|
|
3226
|
-
if (
|
|
3026
|
+
if (import_internal4.TAGS_REQUIRING_RAW_TEXT.has(tagName)) {
|
|
3227
3027
|
const fallback = rawTextFallbacks.get(tagName)?.shift();
|
|
3228
|
-
const text2 = (0,
|
|
3028
|
+
const text2 = (0, import_internal4.choosePreferredPayloadText)(tag.resolvedPayloadText, fallback?.text ?? "");
|
|
3229
3029
|
if (text2 === "") continue;
|
|
3230
3030
|
const provenance2 = provenanceForParsedTag(tag, sourceFile, file);
|
|
3231
3031
|
if (tagName === "defaultValue") {
|
|
3232
|
-
annotations.push((0,
|
|
3032
|
+
annotations.push((0, import_internal4.parseDefaultValueTagValue)(text2, provenance2));
|
|
3233
3033
|
continue;
|
|
3234
3034
|
}
|
|
3235
3035
|
processConstraintTag(
|
|
@@ -3239,7 +3039,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3239
3039
|
provenance2,
|
|
3240
3040
|
node,
|
|
3241
3041
|
sourceFile,
|
|
3242
|
-
supportingDeclarations,
|
|
3243
3042
|
options,
|
|
3244
3043
|
constraints,
|
|
3245
3044
|
diagnostics
|
|
@@ -3257,7 +3056,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3257
3056
|
provenance,
|
|
3258
3057
|
node,
|
|
3259
3058
|
sourceFile,
|
|
3260
|
-
supportingDeclarations,
|
|
3261
3059
|
options,
|
|
3262
3060
|
constraints,
|
|
3263
3061
|
diagnostics
|
|
@@ -3311,7 +3109,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3311
3109
|
if (text === "") continue;
|
|
3312
3110
|
const provenance = fallback.provenance;
|
|
3313
3111
|
if (tagName === "defaultValue") {
|
|
3314
|
-
annotations.push((0,
|
|
3112
|
+
annotations.push((0, import_internal4.parseDefaultValueTagValue)(text, provenance));
|
|
3315
3113
|
continue;
|
|
3316
3114
|
}
|
|
3317
3115
|
processConstraintTag(
|
|
@@ -3321,7 +3119,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3321
3119
|
provenance,
|
|
3322
3120
|
node,
|
|
3323
3121
|
sourceFile,
|
|
3324
|
-
supportingDeclarations,
|
|
3325
3122
|
options,
|
|
3326
3123
|
constraints,
|
|
3327
3124
|
diagnostics
|
|
@@ -3337,13 +3134,13 @@ function extractDisplayNameMetadata(node) {
|
|
|
3337
3134
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3338
3135
|
const sourceFile = node.getSourceFile();
|
|
3339
3136
|
const sourceText = sourceFile.getFullText();
|
|
3340
|
-
const commentRanges =
|
|
3137
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3341
3138
|
if (commentRanges) {
|
|
3342
3139
|
for (const range of commentRanges) {
|
|
3343
|
-
if (range.kind !==
|
|
3140
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3344
3141
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3345
3142
|
if (!commentText.startsWith("/**")) continue;
|
|
3346
|
-
const unified = (0,
|
|
3143
|
+
const unified = (0, import_internal4.parseUnifiedComment)(commentText);
|
|
3347
3144
|
for (const tag of unified.tags) {
|
|
3348
3145
|
if (tag.normalizedTagName !== "displayName") {
|
|
3349
3146
|
continue;
|
|
@@ -3365,9 +3162,9 @@ function extractDisplayNameMetadata(node) {
|
|
|
3365
3162
|
}
|
|
3366
3163
|
function collectRawTextFallbacks(node, file) {
|
|
3367
3164
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3368
|
-
for (const tag of
|
|
3165
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
3369
3166
|
const tagName = (0, import_internals4.normalizeConstraintTagName)(tag.tagName.text);
|
|
3370
|
-
if (!
|
|
3167
|
+
if (!import_internal4.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3371
3168
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
3372
3169
|
if (commentText === "") continue;
|
|
3373
3170
|
const entries = fallbacks.get(tagName) ?? [];
|
|
@@ -3380,7 +3177,7 @@ function collectRawTextFallbacks(node, file) {
|
|
|
3380
3177
|
return fallbacks;
|
|
3381
3178
|
}
|
|
3382
3179
|
function isMemberTargetDisplayName(text) {
|
|
3383
|
-
return (0,
|
|
3180
|
+
return (0, import_internal4.parseTagSyntax)("displayName", text).target !== null;
|
|
3384
3181
|
}
|
|
3385
3182
|
function provenanceForComment(range, sourceFile, file, tagName) {
|
|
3386
3183
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);
|
|
@@ -3420,21 +3217,21 @@ function getTagCommentText(tag) {
|
|
|
3420
3217
|
if (typeof tag.comment === "string") {
|
|
3421
3218
|
return tag.comment;
|
|
3422
3219
|
}
|
|
3423
|
-
return
|
|
3220
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
3424
3221
|
}
|
|
3425
|
-
var
|
|
3222
|
+
var ts3, import_internal4, import_internals4, import_internals5, import_core4, import_internal5, TYPE_FORMAT_FLAGS, MAX_HINT_CANDIDATES, MAX_HINT_DEPTH, parseResultCache;
|
|
3426
3223
|
var init_tsdoc_parser = __esm({
|
|
3427
3224
|
"src/analyzer/tsdoc-parser.ts"() {
|
|
3428
3225
|
"use strict";
|
|
3429
|
-
|
|
3430
|
-
|
|
3226
|
+
ts3 = __toESM(require("typescript"), 1);
|
|
3227
|
+
import_internal4 = require("@formspec/analysis/internal");
|
|
3431
3228
|
import_internals4 = require("@formspec/core/internals");
|
|
3432
3229
|
import_internals5 = require("@formspec/core/internals");
|
|
3433
3230
|
import_core4 = require("@formspec/core");
|
|
3434
3231
|
init_resolve_custom_type();
|
|
3435
3232
|
init_builtin_brands();
|
|
3436
|
-
|
|
3437
|
-
|
|
3233
|
+
import_internal5 = require("@formspec/analysis/internal");
|
|
3234
|
+
TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
3438
3235
|
MAX_HINT_CANDIDATES = 5;
|
|
3439
3236
|
MAX_HINT_DEPTH = 3;
|
|
3440
3237
|
parseResultCache = /* @__PURE__ */ new Map();
|
|
@@ -3456,18 +3253,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3456
3253
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3457
3254
|
if (!initializer) return null;
|
|
3458
3255
|
let value;
|
|
3459
|
-
if (
|
|
3256
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
3460
3257
|
value = initializer.text;
|
|
3461
|
-
} else if (
|
|
3258
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
3462
3259
|
value = Number(initializer.text);
|
|
3463
|
-
} else if (initializer.kind ===
|
|
3260
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
3464
3261
|
value = true;
|
|
3465
|
-
} else if (initializer.kind ===
|
|
3262
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
3466
3263
|
value = false;
|
|
3467
|
-
} else if (initializer.kind ===
|
|
3264
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
3468
3265
|
value = null;
|
|
3469
|
-
} else if (
|
|
3470
|
-
if (initializer.operator ===
|
|
3266
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
3267
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
3471
3268
|
value = -Number(initializer.operand.text);
|
|
3472
3269
|
}
|
|
3473
3270
|
}
|
|
@@ -3486,39 +3283,39 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3486
3283
|
}
|
|
3487
3284
|
};
|
|
3488
3285
|
}
|
|
3489
|
-
var
|
|
3286
|
+
var ts4;
|
|
3490
3287
|
var init_jsdoc_constraints = __esm({
|
|
3491
3288
|
"src/analyzer/jsdoc-constraints.ts"() {
|
|
3492
3289
|
"use strict";
|
|
3493
|
-
|
|
3290
|
+
ts4 = __toESM(require("typescript"), 1);
|
|
3494
3291
|
init_tsdoc_parser();
|
|
3495
3292
|
}
|
|
3496
3293
|
});
|
|
3497
3294
|
|
|
3498
3295
|
// src/analyzer/class-analyzer.ts
|
|
3499
3296
|
function isObjectType(type) {
|
|
3500
|
-
return !!(type.flags &
|
|
3297
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
3501
3298
|
}
|
|
3502
3299
|
function isIntersectionType(type) {
|
|
3503
|
-
return !!(type.flags &
|
|
3300
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
3504
3301
|
}
|
|
3505
3302
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3506
|
-
if (
|
|
3303
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3507
3304
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3508
3305
|
}
|
|
3509
|
-
if (
|
|
3306
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
3510
3307
|
return true;
|
|
3511
3308
|
}
|
|
3512
|
-
return
|
|
3309
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3513
3310
|
}
|
|
3514
3311
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3515
3312
|
if (isIntersectionType(type)) {
|
|
3516
3313
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3517
3314
|
}
|
|
3518
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3315
|
+
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);
|
|
3519
3316
|
}
|
|
3520
3317
|
function isTypeReference(type) {
|
|
3521
|
-
return !!(type.flags &
|
|
3318
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
3522
3319
|
}
|
|
3523
3320
|
function makeParseOptions(extensionRegistry, fieldType, checker, subjectType, hostType) {
|
|
3524
3321
|
if (extensionRegistry === void 0 && fieldType === void 0 && checker === void 0 && subjectType === void 0 && hostType === void 0) {
|
|
@@ -3539,8 +3336,19 @@ function createAnalyzerMetadataPolicy(input, discriminator) {
|
|
|
3539
3336
|
discriminator
|
|
3540
3337
|
};
|
|
3541
3338
|
}
|
|
3339
|
+
function deduplicateDiagnostics(diagnostics) {
|
|
3340
|
+
if (diagnostics.length <= 1) return diagnostics;
|
|
3341
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3342
|
+
return diagnostics.filter((d) => {
|
|
3343
|
+
if (!DEDUPLICATABLE_DIAGNOSTIC_CODES.has(d.code)) return true;
|
|
3344
|
+
const key = `${d.code}\0${d.message}`;
|
|
3345
|
+
if (seen.has(key)) return false;
|
|
3346
|
+
seen.add(key);
|
|
3347
|
+
return true;
|
|
3348
|
+
});
|
|
3349
|
+
}
|
|
3542
3350
|
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
3543
|
-
const analysis = (0,
|
|
3351
|
+
const analysis = (0, import_internal6.analyzeMetadataForNodeWithChecker)({
|
|
3544
3352
|
checker,
|
|
3545
3353
|
node,
|
|
3546
3354
|
logicalName,
|
|
@@ -3575,10 +3383,120 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3575
3383
|
}
|
|
3576
3384
|
return resolvedMetadata;
|
|
3577
3385
|
}
|
|
3386
|
+
function getInheritableAnnotationStringValue(annotation) {
|
|
3387
|
+
if (annotation.annotationKind === "format") return annotation.value;
|
|
3388
|
+
return void 0;
|
|
3389
|
+
}
|
|
3390
|
+
function isOverridingInheritableAnnotation(annotation) {
|
|
3391
|
+
const value = getInheritableAnnotationStringValue(annotation);
|
|
3392
|
+
if (value === void 0) return true;
|
|
3393
|
+
return value.trim().length > 0;
|
|
3394
|
+
}
|
|
3395
|
+
function collectInheritedTypeAnnotations(derivedDecl, existingAnnotations, checker, extensionRegistry) {
|
|
3396
|
+
const existingKinds = new Set(
|
|
3397
|
+
existingAnnotations.filter(isOverridingInheritableAnnotation).map((a) => a.annotationKind)
|
|
3398
|
+
);
|
|
3399
|
+
const needed = /* @__PURE__ */ new Set();
|
|
3400
|
+
for (const kind of INHERITABLE_TYPE_ANNOTATION_KINDS) {
|
|
3401
|
+
if (!existingKinds.has(kind)) needed.add(kind);
|
|
3402
|
+
}
|
|
3403
|
+
if (needed.size === 0) return [];
|
|
3404
|
+
const inherited = [];
|
|
3405
|
+
const seen = /* @__PURE__ */ new Set([derivedDecl]);
|
|
3406
|
+
const queue = [];
|
|
3407
|
+
const resolveSymbolTarget = (sym) => {
|
|
3408
|
+
if ((sym.flags & ts5.SymbolFlags.Alias) === 0) return sym;
|
|
3409
|
+
try {
|
|
3410
|
+
return checker.getAliasedSymbol(sym);
|
|
3411
|
+
} catch {
|
|
3412
|
+
return sym;
|
|
3413
|
+
}
|
|
3414
|
+
};
|
|
3415
|
+
const isObjectShapedTypeAlias = (alias) => {
|
|
3416
|
+
const type = checker.getTypeFromTypeNode(alias.type);
|
|
3417
|
+
if ((type.flags & ts5.TypeFlags.Object) !== 0) return true;
|
|
3418
|
+
if (type.isIntersection()) return true;
|
|
3419
|
+
return false;
|
|
3420
|
+
};
|
|
3421
|
+
const enqueueCandidate = (baseDecl, fromTypeAliasRhs) => {
|
|
3422
|
+
if (seen.has(baseDecl)) return;
|
|
3423
|
+
if (ts5.isClassDeclaration(baseDecl) || ts5.isInterfaceDeclaration(baseDecl)) {
|
|
3424
|
+
seen.add(baseDecl);
|
|
3425
|
+
queue.push(baseDecl);
|
|
3426
|
+
return;
|
|
3427
|
+
}
|
|
3428
|
+
if (ts5.isTypeAliasDeclaration(baseDecl)) {
|
|
3429
|
+
if (!fromTypeAliasRhs && !isObjectShapedTypeAlias(baseDecl)) return;
|
|
3430
|
+
seen.add(baseDecl);
|
|
3431
|
+
queue.push(baseDecl);
|
|
3432
|
+
}
|
|
3433
|
+
};
|
|
3434
|
+
const enqueueBasesOf = (decl) => {
|
|
3435
|
+
if (ts5.isTypeAliasDeclaration(decl)) {
|
|
3436
|
+
const rhs = decl.type;
|
|
3437
|
+
if (!ts5.isTypeReferenceNode(rhs)) return;
|
|
3438
|
+
const sym = checker.getSymbolAtLocation(rhs.typeName);
|
|
3439
|
+
if (!sym) return;
|
|
3440
|
+
const target = resolveSymbolTarget(sym);
|
|
3441
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
3442
|
+
enqueueCandidate(
|
|
3443
|
+
baseDecl,
|
|
3444
|
+
/*fromTypeAliasRhs*/
|
|
3445
|
+
true
|
|
3446
|
+
);
|
|
3447
|
+
}
|
|
3448
|
+
return;
|
|
3449
|
+
}
|
|
3450
|
+
const heritageClauses = decl.heritageClauses;
|
|
3451
|
+
if (!heritageClauses) return;
|
|
3452
|
+
for (const clause of heritageClauses) {
|
|
3453
|
+
if (clause.token !== ts5.SyntaxKind.ExtendsKeyword) continue;
|
|
3454
|
+
for (const typeExpr of clause.types) {
|
|
3455
|
+
const sym = checker.getSymbolAtLocation(typeExpr.expression);
|
|
3456
|
+
if (!sym) continue;
|
|
3457
|
+
const target = resolveSymbolTarget(sym);
|
|
3458
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
3459
|
+
enqueueCandidate(
|
|
3460
|
+
baseDecl,
|
|
3461
|
+
/*fromTypeAliasRhs*/
|
|
3462
|
+
false
|
|
3463
|
+
);
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
};
|
|
3468
|
+
enqueueBasesOf(derivedDecl);
|
|
3469
|
+
for (let queueIndex = 0; queueIndex < queue.length && needed.size > 0; queueIndex++) {
|
|
3470
|
+
const baseDecl = queue[queueIndex];
|
|
3471
|
+
if (baseDecl === void 0) continue;
|
|
3472
|
+
const baseFile = baseDecl.getSourceFile().fileName;
|
|
3473
|
+
const baseAnnotations = extractJSDocAnnotationNodes(
|
|
3474
|
+
baseDecl,
|
|
3475
|
+
baseFile,
|
|
3476
|
+
makeParseOptions(extensionRegistry)
|
|
3477
|
+
);
|
|
3478
|
+
for (const annotation of baseAnnotations) {
|
|
3479
|
+
if (!needed.has(annotation.annotationKind)) continue;
|
|
3480
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
3481
|
+
inherited.push(annotation);
|
|
3482
|
+
needed.delete(annotation.annotationKind);
|
|
3483
|
+
}
|
|
3484
|
+
if (needed.size > 0) {
|
|
3485
|
+
enqueueBasesOf(baseDecl);
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
return inherited;
|
|
3489
|
+
}
|
|
3490
|
+
function extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) {
|
|
3491
|
+
const local = extractJSDocAnnotationNodes(namedDecl, file, makeParseOptions(extensionRegistry));
|
|
3492
|
+
const inherited = collectInheritedTypeAnnotations(namedDecl, local, checker, extensionRegistry);
|
|
3493
|
+
if (inherited.length === 0) return [...local];
|
|
3494
|
+
return [...local, ...inherited];
|
|
3495
|
+
}
|
|
3578
3496
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3579
3497
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3580
3498
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3581
|
-
const logicalName =
|
|
3499
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3582
3500
|
const docResult = extractJSDocParseResult(
|
|
3583
3501
|
declaration,
|
|
3584
3502
|
file,
|
|
@@ -3620,13 +3538,19 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3620
3538
|
file,
|
|
3621
3539
|
makeParseOptions(extensionRegistry, void 0, checker, classType, classType)
|
|
3622
3540
|
);
|
|
3623
|
-
const
|
|
3541
|
+
const inheritedClassAnnotations = collectInheritedTypeAnnotations(
|
|
3542
|
+
classDecl,
|
|
3543
|
+
classDoc.annotations,
|
|
3544
|
+
checker,
|
|
3545
|
+
extensionRegistry
|
|
3546
|
+
);
|
|
3547
|
+
const annotations = [...classDoc.annotations, ...inheritedClassAnnotations];
|
|
3624
3548
|
diagnostics.push(...classDoc.diagnostics);
|
|
3625
3549
|
const visiting = /* @__PURE__ */ new Set();
|
|
3626
3550
|
const instanceMethods = [];
|
|
3627
3551
|
const staticMethods = [];
|
|
3628
3552
|
for (const member of classDecl.members) {
|
|
3629
|
-
if (
|
|
3553
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
3630
3554
|
const fieldNode = analyzeFieldToIR(
|
|
3631
3555
|
member,
|
|
3632
3556
|
checker,
|
|
@@ -3642,10 +3566,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3642
3566
|
fields.push(fieldNode);
|
|
3643
3567
|
fieldLayouts.push({});
|
|
3644
3568
|
}
|
|
3645
|
-
} else if (
|
|
3569
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
3646
3570
|
const methodInfo = analyzeMethod(member, checker);
|
|
3647
3571
|
if (methodInfo) {
|
|
3648
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3572
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
3649
3573
|
if (isStatic) {
|
|
3650
3574
|
staticMethods.push(methodInfo);
|
|
3651
3575
|
} else {
|
|
@@ -3677,6 +3601,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3677
3601
|
hostType: classType
|
|
3678
3602
|
}
|
|
3679
3603
|
);
|
|
3604
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3680
3605
|
return {
|
|
3681
3606
|
name,
|
|
3682
3607
|
...metadata !== void 0 && { metadata },
|
|
@@ -3684,7 +3609,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3684
3609
|
fieldLayouts,
|
|
3685
3610
|
typeRegistry,
|
|
3686
3611
|
...annotations.length > 0 && { annotations },
|
|
3687
|
-
...
|
|
3612
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3688
3613
|
instanceMethods,
|
|
3689
3614
|
staticMethods
|
|
3690
3615
|
};
|
|
@@ -3704,11 +3629,20 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3704
3629
|
file,
|
|
3705
3630
|
makeParseOptions(extensionRegistry, void 0, checker, interfaceType, interfaceType)
|
|
3706
3631
|
);
|
|
3707
|
-
const
|
|
3632
|
+
const inheritedInterfaceAnnotations = collectInheritedTypeAnnotations(
|
|
3633
|
+
interfaceDecl,
|
|
3634
|
+
interfaceDoc.annotations,
|
|
3635
|
+
checker,
|
|
3636
|
+
extensionRegistry
|
|
3637
|
+
);
|
|
3638
|
+
const annotations = [
|
|
3639
|
+
...interfaceDoc.annotations,
|
|
3640
|
+
...inheritedInterfaceAnnotations
|
|
3641
|
+
];
|
|
3708
3642
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3709
3643
|
const visiting = /* @__PURE__ */ new Set();
|
|
3710
3644
|
for (const member of interfaceDecl.members) {
|
|
3711
|
-
if (
|
|
3645
|
+
if (ts5.isPropertySignature(member)) {
|
|
3712
3646
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3713
3647
|
member,
|
|
3714
3648
|
checker,
|
|
@@ -3749,6 +3683,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3749
3683
|
hostType: interfaceType
|
|
3750
3684
|
}
|
|
3751
3685
|
);
|
|
3686
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3752
3687
|
return {
|
|
3753
3688
|
name,
|
|
3754
3689
|
...metadata !== void 0 && { metadata },
|
|
@@ -3756,7 +3691,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3756
3691
|
fieldLayouts,
|
|
3757
3692
|
typeRegistry,
|
|
3758
3693
|
...annotations.length > 0 && { annotations },
|
|
3759
|
-
...
|
|
3694
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3760
3695
|
instanceMethods: [],
|
|
3761
3696
|
staticMethods: []
|
|
3762
3697
|
};
|
|
@@ -3766,7 +3701,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3766
3701
|
if (members === null) {
|
|
3767
3702
|
const sourceFile = typeAlias.getSourceFile();
|
|
3768
3703
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3769
|
-
const kindDesc =
|
|
3704
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3770
3705
|
return {
|
|
3771
3706
|
ok: false,
|
|
3772
3707
|
kind: "not-object-like",
|
|
@@ -3801,7 +3736,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3801
3736
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3802
3737
|
const visiting = /* @__PURE__ */ new Set();
|
|
3803
3738
|
for (const member of members) {
|
|
3804
|
-
if (
|
|
3739
|
+
if (ts5.isPropertySignature(member)) {
|
|
3805
3740
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3806
3741
|
member,
|
|
3807
3742
|
checker,
|
|
@@ -3841,6 +3776,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3841
3776
|
hostType: aliasType
|
|
3842
3777
|
}
|
|
3843
3778
|
);
|
|
3779
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
3844
3780
|
return {
|
|
3845
3781
|
ok: true,
|
|
3846
3782
|
analysis: {
|
|
@@ -3850,7 +3786,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3850
3786
|
fieldLayouts: specializedFields.map(() => ({})),
|
|
3851
3787
|
typeRegistry,
|
|
3852
3788
|
...annotations.length > 0 && { annotations },
|
|
3853
|
-
...
|
|
3789
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
3854
3790
|
instanceMethods: [],
|
|
3855
3791
|
staticMethods: []
|
|
3856
3792
|
}
|
|
@@ -3868,20 +3804,20 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3868
3804
|
function getLeadingParsedTags(node) {
|
|
3869
3805
|
const sourceFile = node.getSourceFile();
|
|
3870
3806
|
const sourceText = sourceFile.getFullText();
|
|
3871
|
-
const commentRanges =
|
|
3807
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3872
3808
|
if (commentRanges === void 0) {
|
|
3873
3809
|
return [];
|
|
3874
3810
|
}
|
|
3875
3811
|
const parsedTags = [];
|
|
3876
3812
|
for (const range of commentRanges) {
|
|
3877
|
-
if (range.kind !==
|
|
3813
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
3878
3814
|
continue;
|
|
3879
3815
|
}
|
|
3880
3816
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
3881
3817
|
if (!commentText.startsWith("/**")) {
|
|
3882
3818
|
continue;
|
|
3883
3819
|
}
|
|
3884
|
-
parsedTags.push(...(0,
|
|
3820
|
+
parsedTags.push(...(0, import_internal6.parseCommentBlock)(commentText, { offset: range.pos }).tags);
|
|
3885
3821
|
}
|
|
3886
3822
|
return parsedTags;
|
|
3887
3823
|
}
|
|
@@ -3892,19 +3828,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3892
3828
|
return null;
|
|
3893
3829
|
}
|
|
3894
3830
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3895
|
-
(candidate) =>
|
|
3831
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
3896
3832
|
) ?? propertySymbol.declarations?.[0];
|
|
3897
3833
|
return {
|
|
3898
3834
|
declaration,
|
|
3899
3835
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3900
|
-
optional: !!(propertySymbol.flags &
|
|
3836
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3901
3837
|
};
|
|
3902
3838
|
}
|
|
3903
3839
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3904
3840
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3905
3841
|
}
|
|
3906
3842
|
function isNullishSemanticType(type) {
|
|
3907
|
-
if (type.flags & (
|
|
3843
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
3908
3844
|
return true;
|
|
3909
3845
|
}
|
|
3910
3846
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3914,7 +3850,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3914
3850
|
return false;
|
|
3915
3851
|
}
|
|
3916
3852
|
seen.add(type);
|
|
3917
|
-
if (type.flags &
|
|
3853
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
3918
3854
|
return true;
|
|
3919
3855
|
}
|
|
3920
3856
|
if (type.isUnion()) {
|
|
@@ -3927,13 +3863,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3927
3863
|
return false;
|
|
3928
3864
|
}
|
|
3929
3865
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3930
|
-
if (
|
|
3866
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3931
3867
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3932
3868
|
}
|
|
3933
|
-
if (
|
|
3869
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
3934
3870
|
return [...typeNode.members];
|
|
3935
3871
|
}
|
|
3936
|
-
if (
|
|
3872
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
3937
3873
|
const members = [];
|
|
3938
3874
|
for (const intersectionMember of typeNode.types) {
|
|
3939
3875
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -4096,7 +4032,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
4096
4032
|
}
|
|
4097
4033
|
if (propertyType.isUnion()) {
|
|
4098
4034
|
const nonNullMembers = propertyType.types.filter(
|
|
4099
|
-
(member) => !(member.flags & (
|
|
4035
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4100
4036
|
);
|
|
4101
4037
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4102
4038
|
diagnostics.push(
|
|
@@ -4145,13 +4081,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
4145
4081
|
seen.add(type);
|
|
4146
4082
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
4147
4083
|
if (symbol !== void 0) {
|
|
4148
|
-
const aliased = symbol.flags &
|
|
4084
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
4149
4085
|
const targetSymbol = aliased ?? symbol;
|
|
4150
4086
|
const declaration = targetSymbol.declarations?.find(
|
|
4151
|
-
(candidate) =>
|
|
4087
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
4152
4088
|
);
|
|
4153
4089
|
if (declaration !== void 0) {
|
|
4154
|
-
if (
|
|
4090
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
4155
4091
|
return resolveNamedDiscriminatorDeclaration(
|
|
4156
4092
|
checker.getTypeFromTypeNode(declaration.type),
|
|
4157
4093
|
checker,
|
|
@@ -4179,7 +4115,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4179
4115
|
}
|
|
4180
4116
|
if (boundType.isUnion()) {
|
|
4181
4117
|
const nonNullMembers = boundType.types.filter(
|
|
4182
|
-
(member) => !(member.flags & (
|
|
4118
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4183
4119
|
);
|
|
4184
4120
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4185
4121
|
diagnostics.push(
|
|
@@ -4224,7 +4160,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4224
4160
|
return null;
|
|
4225
4161
|
}
|
|
4226
4162
|
function getDeclarationName(node) {
|
|
4227
|
-
if (
|
|
4163
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
4228
4164
|
return node.name?.text ?? "anonymous";
|
|
4229
4165
|
}
|
|
4230
4166
|
return "anonymous";
|
|
@@ -4279,11 +4215,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4279
4215
|
if (sourceTypeNode === void 0) {
|
|
4280
4216
|
return [];
|
|
4281
4217
|
}
|
|
4282
|
-
const unwrapParentheses = (typeNode) =>
|
|
4218
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4283
4219
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4284
|
-
const referenceTypeNode =
|
|
4220
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4285
4221
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4286
|
-
return
|
|
4222
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4287
4223
|
})();
|
|
4288
4224
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4289
4225
|
return [];
|
|
@@ -4291,7 +4227,7 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4291
4227
|
return referenceTypeNode.typeArguments.map((argumentNode) => {
|
|
4292
4228
|
const argumentType = checker.getTypeFromTypeNode(argumentNode);
|
|
4293
4229
|
const baseSymbol = argumentType.aliasSymbol ?? argumentType.getSymbol();
|
|
4294
|
-
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags &
|
|
4230
|
+
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(baseSymbol) : baseSymbol;
|
|
4295
4231
|
const argumentDecl = argumentSymbol?.declarations?.[0];
|
|
4296
4232
|
if (argumentDecl !== void 0 && argumentDecl.getSourceFile().fileName !== file) {
|
|
4297
4233
|
const argumentName = argumentSymbol?.getName() ?? baseSymbol?.getName();
|
|
@@ -4354,7 +4290,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4354
4290
|
);
|
|
4355
4291
|
}
|
|
4356
4292
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4357
|
-
if (!
|
|
4293
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
4358
4294
|
return null;
|
|
4359
4295
|
}
|
|
4360
4296
|
const name = prop.name.text;
|
|
@@ -4481,7 +4417,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4481
4417
|
const seen = /* @__PURE__ */ new Set();
|
|
4482
4418
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4483
4419
|
for (const member of members) {
|
|
4484
|
-
if (!
|
|
4420
|
+
if (!ts5.isPropertySignature(member)) {
|
|
4485
4421
|
continue;
|
|
4486
4422
|
}
|
|
4487
4423
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4497,7 +4433,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4497
4433
|
return [...duplicates].sort();
|
|
4498
4434
|
}
|
|
4499
4435
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4500
|
-
if (
|
|
4436
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
4501
4437
|
return name.text;
|
|
4502
4438
|
}
|
|
4503
4439
|
return null;
|
|
@@ -4592,28 +4528,28 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4592
4528
|
if (primitiveAlias) {
|
|
4593
4529
|
return primitiveAlias;
|
|
4594
4530
|
}
|
|
4595
|
-
if (
|
|
4531
|
+
if ((0, import_internal3._isIntegerBrandedType)(type)) {
|
|
4596
4532
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4597
4533
|
}
|
|
4598
|
-
if (type.flags &
|
|
4534
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4599
4535
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4600
4536
|
}
|
|
4601
|
-
if (type.flags &
|
|
4537
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4602
4538
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4603
4539
|
}
|
|
4604
|
-
if (type.flags & (
|
|
4540
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4605
4541
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4606
4542
|
}
|
|
4607
|
-
if (type.flags &
|
|
4543
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4608
4544
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4609
4545
|
}
|
|
4610
|
-
if (type.flags &
|
|
4546
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4611
4547
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4612
4548
|
}
|
|
4613
|
-
if (type.flags &
|
|
4549
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
4614
4550
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4615
4551
|
}
|
|
4616
|
-
if (type.flags &
|
|
4552
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
4617
4553
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4618
4554
|
}
|
|
4619
4555
|
if (type.isStringLiteral()) {
|
|
@@ -4700,10 +4636,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4700
4636
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4701
4637
|
}
|
|
4702
4638
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4703
|
-
if (!(type.flags & (
|
|
4639
|
+
if (!(type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null)) && !(0, import_internal3._isIntegerBrandedType)(type)) {
|
|
4704
4640
|
return null;
|
|
4705
4641
|
}
|
|
4706
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4642
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4707
4643
|
if (!aliasDecl) {
|
|
4708
4644
|
return null;
|
|
4709
4645
|
}
|
|
@@ -4714,11 +4650,18 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4714
4650
|
...extractJSDocConstraintNodes(aliasDecl, file, makeParseOptions(extensionRegistry)),
|
|
4715
4651
|
...extractTypeAliasConstraintNodes(aliasDecl.type, checker, file, extensionRegistry)
|
|
4716
4652
|
];
|
|
4717
|
-
const
|
|
4653
|
+
const localAnnotations = extractJSDocAnnotationNodes(
|
|
4718
4654
|
aliasDecl,
|
|
4719
4655
|
file,
|
|
4720
4656
|
makeParseOptions(extensionRegistry)
|
|
4721
4657
|
);
|
|
4658
|
+
const inheritedAnnotations = collectInheritedTypeAnnotations(
|
|
4659
|
+
aliasDecl,
|
|
4660
|
+
localAnnotations,
|
|
4661
|
+
checker,
|
|
4662
|
+
extensionRegistry
|
|
4663
|
+
);
|
|
4664
|
+
const annotations = [...localAnnotations, ...inheritedAnnotations];
|
|
4722
4665
|
const metadata = resolveNodeMetadata(
|
|
4723
4666
|
metadataPolicy,
|
|
4724
4667
|
"type",
|
|
@@ -4753,8 +4696,8 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4753
4696
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4754
4697
|
}
|
|
4755
4698
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4756
|
-
const typeNode = sourceNode && (
|
|
4757
|
-
if (!typeNode || !
|
|
4699
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4700
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
4758
4701
|
return void 0;
|
|
4759
4702
|
}
|
|
4760
4703
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4775,7 +4718,7 @@ function resolveNamedTypeWithSourceRecovery(type, sourceNode, checker) {
|
|
|
4775
4718
|
return { typeName: refAliasDecl.name.text, namedDecl: refAliasDecl };
|
|
4776
4719
|
}
|
|
4777
4720
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4778
|
-
if (!
|
|
4721
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
4779
4722
|
return false;
|
|
4780
4723
|
}
|
|
4781
4724
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4783,10 +4726,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4783
4726
|
return false;
|
|
4784
4727
|
}
|
|
4785
4728
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4786
|
-
return !!(resolved.flags & (
|
|
4729
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
4787
4730
|
}
|
|
4788
4731
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4789
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4732
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
4790
4733
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4791
4734
|
visitedAliases.add(nestedAliasDecl);
|
|
4792
4735
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4801,22 +4744,22 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4801
4744
|
visitedAliases
|
|
4802
4745
|
);
|
|
4803
4746
|
}
|
|
4804
|
-
if (
|
|
4747
|
+
if ((0, import_internal3._isIntegerBrandedType)(type)) {
|
|
4805
4748
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4806
4749
|
}
|
|
4807
|
-
if (type.flags &
|
|
4750
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4808
4751
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4809
4752
|
}
|
|
4810
|
-
if (type.flags &
|
|
4753
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4811
4754
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4812
4755
|
}
|
|
4813
|
-
if (type.flags & (
|
|
4756
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4814
4757
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4815
4758
|
}
|
|
4816
|
-
if (type.flags &
|
|
4759
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4817
4760
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4818
4761
|
}
|
|
4819
|
-
if (type.flags &
|
|
4762
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4820
4763
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4821
4764
|
}
|
|
4822
4765
|
return resolveTypeNode(
|
|
@@ -4836,7 +4779,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4836
4779
|
let typeName = null;
|
|
4837
4780
|
let namedDecl;
|
|
4838
4781
|
if (recovered !== null) {
|
|
4839
|
-
const recoveredAliasDecl =
|
|
4782
|
+
const recoveredAliasDecl = ts5.isTypeAliasDeclaration(recovered.namedDecl) ? recovered.namedDecl : void 0;
|
|
4840
4783
|
if (recoveredAliasDecl !== void 0) {
|
|
4841
4784
|
const aliasUnderlyingType = checker.getTypeFromTypeNode(recoveredAliasDecl.type);
|
|
4842
4785
|
const isNonGeneric = recoveredAliasDecl.typeParameters === void 0 || recoveredAliasDecl.typeParameters.length === 0;
|
|
@@ -4858,13 +4801,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4858
4801
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4859
4802
|
);
|
|
4860
4803
|
const nonNullTypes = allTypes.filter(
|
|
4861
|
-
(memberType) => !(memberType.flags & (
|
|
4804
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4862
4805
|
);
|
|
4863
4806
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4864
4807
|
memberType,
|
|
4865
4808
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4866
4809
|
}));
|
|
4867
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4810
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
4868
4811
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4869
4812
|
if (namedDecl) {
|
|
4870
4813
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4884,7 +4827,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4884
4827
|
if (existing !== void 0 && existing.type !== RESOLVING_TYPE_PLACEHOLDER) {
|
|
4885
4828
|
return { kind: "reference", name: typeName, typeArguments: [] };
|
|
4886
4829
|
}
|
|
4887
|
-
const annotations = namedDecl ?
|
|
4830
|
+
const annotations = namedDecl ? extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) : void 0;
|
|
4888
4831
|
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4889
4832
|
metadataPolicy,
|
|
4890
4833
|
"type",
|
|
@@ -4911,7 +4854,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4911
4854
|
const displayName = memberDisplayNames.get(String(value));
|
|
4912
4855
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4913
4856
|
});
|
|
4914
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4857
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
4915
4858
|
if (isBooleanUnion2) {
|
|
4916
4859
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4917
4860
|
const result = hasNull ? {
|
|
@@ -5003,7 +4946,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
5003
4946
|
if (type.getProperties().length > 0) {
|
|
5004
4947
|
return null;
|
|
5005
4948
|
}
|
|
5006
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4949
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
5007
4950
|
if (!indexInfo) {
|
|
5008
4951
|
return null;
|
|
5009
4952
|
}
|
|
@@ -5051,20 +4994,53 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
5051
4994
|
}
|
|
5052
4995
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
5053
4996
|
const name = declaration.name;
|
|
5054
|
-
if (
|
|
4997
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
5055
4998
|
return false;
|
|
5056
4999
|
}
|
|
5057
|
-
if (!
|
|
5000
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
5058
5001
|
return false;
|
|
5059
5002
|
}
|
|
5060
5003
|
}
|
|
5061
5004
|
return true;
|
|
5062
5005
|
}
|
|
5006
|
+
function getPassThroughTypeAliasFromSourceNode(sourceNode, checker, extensionRegistry, resolvedTypeName) {
|
|
5007
|
+
const aliasDecl = getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
5008
|
+
if (!aliasDecl) return void 0;
|
|
5009
|
+
const aliasName = aliasDecl.name.text;
|
|
5010
|
+
if (aliasName === resolvedTypeName) return void 0;
|
|
5011
|
+
if (!ts5.isTypeReferenceNode(aliasDecl.type)) return void 0;
|
|
5012
|
+
if (!hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry)) {
|
|
5013
|
+
return void 0;
|
|
5014
|
+
}
|
|
5015
|
+
return { aliasName, aliasDecl };
|
|
5016
|
+
}
|
|
5017
|
+
function hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry) {
|
|
5018
|
+
const file = aliasDecl.getSourceFile().fileName;
|
|
5019
|
+
const local = extractJSDocAnnotationNodes(aliasDecl, file, makeParseOptions(extensionRegistry));
|
|
5020
|
+
for (const annotation of local) {
|
|
5021
|
+
if (!INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) continue;
|
|
5022
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
5023
|
+
return true;
|
|
5024
|
+
}
|
|
5025
|
+
const inherited = collectInheritedTypeAnnotations(aliasDecl, local, checker, extensionRegistry);
|
|
5026
|
+
for (const annotation of inherited) {
|
|
5027
|
+
if (INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) return true;
|
|
5028
|
+
}
|
|
5029
|
+
return false;
|
|
5030
|
+
}
|
|
5063
5031
|
function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
5064
5032
|
const collectedDiagnostics = diagnostics ?? [];
|
|
5065
5033
|
const typeName = getNamedTypeName(type);
|
|
5066
5034
|
const namedTypeName = typeName ?? void 0;
|
|
5067
5035
|
const namedDecl = getNamedTypeDeclaration(type);
|
|
5036
|
+
const passThroughAlias = getPassThroughTypeAliasFromSourceNode(
|
|
5037
|
+
sourceNode,
|
|
5038
|
+
checker,
|
|
5039
|
+
extensionRegistry,
|
|
5040
|
+
namedTypeName
|
|
5041
|
+
);
|
|
5042
|
+
const effectiveTypeName = passThroughAlias?.aliasName ?? namedTypeName;
|
|
5043
|
+
const effectiveNamedDecl = passThroughAlias?.aliasDecl ?? namedDecl;
|
|
5068
5044
|
const referenceTypeArguments = extractReferenceTypeArguments(
|
|
5069
5045
|
type,
|
|
5070
5046
|
checker,
|
|
@@ -5076,13 +5052,13 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5076
5052
|
extensionRegistry,
|
|
5077
5053
|
collectedDiagnostics
|
|
5078
5054
|
);
|
|
5079
|
-
const instantiatedTypeName =
|
|
5080
|
-
|
|
5055
|
+
const instantiatedTypeName = effectiveTypeName !== void 0 && referenceTypeArguments.length > 0 ? buildInstantiatedReferenceName(
|
|
5056
|
+
effectiveTypeName,
|
|
5081
5057
|
referenceTypeArguments.map((argument) => argument.tsType),
|
|
5082
5058
|
checker
|
|
5083
5059
|
) : void 0;
|
|
5084
|
-
const registryTypeName = instantiatedTypeName ??
|
|
5085
|
-
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" &&
|
|
5060
|
+
const registryTypeName = instantiatedTypeName ?? effectiveTypeName;
|
|
5061
|
+
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" && effectiveNamedDecl?.getSourceFile().fileName !== file);
|
|
5086
5062
|
const clearNamedTypeRegistration = () => {
|
|
5087
5063
|
if (registryTypeName === void 0 || !shouldRegisterNamedType) {
|
|
5088
5064
|
return;
|
|
@@ -5103,7 +5079,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5103
5079
|
typeRegistry[registryTypeName] = {
|
|
5104
5080
|
name: registryTypeName,
|
|
5105
5081
|
type: RESOLVING_TYPE_PLACEHOLDER,
|
|
5106
|
-
provenance: provenanceForDeclaration(
|
|
5082
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5107
5083
|
};
|
|
5108
5084
|
}
|
|
5109
5085
|
visiting.add(type);
|
|
@@ -5135,17 +5111,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5135
5111
|
clearNamedTypeRegistration();
|
|
5136
5112
|
return recordNode;
|
|
5137
5113
|
}
|
|
5138
|
-
const annotations =
|
|
5139
|
-
const metadata =
|
|
5114
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5115
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
5140
5116
|
metadataPolicy,
|
|
5141
5117
|
"type",
|
|
5142
5118
|
registryTypeName,
|
|
5143
|
-
|
|
5119
|
+
effectiveNamedDecl,
|
|
5144
5120
|
checker,
|
|
5145
5121
|
extensionRegistry,
|
|
5146
5122
|
{
|
|
5147
5123
|
checker,
|
|
5148
|
-
declaration:
|
|
5124
|
+
declaration: effectiveNamedDecl,
|
|
5149
5125
|
subjectType: type
|
|
5150
5126
|
}
|
|
5151
5127
|
) : void 0;
|
|
@@ -5154,7 +5130,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5154
5130
|
...metadata !== void 0 && { metadata },
|
|
5155
5131
|
type: recordNode,
|
|
5156
5132
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5157
|
-
provenance: provenanceForDeclaration(
|
|
5133
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5158
5134
|
};
|
|
5159
5135
|
return {
|
|
5160
5136
|
kind: "reference",
|
|
@@ -5180,7 +5156,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5180
5156
|
if (!declaration) continue;
|
|
5181
5157
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
5182
5158
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
5183
|
-
const optional = !!(prop.flags &
|
|
5159
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
5184
5160
|
const propTypeNode = resolveTypeNode(
|
|
5185
5161
|
propType,
|
|
5186
5162
|
checker,
|
|
@@ -5193,7 +5169,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5193
5169
|
collectedDiagnostics
|
|
5194
5170
|
);
|
|
5195
5171
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
5196
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
5172
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
5197
5173
|
declaration,
|
|
5198
5174
|
checker,
|
|
5199
5175
|
file,
|
|
@@ -5203,7 +5179,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5203
5179
|
type,
|
|
5204
5180
|
metadataPolicy,
|
|
5205
5181
|
extensionRegistry
|
|
5206
|
-
) :
|
|
5182
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
5207
5183
|
declaration,
|
|
5208
5184
|
checker,
|
|
5209
5185
|
file,
|
|
@@ -5231,9 +5207,9 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5231
5207
|
visiting.delete(type);
|
|
5232
5208
|
const objectNode = {
|
|
5233
5209
|
kind: "object",
|
|
5234
|
-
properties:
|
|
5210
|
+
properties: effectiveNamedDecl !== void 0 && (ts5.isClassDeclaration(effectiveNamedDecl) || ts5.isInterfaceDeclaration(effectiveNamedDecl) || ts5.isTypeAliasDeclaration(effectiveNamedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
5235
5211
|
properties,
|
|
5236
|
-
|
|
5212
|
+
effectiveNamedDecl,
|
|
5237
5213
|
type,
|
|
5238
5214
|
checker,
|
|
5239
5215
|
file,
|
|
@@ -5243,17 +5219,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5243
5219
|
additionalProperties: true
|
|
5244
5220
|
};
|
|
5245
5221
|
if (registryTypeName !== void 0 && shouldRegisterNamedType) {
|
|
5246
|
-
const annotations =
|
|
5247
|
-
const metadata =
|
|
5222
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
5223
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
5248
5224
|
metadataPolicy,
|
|
5249
5225
|
"type",
|
|
5250
5226
|
registryTypeName,
|
|
5251
|
-
|
|
5227
|
+
effectiveNamedDecl,
|
|
5252
5228
|
checker,
|
|
5253
5229
|
extensionRegistry,
|
|
5254
5230
|
{
|
|
5255
5231
|
checker,
|
|
5256
|
-
declaration:
|
|
5232
|
+
declaration: effectiveNamedDecl,
|
|
5257
5233
|
subjectType: type
|
|
5258
5234
|
}
|
|
5259
5235
|
) : void 0;
|
|
@@ -5262,7 +5238,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
5262
5238
|
...metadata !== void 0 && { metadata },
|
|
5263
5239
|
type: objectNode,
|
|
5264
5240
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
5265
|
-
provenance: provenanceForDeclaration(
|
|
5241
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
5266
5242
|
};
|
|
5267
5243
|
return {
|
|
5268
5244
|
kind: "reference",
|
|
@@ -5279,12 +5255,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5279
5255
|
for (const symbol of symbols) {
|
|
5280
5256
|
const declarations = symbol.declarations;
|
|
5281
5257
|
if (!declarations) continue;
|
|
5282
|
-
const classDecl = declarations.find(
|
|
5258
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
5283
5259
|
if (classDecl) {
|
|
5284
5260
|
const map = /* @__PURE__ */ new Map();
|
|
5285
5261
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
5286
5262
|
for (const member of classDecl.members) {
|
|
5287
|
-
if (
|
|
5263
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
5288
5264
|
const fieldNode = analyzeFieldToIR(
|
|
5289
5265
|
member,
|
|
5290
5266
|
checker,
|
|
@@ -5308,7 +5284,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5308
5284
|
}
|
|
5309
5285
|
return map;
|
|
5310
5286
|
}
|
|
5311
|
-
const interfaceDecl = declarations.find(
|
|
5287
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
5312
5288
|
if (interfaceDecl) {
|
|
5313
5289
|
return buildFieldNodeInfoMap(
|
|
5314
5290
|
interfaceDecl.members,
|
|
@@ -5322,7 +5298,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5322
5298
|
extensionRegistry
|
|
5323
5299
|
);
|
|
5324
5300
|
}
|
|
5325
|
-
const typeAliasDecl = declarations.find(
|
|
5301
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
5326
5302
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5327
5303
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5328
5304
|
return buildFieldNodeInfoMap(
|
|
@@ -5346,10 +5322,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5346
5322
|
return void 0;
|
|
5347
5323
|
}
|
|
5348
5324
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5349
|
-
if (
|
|
5325
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
5350
5326
|
return resolvedTypeNode.elementType;
|
|
5351
5327
|
}
|
|
5352
|
-
if (
|
|
5328
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5353
5329
|
return resolvedTypeNode.typeArguments[0];
|
|
5354
5330
|
}
|
|
5355
5331
|
return void 0;
|
|
@@ -5360,13 +5336,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5360
5336
|
return [];
|
|
5361
5337
|
}
|
|
5362
5338
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5363
|
-
return
|
|
5339
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5364
5340
|
}
|
|
5365
5341
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5366
|
-
if (
|
|
5342
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
5367
5343
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5368
5344
|
}
|
|
5369
|
-
if (!
|
|
5345
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
5370
5346
|
return typeNode;
|
|
5371
5347
|
}
|
|
5372
5348
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5377,15 +5353,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5377
5353
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5378
5354
|
}
|
|
5379
5355
|
function isNullishTypeNode(typeNode) {
|
|
5380
|
-
if (typeNode.kind ===
|
|
5356
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
5381
5357
|
return true;
|
|
5382
5358
|
}
|
|
5383
|
-
return
|
|
5359
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
5384
5360
|
}
|
|
5385
5361
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5386
5362
|
const map = /* @__PURE__ */ new Map();
|
|
5387
5363
|
for (const member of members) {
|
|
5388
|
-
if (
|
|
5364
|
+
if (ts5.isPropertySignature(member)) {
|
|
5389
5365
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5390
5366
|
member,
|
|
5391
5367
|
checker,
|
|
@@ -5410,7 +5386,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5410
5386
|
return map;
|
|
5411
5387
|
}
|
|
5412
5388
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5413
|
-
if (!
|
|
5389
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
5414
5390
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5415
5391
|
const aliasName = typeNode.typeName.getText();
|
|
5416
5392
|
throw new Error(
|
|
@@ -5419,7 +5395,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5419
5395
|
}
|
|
5420
5396
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5421
5397
|
if (!aliasDecl) return [];
|
|
5422
|
-
if (
|
|
5398
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5423
5399
|
const aliasFieldType = resolveTypeNode(
|
|
5424
5400
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5425
5401
|
checker,
|
|
@@ -5463,14 +5439,14 @@ function getNamedTypeName(type) {
|
|
|
5463
5439
|
const symbol = type.getSymbol();
|
|
5464
5440
|
if (symbol?.declarations) {
|
|
5465
5441
|
const decl = symbol.declarations[0];
|
|
5466
|
-
if (decl && (
|
|
5467
|
-
const name =
|
|
5442
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5443
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5468
5444
|
if (name) return name;
|
|
5469
5445
|
}
|
|
5470
5446
|
}
|
|
5471
5447
|
const aliasSymbol = type.aliasSymbol;
|
|
5472
5448
|
if (aliasSymbol?.declarations) {
|
|
5473
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5449
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5474
5450
|
if (aliasDecl) {
|
|
5475
5451
|
return aliasDecl.name.text;
|
|
5476
5452
|
}
|
|
@@ -5481,24 +5457,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5481
5457
|
const symbol = type.getSymbol();
|
|
5482
5458
|
if (symbol?.declarations) {
|
|
5483
5459
|
const decl = symbol.declarations[0];
|
|
5484
|
-
if (decl && (
|
|
5460
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5485
5461
|
return decl;
|
|
5486
5462
|
}
|
|
5487
5463
|
}
|
|
5488
5464
|
const aliasSymbol = type.aliasSymbol;
|
|
5489
5465
|
if (aliasSymbol?.declarations) {
|
|
5490
|
-
return aliasSymbol.declarations.find(
|
|
5466
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5491
5467
|
}
|
|
5492
5468
|
return void 0;
|
|
5493
5469
|
}
|
|
5494
5470
|
function analyzeMethod(method, checker) {
|
|
5495
|
-
if (!
|
|
5471
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
5496
5472
|
return null;
|
|
5497
5473
|
}
|
|
5498
5474
|
const name = method.name.text;
|
|
5499
5475
|
const parameters = [];
|
|
5500
5476
|
for (const param of method.parameters) {
|
|
5501
|
-
if (
|
|
5477
|
+
if (ts5.isIdentifier(param.name)) {
|
|
5502
5478
|
const paramInfo = analyzeParameter(param, checker);
|
|
5503
5479
|
parameters.push(paramInfo);
|
|
5504
5480
|
}
|
|
@@ -5509,7 +5485,7 @@ function analyzeMethod(method, checker) {
|
|
|
5509
5485
|
return { name, parameters, returnTypeNode, returnType };
|
|
5510
5486
|
}
|
|
5511
5487
|
function analyzeParameter(param, checker) {
|
|
5512
|
-
const name =
|
|
5488
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
5513
5489
|
const typeNode = param.type;
|
|
5514
5490
|
const type = checker.getTypeAtLocation(param);
|
|
5515
5491
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5518,25 +5494,25 @@ function analyzeParameter(param, checker) {
|
|
|
5518
5494
|
}
|
|
5519
5495
|
function detectFormSpecReference(typeNode) {
|
|
5520
5496
|
if (!typeNode) return null;
|
|
5521
|
-
if (!
|
|
5522
|
-
const typeName =
|
|
5497
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
5498
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5523
5499
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5524
5500
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5525
|
-
if (!typeArg || !
|
|
5526
|
-
if (
|
|
5501
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
5502
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
5527
5503
|
return typeArg.exprName.text;
|
|
5528
5504
|
}
|
|
5529
|
-
if (
|
|
5505
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
5530
5506
|
return typeArg.exprName.right.text;
|
|
5531
5507
|
}
|
|
5532
5508
|
return null;
|
|
5533
5509
|
}
|
|
5534
|
-
var
|
|
5510
|
+
var ts5, import_internal6, RESOLVING_TYPE_PLACEHOLDER, DEDUPLICATABLE_DIAGNOSTIC_CODES, INHERITABLE_TYPE_ANNOTATION_KINDS, MAX_ALIAS_CHAIN_DEPTH;
|
|
5535
5511
|
var init_class_analyzer = __esm({
|
|
5536
5512
|
"src/analyzer/class-analyzer.ts"() {
|
|
5537
5513
|
"use strict";
|
|
5538
|
-
|
|
5539
|
-
|
|
5514
|
+
ts5 = __toESM(require("typescript"), 1);
|
|
5515
|
+
import_internal6 = require("@formspec/analysis/internal");
|
|
5540
5516
|
init_jsdoc_constraints();
|
|
5541
5517
|
init_tsdoc_parser();
|
|
5542
5518
|
init_resolve_custom_type();
|
|
@@ -5548,6 +5524,11 @@ var init_class_analyzer = __esm({
|
|
|
5548
5524
|
properties: [],
|
|
5549
5525
|
additionalProperties: true
|
|
5550
5526
|
};
|
|
5527
|
+
DEDUPLICATABLE_DIAGNOSTIC_CODES = /* @__PURE__ */ new Set([
|
|
5528
|
+
"SYNTHETIC_SETUP_FAILURE",
|
|
5529
|
+
"UNSUPPORTED_CUSTOM_TYPE_OVERRIDE"
|
|
5530
|
+
]);
|
|
5531
|
+
INHERITABLE_TYPE_ANNOTATION_KINDS = /* @__PURE__ */ new Set(["format"]);
|
|
5551
5532
|
MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5552
5533
|
}
|
|
5553
5534
|
});
|
|
@@ -5568,23 +5549,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5568
5549
|
function createProgramContext(filePath, additionalFiles) {
|
|
5569
5550
|
const absolutePath = path.resolve(filePath);
|
|
5570
5551
|
const fileDir = path.dirname(absolutePath);
|
|
5571
|
-
const configPath =
|
|
5552
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
5572
5553
|
let compilerOptions;
|
|
5573
5554
|
let fileNames;
|
|
5574
5555
|
if (configPath) {
|
|
5575
|
-
const configFile =
|
|
5556
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
5576
5557
|
if (configFile.error) {
|
|
5577
5558
|
throw new Error(
|
|
5578
|
-
`Error reading tsconfig.json: ${
|
|
5559
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5579
5560
|
);
|
|
5580
5561
|
}
|
|
5581
|
-
const parsed =
|
|
5562
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
5582
5563
|
configFile.config,
|
|
5583
|
-
|
|
5564
|
+
ts6.sys,
|
|
5584
5565
|
path.dirname(configPath)
|
|
5585
5566
|
);
|
|
5586
5567
|
if (parsed.errors.length > 0) {
|
|
5587
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5568
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5588
5569
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5589
5570
|
}
|
|
5590
5571
|
compilerOptions = parsed.options;
|
|
@@ -5592,9 +5573,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5592
5573
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5593
5574
|
} else {
|
|
5594
5575
|
compilerOptions = {
|
|
5595
|
-
target:
|
|
5596
|
-
module:
|
|
5597
|
-
moduleResolution:
|
|
5576
|
+
target: ts6.ScriptTarget.ES2022,
|
|
5577
|
+
module: ts6.ModuleKind.NodeNext,
|
|
5578
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
5598
5579
|
strict: true,
|
|
5599
5580
|
skipLibCheck: true,
|
|
5600
5581
|
declaration: true
|
|
@@ -5602,7 +5583,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5602
5583
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5603
5584
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5604
5585
|
}
|
|
5605
|
-
const program =
|
|
5586
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
5606
5587
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5607
5588
|
if (!sourceFile) {
|
|
5608
5589
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5621,19 +5602,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5621
5602
|
result = node;
|
|
5622
5603
|
return;
|
|
5623
5604
|
}
|
|
5624
|
-
|
|
5605
|
+
ts6.forEachChild(node, visit);
|
|
5625
5606
|
}
|
|
5626
5607
|
visit(sourceFile);
|
|
5627
5608
|
return result;
|
|
5628
5609
|
}
|
|
5629
5610
|
function findClassByName(sourceFile, className) {
|
|
5630
|
-
return findNodeByName(sourceFile, className,
|
|
5611
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
5631
5612
|
}
|
|
5632
5613
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5633
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5614
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
5634
5615
|
}
|
|
5635
5616
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5636
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5617
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5637
5618
|
}
|
|
5638
5619
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5639
5620
|
if (rootType.kind === "object") {
|
|
@@ -5673,22 +5654,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5673
5654
|
};
|
|
5674
5655
|
}
|
|
5675
5656
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5676
|
-
if (
|
|
5657
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5677
5658
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5678
5659
|
}
|
|
5679
|
-
if (
|
|
5660
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5680
5661
|
return true;
|
|
5681
5662
|
}
|
|
5682
|
-
return
|
|
5663
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5683
5664
|
}
|
|
5684
5665
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5685
|
-
if (
|
|
5666
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5686
5667
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5687
5668
|
}
|
|
5688
|
-
if (
|
|
5669
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
5689
5670
|
const propertyNames = [];
|
|
5690
5671
|
for (const member of typeNode.members) {
|
|
5691
|
-
if (!
|
|
5672
|
+
if (!ts6.isPropertySignature(member)) {
|
|
5692
5673
|
continue;
|
|
5693
5674
|
}
|
|
5694
5675
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5698,13 +5679,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5698
5679
|
}
|
|
5699
5680
|
return propertyNames;
|
|
5700
5681
|
}
|
|
5701
|
-
if (
|
|
5682
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5702
5683
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5703
5684
|
}
|
|
5704
5685
|
return null;
|
|
5705
5686
|
}
|
|
5706
5687
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5707
|
-
if (!
|
|
5688
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
5708
5689
|
return [];
|
|
5709
5690
|
}
|
|
5710
5691
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5903,11 +5884,11 @@ function makeFileProvenance(filePath) {
|
|
|
5903
5884
|
column: 0
|
|
5904
5885
|
};
|
|
5905
5886
|
}
|
|
5906
|
-
var
|
|
5887
|
+
var ts6, path;
|
|
5907
5888
|
var init_program = __esm({
|
|
5908
5889
|
"src/analyzer/program.ts"() {
|
|
5909
5890
|
"use strict";
|
|
5910
|
-
|
|
5891
|
+
ts6 = __toESM(require("typescript"), 1);
|
|
5911
5892
|
path = __toESM(require("path"), 1);
|
|
5912
5893
|
init_class_analyzer();
|
|
5913
5894
|
}
|
|
@@ -5922,10 +5903,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5922
5903
|
return symbolMap;
|
|
5923
5904
|
}
|
|
5924
5905
|
function visit(node) {
|
|
5925
|
-
if (
|
|
5906
|
+
if (ts7.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5926
5907
|
processDefineCustomTypeCall(node);
|
|
5927
5908
|
}
|
|
5928
|
-
|
|
5909
|
+
ts7.forEachChild(node, visit);
|
|
5929
5910
|
}
|
|
5930
5911
|
function processDefineCustomTypeCall(call) {
|
|
5931
5912
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5962,7 +5943,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5962
5943
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5963
5944
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5964
5945
|
if (callSymbol !== void 0) {
|
|
5965
|
-
const resolved = callSymbol.flags &
|
|
5946
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5966
5947
|
const decl = resolved.declarations?.[0];
|
|
5967
5948
|
if (decl !== void 0) {
|
|
5968
5949
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5970,24 +5951,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5970
5951
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5971
5952
|
}
|
|
5972
5953
|
}
|
|
5973
|
-
return
|
|
5954
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5974
5955
|
}
|
|
5975
5956
|
function extractTypeNameFromCallArg(call) {
|
|
5976
5957
|
const arg = call.arguments[0];
|
|
5977
|
-
if (arg === void 0 || !
|
|
5958
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5978
5959
|
return null;
|
|
5979
5960
|
}
|
|
5980
5961
|
const typeNameProp = arg.properties.find(
|
|
5981
|
-
(p) =>
|
|
5962
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5982
5963
|
);
|
|
5983
|
-
if (typeNameProp === void 0 || !
|
|
5964
|
+
if (typeNameProp === void 0 || !ts7.isStringLiteral(typeNameProp.initializer)) {
|
|
5984
5965
|
return null;
|
|
5985
5966
|
}
|
|
5986
5967
|
return typeNameProp.initializer.text;
|
|
5987
5968
|
}
|
|
5988
5969
|
function extractEnclosingExtensionId(call, checker) {
|
|
5989
|
-
for (let node = call.parent; !
|
|
5990
|
-
if (
|
|
5970
|
+
for (let node = call.parent; !ts7.isSourceFile(node); node = node.parent) {
|
|
5971
|
+
if (ts7.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5991
5972
|
return extractExtensionIdFromCallArg(node);
|
|
5992
5973
|
}
|
|
5993
5974
|
}
|
|
@@ -5996,24 +5977,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5996
5977
|
function isDefineExtensionCall(node, checker) {
|
|
5997
5978
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5998
5979
|
if (callSymbol !== void 0) {
|
|
5999
|
-
const resolved = callSymbol.flags &
|
|
5980
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
6000
5981
|
const decl = resolved.declarations?.[0];
|
|
6001
5982
|
if (decl !== void 0) {
|
|
6002
5983
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
6003
5984
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
6004
5985
|
}
|
|
6005
5986
|
}
|
|
6006
|
-
return
|
|
5987
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
6007
5988
|
}
|
|
6008
5989
|
function extractExtensionIdFromCallArg(call) {
|
|
6009
5990
|
const arg = call.arguments[0];
|
|
6010
|
-
if (arg === void 0 || !
|
|
5991
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
6011
5992
|
return null;
|
|
6012
5993
|
}
|
|
6013
5994
|
const prop = arg.properties.find(
|
|
6014
|
-
(p) =>
|
|
5995
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
6015
5996
|
);
|
|
6016
|
-
if (prop === void 0 || !
|
|
5997
|
+
if (prop === void 0 || !ts7.isStringLiteral(prop.initializer)) {
|
|
6017
5998
|
return null;
|
|
6018
5999
|
}
|
|
6019
6000
|
return prop.initializer.text;
|
|
@@ -6031,11 +6012,11 @@ function findRegistrationByTypeName(registry, typeName) {
|
|
|
6031
6012
|
}
|
|
6032
6013
|
return void 0;
|
|
6033
6014
|
}
|
|
6034
|
-
var
|
|
6015
|
+
var ts7, path2;
|
|
6035
6016
|
var init_symbol_registry = __esm({
|
|
6036
6017
|
"src/extensions/symbol-registry.ts"() {
|
|
6037
6018
|
"use strict";
|
|
6038
|
-
|
|
6019
|
+
ts7 = __toESM(require("typescript"), 1);
|
|
6039
6020
|
path2 = __toESM(require("path"), 1);
|
|
6040
6021
|
init_ts_type_utils();
|
|
6041
6022
|
}
|
|
@@ -6043,7 +6024,7 @@ var init_symbol_registry = __esm({
|
|
|
6043
6024
|
|
|
6044
6025
|
// src/validate/constraint-validator.ts
|
|
6045
6026
|
function validateFieldNode(ctx, field) {
|
|
6046
|
-
const analysis = (0,
|
|
6027
|
+
const analysis = (0, import_internal7.analyzeConstraintTargets)(
|
|
6047
6028
|
field.name,
|
|
6048
6029
|
field.type,
|
|
6049
6030
|
field.constraints,
|
|
@@ -6061,7 +6042,7 @@ function validateFieldNode(ctx, field) {
|
|
|
6061
6042
|
}
|
|
6062
6043
|
function validateObjectProperty(ctx, parentName, property) {
|
|
6063
6044
|
const qualifiedName = `${parentName}.${property.name}`;
|
|
6064
|
-
const analysis = (0,
|
|
6045
|
+
const analysis = (0, import_internal7.analyzeConstraintTargets)(
|
|
6065
6046
|
qualifiedName,
|
|
6066
6047
|
property.type,
|
|
6067
6048
|
property.constraints,
|
|
@@ -6112,11 +6093,11 @@ function validateIR(ir, options) {
|
|
|
6112
6093
|
valid: ctx.diagnostics.every((diagnostic) => diagnostic.severity !== "error")
|
|
6113
6094
|
};
|
|
6114
6095
|
}
|
|
6115
|
-
var
|
|
6096
|
+
var import_internal7;
|
|
6116
6097
|
var init_constraint_validator = __esm({
|
|
6117
6098
|
"src/validate/constraint-validator.ts"() {
|
|
6118
6099
|
"use strict";
|
|
6119
|
-
|
|
6100
|
+
import_internal7 = require("@formspec/analysis/internal");
|
|
6120
6101
|
}
|
|
6121
6102
|
});
|
|
6122
6103
|
|
|
@@ -6298,7 +6279,7 @@ function generateSchemasBatch(options) {
|
|
|
6298
6279
|
return options.targets.map((target) => {
|
|
6299
6280
|
let ctx;
|
|
6300
6281
|
try {
|
|
6301
|
-
const cacheKey =
|
|
6282
|
+
const cacheKey = ts8.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
6302
6283
|
const cachedContext = contextCache.get(cacheKey);
|
|
6303
6284
|
if (cachedContext === void 0) {
|
|
6304
6285
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6357,7 +6338,7 @@ function isMutableRegistry(reg) {
|
|
|
6357
6338
|
}
|
|
6358
6339
|
function resolveStaticOptions(options) {
|
|
6359
6340
|
const legacyRegistry = options.extensionRegistry;
|
|
6360
|
-
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6341
|
+
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6361
6342
|
return {
|
|
6362
6343
|
extensionRegistry: legacyRegistry ?? configRegistry,
|
|
6363
6344
|
// eslint-disable-next-line @typescript-eslint/no-deprecated -- migration bridge reads deprecated fields
|
|
@@ -6369,7 +6350,7 @@ function resolveStaticOptions(options) {
|
|
|
6369
6350
|
};
|
|
6370
6351
|
}
|
|
6371
6352
|
function resolveOptions(options) {
|
|
6372
|
-
const configRegistry = options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6353
|
+
const configRegistry = options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6373
6354
|
const legacyRegistry = options.extensionRegistry;
|
|
6374
6355
|
return {
|
|
6375
6356
|
// When the caller provides the deprecated extensionRegistry field directly,
|
|
@@ -6452,11 +6433,11 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6452
6433
|
relatedLocations: []
|
|
6453
6434
|
};
|
|
6454
6435
|
}
|
|
6455
|
-
var
|
|
6436
|
+
var ts8;
|
|
6456
6437
|
var init_class_schema = __esm({
|
|
6457
6438
|
"src/generators/class-schema.ts"() {
|
|
6458
6439
|
"use strict";
|
|
6459
|
-
|
|
6440
|
+
ts8 = __toESM(require("typescript"), 1);
|
|
6460
6441
|
init_program();
|
|
6461
6442
|
init_class_analyzer();
|
|
6462
6443
|
init_canonicalize();
|
|
@@ -6483,7 +6464,7 @@ function getModuleSymbol(context) {
|
|
|
6483
6464
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6484
6465
|
}
|
|
6485
6466
|
function isSchemaSourceDeclaration(declaration) {
|
|
6486
|
-
return
|
|
6467
|
+
return ts9.isClassDeclaration(declaration) || ts9.isInterfaceDeclaration(declaration) || ts9.isTypeAliasDeclaration(declaration);
|
|
6487
6468
|
}
|
|
6488
6469
|
function resolveModuleExport(context, exportName = "default") {
|
|
6489
6470
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6494,16 +6475,16 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6494
6475
|
if (exportSymbol === null) {
|
|
6495
6476
|
return null;
|
|
6496
6477
|
}
|
|
6497
|
-
return exportSymbol.flags &
|
|
6478
|
+
return exportSymbol.flags & ts9.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6498
6479
|
}
|
|
6499
6480
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6500
6481
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6501
6482
|
}
|
|
6502
|
-
var
|
|
6483
|
+
var ts9;
|
|
6503
6484
|
var init_static_build = __esm({
|
|
6504
6485
|
"src/static-build.ts"() {
|
|
6505
6486
|
"use strict";
|
|
6506
|
-
|
|
6487
|
+
ts9 = __toESM(require("typescript"), 1);
|
|
6507
6488
|
init_program();
|
|
6508
6489
|
}
|
|
6509
6490
|
});
|
|
@@ -6516,17 +6497,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6516
6497
|
};
|
|
6517
6498
|
}
|
|
6518
6499
|
function isNamedTypeDeclaration(declaration) {
|
|
6519
|
-
return
|
|
6500
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6520
6501
|
}
|
|
6521
6502
|
function hasConcreteTypeArguments(type, checker) {
|
|
6522
6503
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6523
6504
|
return true;
|
|
6524
6505
|
}
|
|
6525
|
-
if ((type.flags &
|
|
6506
|
+
if ((type.flags & ts10.TypeFlags.Object) === 0) {
|
|
6526
6507
|
return false;
|
|
6527
6508
|
}
|
|
6528
6509
|
const objectType = type;
|
|
6529
|
-
if ((objectType.objectFlags &
|
|
6510
|
+
if ((objectType.objectFlags & ts10.ObjectFlags.Reference) === 0) {
|
|
6530
6511
|
return false;
|
|
6531
6512
|
}
|
|
6532
6513
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6539,13 +6520,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6539
6520
|
return declaration;
|
|
6540
6521
|
}
|
|
6541
6522
|
}
|
|
6542
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6523
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts10.isTypeAliasDeclaration);
|
|
6543
6524
|
return aliasDeclaration;
|
|
6544
6525
|
}
|
|
6545
6526
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6546
6527
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6547
6528
|
const namedNode = sourceNode;
|
|
6548
|
-
if (namedNode.name !== void 0 &&
|
|
6529
|
+
if (namedNode.name !== void 0 && ts10.isIdentifier(namedNode.name)) {
|
|
6549
6530
|
return namedNode.name.text;
|
|
6550
6531
|
}
|
|
6551
6532
|
}
|
|
@@ -6767,7 +6748,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6767
6748
|
function generateSchemasFromDeclaration(options) {
|
|
6768
6749
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6769
6750
|
const resolved = resolveStaticOptions(options);
|
|
6770
|
-
if (
|
|
6751
|
+
if (ts10.isClassDeclaration(options.declaration)) {
|
|
6771
6752
|
return generateSchemasFromAnalysis(
|
|
6772
6753
|
analyzeClassToIR(
|
|
6773
6754
|
options.declaration,
|
|
@@ -6781,7 +6762,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6781
6762
|
resolved
|
|
6782
6763
|
);
|
|
6783
6764
|
}
|
|
6784
|
-
if (
|
|
6765
|
+
if (ts10.isInterfaceDeclaration(options.declaration)) {
|
|
6785
6766
|
return generateSchemasFromAnalysis(
|
|
6786
6767
|
analyzeInterfaceToIR(
|
|
6787
6768
|
options.declaration,
|
|
@@ -6795,7 +6776,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6795
6776
|
resolved
|
|
6796
6777
|
);
|
|
6797
6778
|
}
|
|
6798
|
-
if (
|
|
6779
|
+
if (ts10.isTypeAliasDeclaration(options.declaration)) {
|
|
6799
6780
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6800
6781
|
options.declaration,
|
|
6801
6782
|
options.context.checker,
|
|
@@ -6854,7 +6835,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6854
6835
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6855
6836
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6856
6837
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6857
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6838
|
+
const fallbackName = options.declaration.name !== void 0 && ts10.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6858
6839
|
return generateSchemasFromResolvedType({
|
|
6859
6840
|
...options,
|
|
6860
6841
|
type,
|
|
@@ -6864,7 +6845,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6864
6845
|
}
|
|
6865
6846
|
function resolveDeclarationMetadata(options) {
|
|
6866
6847
|
const resolved = resolveStaticOptions(options);
|
|
6867
|
-
const analysis = (0,
|
|
6848
|
+
const analysis = (0, import_internal8.analyzeMetadataForNodeWithChecker)({
|
|
6868
6849
|
checker: options.context.checker,
|
|
6869
6850
|
node: options.declaration,
|
|
6870
6851
|
metadata: resolved.metadata,
|
|
@@ -6901,21 +6882,21 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6901
6882
|
if (typeNode === void 0) {
|
|
6902
6883
|
return void 0;
|
|
6903
6884
|
}
|
|
6904
|
-
if (
|
|
6885
|
+
if (ts10.isParenthesizedTypeNode(typeNode)) {
|
|
6905
6886
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6906
6887
|
return unwrapped ?? typeNode;
|
|
6907
6888
|
}
|
|
6908
6889
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6909
6890
|
}
|
|
6910
6891
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6911
|
-
return
|
|
6892
|
+
return ts10.isTypeReferenceNode(typeNode) && ts10.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6912
6893
|
}
|
|
6913
|
-
var
|
|
6894
|
+
var ts10, import_internal8, import_internals6;
|
|
6914
6895
|
var init_discovered_schema = __esm({
|
|
6915
6896
|
"src/generators/discovered-schema.ts"() {
|
|
6916
6897
|
"use strict";
|
|
6917
|
-
|
|
6918
|
-
|
|
6898
|
+
ts10 = __toESM(require("typescript"), 1);
|
|
6899
|
+
import_internal8 = require("@formspec/analysis/internal");
|
|
6919
6900
|
init_class_analyzer();
|
|
6920
6901
|
init_class_schema();
|
|
6921
6902
|
init_ir_generator();
|