@formspec/build 0.1.0-alpha.49 → 0.1.0-alpha.50
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/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/cli.cjs +381 -374
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +339 -334
- package/dist/cli.js.map +1 -1
- package/dist/extensions/resolve-custom-type.d.ts +37 -0
- package/dist/extensions/resolve-custom-type.d.ts.map +1 -0
- package/dist/extensions/symbol-registry.d.ts.map +1 -1
- package/dist/extensions/ts-type-utils.d.ts +40 -0
- package/dist/extensions/ts-type-utils.d.ts.map +1 -0
- package/dist/index.cjs +359 -365
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +328 -334
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +332 -333
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +297 -298
- package/dist/internals.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2219,31 +2219,150 @@ var jsonSchema7Schema = import_zod3.z.lazy(
|
|
|
2219
2219
|
);
|
|
2220
2220
|
|
|
2221
2221
|
// src/generators/class-schema.ts
|
|
2222
|
-
var
|
|
2222
|
+
var ts8 = __toESM(require("typescript"), 1);
|
|
2223
2223
|
|
|
2224
2224
|
// src/analyzer/program.ts
|
|
2225
|
-
var
|
|
2225
|
+
var ts6 = __toESM(require("typescript"), 1);
|
|
2226
2226
|
var path = __toESM(require("path"), 1);
|
|
2227
2227
|
|
|
2228
2228
|
// src/analyzer/class-analyzer.ts
|
|
2229
|
-
var
|
|
2230
|
-
var
|
|
2229
|
+
var ts5 = __toESM(require("typescript"), 1);
|
|
2230
|
+
var import_internal4 = require("@formspec/analysis/internal");
|
|
2231
2231
|
|
|
2232
2232
|
// src/analyzer/jsdoc-constraints.ts
|
|
2233
|
-
var
|
|
2233
|
+
var ts4 = __toESM(require("typescript"), 1);
|
|
2234
2234
|
|
|
2235
2235
|
// src/analyzer/tsdoc-parser.ts
|
|
2236
|
-
var
|
|
2237
|
-
var
|
|
2236
|
+
var ts3 = __toESM(require("typescript"), 1);
|
|
2237
|
+
var import_internal3 = require("@formspec/analysis/internal");
|
|
2238
2238
|
var import_internals4 = require("@formspec/core/internals");
|
|
2239
2239
|
var import_internals5 = require("@formspec/core/internals");
|
|
2240
|
+
|
|
2241
|
+
// src/extensions/resolve-custom-type.ts
|
|
2242
|
+
var ts2 = __toESM(require("typescript"), 1);
|
|
2243
|
+
var import_internal2 = require("@formspec/analysis/internal");
|
|
2244
|
+
|
|
2245
|
+
// src/extensions/ts-type-utils.ts
|
|
2246
|
+
var ts = __toESM(require("typescript"), 1);
|
|
2247
|
+
function collectBrandIdentifiers(type) {
|
|
2248
|
+
if (!type.isIntersection()) {
|
|
2249
|
+
return [];
|
|
2250
|
+
}
|
|
2251
|
+
const brands = [];
|
|
2252
|
+
for (const prop of type.getProperties()) {
|
|
2253
|
+
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
2254
|
+
if (decl === void 0) continue;
|
|
2255
|
+
if (!ts.isPropertySignature(decl) && !ts.isPropertyDeclaration(decl)) continue;
|
|
2256
|
+
if (!ts.isComputedPropertyName(decl.name)) continue;
|
|
2257
|
+
if (!ts.isIdentifier(decl.name.expression)) continue;
|
|
2258
|
+
brands.push(decl.name.expression.text);
|
|
2259
|
+
}
|
|
2260
|
+
return brands;
|
|
2261
|
+
}
|
|
2262
|
+
function resolveCanonicalSymbol(type, checker) {
|
|
2263
|
+
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
2264
|
+
if (raw === void 0) return void 0;
|
|
2265
|
+
return raw.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
2266
|
+
}
|
|
2267
|
+
function extractTypeNodeFromSource(sourceNode) {
|
|
2268
|
+
if (ts.isPropertyDeclaration(sourceNode) || ts.isPropertySignature(sourceNode) || ts.isParameter(sourceNode) || ts.isTypeAliasDeclaration(sourceNode)) {
|
|
2269
|
+
return sourceNode.type;
|
|
2270
|
+
}
|
|
2271
|
+
if (ts.isTypeNode(sourceNode)) {
|
|
2272
|
+
return sourceNode;
|
|
2273
|
+
}
|
|
2274
|
+
return void 0;
|
|
2275
|
+
}
|
|
2276
|
+
function resolveAliasedSymbol(symbol, checker) {
|
|
2277
|
+
if (symbol === void 0) return void 0;
|
|
2278
|
+
return symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
2279
|
+
}
|
|
2280
|
+
function getTypeAliasDeclarationFromTypeReference(typeNode, checker) {
|
|
2281
|
+
const symbol = checker.getSymbolAtLocation(typeNode.typeName);
|
|
2282
|
+
return resolveAliasedSymbol(symbol, checker)?.declarations?.find(ts.isTypeAliasDeclaration);
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
// src/extensions/resolve-custom-type.ts
|
|
2286
|
+
function getTypeNodeRegistrationName(typeNode) {
|
|
2287
|
+
if (ts2.isTypeReferenceNode(typeNode)) {
|
|
2288
|
+
return ts2.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : typeNode.typeName.right.text;
|
|
2289
|
+
}
|
|
2290
|
+
if (ts2.isParenthesizedTypeNode(typeNode)) {
|
|
2291
|
+
return getTypeNodeRegistrationName(typeNode.type);
|
|
2292
|
+
}
|
|
2293
|
+
if (typeNode.kind === ts2.SyntaxKind.BigIntKeyword || typeNode.kind === ts2.SyntaxKind.StringKeyword || typeNode.kind === ts2.SyntaxKind.NumberKeyword || typeNode.kind === ts2.SyntaxKind.BooleanKeyword) {
|
|
2294
|
+
return typeNode.getText();
|
|
2295
|
+
}
|
|
2296
|
+
return null;
|
|
2297
|
+
}
|
|
2298
|
+
function resolveByNameFromTypeNode(typeNode, registry, checker) {
|
|
2299
|
+
if (ts2.isParenthesizedTypeNode(typeNode)) {
|
|
2300
|
+
return resolveByNameFromTypeNode(typeNode.type, registry, checker);
|
|
2301
|
+
}
|
|
2302
|
+
const typeName = getTypeNodeRegistrationName(typeNode);
|
|
2303
|
+
if (typeName !== null) {
|
|
2304
|
+
const byName = registry.findTypeByName(typeName);
|
|
2305
|
+
if (byName !== void 0) {
|
|
2306
|
+
return byName;
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
if (ts2.isTypeReferenceNode(typeNode) && ts2.isIdentifier(typeNode.typeName)) {
|
|
2310
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
2311
|
+
if (aliasDecl !== void 0) {
|
|
2312
|
+
return resolveByNameFromTypeNode(aliasDecl.type, registry, checker);
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
return null;
|
|
2316
|
+
}
|
|
2317
|
+
function resolveCustomTypeFromTsType(type, checker, registry, sourceNode) {
|
|
2318
|
+
if (registry === void 0) {
|
|
2319
|
+
return null;
|
|
2320
|
+
}
|
|
2321
|
+
const stripped = (0, import_internal2.stripNullishUnion)(type);
|
|
2322
|
+
if (sourceNode !== void 0) {
|
|
2323
|
+
const typeNode = extractTypeNodeFromSource(sourceNode);
|
|
2324
|
+
if (typeNode !== void 0) {
|
|
2325
|
+
const byName = resolveByNameFromTypeNode(typeNode, registry, checker);
|
|
2326
|
+
if (byName !== null) {
|
|
2327
|
+
return byName;
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
} else {
|
|
2331
|
+
const typeName = (stripped.aliasSymbol ?? stripped.getSymbol())?.getName();
|
|
2332
|
+
if (typeName !== void 0) {
|
|
2333
|
+
const byName = registry.findTypeByName(typeName);
|
|
2334
|
+
if (byName !== void 0) {
|
|
2335
|
+
return byName;
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
const canonical = resolveCanonicalSymbol(stripped, checker);
|
|
2340
|
+
if (canonical !== void 0) {
|
|
2341
|
+
const bySymbol = registry.findTypeBySymbol(canonical);
|
|
2342
|
+
if (bySymbol !== void 0) {
|
|
2343
|
+
return bySymbol;
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
for (const brand of collectBrandIdentifiers(stripped)) {
|
|
2347
|
+
const byBrand = registry.findTypeByBrand(brand);
|
|
2348
|
+
if (byBrand !== void 0) {
|
|
2349
|
+
return byBrand;
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
return null;
|
|
2353
|
+
}
|
|
2354
|
+
function customTypeIdFromLookup(result) {
|
|
2355
|
+
return `${result.extensionId}/${result.registration.typeName}`;
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
// src/analyzer/tsdoc-parser.ts
|
|
2240
2359
|
function sharedTagValueOptions(options) {
|
|
2241
2360
|
return {
|
|
2242
2361
|
...options?.extensionRegistry !== void 0 ? { registry: options.extensionRegistry } : {},
|
|
2243
2362
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2244
2363
|
};
|
|
2245
2364
|
}
|
|
2246
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
2365
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2247
2366
|
function getExtensionTypeNames(registry) {
|
|
2248
2367
|
if (registry === void 0) {
|
|
2249
2368
|
return /* @__PURE__ */ new Set();
|
|
@@ -2257,23 +2376,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2257
2376
|
function collectImportedNames(sourceFile) {
|
|
2258
2377
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2259
2378
|
for (const statement of sourceFile.statements) {
|
|
2260
|
-
if (
|
|
2379
|
+
if (ts3.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2261
2380
|
const clause = statement.importClause;
|
|
2262
2381
|
if (clause.name !== void 0) {
|
|
2263
2382
|
importedNames.add(clause.name.text);
|
|
2264
2383
|
}
|
|
2265
2384
|
if (clause.namedBindings !== void 0) {
|
|
2266
|
-
if (
|
|
2385
|
+
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
2267
2386
|
for (const specifier of clause.namedBindings.elements) {
|
|
2268
2387
|
importedNames.add(specifier.name.text);
|
|
2269
2388
|
}
|
|
2270
|
-
} else if (
|
|
2389
|
+
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
2271
2390
|
importedNames.add(clause.namedBindings.name.text);
|
|
2272
2391
|
}
|
|
2273
2392
|
}
|
|
2274
2393
|
continue;
|
|
2275
2394
|
}
|
|
2276
|
-
if (
|
|
2395
|
+
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
2277
2396
|
importedNames.add(statement.name.text);
|
|
2278
2397
|
}
|
|
2279
2398
|
}
|
|
@@ -2281,13 +2400,13 @@ function collectImportedNames(sourceFile) {
|
|
|
2281
2400
|
}
|
|
2282
2401
|
function isNonReferenceIdentifier(node) {
|
|
2283
2402
|
const parent = node.parent;
|
|
2284
|
-
if ((
|
|
2403
|
+
if ((ts3.isBindingElement(parent) || ts3.isClassDeclaration(parent) || ts3.isEnumDeclaration(parent) || ts3.isEnumMember(parent) || ts3.isFunctionDeclaration(parent) || ts3.isFunctionExpression(parent) || ts3.isImportClause(parent) || ts3.isImportEqualsDeclaration(parent) || ts3.isImportSpecifier(parent) || ts3.isInterfaceDeclaration(parent) || ts3.isMethodDeclaration(parent) || ts3.isMethodSignature(parent) || ts3.isModuleDeclaration(parent) || ts3.isNamespaceExport(parent) || ts3.isNamespaceImport(parent) || ts3.isParameter(parent) || ts3.isPropertyDeclaration(parent) || ts3.isPropertySignature(parent) || ts3.isSetAccessorDeclaration(parent) || ts3.isGetAccessorDeclaration(parent) || ts3.isTypeAliasDeclaration(parent) || ts3.isTypeParameterDeclaration(parent) || ts3.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2285
2404
|
return true;
|
|
2286
2405
|
}
|
|
2287
|
-
if ((
|
|
2406
|
+
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2288
2407
|
return true;
|
|
2289
2408
|
}
|
|
2290
|
-
if (
|
|
2409
|
+
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
2291
2410
|
return true;
|
|
2292
2411
|
}
|
|
2293
2412
|
return false;
|
|
@@ -2301,11 +2420,11 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
2301
2420
|
if (referencesImportedName) {
|
|
2302
2421
|
return;
|
|
2303
2422
|
}
|
|
2304
|
-
if (
|
|
2423
|
+
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2305
2424
|
referencesImportedName = true;
|
|
2306
2425
|
return;
|
|
2307
2426
|
}
|
|
2308
|
-
|
|
2427
|
+
ts3.forEachChild(node, visit);
|
|
2309
2428
|
};
|
|
2310
2429
|
visit(statement);
|
|
2311
2430
|
return referencesImportedName;
|
|
@@ -2316,9 +2435,9 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
2316
2435
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2317
2436
|
);
|
|
2318
2437
|
return sourceFile.statements.filter((statement) => {
|
|
2319
|
-
if (
|
|
2320
|
-
if (
|
|
2321
|
-
if (
|
|
2438
|
+
if (ts3.isImportDeclaration(statement)) return false;
|
|
2439
|
+
if (ts3.isImportEqualsDeclaration(statement)) return false;
|
|
2440
|
+
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
2322
2441
|
return false;
|
|
2323
2442
|
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2324
2443
|
return false;
|
|
@@ -2350,7 +2469,7 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
2350
2469
|
pushUniqueCompilerDiagnostics(diagnostics, compilerDiagnostics);
|
|
2351
2470
|
return;
|
|
2352
2471
|
}
|
|
2353
|
-
const constraintNode = (0,
|
|
2472
|
+
const constraintNode = (0, import_internal3.parseConstraintTagValue)(
|
|
2354
2473
|
tagName,
|
|
2355
2474
|
text,
|
|
2356
2475
|
provenance,
|
|
@@ -2400,12 +2519,12 @@ function supportsConstraintCapability(type, checker, capability) {
|
|
|
2400
2519
|
if (capability === void 0) {
|
|
2401
2520
|
return true;
|
|
2402
2521
|
}
|
|
2403
|
-
if ((0,
|
|
2522
|
+
if ((0, import_internal3.hasTypeSemanticCapability)(type, checker, capability)) {
|
|
2404
2523
|
return true;
|
|
2405
2524
|
}
|
|
2406
2525
|
if (capability === "string-like") {
|
|
2407
2526
|
const itemType = getArrayElementType(type, checker);
|
|
2408
|
-
return itemType !== null && (0,
|
|
2527
|
+
return itemType !== null && (0, import_internal3.hasTypeSemanticCapability)(itemType, checker, capability);
|
|
2409
2528
|
}
|
|
2410
2529
|
return false;
|
|
2411
2530
|
}
|
|
@@ -2416,7 +2535,7 @@ function stripHintNullishUnion(type) {
|
|
|
2416
2535
|
return type;
|
|
2417
2536
|
}
|
|
2418
2537
|
const nonNullish = type.types.filter(
|
|
2419
|
-
(member) => (member.flags & (
|
|
2538
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
2420
2539
|
);
|
|
2421
2540
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2422
2541
|
return nonNullish[0];
|
|
@@ -2432,10 +2551,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2432
2551
|
}
|
|
2433
2552
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2434
2553
|
const name = declaration.name;
|
|
2435
|
-
if (
|
|
2554
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
2436
2555
|
return false;
|
|
2437
2556
|
}
|
|
2438
|
-
if (!
|
|
2557
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
2439
2558
|
return false;
|
|
2440
2559
|
}
|
|
2441
2560
|
}
|
|
@@ -2451,7 +2570,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2451
2570
|
if (isCallableType(stripped)) {
|
|
2452
2571
|
return;
|
|
2453
2572
|
}
|
|
2454
|
-
if (!(0,
|
|
2573
|
+
if (!(0, import_internal3.hasTypeSemanticCapability)(stripped, checker, "object-like")) {
|
|
2455
2574
|
return;
|
|
2456
2575
|
}
|
|
2457
2576
|
for (const property of stripped.getProperties()) {
|
|
@@ -2469,7 +2588,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2469
2588
|
continue;
|
|
2470
2589
|
}
|
|
2471
2590
|
const strippedPropertyType = stripHintNullishUnion(propertyType);
|
|
2472
|
-
if (!isCallableType(strippedPropertyType) && (0,
|
|
2591
|
+
if (!isCallableType(strippedPropertyType) && (0, import_internal3.hasTypeSemanticCapability)(strippedPropertyType, checker, "object-like")) {
|
|
2473
2592
|
visit(strippedPropertyType, path4, depth + 1);
|
|
2474
2593
|
}
|
|
2475
2594
|
}
|
|
@@ -2478,7 +2597,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
2478
2597
|
return out;
|
|
2479
2598
|
}
|
|
2480
2599
|
function buildPathTargetHint(subjectType, checker, capability, tagName, argumentText) {
|
|
2481
|
-
if (!(0,
|
|
2600
|
+
if (!(0, import_internal3.hasTypeSemanticCapability)(subjectType, checker, "object-like")) {
|
|
2482
2601
|
return null;
|
|
2483
2602
|
}
|
|
2484
2603
|
const candidates = collectObjectSubfieldCandidates(subjectType, checker, capability);
|
|
@@ -2589,11 +2708,11 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2589
2708
|
if (checker === void 0 || subjectType === void 0) {
|
|
2590
2709
|
return [];
|
|
2591
2710
|
}
|
|
2592
|
-
const placement = (0,
|
|
2711
|
+
const placement = (0, import_internal3.resolveDeclarationPlacement)(node);
|
|
2593
2712
|
if (placement === null) {
|
|
2594
2713
|
return [];
|
|
2595
2714
|
}
|
|
2596
|
-
const definition = (0,
|
|
2715
|
+
const definition = (0, import_internal3.getTagDefinition)(tagName, options?.extensionRegistry?.extensions);
|
|
2597
2716
|
if (definition === null) {
|
|
2598
2717
|
return [];
|
|
2599
2718
|
}
|
|
@@ -2607,7 +2726,8 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2607
2726
|
];
|
|
2608
2727
|
}
|
|
2609
2728
|
const target = parsedTag?.target ?? null;
|
|
2610
|
-
|
|
2729
|
+
let evaluatedType = subjectType;
|
|
2730
|
+
let targetLabel = node.getText(sourceFile);
|
|
2611
2731
|
if (target !== null) {
|
|
2612
2732
|
if (target.kind !== "path") {
|
|
2613
2733
|
return [
|
|
@@ -2627,7 +2747,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2627
2747
|
)
|
|
2628
2748
|
];
|
|
2629
2749
|
}
|
|
2630
|
-
const resolution = (0,
|
|
2750
|
+
const resolution = (0, import_internal3.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
2631
2751
|
if (resolution.kind === "missing-property") {
|
|
2632
2752
|
return [
|
|
2633
2753
|
makeDiagnostic(
|
|
@@ -2647,29 +2767,30 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2647
2767
|
)
|
|
2648
2768
|
];
|
|
2649
2769
|
}
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
`Target "${target.rawText}": constraint "${tagName}" is only valid on ${capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`,
|
|
2657
|
-
provenance
|
|
2658
|
-
)
|
|
2659
|
-
];
|
|
2770
|
+
evaluatedType = resolution.type;
|
|
2771
|
+
targetLabel = target.rawText;
|
|
2772
|
+
}
|
|
2773
|
+
const hasBroadening = (() => {
|
|
2774
|
+
if (target === null) {
|
|
2775
|
+
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2660
2776
|
}
|
|
2661
|
-
|
|
2777
|
+
const registry = options?.extensionRegistry;
|
|
2778
|
+
if (registry === void 0) return false;
|
|
2779
|
+
const resolved = resolveCustomTypeFromTsType(evaluatedType, checker, registry);
|
|
2780
|
+
return resolved !== null && registry.findBuiltinConstraintBroadening(customTypeIdFromLookup(resolved), tagName) !== void 0;
|
|
2781
|
+
})();
|
|
2782
|
+
if (!hasBroadening) {
|
|
2662
2783
|
const requiredCapability = definition.capabilities[0];
|
|
2663
|
-
if (requiredCapability !== void 0 && !supportsConstraintCapability(
|
|
2664
|
-
const actualType = checker.typeToString(
|
|
2665
|
-
const baseMessage = `Target "${
|
|
2666
|
-
const hint = buildPathTargetHint(
|
|
2784
|
+
if (requiredCapability !== void 0 && !supportsConstraintCapability(evaluatedType, checker, requiredCapability)) {
|
|
2785
|
+
const actualType = checker.typeToString(evaluatedType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2786
|
+
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`;
|
|
2787
|
+
const hint = target === null ? buildPathTargetHint(
|
|
2667
2788
|
subjectType,
|
|
2668
2789
|
checker,
|
|
2669
2790
|
requiredCapability,
|
|
2670
2791
|
tagName,
|
|
2671
2792
|
parsedTag?.argumentText
|
|
2672
|
-
);
|
|
2793
|
+
) : null;
|
|
2673
2794
|
return [
|
|
2674
2795
|
makeDiagnostic(
|
|
2675
2796
|
"TYPE_MISMATCH",
|
|
@@ -2692,7 +2813,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2692
2813
|
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2693
2814
|
const hostType = options?.hostType ?? subjectType;
|
|
2694
2815
|
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2695
|
-
const result = (0,
|
|
2816
|
+
const result = (0, import_internal3.checkSyntheticTagApplication)({
|
|
2696
2817
|
tagName,
|
|
2697
2818
|
placement,
|
|
2698
2819
|
hostType: hostTypeText,
|
|
@@ -2743,10 +2864,10 @@ var parseResultCache = /* @__PURE__ */ new Map();
|
|
|
2743
2864
|
function getExtensionTagNames(options) {
|
|
2744
2865
|
return [
|
|
2745
2866
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
2746
|
-
(extension) => (extension.constraintTags ?? []).map((tag) => (0,
|
|
2867
|
+
(extension) => (extension.constraintTags ?? []).map((tag) => (0, import_internal3.normalizeFormSpecTagName)(tag.tagName))
|
|
2747
2868
|
) ?? [],
|
|
2748
2869
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
2749
|
-
(extension) => (extension.metadataSlots ?? []).map((slot) => (0,
|
|
2870
|
+
(extension) => (extension.metadataSlots ?? []).map((slot) => (0, import_internal3.normalizeFormSpecTagName)(slot.tagName))
|
|
2750
2871
|
) ?? []
|
|
2751
2872
|
].sort();
|
|
2752
2873
|
}
|
|
@@ -2758,9 +2879,9 @@ function getExtensionRegistryCacheKey(registry) {
|
|
|
2758
2879
|
(extension) => JSON.stringify({
|
|
2759
2880
|
extensionId: extension.extensionId,
|
|
2760
2881
|
typeNames: extension.types?.map((type) => type.typeName) ?? [],
|
|
2761
|
-
constraintTags: extension.constraintTags?.map((tag) => (0,
|
|
2882
|
+
constraintTags: extension.constraintTags?.map((tag) => (0, import_internal3.normalizeFormSpecTagName)(tag.tagName)) ?? [],
|
|
2762
2883
|
metadataSlots: extension.metadataSlots?.map((slot) => ({
|
|
2763
|
-
tagName: (0,
|
|
2884
|
+
tagName: (0, import_internal3.normalizeFormSpecTagName)(slot.tagName),
|
|
2764
2885
|
declarationKinds: [...slot.declarationKinds].sort(),
|
|
2765
2886
|
allowBare: slot.allowBare !== false,
|
|
2766
2887
|
qualifiers: (slot.qualifiers ?? []).map((qualifier) => ({
|
|
@@ -2803,12 +2924,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2803
2924
|
const sourceText = sourceFile.getFullText();
|
|
2804
2925
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2805
2926
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2806
|
-
const commentRanges =
|
|
2927
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2807
2928
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2808
2929
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2809
2930
|
if (commentRanges) {
|
|
2810
2931
|
for (const range of commentRanges) {
|
|
2811
|
-
if (range.kind !==
|
|
2932
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
2812
2933
|
continue;
|
|
2813
2934
|
}
|
|
2814
2935
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -2816,7 +2937,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2816
2937
|
continue;
|
|
2817
2938
|
}
|
|
2818
2939
|
const extensions = options?.extensionRegistry?.extensions;
|
|
2819
|
-
const unified = (0,
|
|
2940
|
+
const unified = (0, import_internal3.parseUnifiedComment)(commentText, {
|
|
2820
2941
|
offset: range.pos,
|
|
2821
2942
|
extensionTagNames,
|
|
2822
2943
|
...extensions !== void 0 ? { extensions } : {}
|
|
@@ -2851,13 +2972,13 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2851
2972
|
}
|
|
2852
2973
|
continue;
|
|
2853
2974
|
}
|
|
2854
|
-
if (
|
|
2975
|
+
if (import_internal3.TAGS_REQUIRING_RAW_TEXT.has(tagName)) {
|
|
2855
2976
|
const fallback = rawTextFallbacks.get(tagName)?.shift();
|
|
2856
|
-
const text2 = (0,
|
|
2977
|
+
const text2 = (0, import_internal3.choosePreferredPayloadText)(tag.resolvedPayloadText, fallback?.text ?? "");
|
|
2857
2978
|
if (text2 === "") continue;
|
|
2858
2979
|
const provenance2 = provenanceForParsedTag(tag, sourceFile, file);
|
|
2859
2980
|
if (tagName === "defaultValue") {
|
|
2860
|
-
annotations.push((0,
|
|
2981
|
+
annotations.push((0, import_internal3.parseDefaultValueTagValue)(text2, provenance2));
|
|
2861
2982
|
continue;
|
|
2862
2983
|
}
|
|
2863
2984
|
processConstraintTag(
|
|
@@ -2939,7 +3060,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2939
3060
|
if (text === "") continue;
|
|
2940
3061
|
const provenance = fallback.provenance;
|
|
2941
3062
|
if (tagName === "defaultValue") {
|
|
2942
|
-
annotations.push((0,
|
|
3063
|
+
annotations.push((0, import_internal3.parseDefaultValueTagValue)(text, provenance));
|
|
2943
3064
|
continue;
|
|
2944
3065
|
}
|
|
2945
3066
|
processConstraintTag(
|
|
@@ -2965,13 +3086,13 @@ function extractDisplayNameMetadata(node) {
|
|
|
2965
3086
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
2966
3087
|
const sourceFile = node.getSourceFile();
|
|
2967
3088
|
const sourceText = sourceFile.getFullText();
|
|
2968
|
-
const commentRanges =
|
|
3089
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2969
3090
|
if (commentRanges) {
|
|
2970
3091
|
for (const range of commentRanges) {
|
|
2971
|
-
if (range.kind !==
|
|
3092
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
2972
3093
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
2973
3094
|
if (!commentText.startsWith("/**")) continue;
|
|
2974
|
-
const unified = (0,
|
|
3095
|
+
const unified = (0, import_internal3.parseUnifiedComment)(commentText);
|
|
2975
3096
|
for (const tag of unified.tags) {
|
|
2976
3097
|
if (tag.normalizedTagName !== "displayName") {
|
|
2977
3098
|
continue;
|
|
@@ -2993,9 +3114,9 @@ function extractDisplayNameMetadata(node) {
|
|
|
2993
3114
|
}
|
|
2994
3115
|
function collectRawTextFallbacks(node, file) {
|
|
2995
3116
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
2996
|
-
for (const tag of
|
|
3117
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
2997
3118
|
const tagName = (0, import_internals4.normalizeConstraintTagName)(tag.tagName.text);
|
|
2998
|
-
if (!
|
|
3119
|
+
if (!import_internal3.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
2999
3120
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
3000
3121
|
if (commentText === "") continue;
|
|
3001
3122
|
const entries = fallbacks.get(tagName) ?? [];
|
|
@@ -3008,7 +3129,7 @@ function collectRawTextFallbacks(node, file) {
|
|
|
3008
3129
|
return fallbacks;
|
|
3009
3130
|
}
|
|
3010
3131
|
function isMemberTargetDisplayName(text) {
|
|
3011
|
-
return (0,
|
|
3132
|
+
return (0, import_internal3.parseTagSyntax)("displayName", text).target !== null;
|
|
3012
3133
|
}
|
|
3013
3134
|
function provenanceForComment(range, sourceFile, file, tagName) {
|
|
3014
3135
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);
|
|
@@ -3048,7 +3169,7 @@ function getTagCommentText(tag) {
|
|
|
3048
3169
|
if (typeof tag.comment === "string") {
|
|
3049
3170
|
return tag.comment;
|
|
3050
3171
|
}
|
|
3051
|
-
return
|
|
3172
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
3052
3173
|
}
|
|
3053
3174
|
|
|
3054
3175
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3066,18 +3187,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3066
3187
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3067
3188
|
if (!initializer) return null;
|
|
3068
3189
|
let value;
|
|
3069
|
-
if (
|
|
3190
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
3070
3191
|
value = initializer.text;
|
|
3071
|
-
} else if (
|
|
3192
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
3072
3193
|
value = Number(initializer.text);
|
|
3073
|
-
} else if (initializer.kind ===
|
|
3194
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
3074
3195
|
value = true;
|
|
3075
|
-
} else if (initializer.kind ===
|
|
3196
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
3076
3197
|
value = false;
|
|
3077
|
-
} else if (initializer.kind ===
|
|
3198
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
3078
3199
|
value = null;
|
|
3079
|
-
} else if (
|
|
3080
|
-
if (initializer.operator ===
|
|
3200
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
3201
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
3081
3202
|
value = -Number(initializer.operand.text);
|
|
3082
3203
|
}
|
|
3083
3204
|
}
|
|
@@ -3099,93 +3220,38 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3099
3220
|
|
|
3100
3221
|
// src/analyzer/class-analyzer.ts
|
|
3101
3222
|
function isObjectType(type) {
|
|
3102
|
-
return !!(type.flags &
|
|
3223
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
3103
3224
|
}
|
|
3104
3225
|
function isIntersectionType(type) {
|
|
3105
|
-
return !!(type.flags &
|
|
3106
|
-
}
|
|
3107
|
-
function collectBrandIdentifiers(type) {
|
|
3108
|
-
if (!type.isIntersection()) {
|
|
3109
|
-
return [];
|
|
3110
|
-
}
|
|
3111
|
-
const brands = [];
|
|
3112
|
-
for (const prop of type.getProperties()) {
|
|
3113
|
-
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
3114
|
-
if (decl === void 0) continue;
|
|
3115
|
-
if (!ts3.isPropertySignature(decl) && !ts3.isPropertyDeclaration(decl)) continue;
|
|
3116
|
-
if (!ts3.isComputedPropertyName(decl.name)) continue;
|
|
3117
|
-
if (!ts3.isIdentifier(decl.name.expression)) continue;
|
|
3118
|
-
brands.push(decl.name.expression.text);
|
|
3119
|
-
}
|
|
3120
|
-
return brands;
|
|
3121
|
-
}
|
|
3122
|
-
function resolveCanonicalSymbol(type, checker) {
|
|
3123
|
-
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
3124
|
-
if (raw === void 0) return void 0;
|
|
3125
|
-
return raw.flags & ts3.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
3126
|
-
}
|
|
3127
|
-
function resolveSymbolBasedCustomType(type, extensionRegistry, checker) {
|
|
3128
|
-
if (extensionRegistry === void 0) {
|
|
3129
|
-
return null;
|
|
3130
|
-
}
|
|
3131
|
-
const canonical = resolveCanonicalSymbol(type, checker);
|
|
3132
|
-
if (canonical === void 0) {
|
|
3133
|
-
return null;
|
|
3134
|
-
}
|
|
3135
|
-
const registration = extensionRegistry.findTypeBySymbol(canonical);
|
|
3136
|
-
if (registration === void 0) {
|
|
3137
|
-
return null;
|
|
3138
|
-
}
|
|
3139
|
-
return {
|
|
3140
|
-
kind: "custom",
|
|
3141
|
-
typeId: `${registration.extensionId}/${registration.registration.typeName}`,
|
|
3142
|
-
payload: null
|
|
3143
|
-
};
|
|
3226
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
3144
3227
|
}
|
|
3145
3228
|
function isIntegerBrandedType(type) {
|
|
3146
3229
|
if (!type.isIntersection()) {
|
|
3147
3230
|
return false;
|
|
3148
3231
|
}
|
|
3149
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags &
|
|
3232
|
+
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3150
3233
|
if (!hasNumberBase) {
|
|
3151
3234
|
return false;
|
|
3152
3235
|
}
|
|
3153
3236
|
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3154
3237
|
}
|
|
3155
|
-
function resolveBrandedCustomType(type, extensionRegistry) {
|
|
3156
|
-
if (extensionRegistry === void 0) {
|
|
3157
|
-
return null;
|
|
3158
|
-
}
|
|
3159
|
-
for (const brand of collectBrandIdentifiers(type)) {
|
|
3160
|
-
const registration = extensionRegistry.findTypeByBrand(brand);
|
|
3161
|
-
if (registration === void 0) {
|
|
3162
|
-
continue;
|
|
3163
|
-
}
|
|
3164
|
-
return {
|
|
3165
|
-
kind: "custom",
|
|
3166
|
-
typeId: `${registration.extensionId}/${registration.registration.typeName}`,
|
|
3167
|
-
payload: null
|
|
3168
|
-
};
|
|
3169
|
-
}
|
|
3170
|
-
return null;
|
|
3171
|
-
}
|
|
3172
3238
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3173
|
-
if (
|
|
3239
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3174
3240
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3175
3241
|
}
|
|
3176
|
-
if (
|
|
3242
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
3177
3243
|
return true;
|
|
3178
3244
|
}
|
|
3179
|
-
return
|
|
3245
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3180
3246
|
}
|
|
3181
3247
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3182
3248
|
if (isIntersectionType(type)) {
|
|
3183
3249
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3184
3250
|
}
|
|
3185
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3251
|
+
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);
|
|
3186
3252
|
}
|
|
3187
3253
|
function isTypeReference(type) {
|
|
3188
|
-
return !!(type.flags &
|
|
3254
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
3189
3255
|
}
|
|
3190
3256
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3191
3257
|
kind: "object",
|
|
@@ -3212,7 +3278,7 @@ function createAnalyzerMetadataPolicy(input, discriminator) {
|
|
|
3212
3278
|
};
|
|
3213
3279
|
}
|
|
3214
3280
|
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
3215
|
-
const analysis = (0,
|
|
3281
|
+
const analysis = (0, import_internal4.analyzeMetadataForNodeWithChecker)({
|
|
3216
3282
|
checker,
|
|
3217
3283
|
node,
|
|
3218
3284
|
logicalName,
|
|
@@ -3250,7 +3316,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3250
3316
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3251
3317
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3252
3318
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3253
|
-
const logicalName =
|
|
3319
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3254
3320
|
const docResult = extractJSDocParseResult(
|
|
3255
3321
|
declaration,
|
|
3256
3322
|
file,
|
|
@@ -3298,7 +3364,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3298
3364
|
const instanceMethods = [];
|
|
3299
3365
|
const staticMethods = [];
|
|
3300
3366
|
for (const member of classDecl.members) {
|
|
3301
|
-
if (
|
|
3367
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
3302
3368
|
const fieldNode = analyzeFieldToIR(
|
|
3303
3369
|
member,
|
|
3304
3370
|
checker,
|
|
@@ -3314,10 +3380,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3314
3380
|
fields.push(fieldNode);
|
|
3315
3381
|
fieldLayouts.push({});
|
|
3316
3382
|
}
|
|
3317
|
-
} else if (
|
|
3383
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
3318
3384
|
const methodInfo = analyzeMethod(member, checker);
|
|
3319
3385
|
if (methodInfo) {
|
|
3320
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3386
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
3321
3387
|
if (isStatic) {
|
|
3322
3388
|
staticMethods.push(methodInfo);
|
|
3323
3389
|
} else {
|
|
@@ -3380,7 +3446,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3380
3446
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3381
3447
|
const visiting = /* @__PURE__ */ new Set();
|
|
3382
3448
|
for (const member of interfaceDecl.members) {
|
|
3383
|
-
if (
|
|
3449
|
+
if (ts5.isPropertySignature(member)) {
|
|
3384
3450
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3385
3451
|
member,
|
|
3386
3452
|
checker,
|
|
@@ -3438,7 +3504,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3438
3504
|
if (members === null) {
|
|
3439
3505
|
const sourceFile = typeAlias.getSourceFile();
|
|
3440
3506
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3441
|
-
const kindDesc =
|
|
3507
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3442
3508
|
return {
|
|
3443
3509
|
ok: false,
|
|
3444
3510
|
kind: "not-object-like",
|
|
@@ -3473,7 +3539,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3473
3539
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3474
3540
|
const visiting = /* @__PURE__ */ new Set();
|
|
3475
3541
|
for (const member of members) {
|
|
3476
|
-
if (
|
|
3542
|
+
if (ts5.isPropertySignature(member)) {
|
|
3477
3543
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3478
3544
|
member,
|
|
3479
3545
|
checker,
|
|
@@ -3540,20 +3606,20 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3540
3606
|
function getLeadingParsedTags(node) {
|
|
3541
3607
|
const sourceFile = node.getSourceFile();
|
|
3542
3608
|
const sourceText = sourceFile.getFullText();
|
|
3543
|
-
const commentRanges =
|
|
3609
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3544
3610
|
if (commentRanges === void 0) {
|
|
3545
3611
|
return [];
|
|
3546
3612
|
}
|
|
3547
3613
|
const parsedTags = [];
|
|
3548
3614
|
for (const range of commentRanges) {
|
|
3549
|
-
if (range.kind !==
|
|
3615
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
3550
3616
|
continue;
|
|
3551
3617
|
}
|
|
3552
3618
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
3553
3619
|
if (!commentText.startsWith("/**")) {
|
|
3554
3620
|
continue;
|
|
3555
3621
|
}
|
|
3556
|
-
parsedTags.push(...(0,
|
|
3622
|
+
parsedTags.push(...(0, import_internal4.parseCommentBlock)(commentText, { offset: range.pos }).tags);
|
|
3557
3623
|
}
|
|
3558
3624
|
return parsedTags;
|
|
3559
3625
|
}
|
|
@@ -3564,19 +3630,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3564
3630
|
return null;
|
|
3565
3631
|
}
|
|
3566
3632
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3567
|
-
(candidate) =>
|
|
3633
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
3568
3634
|
) ?? propertySymbol.declarations?.[0];
|
|
3569
3635
|
return {
|
|
3570
3636
|
declaration,
|
|
3571
3637
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3572
|
-
optional: !!(propertySymbol.flags &
|
|
3638
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3573
3639
|
};
|
|
3574
3640
|
}
|
|
3575
3641
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3576
3642
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3577
3643
|
}
|
|
3578
3644
|
function isNullishSemanticType(type) {
|
|
3579
|
-
if (type.flags & (
|
|
3645
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
3580
3646
|
return true;
|
|
3581
3647
|
}
|
|
3582
3648
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3586,7 +3652,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3586
3652
|
return false;
|
|
3587
3653
|
}
|
|
3588
3654
|
seen.add(type);
|
|
3589
|
-
if (type.flags &
|
|
3655
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
3590
3656
|
return true;
|
|
3591
3657
|
}
|
|
3592
3658
|
if (type.isUnion()) {
|
|
@@ -3599,13 +3665,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3599
3665
|
return false;
|
|
3600
3666
|
}
|
|
3601
3667
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3602
|
-
if (
|
|
3668
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3603
3669
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3604
3670
|
}
|
|
3605
|
-
if (
|
|
3671
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
3606
3672
|
return [...typeNode.members];
|
|
3607
3673
|
}
|
|
3608
|
-
if (
|
|
3674
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
3609
3675
|
const members = [];
|
|
3610
3676
|
for (const intersectionMember of typeNode.types) {
|
|
3611
3677
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3768,7 +3834,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3768
3834
|
}
|
|
3769
3835
|
if (propertyType.isUnion()) {
|
|
3770
3836
|
const nonNullMembers = propertyType.types.filter(
|
|
3771
|
-
(member) => !(member.flags & (
|
|
3837
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3772
3838
|
);
|
|
3773
3839
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3774
3840
|
diagnostics.push(
|
|
@@ -3817,13 +3883,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3817
3883
|
seen.add(type);
|
|
3818
3884
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3819
3885
|
if (symbol !== void 0) {
|
|
3820
|
-
const aliased = symbol.flags &
|
|
3886
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3821
3887
|
const targetSymbol = aliased ?? symbol;
|
|
3822
3888
|
const declaration = targetSymbol.declarations?.find(
|
|
3823
|
-
(candidate) =>
|
|
3889
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
3824
3890
|
);
|
|
3825
3891
|
if (declaration !== void 0) {
|
|
3826
|
-
if (
|
|
3892
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3827
3893
|
return resolveNamedDiscriminatorDeclaration(
|
|
3828
3894
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3829
3895
|
checker,
|
|
@@ -3851,7 +3917,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3851
3917
|
}
|
|
3852
3918
|
if (boundType.isUnion()) {
|
|
3853
3919
|
const nonNullMembers = boundType.types.filter(
|
|
3854
|
-
(member) => !(member.flags & (
|
|
3920
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3855
3921
|
);
|
|
3856
3922
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3857
3923
|
diagnostics.push(
|
|
@@ -3896,7 +3962,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3896
3962
|
return null;
|
|
3897
3963
|
}
|
|
3898
3964
|
function getDeclarationName(node) {
|
|
3899
|
-
if (
|
|
3965
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
3900
3966
|
return node.name?.text ?? "anonymous";
|
|
3901
3967
|
}
|
|
3902
3968
|
return "anonymous";
|
|
@@ -3951,11 +4017,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
3951
4017
|
if (sourceTypeNode === void 0) {
|
|
3952
4018
|
return [];
|
|
3953
4019
|
}
|
|
3954
|
-
const unwrapParentheses = (typeNode) =>
|
|
4020
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
3955
4021
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
3956
|
-
const referenceTypeNode =
|
|
4022
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
3957
4023
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
3958
|
-
return
|
|
4024
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
3959
4025
|
})();
|
|
3960
4026
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
3961
4027
|
return [];
|
|
@@ -4010,7 +4076,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4010
4076
|
);
|
|
4011
4077
|
}
|
|
4012
4078
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4013
|
-
if (!
|
|
4079
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
4014
4080
|
return null;
|
|
4015
4081
|
}
|
|
4016
4082
|
const name = prop.name.text;
|
|
@@ -4137,7 +4203,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4137
4203
|
const seen = /* @__PURE__ */ new Set();
|
|
4138
4204
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4139
4205
|
for (const member of members) {
|
|
4140
|
-
if (!
|
|
4206
|
+
if (!ts5.isPropertySignature(member)) {
|
|
4141
4207
|
continue;
|
|
4142
4208
|
}
|
|
4143
4209
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4153,7 +4219,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4153
4219
|
return [...duplicates].sort();
|
|
4154
4220
|
}
|
|
4155
4221
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4156
|
-
if (
|
|
4222
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
4157
4223
|
return name.text;
|
|
4158
4224
|
}
|
|
4159
4225
|
return null;
|
|
@@ -4220,74 +4286,20 @@ function parseEnumMemberDisplayName(value) {
|
|
|
4220
4286
|
if (label === "") return null;
|
|
4221
4287
|
return { value: match[1], label };
|
|
4222
4288
|
}
|
|
4223
|
-
function
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
return resolveRegisteredCustomTypeFromTypeNode(typeNode, extensionRegistry, checker);
|
|
4232
|
-
}
|
|
4233
|
-
function resolveRegisteredCustomTypeFromTypeNode(typeNode, extensionRegistry, checker) {
|
|
4234
|
-
if (ts3.isParenthesizedTypeNode(typeNode)) {
|
|
4235
|
-
return resolveRegisteredCustomTypeFromTypeNode(typeNode.type, extensionRegistry, checker);
|
|
4236
|
-
}
|
|
4237
|
-
const typeName = getTypeNodeRegistrationName(typeNode);
|
|
4238
|
-
if (typeName === null) {
|
|
4239
|
-
return null;
|
|
4240
|
-
}
|
|
4241
|
-
const registration = extensionRegistry.findTypeByName(typeName);
|
|
4242
|
-
if (registration !== void 0) {
|
|
4289
|
+
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4290
|
+
const customTypeLookup = resolveCustomTypeFromTsType(
|
|
4291
|
+
type,
|
|
4292
|
+
checker,
|
|
4293
|
+
extensionRegistry,
|
|
4294
|
+
sourceNode
|
|
4295
|
+
);
|
|
4296
|
+
if (customTypeLookup !== null) {
|
|
4243
4297
|
return {
|
|
4244
4298
|
kind: "custom",
|
|
4245
|
-
typeId:
|
|
4299
|
+
typeId: customTypeIdFromLookup(customTypeLookup),
|
|
4246
4300
|
payload: null
|
|
4247
4301
|
};
|
|
4248
4302
|
}
|
|
4249
|
-
if (ts3.isTypeReferenceNode(typeNode) && ts3.isIdentifier(typeNode.typeName)) {
|
|
4250
|
-
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4251
|
-
if (aliasDecl !== void 0) {
|
|
4252
|
-
return resolveRegisteredCustomTypeFromTypeNode(aliasDecl.type, extensionRegistry, checker);
|
|
4253
|
-
}
|
|
4254
|
-
}
|
|
4255
|
-
return null;
|
|
4256
|
-
}
|
|
4257
|
-
function extractTypeNodeFromSource(sourceNode) {
|
|
4258
|
-
if (ts3.isPropertyDeclaration(sourceNode) || ts3.isPropertySignature(sourceNode) || ts3.isParameter(sourceNode) || ts3.isTypeAliasDeclaration(sourceNode)) {
|
|
4259
|
-
return sourceNode.type;
|
|
4260
|
-
}
|
|
4261
|
-
if (ts3.isTypeNode(sourceNode)) {
|
|
4262
|
-
return sourceNode;
|
|
4263
|
-
}
|
|
4264
|
-
return void 0;
|
|
4265
|
-
}
|
|
4266
|
-
function getTypeNodeRegistrationName(typeNode) {
|
|
4267
|
-
if (ts3.isTypeReferenceNode(typeNode)) {
|
|
4268
|
-
return ts3.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : typeNode.typeName.right.text;
|
|
4269
|
-
}
|
|
4270
|
-
if (ts3.isParenthesizedTypeNode(typeNode)) {
|
|
4271
|
-
return getTypeNodeRegistrationName(typeNode.type);
|
|
4272
|
-
}
|
|
4273
|
-
if (typeNode.kind === ts3.SyntaxKind.BigIntKeyword || typeNode.kind === ts3.SyntaxKind.StringKeyword || typeNode.kind === ts3.SyntaxKind.NumberKeyword || typeNode.kind === ts3.SyntaxKind.BooleanKeyword) {
|
|
4274
|
-
return typeNode.getText();
|
|
4275
|
-
}
|
|
4276
|
-
return null;
|
|
4277
|
-
}
|
|
4278
|
-
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4279
|
-
const customType = resolveRegisteredCustomType(sourceNode, extensionRegistry, checker);
|
|
4280
|
-
if (customType) {
|
|
4281
|
-
return customType;
|
|
4282
|
-
}
|
|
4283
|
-
const symbolCustomType = resolveSymbolBasedCustomType(type, extensionRegistry, checker);
|
|
4284
|
-
if (symbolCustomType) {
|
|
4285
|
-
return symbolCustomType;
|
|
4286
|
-
}
|
|
4287
|
-
const brandedCustomType = resolveBrandedCustomType(type, extensionRegistry);
|
|
4288
|
-
if (brandedCustomType) {
|
|
4289
|
-
return brandedCustomType;
|
|
4290
|
-
}
|
|
4291
4303
|
const primitiveAlias = tryResolveNamedPrimitiveAlias(
|
|
4292
4304
|
type,
|
|
4293
4305
|
checker,
|
|
@@ -4305,25 +4317,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4305
4317
|
if (isIntegerBrandedType(type)) {
|
|
4306
4318
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4307
4319
|
}
|
|
4308
|
-
if (type.flags &
|
|
4320
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4309
4321
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4310
4322
|
}
|
|
4311
|
-
if (type.flags &
|
|
4323
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4312
4324
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4313
4325
|
}
|
|
4314
|
-
if (type.flags & (
|
|
4326
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4315
4327
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4316
4328
|
}
|
|
4317
|
-
if (type.flags &
|
|
4329
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4318
4330
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4319
4331
|
}
|
|
4320
|
-
if (type.flags &
|
|
4332
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4321
4333
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4322
4334
|
}
|
|
4323
|
-
if (type.flags &
|
|
4335
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
4324
4336
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4325
4337
|
}
|
|
4326
|
-
if (type.flags &
|
|
4338
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
4327
4339
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4328
4340
|
}
|
|
4329
4341
|
if (type.isStringLiteral()) {
|
|
@@ -4410,10 +4422,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4410
4422
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4411
4423
|
}
|
|
4412
4424
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4413
|
-
if (!(type.flags & (
|
|
4425
|
+
if (!(type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4414
4426
|
return null;
|
|
4415
4427
|
}
|
|
4416
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4428
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4417
4429
|
if (!aliasDecl) {
|
|
4418
4430
|
return null;
|
|
4419
4431
|
}
|
|
@@ -4463,14 +4475,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4463
4475
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4464
4476
|
}
|
|
4465
4477
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4466
|
-
const typeNode = sourceNode && (
|
|
4467
|
-
if (!typeNode || !
|
|
4478
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4479
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
4468
4480
|
return void 0;
|
|
4469
4481
|
}
|
|
4470
4482
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4471
4483
|
}
|
|
4472
4484
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4473
|
-
if (!
|
|
4485
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
4474
4486
|
return false;
|
|
4475
4487
|
}
|
|
4476
4488
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4478,10 +4490,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4478
4490
|
return false;
|
|
4479
4491
|
}
|
|
4480
4492
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4481
|
-
return !!(resolved.flags & (
|
|
4493
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
4482
4494
|
}
|
|
4483
4495
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4484
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4496
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
4485
4497
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4486
4498
|
visitedAliases.add(nestedAliasDecl);
|
|
4487
4499
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4499,19 +4511,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4499
4511
|
if (isIntegerBrandedType(type)) {
|
|
4500
4512
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4501
4513
|
}
|
|
4502
|
-
if (type.flags &
|
|
4514
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4503
4515
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4504
4516
|
}
|
|
4505
|
-
if (type.flags &
|
|
4517
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4506
4518
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4507
4519
|
}
|
|
4508
|
-
if (type.flags & (
|
|
4520
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4509
4521
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4510
4522
|
}
|
|
4511
|
-
if (type.flags &
|
|
4523
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4512
4524
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4513
4525
|
}
|
|
4514
|
-
if (type.flags &
|
|
4526
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4515
4527
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4516
4528
|
}
|
|
4517
4529
|
return resolveTypeNode(
|
|
@@ -4538,13 +4550,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4538
4550
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4539
4551
|
);
|
|
4540
4552
|
const nonNullTypes = allTypes.filter(
|
|
4541
|
-
(memberType) => !(memberType.flags & (
|
|
4553
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4542
4554
|
);
|
|
4543
4555
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4544
4556
|
memberType,
|
|
4545
4557
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4546
4558
|
}));
|
|
4547
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4559
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
4548
4560
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4549
4561
|
if (namedDecl) {
|
|
4550
4562
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4587,7 +4599,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4587
4599
|
const displayName = memberDisplayNames.get(String(value));
|
|
4588
4600
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4589
4601
|
});
|
|
4590
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4602
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
4591
4603
|
if (isBooleanUnion2) {
|
|
4592
4604
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4593
4605
|
const result = hasNull ? {
|
|
@@ -4679,7 +4691,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4679
4691
|
if (type.getProperties().length > 0) {
|
|
4680
4692
|
return null;
|
|
4681
4693
|
}
|
|
4682
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4694
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
4683
4695
|
if (!indexInfo) {
|
|
4684
4696
|
return null;
|
|
4685
4697
|
}
|
|
@@ -4727,10 +4739,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4727
4739
|
}
|
|
4728
4740
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4729
4741
|
const name = declaration.name;
|
|
4730
|
-
if (
|
|
4742
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
4731
4743
|
return false;
|
|
4732
4744
|
}
|
|
4733
|
-
if (!
|
|
4745
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
4734
4746
|
return false;
|
|
4735
4747
|
}
|
|
4736
4748
|
}
|
|
@@ -4856,7 +4868,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4856
4868
|
if (!declaration) continue;
|
|
4857
4869
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4858
4870
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4859
|
-
const optional = !!(prop.flags &
|
|
4871
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
4860
4872
|
const propTypeNode = resolveTypeNode(
|
|
4861
4873
|
propType,
|
|
4862
4874
|
checker,
|
|
@@ -4869,7 +4881,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4869
4881
|
collectedDiagnostics
|
|
4870
4882
|
);
|
|
4871
4883
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4872
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
4884
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4873
4885
|
declaration,
|
|
4874
4886
|
checker,
|
|
4875
4887
|
file,
|
|
@@ -4879,7 +4891,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4879
4891
|
type,
|
|
4880
4892
|
metadataPolicy,
|
|
4881
4893
|
extensionRegistry
|
|
4882
|
-
) :
|
|
4894
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4883
4895
|
declaration,
|
|
4884
4896
|
checker,
|
|
4885
4897
|
file,
|
|
@@ -4907,7 +4919,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4907
4919
|
visiting.delete(type);
|
|
4908
4920
|
const objectNode = {
|
|
4909
4921
|
kind: "object",
|
|
4910
|
-
properties: namedDecl !== void 0 && (
|
|
4922
|
+
properties: namedDecl !== void 0 && (ts5.isClassDeclaration(namedDecl) || ts5.isInterfaceDeclaration(namedDecl) || ts5.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
4911
4923
|
properties,
|
|
4912
4924
|
namedDecl,
|
|
4913
4925
|
type,
|
|
@@ -4955,12 +4967,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4955
4967
|
for (const symbol of symbols) {
|
|
4956
4968
|
const declarations = symbol.declarations;
|
|
4957
4969
|
if (!declarations) continue;
|
|
4958
|
-
const classDecl = declarations.find(
|
|
4970
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
4959
4971
|
if (classDecl) {
|
|
4960
4972
|
const map = /* @__PURE__ */ new Map();
|
|
4961
4973
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
4962
4974
|
for (const member of classDecl.members) {
|
|
4963
|
-
if (
|
|
4975
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
4964
4976
|
const fieldNode = analyzeFieldToIR(
|
|
4965
4977
|
member,
|
|
4966
4978
|
checker,
|
|
@@ -4984,7 +4996,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4984
4996
|
}
|
|
4985
4997
|
return map;
|
|
4986
4998
|
}
|
|
4987
|
-
const interfaceDecl = declarations.find(
|
|
4999
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
4988
5000
|
if (interfaceDecl) {
|
|
4989
5001
|
return buildFieldNodeInfoMap(
|
|
4990
5002
|
interfaceDecl.members,
|
|
@@ -4998,7 +5010,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4998
5010
|
extensionRegistry
|
|
4999
5011
|
);
|
|
5000
5012
|
}
|
|
5001
|
-
const typeAliasDecl = declarations.find(
|
|
5013
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
5002
5014
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5003
5015
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5004
5016
|
return buildFieldNodeInfoMap(
|
|
@@ -5022,10 +5034,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5022
5034
|
return void 0;
|
|
5023
5035
|
}
|
|
5024
5036
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5025
|
-
if (
|
|
5037
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
5026
5038
|
return resolvedTypeNode.elementType;
|
|
5027
5039
|
}
|
|
5028
|
-
if (
|
|
5040
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5029
5041
|
return resolvedTypeNode.typeArguments[0];
|
|
5030
5042
|
}
|
|
5031
5043
|
return void 0;
|
|
@@ -5036,13 +5048,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5036
5048
|
return [];
|
|
5037
5049
|
}
|
|
5038
5050
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5039
|
-
return
|
|
5051
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5040
5052
|
}
|
|
5041
5053
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5042
|
-
if (
|
|
5054
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
5043
5055
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5044
5056
|
}
|
|
5045
|
-
if (!
|
|
5057
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
5046
5058
|
return typeNode;
|
|
5047
5059
|
}
|
|
5048
5060
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5053,15 +5065,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5053
5065
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5054
5066
|
}
|
|
5055
5067
|
function isNullishTypeNode(typeNode) {
|
|
5056
|
-
if (typeNode.kind ===
|
|
5068
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
5057
5069
|
return true;
|
|
5058
5070
|
}
|
|
5059
|
-
return
|
|
5071
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
5060
5072
|
}
|
|
5061
5073
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5062
5074
|
const map = /* @__PURE__ */ new Map();
|
|
5063
5075
|
for (const member of members) {
|
|
5064
|
-
if (
|
|
5076
|
+
if (ts5.isPropertySignature(member)) {
|
|
5065
5077
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5066
5078
|
member,
|
|
5067
5079
|
checker,
|
|
@@ -5087,17 +5099,16 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5087
5099
|
}
|
|
5088
5100
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5089
5101
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5090
|
-
if (!
|
|
5102
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
5091
5103
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5092
5104
|
const aliasName = typeNode.typeName.getText();
|
|
5093
5105
|
throw new Error(
|
|
5094
5106
|
`Type alias chain exceeds maximum depth of ${String(MAX_ALIAS_CHAIN_DEPTH)} at alias "${aliasName}" in ${file}. Simplify the alias chain or check for circular references.`
|
|
5095
5107
|
);
|
|
5096
5108
|
}
|
|
5097
|
-
const
|
|
5098
|
-
const aliasDecl = getAliasedTypeAliasDeclaration(symbol, checker);
|
|
5109
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5099
5110
|
if (!aliasDecl) return [];
|
|
5100
|
-
if (
|
|
5111
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5101
5112
|
const aliasFieldType = resolveTypeNode(
|
|
5102
5113
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5103
5114
|
checker,
|
|
@@ -5118,18 +5129,6 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5118
5129
|
);
|
|
5119
5130
|
return constraints;
|
|
5120
5131
|
}
|
|
5121
|
-
function getAliasedSymbol(symbol, checker) {
|
|
5122
|
-
if (symbol === void 0) {
|
|
5123
|
-
return void 0;
|
|
5124
|
-
}
|
|
5125
|
-
return symbol.flags & ts3.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
5126
|
-
}
|
|
5127
|
-
function getAliasedTypeAliasDeclaration(symbol, checker) {
|
|
5128
|
-
return getAliasedSymbol(symbol, checker)?.declarations?.find(ts3.isTypeAliasDeclaration);
|
|
5129
|
-
}
|
|
5130
|
-
function getTypeAliasDeclarationFromTypeReference(typeNode, checker) {
|
|
5131
|
-
return getAliasedTypeAliasDeclaration(checker.getSymbolAtLocation(typeNode.typeName), checker);
|
|
5132
|
-
}
|
|
5133
5132
|
function provenanceForNode(node, file) {
|
|
5134
5133
|
const sourceFile = node.getSourceFile();
|
|
5135
5134
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
@@ -5153,14 +5152,14 @@ function getNamedTypeName(type) {
|
|
|
5153
5152
|
const symbol = type.getSymbol();
|
|
5154
5153
|
if (symbol?.declarations) {
|
|
5155
5154
|
const decl = symbol.declarations[0];
|
|
5156
|
-
if (decl && (
|
|
5157
|
-
const name =
|
|
5155
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5156
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5158
5157
|
if (name) return name;
|
|
5159
5158
|
}
|
|
5160
5159
|
}
|
|
5161
5160
|
const aliasSymbol = type.aliasSymbol;
|
|
5162
5161
|
if (aliasSymbol?.declarations) {
|
|
5163
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5162
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5164
5163
|
if (aliasDecl) {
|
|
5165
5164
|
return aliasDecl.name.text;
|
|
5166
5165
|
}
|
|
@@ -5171,24 +5170,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5171
5170
|
const symbol = type.getSymbol();
|
|
5172
5171
|
if (symbol?.declarations) {
|
|
5173
5172
|
const decl = symbol.declarations[0];
|
|
5174
|
-
if (decl && (
|
|
5173
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5175
5174
|
return decl;
|
|
5176
5175
|
}
|
|
5177
5176
|
}
|
|
5178
5177
|
const aliasSymbol = type.aliasSymbol;
|
|
5179
5178
|
if (aliasSymbol?.declarations) {
|
|
5180
|
-
return aliasSymbol.declarations.find(
|
|
5179
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5181
5180
|
}
|
|
5182
5181
|
return void 0;
|
|
5183
5182
|
}
|
|
5184
5183
|
function analyzeMethod(method, checker) {
|
|
5185
|
-
if (!
|
|
5184
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
5186
5185
|
return null;
|
|
5187
5186
|
}
|
|
5188
5187
|
const name = method.name.text;
|
|
5189
5188
|
const parameters = [];
|
|
5190
5189
|
for (const param of method.parameters) {
|
|
5191
|
-
if (
|
|
5190
|
+
if (ts5.isIdentifier(param.name)) {
|
|
5192
5191
|
const paramInfo = analyzeParameter(param, checker);
|
|
5193
5192
|
parameters.push(paramInfo);
|
|
5194
5193
|
}
|
|
@@ -5199,7 +5198,7 @@ function analyzeMethod(method, checker) {
|
|
|
5199
5198
|
return { name, parameters, returnTypeNode, returnType };
|
|
5200
5199
|
}
|
|
5201
5200
|
function analyzeParameter(param, checker) {
|
|
5202
|
-
const name =
|
|
5201
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
5203
5202
|
const typeNode = param.type;
|
|
5204
5203
|
const type = checker.getTypeAtLocation(param);
|
|
5205
5204
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5208,15 +5207,15 @@ function analyzeParameter(param, checker) {
|
|
|
5208
5207
|
}
|
|
5209
5208
|
function detectFormSpecReference(typeNode) {
|
|
5210
5209
|
if (!typeNode) return null;
|
|
5211
|
-
if (!
|
|
5212
|
-
const typeName =
|
|
5210
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
5211
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5213
5212
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5214
5213
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5215
|
-
if (!typeArg || !
|
|
5216
|
-
if (
|
|
5214
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
5215
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
5217
5216
|
return typeArg.exprName.text;
|
|
5218
5217
|
}
|
|
5219
|
-
if (
|
|
5218
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
5220
5219
|
return typeArg.exprName.right.text;
|
|
5221
5220
|
}
|
|
5222
5221
|
return null;
|
|
@@ -5238,23 +5237,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5238
5237
|
function createProgramContext(filePath, additionalFiles) {
|
|
5239
5238
|
const absolutePath = path.resolve(filePath);
|
|
5240
5239
|
const fileDir = path.dirname(absolutePath);
|
|
5241
|
-
const configPath =
|
|
5240
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
5242
5241
|
let compilerOptions;
|
|
5243
5242
|
let fileNames;
|
|
5244
5243
|
if (configPath) {
|
|
5245
|
-
const configFile =
|
|
5244
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
5246
5245
|
if (configFile.error) {
|
|
5247
5246
|
throw new Error(
|
|
5248
|
-
`Error reading tsconfig.json: ${
|
|
5247
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5249
5248
|
);
|
|
5250
5249
|
}
|
|
5251
|
-
const parsed =
|
|
5250
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
5252
5251
|
configFile.config,
|
|
5253
|
-
|
|
5252
|
+
ts6.sys,
|
|
5254
5253
|
path.dirname(configPath)
|
|
5255
5254
|
);
|
|
5256
5255
|
if (parsed.errors.length > 0) {
|
|
5257
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5256
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5258
5257
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5259
5258
|
}
|
|
5260
5259
|
compilerOptions = parsed.options;
|
|
@@ -5262,9 +5261,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5262
5261
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5263
5262
|
} else {
|
|
5264
5263
|
compilerOptions = {
|
|
5265
|
-
target:
|
|
5266
|
-
module:
|
|
5267
|
-
moduleResolution:
|
|
5264
|
+
target: ts6.ScriptTarget.ES2022,
|
|
5265
|
+
module: ts6.ModuleKind.NodeNext,
|
|
5266
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
5268
5267
|
strict: true,
|
|
5269
5268
|
skipLibCheck: true,
|
|
5270
5269
|
declaration: true
|
|
@@ -5272,7 +5271,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5272
5271
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5273
5272
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5274
5273
|
}
|
|
5275
|
-
const program =
|
|
5274
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
5276
5275
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5277
5276
|
if (!sourceFile) {
|
|
5278
5277
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5291,19 +5290,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5291
5290
|
result = node;
|
|
5292
5291
|
return;
|
|
5293
5292
|
}
|
|
5294
|
-
|
|
5293
|
+
ts6.forEachChild(node, visit);
|
|
5295
5294
|
}
|
|
5296
5295
|
visit(sourceFile);
|
|
5297
5296
|
return result;
|
|
5298
5297
|
}
|
|
5299
5298
|
function findClassByName(sourceFile, className) {
|
|
5300
|
-
return findNodeByName(sourceFile, className,
|
|
5299
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
5301
5300
|
}
|
|
5302
5301
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5303
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5302
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
5304
5303
|
}
|
|
5305
5304
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5306
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5305
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5307
5306
|
}
|
|
5308
5307
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5309
5308
|
if (rootType.kind === "object") {
|
|
@@ -5343,22 +5342,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5343
5342
|
};
|
|
5344
5343
|
}
|
|
5345
5344
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5346
|
-
if (
|
|
5345
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5347
5346
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5348
5347
|
}
|
|
5349
|
-
if (
|
|
5348
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5350
5349
|
return true;
|
|
5351
5350
|
}
|
|
5352
|
-
return
|
|
5351
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5353
5352
|
}
|
|
5354
5353
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5355
|
-
if (
|
|
5354
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5356
5355
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5357
5356
|
}
|
|
5358
|
-
if (
|
|
5357
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
5359
5358
|
const propertyNames = [];
|
|
5360
5359
|
for (const member of typeNode.members) {
|
|
5361
|
-
if (!
|
|
5360
|
+
if (!ts6.isPropertySignature(member)) {
|
|
5362
5361
|
continue;
|
|
5363
5362
|
}
|
|
5364
5363
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5368,13 +5367,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5368
5367
|
}
|
|
5369
5368
|
return propertyNames;
|
|
5370
5369
|
}
|
|
5371
|
-
if (
|
|
5370
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5372
5371
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5373
5372
|
}
|
|
5374
5373
|
return null;
|
|
5375
5374
|
}
|
|
5376
5375
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5377
|
-
if (!
|
|
5376
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
5378
5377
|
return [];
|
|
5379
5378
|
}
|
|
5380
5379
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5575,7 +5574,7 @@ function makeFileProvenance(filePath) {
|
|
|
5575
5574
|
}
|
|
5576
5575
|
|
|
5577
5576
|
// src/extensions/symbol-registry.ts
|
|
5578
|
-
var
|
|
5577
|
+
var ts7 = __toESM(require("typescript"), 1);
|
|
5579
5578
|
var path2 = __toESM(require("path"), 1);
|
|
5580
5579
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5581
5580
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5585,10 +5584,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5585
5584
|
return symbolMap;
|
|
5586
5585
|
}
|
|
5587
5586
|
function visit(node) {
|
|
5588
|
-
if (
|
|
5587
|
+
if (ts7.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5589
5588
|
processDefineCustomTypeCall(node);
|
|
5590
5589
|
}
|
|
5591
|
-
|
|
5590
|
+
ts7.forEachChild(node, visit);
|
|
5592
5591
|
}
|
|
5593
5592
|
function processDefineCustomTypeCall(call) {
|
|
5594
5593
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5596,7 +5595,7 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5596
5595
|
return;
|
|
5597
5596
|
}
|
|
5598
5597
|
const resolvedType = checker.getTypeFromTypeNode(typeArgNode);
|
|
5599
|
-
const canonical =
|
|
5598
|
+
const canonical = resolveCanonicalSymbol(resolvedType, checker);
|
|
5600
5599
|
if (canonical === void 0) {
|
|
5601
5600
|
return;
|
|
5602
5601
|
}
|
|
@@ -5625,7 +5624,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5625
5624
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5626
5625
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5627
5626
|
if (callSymbol !== void 0) {
|
|
5628
|
-
const resolved = callSymbol.flags &
|
|
5627
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5629
5628
|
const decl = resolved.declarations?.[0];
|
|
5630
5629
|
if (decl !== void 0) {
|
|
5631
5630
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5633,29 +5632,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5633
5632
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5634
5633
|
}
|
|
5635
5634
|
}
|
|
5636
|
-
return
|
|
5637
|
-
}
|
|
5638
|
-
function resolveCanonicalSymbol2(type, checker) {
|
|
5639
|
-
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
5640
|
-
if (raw === void 0) return void 0;
|
|
5641
|
-
return raw.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
5635
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5642
5636
|
}
|
|
5643
5637
|
function extractTypeNameFromCallArg(call) {
|
|
5644
5638
|
const arg = call.arguments[0];
|
|
5645
|
-
if (arg === void 0 || !
|
|
5639
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5646
5640
|
return null;
|
|
5647
5641
|
}
|
|
5648
5642
|
const typeNameProp = arg.properties.find(
|
|
5649
|
-
(p) =>
|
|
5643
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5650
5644
|
);
|
|
5651
|
-
if (typeNameProp === void 0 || !
|
|
5645
|
+
if (typeNameProp === void 0 || !ts7.isStringLiteral(typeNameProp.initializer)) {
|
|
5652
5646
|
return null;
|
|
5653
5647
|
}
|
|
5654
5648
|
return typeNameProp.initializer.text;
|
|
5655
5649
|
}
|
|
5656
5650
|
function extractEnclosingExtensionId(call, checker) {
|
|
5657
|
-
for (let node = call.parent; !
|
|
5658
|
-
if (
|
|
5651
|
+
for (let node = call.parent; !ts7.isSourceFile(node); node = node.parent) {
|
|
5652
|
+
if (ts7.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5659
5653
|
return extractExtensionIdFromCallArg(node);
|
|
5660
5654
|
}
|
|
5661
5655
|
}
|
|
@@ -5664,24 +5658,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5664
5658
|
function isDefineExtensionCall(node, checker) {
|
|
5665
5659
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5666
5660
|
if (callSymbol !== void 0) {
|
|
5667
|
-
const resolved = callSymbol.flags &
|
|
5661
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5668
5662
|
const decl = resolved.declarations?.[0];
|
|
5669
5663
|
if (decl !== void 0) {
|
|
5670
5664
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5671
5665
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5672
5666
|
}
|
|
5673
5667
|
}
|
|
5674
|
-
return
|
|
5668
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5675
5669
|
}
|
|
5676
5670
|
function extractExtensionIdFromCallArg(call) {
|
|
5677
5671
|
const arg = call.arguments[0];
|
|
5678
|
-
if (arg === void 0 || !
|
|
5672
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5679
5673
|
return null;
|
|
5680
5674
|
}
|
|
5681
5675
|
const prop = arg.properties.find(
|
|
5682
|
-
(p) =>
|
|
5676
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5683
5677
|
);
|
|
5684
|
-
if (prop === void 0 || !
|
|
5678
|
+
if (prop === void 0 || !ts7.isStringLiteral(prop.initializer)) {
|
|
5685
5679
|
return null;
|
|
5686
5680
|
}
|
|
5687
5681
|
return prop.initializer.text;
|
|
@@ -5701,9 +5695,9 @@ function findRegistrationByTypeName(registry, typeName) {
|
|
|
5701
5695
|
}
|
|
5702
5696
|
|
|
5703
5697
|
// src/validate/constraint-validator.ts
|
|
5704
|
-
var
|
|
5698
|
+
var import_internal5 = require("@formspec/analysis/internal");
|
|
5705
5699
|
function validateFieldNode(ctx, field) {
|
|
5706
|
-
const analysis = (0,
|
|
5700
|
+
const analysis = (0, import_internal5.analyzeConstraintTargets)(
|
|
5707
5701
|
field.name,
|
|
5708
5702
|
field.type,
|
|
5709
5703
|
field.constraints,
|
|
@@ -5721,7 +5715,7 @@ function validateFieldNode(ctx, field) {
|
|
|
5721
5715
|
}
|
|
5722
5716
|
function validateObjectProperty(ctx, parentName, property) {
|
|
5723
5717
|
const qualifiedName = `${parentName}.${property.name}`;
|
|
5724
|
-
const analysis = (0,
|
|
5718
|
+
const analysis = (0, import_internal5.analyzeConstraintTargets)(
|
|
5725
5719
|
qualifiedName,
|
|
5726
5720
|
property.type,
|
|
5727
5721
|
property.constraints,
|
|
@@ -5943,7 +5937,7 @@ function generateSchemasBatch(options) {
|
|
|
5943
5937
|
return options.targets.map((target) => {
|
|
5944
5938
|
let ctx;
|
|
5945
5939
|
try {
|
|
5946
|
-
const cacheKey =
|
|
5940
|
+
const cacheKey = ts8.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
5947
5941
|
const cachedContext = contextCache.get(cacheKey);
|
|
5948
5942
|
if (cachedContext === void 0) {
|
|
5949
5943
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6099,7 +6093,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6099
6093
|
}
|
|
6100
6094
|
|
|
6101
6095
|
// src/static-build.ts
|
|
6102
|
-
var
|
|
6096
|
+
var ts9 = __toESM(require("typescript"), 1);
|
|
6103
6097
|
function toStaticBuildContext(context) {
|
|
6104
6098
|
return context;
|
|
6105
6099
|
}
|
|
@@ -6114,7 +6108,7 @@ function getModuleSymbol(context) {
|
|
|
6114
6108
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6115
6109
|
}
|
|
6116
6110
|
function isSchemaSourceDeclaration(declaration) {
|
|
6117
|
-
return
|
|
6111
|
+
return ts9.isClassDeclaration(declaration) || ts9.isInterfaceDeclaration(declaration) || ts9.isTypeAliasDeclaration(declaration);
|
|
6118
6112
|
}
|
|
6119
6113
|
function resolveModuleExport(context, exportName = "default") {
|
|
6120
6114
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6125,15 +6119,15 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6125
6119
|
if (exportSymbol === null) {
|
|
6126
6120
|
return null;
|
|
6127
6121
|
}
|
|
6128
|
-
return exportSymbol.flags &
|
|
6122
|
+
return exportSymbol.flags & ts9.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6129
6123
|
}
|
|
6130
6124
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6131
6125
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6132
6126
|
}
|
|
6133
6127
|
|
|
6134
6128
|
// src/generators/discovered-schema.ts
|
|
6135
|
-
var
|
|
6136
|
-
var
|
|
6129
|
+
var ts10 = __toESM(require("typescript"), 1);
|
|
6130
|
+
var import_internal6 = require("@formspec/analysis/internal");
|
|
6137
6131
|
var import_internals6 = require("@formspec/core/internals");
|
|
6138
6132
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
6139
6133
|
return {
|
|
@@ -6142,17 +6136,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6142
6136
|
};
|
|
6143
6137
|
}
|
|
6144
6138
|
function isNamedTypeDeclaration(declaration) {
|
|
6145
|
-
return
|
|
6139
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6146
6140
|
}
|
|
6147
6141
|
function hasConcreteTypeArguments(type, checker) {
|
|
6148
6142
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6149
6143
|
return true;
|
|
6150
6144
|
}
|
|
6151
|
-
if ((type.flags &
|
|
6145
|
+
if ((type.flags & ts10.TypeFlags.Object) === 0) {
|
|
6152
6146
|
return false;
|
|
6153
6147
|
}
|
|
6154
6148
|
const objectType = type;
|
|
6155
|
-
if ((objectType.objectFlags &
|
|
6149
|
+
if ((objectType.objectFlags & ts10.ObjectFlags.Reference) === 0) {
|
|
6156
6150
|
return false;
|
|
6157
6151
|
}
|
|
6158
6152
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6165,13 +6159,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6165
6159
|
return declaration;
|
|
6166
6160
|
}
|
|
6167
6161
|
}
|
|
6168
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6162
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts10.isTypeAliasDeclaration);
|
|
6169
6163
|
return aliasDeclaration;
|
|
6170
6164
|
}
|
|
6171
6165
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6172
6166
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6173
6167
|
const namedNode = sourceNode;
|
|
6174
|
-
if (namedNode.name !== void 0 &&
|
|
6168
|
+
if (namedNode.name !== void 0 && ts10.isIdentifier(namedNode.name)) {
|
|
6175
6169
|
return namedNode.name.text;
|
|
6176
6170
|
}
|
|
6177
6171
|
}
|
|
@@ -6393,7 +6387,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6393
6387
|
function generateSchemasFromDeclaration(options) {
|
|
6394
6388
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6395
6389
|
const resolved = resolveStaticOptions(options);
|
|
6396
|
-
if (
|
|
6390
|
+
if (ts10.isClassDeclaration(options.declaration)) {
|
|
6397
6391
|
return generateSchemasFromAnalysis(
|
|
6398
6392
|
analyzeClassToIR(
|
|
6399
6393
|
options.declaration,
|
|
@@ -6407,7 +6401,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6407
6401
|
resolved
|
|
6408
6402
|
);
|
|
6409
6403
|
}
|
|
6410
|
-
if (
|
|
6404
|
+
if (ts10.isInterfaceDeclaration(options.declaration)) {
|
|
6411
6405
|
return generateSchemasFromAnalysis(
|
|
6412
6406
|
analyzeInterfaceToIR(
|
|
6413
6407
|
options.declaration,
|
|
@@ -6421,7 +6415,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6421
6415
|
resolved
|
|
6422
6416
|
);
|
|
6423
6417
|
}
|
|
6424
|
-
if (
|
|
6418
|
+
if (ts10.isTypeAliasDeclaration(options.declaration)) {
|
|
6425
6419
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6426
6420
|
options.declaration,
|
|
6427
6421
|
options.context.checker,
|
|
@@ -6480,7 +6474,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6480
6474
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6481
6475
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6482
6476
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6483
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6477
|
+
const fallbackName = options.declaration.name !== void 0 && ts10.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6484
6478
|
return generateSchemasFromResolvedType({
|
|
6485
6479
|
...options,
|
|
6486
6480
|
type,
|
|
@@ -6490,7 +6484,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6490
6484
|
}
|
|
6491
6485
|
function resolveDeclarationMetadata(options) {
|
|
6492
6486
|
const resolved = resolveStaticOptions(options);
|
|
6493
|
-
const analysis = (0,
|
|
6487
|
+
const analysis = (0, import_internal6.analyzeMetadataForNodeWithChecker)({
|
|
6494
6488
|
checker: options.context.checker,
|
|
6495
6489
|
node: options.declaration,
|
|
6496
6490
|
metadata: resolved.metadata,
|
|
@@ -6527,14 +6521,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6527
6521
|
if (typeNode === void 0) {
|
|
6528
6522
|
return void 0;
|
|
6529
6523
|
}
|
|
6530
|
-
if (
|
|
6524
|
+
if (ts10.isParenthesizedTypeNode(typeNode)) {
|
|
6531
6525
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6532
6526
|
return unwrapped ?? typeNode;
|
|
6533
6527
|
}
|
|
6534
6528
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6535
6529
|
}
|
|
6536
6530
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6537
|
-
return
|
|
6531
|
+
return ts10.isTypeReferenceNode(typeNode) && ts10.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6538
6532
|
}
|
|
6539
6533
|
|
|
6540
6534
|
// src/generators/mixed-authoring.ts
|