@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/cli.js
CHANGED
|
@@ -2275,8 +2275,134 @@ var init_schema2 = __esm({
|
|
|
2275
2275
|
}
|
|
2276
2276
|
});
|
|
2277
2277
|
|
|
2278
|
-
// src/
|
|
2278
|
+
// src/extensions/ts-type-utils.ts
|
|
2279
2279
|
import * as ts from "typescript";
|
|
2280
|
+
function collectBrandIdentifiers(type) {
|
|
2281
|
+
if (!type.isIntersection()) {
|
|
2282
|
+
return [];
|
|
2283
|
+
}
|
|
2284
|
+
const brands = [];
|
|
2285
|
+
for (const prop of type.getProperties()) {
|
|
2286
|
+
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
2287
|
+
if (decl === void 0) continue;
|
|
2288
|
+
if (!ts.isPropertySignature(decl) && !ts.isPropertyDeclaration(decl)) continue;
|
|
2289
|
+
if (!ts.isComputedPropertyName(decl.name)) continue;
|
|
2290
|
+
if (!ts.isIdentifier(decl.name.expression)) continue;
|
|
2291
|
+
brands.push(decl.name.expression.text);
|
|
2292
|
+
}
|
|
2293
|
+
return brands;
|
|
2294
|
+
}
|
|
2295
|
+
function resolveCanonicalSymbol(type, checker) {
|
|
2296
|
+
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
2297
|
+
if (raw === void 0) return void 0;
|
|
2298
|
+
return raw.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
2299
|
+
}
|
|
2300
|
+
function extractTypeNodeFromSource(sourceNode) {
|
|
2301
|
+
if (ts.isPropertyDeclaration(sourceNode) || ts.isPropertySignature(sourceNode) || ts.isParameter(sourceNode) || ts.isTypeAliasDeclaration(sourceNode)) {
|
|
2302
|
+
return sourceNode.type;
|
|
2303
|
+
}
|
|
2304
|
+
if (ts.isTypeNode(sourceNode)) {
|
|
2305
|
+
return sourceNode;
|
|
2306
|
+
}
|
|
2307
|
+
return void 0;
|
|
2308
|
+
}
|
|
2309
|
+
function resolveAliasedSymbol(symbol, checker) {
|
|
2310
|
+
if (symbol === void 0) return void 0;
|
|
2311
|
+
return symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
2312
|
+
}
|
|
2313
|
+
function getTypeAliasDeclarationFromTypeReference(typeNode, checker) {
|
|
2314
|
+
const symbol = checker.getSymbolAtLocation(typeNode.typeName);
|
|
2315
|
+
return resolveAliasedSymbol(symbol, checker)?.declarations?.find(ts.isTypeAliasDeclaration);
|
|
2316
|
+
}
|
|
2317
|
+
var init_ts_type_utils = __esm({
|
|
2318
|
+
"src/extensions/ts-type-utils.ts"() {
|
|
2319
|
+
"use strict";
|
|
2320
|
+
}
|
|
2321
|
+
});
|
|
2322
|
+
|
|
2323
|
+
// src/extensions/resolve-custom-type.ts
|
|
2324
|
+
import * as ts2 from "typescript";
|
|
2325
|
+
import { stripNullishUnion } from "@formspec/analysis/internal";
|
|
2326
|
+
function getTypeNodeRegistrationName(typeNode) {
|
|
2327
|
+
if (ts2.isTypeReferenceNode(typeNode)) {
|
|
2328
|
+
return ts2.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : typeNode.typeName.right.text;
|
|
2329
|
+
}
|
|
2330
|
+
if (ts2.isParenthesizedTypeNode(typeNode)) {
|
|
2331
|
+
return getTypeNodeRegistrationName(typeNode.type);
|
|
2332
|
+
}
|
|
2333
|
+
if (typeNode.kind === ts2.SyntaxKind.BigIntKeyword || typeNode.kind === ts2.SyntaxKind.StringKeyword || typeNode.kind === ts2.SyntaxKind.NumberKeyword || typeNode.kind === ts2.SyntaxKind.BooleanKeyword) {
|
|
2334
|
+
return typeNode.getText();
|
|
2335
|
+
}
|
|
2336
|
+
return null;
|
|
2337
|
+
}
|
|
2338
|
+
function resolveByNameFromTypeNode(typeNode, registry, checker) {
|
|
2339
|
+
if (ts2.isParenthesizedTypeNode(typeNode)) {
|
|
2340
|
+
return resolveByNameFromTypeNode(typeNode.type, registry, checker);
|
|
2341
|
+
}
|
|
2342
|
+
const typeName = getTypeNodeRegistrationName(typeNode);
|
|
2343
|
+
if (typeName !== null) {
|
|
2344
|
+
const byName = registry.findTypeByName(typeName);
|
|
2345
|
+
if (byName !== void 0) {
|
|
2346
|
+
return byName;
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
if (ts2.isTypeReferenceNode(typeNode) && ts2.isIdentifier(typeNode.typeName)) {
|
|
2350
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
2351
|
+
if (aliasDecl !== void 0) {
|
|
2352
|
+
return resolveByNameFromTypeNode(aliasDecl.type, registry, checker);
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
return null;
|
|
2356
|
+
}
|
|
2357
|
+
function resolveCustomTypeFromTsType(type, checker, registry, sourceNode) {
|
|
2358
|
+
if (registry === void 0) {
|
|
2359
|
+
return null;
|
|
2360
|
+
}
|
|
2361
|
+
const stripped = stripNullishUnion(type);
|
|
2362
|
+
if (sourceNode !== void 0) {
|
|
2363
|
+
const typeNode = extractTypeNodeFromSource(sourceNode);
|
|
2364
|
+
if (typeNode !== void 0) {
|
|
2365
|
+
const byName = resolveByNameFromTypeNode(typeNode, registry, checker);
|
|
2366
|
+
if (byName !== null) {
|
|
2367
|
+
return byName;
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
} else {
|
|
2371
|
+
const typeName = (stripped.aliasSymbol ?? stripped.getSymbol())?.getName();
|
|
2372
|
+
if (typeName !== void 0) {
|
|
2373
|
+
const byName = registry.findTypeByName(typeName);
|
|
2374
|
+
if (byName !== void 0) {
|
|
2375
|
+
return byName;
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
const canonical = resolveCanonicalSymbol(stripped, checker);
|
|
2380
|
+
if (canonical !== void 0) {
|
|
2381
|
+
const bySymbol = registry.findTypeBySymbol(canonical);
|
|
2382
|
+
if (bySymbol !== void 0) {
|
|
2383
|
+
return bySymbol;
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
for (const brand of collectBrandIdentifiers(stripped)) {
|
|
2387
|
+
const byBrand = registry.findTypeByBrand(brand);
|
|
2388
|
+
if (byBrand !== void 0) {
|
|
2389
|
+
return byBrand;
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
return null;
|
|
2393
|
+
}
|
|
2394
|
+
function customTypeIdFromLookup(result) {
|
|
2395
|
+
return `${result.extensionId}/${result.registration.typeName}`;
|
|
2396
|
+
}
|
|
2397
|
+
var init_resolve_custom_type = __esm({
|
|
2398
|
+
"src/extensions/resolve-custom-type.ts"() {
|
|
2399
|
+
"use strict";
|
|
2400
|
+
init_ts_type_utils();
|
|
2401
|
+
}
|
|
2402
|
+
});
|
|
2403
|
+
|
|
2404
|
+
// src/analyzer/tsdoc-parser.ts
|
|
2405
|
+
import * as ts3 from "typescript";
|
|
2280
2406
|
import {
|
|
2281
2407
|
checkSyntheticTagApplication,
|
|
2282
2408
|
choosePreferredPayloadText,
|
|
@@ -2317,23 +2443,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2317
2443
|
function collectImportedNames(sourceFile) {
|
|
2318
2444
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2319
2445
|
for (const statement of sourceFile.statements) {
|
|
2320
|
-
if (
|
|
2446
|
+
if (ts3.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2321
2447
|
const clause = statement.importClause;
|
|
2322
2448
|
if (clause.name !== void 0) {
|
|
2323
2449
|
importedNames.add(clause.name.text);
|
|
2324
2450
|
}
|
|
2325
2451
|
if (clause.namedBindings !== void 0) {
|
|
2326
|
-
if (
|
|
2452
|
+
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
2327
2453
|
for (const specifier of clause.namedBindings.elements) {
|
|
2328
2454
|
importedNames.add(specifier.name.text);
|
|
2329
2455
|
}
|
|
2330
|
-
} else if (
|
|
2456
|
+
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
2331
2457
|
importedNames.add(clause.namedBindings.name.text);
|
|
2332
2458
|
}
|
|
2333
2459
|
}
|
|
2334
2460
|
continue;
|
|
2335
2461
|
}
|
|
2336
|
-
if (
|
|
2462
|
+
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
2337
2463
|
importedNames.add(statement.name.text);
|
|
2338
2464
|
}
|
|
2339
2465
|
}
|
|
@@ -2341,13 +2467,13 @@ function collectImportedNames(sourceFile) {
|
|
|
2341
2467
|
}
|
|
2342
2468
|
function isNonReferenceIdentifier(node) {
|
|
2343
2469
|
const parent = node.parent;
|
|
2344
|
-
if ((
|
|
2470
|
+
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) {
|
|
2345
2471
|
return true;
|
|
2346
2472
|
}
|
|
2347
|
-
if ((
|
|
2473
|
+
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2348
2474
|
return true;
|
|
2349
2475
|
}
|
|
2350
|
-
if (
|
|
2476
|
+
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
2351
2477
|
return true;
|
|
2352
2478
|
}
|
|
2353
2479
|
return false;
|
|
@@ -2361,11 +2487,11 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
2361
2487
|
if (referencesImportedName) {
|
|
2362
2488
|
return;
|
|
2363
2489
|
}
|
|
2364
|
-
if (
|
|
2490
|
+
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2365
2491
|
referencesImportedName = true;
|
|
2366
2492
|
return;
|
|
2367
2493
|
}
|
|
2368
|
-
|
|
2494
|
+
ts3.forEachChild(node, visit);
|
|
2369
2495
|
};
|
|
2370
2496
|
visit(statement);
|
|
2371
2497
|
return referencesImportedName;
|
|
@@ -2376,9 +2502,9 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
2376
2502
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2377
2503
|
);
|
|
2378
2504
|
return sourceFile.statements.filter((statement) => {
|
|
2379
|
-
if (
|
|
2380
|
-
if (
|
|
2381
|
-
if (
|
|
2505
|
+
if (ts3.isImportDeclaration(statement)) return false;
|
|
2506
|
+
if (ts3.isImportEqualsDeclaration(statement)) return false;
|
|
2507
|
+
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
2382
2508
|
return false;
|
|
2383
2509
|
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2384
2510
|
return false;
|
|
@@ -2474,7 +2600,7 @@ function stripHintNullishUnion(type) {
|
|
|
2474
2600
|
return type;
|
|
2475
2601
|
}
|
|
2476
2602
|
const nonNullish = type.types.filter(
|
|
2477
|
-
(member) => (member.flags & (
|
|
2603
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
2478
2604
|
);
|
|
2479
2605
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2480
2606
|
return nonNullish[0];
|
|
@@ -2490,10 +2616,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2490
2616
|
}
|
|
2491
2617
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2492
2618
|
const name = declaration.name;
|
|
2493
|
-
if (
|
|
2619
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
2494
2620
|
return false;
|
|
2495
2621
|
}
|
|
2496
|
-
if (!
|
|
2622
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
2497
2623
|
return false;
|
|
2498
2624
|
}
|
|
2499
2625
|
}
|
|
@@ -2665,7 +2791,8 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2665
2791
|
];
|
|
2666
2792
|
}
|
|
2667
2793
|
const target = parsedTag?.target ?? null;
|
|
2668
|
-
|
|
2794
|
+
let evaluatedType = subjectType;
|
|
2795
|
+
let targetLabel = node.getText(sourceFile);
|
|
2669
2796
|
if (target !== null) {
|
|
2670
2797
|
if (target.kind !== "path") {
|
|
2671
2798
|
return [
|
|
@@ -2705,29 +2832,30 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2705
2832
|
)
|
|
2706
2833
|
];
|
|
2707
2834
|
}
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
`Target "${target.rawText}": constraint "${tagName}" is only valid on ${capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`,
|
|
2715
|
-
provenance
|
|
2716
|
-
)
|
|
2717
|
-
];
|
|
2835
|
+
evaluatedType = resolution.type;
|
|
2836
|
+
targetLabel = target.rawText;
|
|
2837
|
+
}
|
|
2838
|
+
const hasBroadening = (() => {
|
|
2839
|
+
if (target === null) {
|
|
2840
|
+
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2718
2841
|
}
|
|
2719
|
-
|
|
2842
|
+
const registry = options?.extensionRegistry;
|
|
2843
|
+
if (registry === void 0) return false;
|
|
2844
|
+
const resolved = resolveCustomTypeFromTsType(evaluatedType, checker, registry);
|
|
2845
|
+
return resolved !== null && registry.findBuiltinConstraintBroadening(customTypeIdFromLookup(resolved), tagName) !== void 0;
|
|
2846
|
+
})();
|
|
2847
|
+
if (!hasBroadening) {
|
|
2720
2848
|
const requiredCapability = definition.capabilities[0];
|
|
2721
|
-
if (requiredCapability !== void 0 && !supportsConstraintCapability(
|
|
2722
|
-
const actualType = checker.typeToString(
|
|
2723
|
-
const baseMessage = `Target "${
|
|
2724
|
-
const hint = buildPathTargetHint(
|
|
2849
|
+
if (requiredCapability !== void 0 && !supportsConstraintCapability(evaluatedType, checker, requiredCapability)) {
|
|
2850
|
+
const actualType = checker.typeToString(evaluatedType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2851
|
+
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`;
|
|
2852
|
+
const hint = target === null ? buildPathTargetHint(
|
|
2725
2853
|
subjectType,
|
|
2726
2854
|
checker,
|
|
2727
2855
|
requiredCapability,
|
|
2728
2856
|
tagName,
|
|
2729
2857
|
parsedTag?.argumentText
|
|
2730
|
-
);
|
|
2858
|
+
) : null;
|
|
2731
2859
|
return [
|
|
2732
2860
|
makeDiagnostic(
|
|
2733
2861
|
"TYPE_MISMATCH",
|
|
@@ -2860,12 +2988,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2860
2988
|
const sourceText = sourceFile.getFullText();
|
|
2861
2989
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2862
2990
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2863
|
-
const commentRanges =
|
|
2991
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2864
2992
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2865
2993
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2866
2994
|
if (commentRanges) {
|
|
2867
2995
|
for (const range of commentRanges) {
|
|
2868
|
-
if (range.kind !==
|
|
2996
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
2869
2997
|
continue;
|
|
2870
2998
|
}
|
|
2871
2999
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3022,10 +3150,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3022
3150
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3023
3151
|
const sourceFile = node.getSourceFile();
|
|
3024
3152
|
const sourceText = sourceFile.getFullText();
|
|
3025
|
-
const commentRanges =
|
|
3153
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3026
3154
|
if (commentRanges) {
|
|
3027
3155
|
for (const range of commentRanges) {
|
|
3028
|
-
if (range.kind !==
|
|
3156
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3029
3157
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3030
3158
|
if (!commentText.startsWith("/**")) continue;
|
|
3031
3159
|
const unified = parseUnifiedComment(commentText);
|
|
@@ -3050,7 +3178,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3050
3178
|
}
|
|
3051
3179
|
function collectRawTextFallbacks(node, file) {
|
|
3052
3180
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3053
|
-
for (const tag of
|
|
3181
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
3054
3182
|
const tagName = normalizeConstraintTagName2(tag.tagName.text);
|
|
3055
3183
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3056
3184
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3105,13 +3233,14 @@ function getTagCommentText(tag) {
|
|
|
3105
3233
|
if (typeof tag.comment === "string") {
|
|
3106
3234
|
return tag.comment;
|
|
3107
3235
|
}
|
|
3108
|
-
return
|
|
3236
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
3109
3237
|
}
|
|
3110
3238
|
var SYNTHETIC_TYPE_FORMAT_FLAGS, MAX_HINT_CANDIDATES, MAX_HINT_DEPTH, parseResultCache;
|
|
3111
3239
|
var init_tsdoc_parser = __esm({
|
|
3112
3240
|
"src/analyzer/tsdoc-parser.ts"() {
|
|
3113
3241
|
"use strict";
|
|
3114
|
-
|
|
3242
|
+
init_resolve_custom_type();
|
|
3243
|
+
SYNTHETIC_TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
3115
3244
|
MAX_HINT_CANDIDATES = 5;
|
|
3116
3245
|
MAX_HINT_DEPTH = 3;
|
|
3117
3246
|
parseResultCache = /* @__PURE__ */ new Map();
|
|
@@ -3119,7 +3248,7 @@ var init_tsdoc_parser = __esm({
|
|
|
3119
3248
|
});
|
|
3120
3249
|
|
|
3121
3250
|
// src/analyzer/jsdoc-constraints.ts
|
|
3122
|
-
import * as
|
|
3251
|
+
import * as ts4 from "typescript";
|
|
3123
3252
|
function extractJSDocParseResult(node, file = "", options) {
|
|
3124
3253
|
return parseTSDocTags(node, file, options);
|
|
3125
3254
|
}
|
|
@@ -3134,18 +3263,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3134
3263
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3135
3264
|
if (!initializer) return null;
|
|
3136
3265
|
let value;
|
|
3137
|
-
if (
|
|
3266
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
3138
3267
|
value = initializer.text;
|
|
3139
|
-
} else if (
|
|
3268
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
3140
3269
|
value = Number(initializer.text);
|
|
3141
|
-
} else if (initializer.kind ===
|
|
3270
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
3142
3271
|
value = true;
|
|
3143
|
-
} else if (initializer.kind ===
|
|
3272
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
3144
3273
|
value = false;
|
|
3145
|
-
} else if (initializer.kind ===
|
|
3274
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
3146
3275
|
value = null;
|
|
3147
|
-
} else if (
|
|
3148
|
-
if (initializer.operator ===
|
|
3276
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
3277
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
3149
3278
|
value = -Number(initializer.operand.text);
|
|
3150
3279
|
}
|
|
3151
3280
|
}
|
|
@@ -3172,99 +3301,44 @@ var init_jsdoc_constraints = __esm({
|
|
|
3172
3301
|
});
|
|
3173
3302
|
|
|
3174
3303
|
// src/analyzer/class-analyzer.ts
|
|
3175
|
-
import * as
|
|
3304
|
+
import * as ts5 from "typescript";
|
|
3176
3305
|
import {
|
|
3177
3306
|
analyzeMetadataForNodeWithChecker,
|
|
3178
3307
|
parseCommentBlock
|
|
3179
3308
|
} from "@formspec/analysis/internal";
|
|
3180
3309
|
function isObjectType(type) {
|
|
3181
|
-
return !!(type.flags &
|
|
3310
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
3182
3311
|
}
|
|
3183
3312
|
function isIntersectionType(type) {
|
|
3184
|
-
return !!(type.flags &
|
|
3185
|
-
}
|
|
3186
|
-
function collectBrandIdentifiers(type) {
|
|
3187
|
-
if (!type.isIntersection()) {
|
|
3188
|
-
return [];
|
|
3189
|
-
}
|
|
3190
|
-
const brands = [];
|
|
3191
|
-
for (const prop of type.getProperties()) {
|
|
3192
|
-
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
3193
|
-
if (decl === void 0) continue;
|
|
3194
|
-
if (!ts3.isPropertySignature(decl) && !ts3.isPropertyDeclaration(decl)) continue;
|
|
3195
|
-
if (!ts3.isComputedPropertyName(decl.name)) continue;
|
|
3196
|
-
if (!ts3.isIdentifier(decl.name.expression)) continue;
|
|
3197
|
-
brands.push(decl.name.expression.text);
|
|
3198
|
-
}
|
|
3199
|
-
return brands;
|
|
3200
|
-
}
|
|
3201
|
-
function resolveCanonicalSymbol(type, checker) {
|
|
3202
|
-
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
3203
|
-
if (raw === void 0) return void 0;
|
|
3204
|
-
return raw.flags & ts3.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
3205
|
-
}
|
|
3206
|
-
function resolveSymbolBasedCustomType(type, extensionRegistry, checker) {
|
|
3207
|
-
if (extensionRegistry === void 0) {
|
|
3208
|
-
return null;
|
|
3209
|
-
}
|
|
3210
|
-
const canonical = resolveCanonicalSymbol(type, checker);
|
|
3211
|
-
if (canonical === void 0) {
|
|
3212
|
-
return null;
|
|
3213
|
-
}
|
|
3214
|
-
const registration = extensionRegistry.findTypeBySymbol(canonical);
|
|
3215
|
-
if (registration === void 0) {
|
|
3216
|
-
return null;
|
|
3217
|
-
}
|
|
3218
|
-
return {
|
|
3219
|
-
kind: "custom",
|
|
3220
|
-
typeId: `${registration.extensionId}/${registration.registration.typeName}`,
|
|
3221
|
-
payload: null
|
|
3222
|
-
};
|
|
3313
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
3223
3314
|
}
|
|
3224
3315
|
function isIntegerBrandedType(type) {
|
|
3225
3316
|
if (!type.isIntersection()) {
|
|
3226
3317
|
return false;
|
|
3227
3318
|
}
|
|
3228
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags &
|
|
3319
|
+
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3229
3320
|
if (!hasNumberBase) {
|
|
3230
3321
|
return false;
|
|
3231
3322
|
}
|
|
3232
3323
|
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3233
3324
|
}
|
|
3234
|
-
function resolveBrandedCustomType(type, extensionRegistry) {
|
|
3235
|
-
if (extensionRegistry === void 0) {
|
|
3236
|
-
return null;
|
|
3237
|
-
}
|
|
3238
|
-
for (const brand of collectBrandIdentifiers(type)) {
|
|
3239
|
-
const registration = extensionRegistry.findTypeByBrand(brand);
|
|
3240
|
-
if (registration === void 0) {
|
|
3241
|
-
continue;
|
|
3242
|
-
}
|
|
3243
|
-
return {
|
|
3244
|
-
kind: "custom",
|
|
3245
|
-
typeId: `${registration.extensionId}/${registration.registration.typeName}`,
|
|
3246
|
-
payload: null
|
|
3247
|
-
};
|
|
3248
|
-
}
|
|
3249
|
-
return null;
|
|
3250
|
-
}
|
|
3251
3325
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3252
|
-
if (
|
|
3326
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3253
3327
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3254
3328
|
}
|
|
3255
|
-
if (
|
|
3329
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
3256
3330
|
return true;
|
|
3257
3331
|
}
|
|
3258
|
-
return
|
|
3332
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3259
3333
|
}
|
|
3260
3334
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3261
3335
|
if (isIntersectionType(type)) {
|
|
3262
3336
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3263
3337
|
}
|
|
3264
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3338
|
+
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);
|
|
3265
3339
|
}
|
|
3266
3340
|
function isTypeReference(type) {
|
|
3267
|
-
return !!(type.flags &
|
|
3341
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
3268
3342
|
}
|
|
3269
3343
|
function makeParseOptions(extensionRegistry, fieldType, checker, subjectType, hostType) {
|
|
3270
3344
|
if (extensionRegistry === void 0 && fieldType === void 0 && checker === void 0 && subjectType === void 0 && hostType === void 0) {
|
|
@@ -3324,7 +3398,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3324
3398
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3325
3399
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3326
3400
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3327
|
-
const logicalName =
|
|
3401
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3328
3402
|
const docResult = extractJSDocParseResult(
|
|
3329
3403
|
declaration,
|
|
3330
3404
|
file,
|
|
@@ -3372,7 +3446,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3372
3446
|
const instanceMethods = [];
|
|
3373
3447
|
const staticMethods = [];
|
|
3374
3448
|
for (const member of classDecl.members) {
|
|
3375
|
-
if (
|
|
3449
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
3376
3450
|
const fieldNode = analyzeFieldToIR(
|
|
3377
3451
|
member,
|
|
3378
3452
|
checker,
|
|
@@ -3388,10 +3462,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3388
3462
|
fields.push(fieldNode);
|
|
3389
3463
|
fieldLayouts.push({});
|
|
3390
3464
|
}
|
|
3391
|
-
} else if (
|
|
3465
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
3392
3466
|
const methodInfo = analyzeMethod(member, checker);
|
|
3393
3467
|
if (methodInfo) {
|
|
3394
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3468
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
3395
3469
|
if (isStatic) {
|
|
3396
3470
|
staticMethods.push(methodInfo);
|
|
3397
3471
|
} else {
|
|
@@ -3454,7 +3528,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3454
3528
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3455
3529
|
const visiting = /* @__PURE__ */ new Set();
|
|
3456
3530
|
for (const member of interfaceDecl.members) {
|
|
3457
|
-
if (
|
|
3531
|
+
if (ts5.isPropertySignature(member)) {
|
|
3458
3532
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3459
3533
|
member,
|
|
3460
3534
|
checker,
|
|
@@ -3512,7 +3586,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3512
3586
|
if (members === null) {
|
|
3513
3587
|
const sourceFile = typeAlias.getSourceFile();
|
|
3514
3588
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3515
|
-
const kindDesc =
|
|
3589
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3516
3590
|
return {
|
|
3517
3591
|
ok: false,
|
|
3518
3592
|
kind: "not-object-like",
|
|
@@ -3547,7 +3621,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3547
3621
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3548
3622
|
const visiting = /* @__PURE__ */ new Set();
|
|
3549
3623
|
for (const member of members) {
|
|
3550
|
-
if (
|
|
3624
|
+
if (ts5.isPropertySignature(member)) {
|
|
3551
3625
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3552
3626
|
member,
|
|
3553
3627
|
checker,
|
|
@@ -3614,13 +3688,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3614
3688
|
function getLeadingParsedTags(node) {
|
|
3615
3689
|
const sourceFile = node.getSourceFile();
|
|
3616
3690
|
const sourceText = sourceFile.getFullText();
|
|
3617
|
-
const commentRanges =
|
|
3691
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3618
3692
|
if (commentRanges === void 0) {
|
|
3619
3693
|
return [];
|
|
3620
3694
|
}
|
|
3621
3695
|
const parsedTags = [];
|
|
3622
3696
|
for (const range of commentRanges) {
|
|
3623
|
-
if (range.kind !==
|
|
3697
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
3624
3698
|
continue;
|
|
3625
3699
|
}
|
|
3626
3700
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3638,19 +3712,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3638
3712
|
return null;
|
|
3639
3713
|
}
|
|
3640
3714
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3641
|
-
(candidate) =>
|
|
3715
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
3642
3716
|
) ?? propertySymbol.declarations?.[0];
|
|
3643
3717
|
return {
|
|
3644
3718
|
declaration,
|
|
3645
3719
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3646
|
-
optional: !!(propertySymbol.flags &
|
|
3720
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3647
3721
|
};
|
|
3648
3722
|
}
|
|
3649
3723
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3650
3724
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3651
3725
|
}
|
|
3652
3726
|
function isNullishSemanticType(type) {
|
|
3653
|
-
if (type.flags & (
|
|
3727
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
3654
3728
|
return true;
|
|
3655
3729
|
}
|
|
3656
3730
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3660,7 +3734,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3660
3734
|
return false;
|
|
3661
3735
|
}
|
|
3662
3736
|
seen.add(type);
|
|
3663
|
-
if (type.flags &
|
|
3737
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
3664
3738
|
return true;
|
|
3665
3739
|
}
|
|
3666
3740
|
if (type.isUnion()) {
|
|
@@ -3673,13 +3747,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3673
3747
|
return false;
|
|
3674
3748
|
}
|
|
3675
3749
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3676
|
-
if (
|
|
3750
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3677
3751
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3678
3752
|
}
|
|
3679
|
-
if (
|
|
3753
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
3680
3754
|
return [...typeNode.members];
|
|
3681
3755
|
}
|
|
3682
|
-
if (
|
|
3756
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
3683
3757
|
const members = [];
|
|
3684
3758
|
for (const intersectionMember of typeNode.types) {
|
|
3685
3759
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3842,7 +3916,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3842
3916
|
}
|
|
3843
3917
|
if (propertyType.isUnion()) {
|
|
3844
3918
|
const nonNullMembers = propertyType.types.filter(
|
|
3845
|
-
(member) => !(member.flags & (
|
|
3919
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3846
3920
|
);
|
|
3847
3921
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3848
3922
|
diagnostics.push(
|
|
@@ -3891,13 +3965,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3891
3965
|
seen.add(type);
|
|
3892
3966
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3893
3967
|
if (symbol !== void 0) {
|
|
3894
|
-
const aliased = symbol.flags &
|
|
3968
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3895
3969
|
const targetSymbol = aliased ?? symbol;
|
|
3896
3970
|
const declaration = targetSymbol.declarations?.find(
|
|
3897
|
-
(candidate) =>
|
|
3971
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
3898
3972
|
);
|
|
3899
3973
|
if (declaration !== void 0) {
|
|
3900
|
-
if (
|
|
3974
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3901
3975
|
return resolveNamedDiscriminatorDeclaration(
|
|
3902
3976
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3903
3977
|
checker,
|
|
@@ -3925,7 +3999,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3925
3999
|
}
|
|
3926
4000
|
if (boundType.isUnion()) {
|
|
3927
4001
|
const nonNullMembers = boundType.types.filter(
|
|
3928
|
-
(member) => !(member.flags & (
|
|
4002
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3929
4003
|
);
|
|
3930
4004
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3931
4005
|
diagnostics.push(
|
|
@@ -3970,7 +4044,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3970
4044
|
return null;
|
|
3971
4045
|
}
|
|
3972
4046
|
function getDeclarationName(node) {
|
|
3973
|
-
if (
|
|
4047
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
3974
4048
|
return node.name?.text ?? "anonymous";
|
|
3975
4049
|
}
|
|
3976
4050
|
return "anonymous";
|
|
@@ -4025,11 +4099,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4025
4099
|
if (sourceTypeNode === void 0) {
|
|
4026
4100
|
return [];
|
|
4027
4101
|
}
|
|
4028
|
-
const unwrapParentheses = (typeNode) =>
|
|
4102
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4029
4103
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4030
|
-
const referenceTypeNode =
|
|
4104
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4031
4105
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4032
|
-
return
|
|
4106
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4033
4107
|
})();
|
|
4034
4108
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4035
4109
|
return [];
|
|
@@ -4084,7 +4158,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4084
4158
|
);
|
|
4085
4159
|
}
|
|
4086
4160
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4087
|
-
if (!
|
|
4161
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
4088
4162
|
return null;
|
|
4089
4163
|
}
|
|
4090
4164
|
const name = prop.name.text;
|
|
@@ -4211,7 +4285,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4211
4285
|
const seen = /* @__PURE__ */ new Set();
|
|
4212
4286
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4213
4287
|
for (const member of members) {
|
|
4214
|
-
if (!
|
|
4288
|
+
if (!ts5.isPropertySignature(member)) {
|
|
4215
4289
|
continue;
|
|
4216
4290
|
}
|
|
4217
4291
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4227,7 +4301,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4227
4301
|
return [...duplicates].sort();
|
|
4228
4302
|
}
|
|
4229
4303
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4230
|
-
if (
|
|
4304
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
4231
4305
|
return name.text;
|
|
4232
4306
|
}
|
|
4233
4307
|
return null;
|
|
@@ -4294,74 +4368,20 @@ function parseEnumMemberDisplayName(value) {
|
|
|
4294
4368
|
if (label === "") return null;
|
|
4295
4369
|
return { value: match[1], label };
|
|
4296
4370
|
}
|
|
4297
|
-
function
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
return resolveRegisteredCustomTypeFromTypeNode(typeNode, extensionRegistry, checker);
|
|
4306
|
-
}
|
|
4307
|
-
function resolveRegisteredCustomTypeFromTypeNode(typeNode, extensionRegistry, checker) {
|
|
4308
|
-
if (ts3.isParenthesizedTypeNode(typeNode)) {
|
|
4309
|
-
return resolveRegisteredCustomTypeFromTypeNode(typeNode.type, extensionRegistry, checker);
|
|
4310
|
-
}
|
|
4311
|
-
const typeName = getTypeNodeRegistrationName(typeNode);
|
|
4312
|
-
if (typeName === null) {
|
|
4313
|
-
return null;
|
|
4314
|
-
}
|
|
4315
|
-
const registration = extensionRegistry.findTypeByName(typeName);
|
|
4316
|
-
if (registration !== void 0) {
|
|
4371
|
+
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4372
|
+
const customTypeLookup = resolveCustomTypeFromTsType(
|
|
4373
|
+
type,
|
|
4374
|
+
checker,
|
|
4375
|
+
extensionRegistry,
|
|
4376
|
+
sourceNode
|
|
4377
|
+
);
|
|
4378
|
+
if (customTypeLookup !== null) {
|
|
4317
4379
|
return {
|
|
4318
4380
|
kind: "custom",
|
|
4319
|
-
typeId:
|
|
4381
|
+
typeId: customTypeIdFromLookup(customTypeLookup),
|
|
4320
4382
|
payload: null
|
|
4321
4383
|
};
|
|
4322
4384
|
}
|
|
4323
|
-
if (ts3.isTypeReferenceNode(typeNode) && ts3.isIdentifier(typeNode.typeName)) {
|
|
4324
|
-
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4325
|
-
if (aliasDecl !== void 0) {
|
|
4326
|
-
return resolveRegisteredCustomTypeFromTypeNode(aliasDecl.type, extensionRegistry, checker);
|
|
4327
|
-
}
|
|
4328
|
-
}
|
|
4329
|
-
return null;
|
|
4330
|
-
}
|
|
4331
|
-
function extractTypeNodeFromSource(sourceNode) {
|
|
4332
|
-
if (ts3.isPropertyDeclaration(sourceNode) || ts3.isPropertySignature(sourceNode) || ts3.isParameter(sourceNode) || ts3.isTypeAliasDeclaration(sourceNode)) {
|
|
4333
|
-
return sourceNode.type;
|
|
4334
|
-
}
|
|
4335
|
-
if (ts3.isTypeNode(sourceNode)) {
|
|
4336
|
-
return sourceNode;
|
|
4337
|
-
}
|
|
4338
|
-
return void 0;
|
|
4339
|
-
}
|
|
4340
|
-
function getTypeNodeRegistrationName(typeNode) {
|
|
4341
|
-
if (ts3.isTypeReferenceNode(typeNode)) {
|
|
4342
|
-
return ts3.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : typeNode.typeName.right.text;
|
|
4343
|
-
}
|
|
4344
|
-
if (ts3.isParenthesizedTypeNode(typeNode)) {
|
|
4345
|
-
return getTypeNodeRegistrationName(typeNode.type);
|
|
4346
|
-
}
|
|
4347
|
-
if (typeNode.kind === ts3.SyntaxKind.BigIntKeyword || typeNode.kind === ts3.SyntaxKind.StringKeyword || typeNode.kind === ts3.SyntaxKind.NumberKeyword || typeNode.kind === ts3.SyntaxKind.BooleanKeyword) {
|
|
4348
|
-
return typeNode.getText();
|
|
4349
|
-
}
|
|
4350
|
-
return null;
|
|
4351
|
-
}
|
|
4352
|
-
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4353
|
-
const customType = resolveRegisteredCustomType(sourceNode, extensionRegistry, checker);
|
|
4354
|
-
if (customType) {
|
|
4355
|
-
return customType;
|
|
4356
|
-
}
|
|
4357
|
-
const symbolCustomType = resolveSymbolBasedCustomType(type, extensionRegistry, checker);
|
|
4358
|
-
if (symbolCustomType) {
|
|
4359
|
-
return symbolCustomType;
|
|
4360
|
-
}
|
|
4361
|
-
const brandedCustomType = resolveBrandedCustomType(type, extensionRegistry);
|
|
4362
|
-
if (brandedCustomType) {
|
|
4363
|
-
return brandedCustomType;
|
|
4364
|
-
}
|
|
4365
4385
|
const primitiveAlias = tryResolveNamedPrimitiveAlias(
|
|
4366
4386
|
type,
|
|
4367
4387
|
checker,
|
|
@@ -4379,25 +4399,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4379
4399
|
if (isIntegerBrandedType(type)) {
|
|
4380
4400
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4381
4401
|
}
|
|
4382
|
-
if (type.flags &
|
|
4402
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4383
4403
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4384
4404
|
}
|
|
4385
|
-
if (type.flags &
|
|
4405
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4386
4406
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4387
4407
|
}
|
|
4388
|
-
if (type.flags & (
|
|
4408
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4389
4409
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4390
4410
|
}
|
|
4391
|
-
if (type.flags &
|
|
4411
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4392
4412
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4393
4413
|
}
|
|
4394
|
-
if (type.flags &
|
|
4414
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4395
4415
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4396
4416
|
}
|
|
4397
|
-
if (type.flags &
|
|
4417
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
4398
4418
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4399
4419
|
}
|
|
4400
|
-
if (type.flags &
|
|
4420
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
4401
4421
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4402
4422
|
}
|
|
4403
4423
|
if (type.isStringLiteral()) {
|
|
@@ -4484,10 +4504,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4484
4504
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4485
4505
|
}
|
|
4486
4506
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4487
|
-
if (!(type.flags & (
|
|
4507
|
+
if (!(type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4488
4508
|
return null;
|
|
4489
4509
|
}
|
|
4490
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4510
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4491
4511
|
if (!aliasDecl) {
|
|
4492
4512
|
return null;
|
|
4493
4513
|
}
|
|
@@ -4537,14 +4557,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4537
4557
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4538
4558
|
}
|
|
4539
4559
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4540
|
-
const typeNode = sourceNode && (
|
|
4541
|
-
if (!typeNode || !
|
|
4560
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4561
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
4542
4562
|
return void 0;
|
|
4543
4563
|
}
|
|
4544
4564
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4545
4565
|
}
|
|
4546
4566
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4547
|
-
if (!
|
|
4567
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
4548
4568
|
return false;
|
|
4549
4569
|
}
|
|
4550
4570
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4552,10 +4572,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4552
4572
|
return false;
|
|
4553
4573
|
}
|
|
4554
4574
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4555
|
-
return !!(resolved.flags & (
|
|
4575
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
4556
4576
|
}
|
|
4557
4577
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4558
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4578
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
4559
4579
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4560
4580
|
visitedAliases.add(nestedAliasDecl);
|
|
4561
4581
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4573,19 +4593,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4573
4593
|
if (isIntegerBrandedType(type)) {
|
|
4574
4594
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4575
4595
|
}
|
|
4576
|
-
if (type.flags &
|
|
4596
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4577
4597
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4578
4598
|
}
|
|
4579
|
-
if (type.flags &
|
|
4599
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4580
4600
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4581
4601
|
}
|
|
4582
|
-
if (type.flags & (
|
|
4602
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4583
4603
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4584
4604
|
}
|
|
4585
|
-
if (type.flags &
|
|
4605
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4586
4606
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4587
4607
|
}
|
|
4588
|
-
if (type.flags &
|
|
4608
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4589
4609
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4590
4610
|
}
|
|
4591
4611
|
return resolveTypeNode(
|
|
@@ -4612,13 +4632,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4612
4632
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4613
4633
|
);
|
|
4614
4634
|
const nonNullTypes = allTypes.filter(
|
|
4615
|
-
(memberType) => !(memberType.flags & (
|
|
4635
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4616
4636
|
);
|
|
4617
4637
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4618
4638
|
memberType,
|
|
4619
4639
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4620
4640
|
}));
|
|
4621
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4641
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
4622
4642
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4623
4643
|
if (namedDecl) {
|
|
4624
4644
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4661,7 +4681,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4661
4681
|
const displayName = memberDisplayNames.get(String(value));
|
|
4662
4682
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4663
4683
|
});
|
|
4664
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4684
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
4665
4685
|
if (isBooleanUnion2) {
|
|
4666
4686
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4667
4687
|
const result = hasNull ? {
|
|
@@ -4753,7 +4773,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4753
4773
|
if (type.getProperties().length > 0) {
|
|
4754
4774
|
return null;
|
|
4755
4775
|
}
|
|
4756
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4776
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
4757
4777
|
if (!indexInfo) {
|
|
4758
4778
|
return null;
|
|
4759
4779
|
}
|
|
@@ -4801,10 +4821,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4801
4821
|
}
|
|
4802
4822
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4803
4823
|
const name = declaration.name;
|
|
4804
|
-
if (
|
|
4824
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
4805
4825
|
return false;
|
|
4806
4826
|
}
|
|
4807
|
-
if (!
|
|
4827
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
4808
4828
|
return false;
|
|
4809
4829
|
}
|
|
4810
4830
|
}
|
|
@@ -4930,7 +4950,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4930
4950
|
if (!declaration) continue;
|
|
4931
4951
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4932
4952
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4933
|
-
const optional = !!(prop.flags &
|
|
4953
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
4934
4954
|
const propTypeNode = resolveTypeNode(
|
|
4935
4955
|
propType,
|
|
4936
4956
|
checker,
|
|
@@ -4943,7 +4963,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4943
4963
|
collectedDiagnostics
|
|
4944
4964
|
);
|
|
4945
4965
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4946
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
4966
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4947
4967
|
declaration,
|
|
4948
4968
|
checker,
|
|
4949
4969
|
file,
|
|
@@ -4953,7 +4973,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4953
4973
|
type,
|
|
4954
4974
|
metadataPolicy,
|
|
4955
4975
|
extensionRegistry
|
|
4956
|
-
) :
|
|
4976
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4957
4977
|
declaration,
|
|
4958
4978
|
checker,
|
|
4959
4979
|
file,
|
|
@@ -4981,7 +5001,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4981
5001
|
visiting.delete(type);
|
|
4982
5002
|
const objectNode = {
|
|
4983
5003
|
kind: "object",
|
|
4984
|
-
properties: namedDecl !== void 0 && (
|
|
5004
|
+
properties: namedDecl !== void 0 && (ts5.isClassDeclaration(namedDecl) || ts5.isInterfaceDeclaration(namedDecl) || ts5.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
4985
5005
|
properties,
|
|
4986
5006
|
namedDecl,
|
|
4987
5007
|
type,
|
|
@@ -5029,12 +5049,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5029
5049
|
for (const symbol of symbols) {
|
|
5030
5050
|
const declarations = symbol.declarations;
|
|
5031
5051
|
if (!declarations) continue;
|
|
5032
|
-
const classDecl = declarations.find(
|
|
5052
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
5033
5053
|
if (classDecl) {
|
|
5034
5054
|
const map = /* @__PURE__ */ new Map();
|
|
5035
5055
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
5036
5056
|
for (const member of classDecl.members) {
|
|
5037
|
-
if (
|
|
5057
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
5038
5058
|
const fieldNode = analyzeFieldToIR(
|
|
5039
5059
|
member,
|
|
5040
5060
|
checker,
|
|
@@ -5058,7 +5078,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5058
5078
|
}
|
|
5059
5079
|
return map;
|
|
5060
5080
|
}
|
|
5061
|
-
const interfaceDecl = declarations.find(
|
|
5081
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
5062
5082
|
if (interfaceDecl) {
|
|
5063
5083
|
return buildFieldNodeInfoMap(
|
|
5064
5084
|
interfaceDecl.members,
|
|
@@ -5072,7 +5092,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5072
5092
|
extensionRegistry
|
|
5073
5093
|
);
|
|
5074
5094
|
}
|
|
5075
|
-
const typeAliasDecl = declarations.find(
|
|
5095
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
5076
5096
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5077
5097
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5078
5098
|
return buildFieldNodeInfoMap(
|
|
@@ -5096,10 +5116,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5096
5116
|
return void 0;
|
|
5097
5117
|
}
|
|
5098
5118
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5099
|
-
if (
|
|
5119
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
5100
5120
|
return resolvedTypeNode.elementType;
|
|
5101
5121
|
}
|
|
5102
|
-
if (
|
|
5122
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5103
5123
|
return resolvedTypeNode.typeArguments[0];
|
|
5104
5124
|
}
|
|
5105
5125
|
return void 0;
|
|
@@ -5110,13 +5130,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5110
5130
|
return [];
|
|
5111
5131
|
}
|
|
5112
5132
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5113
|
-
return
|
|
5133
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5114
5134
|
}
|
|
5115
5135
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5116
|
-
if (
|
|
5136
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
5117
5137
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5118
5138
|
}
|
|
5119
|
-
if (!
|
|
5139
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
5120
5140
|
return typeNode;
|
|
5121
5141
|
}
|
|
5122
5142
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5127,15 +5147,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5127
5147
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5128
5148
|
}
|
|
5129
5149
|
function isNullishTypeNode(typeNode) {
|
|
5130
|
-
if (typeNode.kind ===
|
|
5150
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
5131
5151
|
return true;
|
|
5132
5152
|
}
|
|
5133
|
-
return
|
|
5153
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
5134
5154
|
}
|
|
5135
5155
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5136
5156
|
const map = /* @__PURE__ */ new Map();
|
|
5137
5157
|
for (const member of members) {
|
|
5138
|
-
if (
|
|
5158
|
+
if (ts5.isPropertySignature(member)) {
|
|
5139
5159
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5140
5160
|
member,
|
|
5141
5161
|
checker,
|
|
@@ -5160,17 +5180,16 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5160
5180
|
return map;
|
|
5161
5181
|
}
|
|
5162
5182
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5163
|
-
if (!
|
|
5183
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
5164
5184
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5165
5185
|
const aliasName = typeNode.typeName.getText();
|
|
5166
5186
|
throw new Error(
|
|
5167
5187
|
`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.`
|
|
5168
5188
|
);
|
|
5169
5189
|
}
|
|
5170
|
-
const
|
|
5171
|
-
const aliasDecl = getAliasedTypeAliasDeclaration(symbol, checker);
|
|
5190
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5172
5191
|
if (!aliasDecl) return [];
|
|
5173
|
-
if (
|
|
5192
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5174
5193
|
const aliasFieldType = resolveTypeNode(
|
|
5175
5194
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5176
5195
|
checker,
|
|
@@ -5191,18 +5210,6 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5191
5210
|
);
|
|
5192
5211
|
return constraints;
|
|
5193
5212
|
}
|
|
5194
|
-
function getAliasedSymbol(symbol, checker) {
|
|
5195
|
-
if (symbol === void 0) {
|
|
5196
|
-
return void 0;
|
|
5197
|
-
}
|
|
5198
|
-
return symbol.flags & ts3.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
5199
|
-
}
|
|
5200
|
-
function getAliasedTypeAliasDeclaration(symbol, checker) {
|
|
5201
|
-
return getAliasedSymbol(symbol, checker)?.declarations?.find(ts3.isTypeAliasDeclaration);
|
|
5202
|
-
}
|
|
5203
|
-
function getTypeAliasDeclarationFromTypeReference(typeNode, checker) {
|
|
5204
|
-
return getAliasedTypeAliasDeclaration(checker.getSymbolAtLocation(typeNode.typeName), checker);
|
|
5205
|
-
}
|
|
5206
5213
|
function provenanceForNode(node, file) {
|
|
5207
5214
|
const sourceFile = node.getSourceFile();
|
|
5208
5215
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
@@ -5226,14 +5233,14 @@ function getNamedTypeName(type) {
|
|
|
5226
5233
|
const symbol = type.getSymbol();
|
|
5227
5234
|
if (symbol?.declarations) {
|
|
5228
5235
|
const decl = symbol.declarations[0];
|
|
5229
|
-
if (decl && (
|
|
5230
|
-
const name =
|
|
5236
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5237
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5231
5238
|
if (name) return name;
|
|
5232
5239
|
}
|
|
5233
5240
|
}
|
|
5234
5241
|
const aliasSymbol = type.aliasSymbol;
|
|
5235
5242
|
if (aliasSymbol?.declarations) {
|
|
5236
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5243
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5237
5244
|
if (aliasDecl) {
|
|
5238
5245
|
return aliasDecl.name.text;
|
|
5239
5246
|
}
|
|
@@ -5244,24 +5251,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5244
5251
|
const symbol = type.getSymbol();
|
|
5245
5252
|
if (symbol?.declarations) {
|
|
5246
5253
|
const decl = symbol.declarations[0];
|
|
5247
|
-
if (decl && (
|
|
5254
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5248
5255
|
return decl;
|
|
5249
5256
|
}
|
|
5250
5257
|
}
|
|
5251
5258
|
const aliasSymbol = type.aliasSymbol;
|
|
5252
5259
|
if (aliasSymbol?.declarations) {
|
|
5253
|
-
return aliasSymbol.declarations.find(
|
|
5260
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5254
5261
|
}
|
|
5255
5262
|
return void 0;
|
|
5256
5263
|
}
|
|
5257
5264
|
function analyzeMethod(method, checker) {
|
|
5258
|
-
if (!
|
|
5265
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
5259
5266
|
return null;
|
|
5260
5267
|
}
|
|
5261
5268
|
const name = method.name.text;
|
|
5262
5269
|
const parameters = [];
|
|
5263
5270
|
for (const param of method.parameters) {
|
|
5264
|
-
if (
|
|
5271
|
+
if (ts5.isIdentifier(param.name)) {
|
|
5265
5272
|
const paramInfo = analyzeParameter(param, checker);
|
|
5266
5273
|
parameters.push(paramInfo);
|
|
5267
5274
|
}
|
|
@@ -5272,7 +5279,7 @@ function analyzeMethod(method, checker) {
|
|
|
5272
5279
|
return { name, parameters, returnTypeNode, returnType };
|
|
5273
5280
|
}
|
|
5274
5281
|
function analyzeParameter(param, checker) {
|
|
5275
|
-
const name =
|
|
5282
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
5276
5283
|
const typeNode = param.type;
|
|
5277
5284
|
const type = checker.getTypeAtLocation(param);
|
|
5278
5285
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5281,15 +5288,15 @@ function analyzeParameter(param, checker) {
|
|
|
5281
5288
|
}
|
|
5282
5289
|
function detectFormSpecReference(typeNode) {
|
|
5283
5290
|
if (!typeNode) return null;
|
|
5284
|
-
if (!
|
|
5285
|
-
const typeName =
|
|
5291
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
5292
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5286
5293
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5287
5294
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5288
|
-
if (!typeArg || !
|
|
5289
|
-
if (
|
|
5295
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
5296
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
5290
5297
|
return typeArg.exprName.text;
|
|
5291
5298
|
}
|
|
5292
|
-
if (
|
|
5299
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
5293
5300
|
return typeArg.exprName.right.text;
|
|
5294
5301
|
}
|
|
5295
5302
|
return null;
|
|
@@ -5300,6 +5307,8 @@ var init_class_analyzer = __esm({
|
|
|
5300
5307
|
"use strict";
|
|
5301
5308
|
init_jsdoc_constraints();
|
|
5302
5309
|
init_tsdoc_parser();
|
|
5310
|
+
init_resolve_custom_type();
|
|
5311
|
+
init_ts_type_utils();
|
|
5303
5312
|
init_metadata();
|
|
5304
5313
|
RESOLVING_TYPE_PLACEHOLDER = {
|
|
5305
5314
|
kind: "object",
|
|
@@ -5311,7 +5320,7 @@ var init_class_analyzer = __esm({
|
|
|
5311
5320
|
});
|
|
5312
5321
|
|
|
5313
5322
|
// src/analyzer/program.ts
|
|
5314
|
-
import * as
|
|
5323
|
+
import * as ts6 from "typescript";
|
|
5315
5324
|
import * as path from "path";
|
|
5316
5325
|
function createProgramContextFromProgram(program, filePath) {
|
|
5317
5326
|
const absolutePath = path.resolve(filePath);
|
|
@@ -5328,23 +5337,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5328
5337
|
function createProgramContext(filePath, additionalFiles) {
|
|
5329
5338
|
const absolutePath = path.resolve(filePath);
|
|
5330
5339
|
const fileDir = path.dirname(absolutePath);
|
|
5331
|
-
const configPath =
|
|
5340
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
5332
5341
|
let compilerOptions;
|
|
5333
5342
|
let fileNames;
|
|
5334
5343
|
if (configPath) {
|
|
5335
|
-
const configFile =
|
|
5344
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
5336
5345
|
if (configFile.error) {
|
|
5337
5346
|
throw new Error(
|
|
5338
|
-
`Error reading tsconfig.json: ${
|
|
5347
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5339
5348
|
);
|
|
5340
5349
|
}
|
|
5341
|
-
const parsed =
|
|
5350
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
5342
5351
|
configFile.config,
|
|
5343
|
-
|
|
5352
|
+
ts6.sys,
|
|
5344
5353
|
path.dirname(configPath)
|
|
5345
5354
|
);
|
|
5346
5355
|
if (parsed.errors.length > 0) {
|
|
5347
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5356
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5348
5357
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5349
5358
|
}
|
|
5350
5359
|
compilerOptions = parsed.options;
|
|
@@ -5352,9 +5361,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5352
5361
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5353
5362
|
} else {
|
|
5354
5363
|
compilerOptions = {
|
|
5355
|
-
target:
|
|
5356
|
-
module:
|
|
5357
|
-
moduleResolution:
|
|
5364
|
+
target: ts6.ScriptTarget.ES2022,
|
|
5365
|
+
module: ts6.ModuleKind.NodeNext,
|
|
5366
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
5358
5367
|
strict: true,
|
|
5359
5368
|
skipLibCheck: true,
|
|
5360
5369
|
declaration: true
|
|
@@ -5362,7 +5371,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5362
5371
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5363
5372
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5364
5373
|
}
|
|
5365
|
-
const program =
|
|
5374
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
5366
5375
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5367
5376
|
if (!sourceFile) {
|
|
5368
5377
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5381,19 +5390,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5381
5390
|
result = node;
|
|
5382
5391
|
return;
|
|
5383
5392
|
}
|
|
5384
|
-
|
|
5393
|
+
ts6.forEachChild(node, visit);
|
|
5385
5394
|
}
|
|
5386
5395
|
visit(sourceFile);
|
|
5387
5396
|
return result;
|
|
5388
5397
|
}
|
|
5389
5398
|
function findClassByName(sourceFile, className) {
|
|
5390
|
-
return findNodeByName(sourceFile, className,
|
|
5399
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
5391
5400
|
}
|
|
5392
5401
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5393
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5402
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
5394
5403
|
}
|
|
5395
5404
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5396
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5405
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5397
5406
|
}
|
|
5398
5407
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5399
5408
|
if (rootType.kind === "object") {
|
|
@@ -5433,22 +5442,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5433
5442
|
};
|
|
5434
5443
|
}
|
|
5435
5444
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5436
|
-
if (
|
|
5445
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5437
5446
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5438
5447
|
}
|
|
5439
|
-
if (
|
|
5448
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5440
5449
|
return true;
|
|
5441
5450
|
}
|
|
5442
|
-
return
|
|
5451
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5443
5452
|
}
|
|
5444
5453
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5445
|
-
if (
|
|
5454
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5446
5455
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5447
5456
|
}
|
|
5448
|
-
if (
|
|
5457
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
5449
5458
|
const propertyNames = [];
|
|
5450
5459
|
for (const member of typeNode.members) {
|
|
5451
|
-
if (!
|
|
5460
|
+
if (!ts6.isPropertySignature(member)) {
|
|
5452
5461
|
continue;
|
|
5453
5462
|
}
|
|
5454
5463
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5458,13 +5467,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5458
5467
|
}
|
|
5459
5468
|
return propertyNames;
|
|
5460
5469
|
}
|
|
5461
|
-
if (
|
|
5470
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5462
5471
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5463
5472
|
}
|
|
5464
5473
|
return null;
|
|
5465
5474
|
}
|
|
5466
5475
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5467
|
-
if (!
|
|
5476
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
5468
5477
|
return [];
|
|
5469
5478
|
}
|
|
5470
5479
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5671,7 +5680,7 @@ var init_program = __esm({
|
|
|
5671
5680
|
});
|
|
5672
5681
|
|
|
5673
5682
|
// src/extensions/symbol-registry.ts
|
|
5674
|
-
import * as
|
|
5683
|
+
import * as ts7 from "typescript";
|
|
5675
5684
|
import * as path2 from "path";
|
|
5676
5685
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5677
5686
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5681,10 +5690,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5681
5690
|
return symbolMap;
|
|
5682
5691
|
}
|
|
5683
5692
|
function visit(node) {
|
|
5684
|
-
if (
|
|
5693
|
+
if (ts7.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5685
5694
|
processDefineCustomTypeCall(node);
|
|
5686
5695
|
}
|
|
5687
|
-
|
|
5696
|
+
ts7.forEachChild(node, visit);
|
|
5688
5697
|
}
|
|
5689
5698
|
function processDefineCustomTypeCall(call) {
|
|
5690
5699
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5692,7 +5701,7 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5692
5701
|
return;
|
|
5693
5702
|
}
|
|
5694
5703
|
const resolvedType = checker.getTypeFromTypeNode(typeArgNode);
|
|
5695
|
-
const canonical =
|
|
5704
|
+
const canonical = resolveCanonicalSymbol(resolvedType, checker);
|
|
5696
5705
|
if (canonical === void 0) {
|
|
5697
5706
|
return;
|
|
5698
5707
|
}
|
|
@@ -5721,7 +5730,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5721
5730
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5722
5731
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5723
5732
|
if (callSymbol !== void 0) {
|
|
5724
|
-
const resolved = callSymbol.flags &
|
|
5733
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5725
5734
|
const decl = resolved.declarations?.[0];
|
|
5726
5735
|
if (decl !== void 0) {
|
|
5727
5736
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5729,29 +5738,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5729
5738
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5730
5739
|
}
|
|
5731
5740
|
}
|
|
5732
|
-
return
|
|
5733
|
-
}
|
|
5734
|
-
function resolveCanonicalSymbol2(type, checker) {
|
|
5735
|
-
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
5736
|
-
if (raw === void 0) return void 0;
|
|
5737
|
-
return raw.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
5741
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5738
5742
|
}
|
|
5739
5743
|
function extractTypeNameFromCallArg(call) {
|
|
5740
5744
|
const arg = call.arguments[0];
|
|
5741
|
-
if (arg === void 0 || !
|
|
5745
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5742
5746
|
return null;
|
|
5743
5747
|
}
|
|
5744
5748
|
const typeNameProp = arg.properties.find(
|
|
5745
|
-
(p) =>
|
|
5749
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5746
5750
|
);
|
|
5747
|
-
if (typeNameProp === void 0 || !
|
|
5751
|
+
if (typeNameProp === void 0 || !ts7.isStringLiteral(typeNameProp.initializer)) {
|
|
5748
5752
|
return null;
|
|
5749
5753
|
}
|
|
5750
5754
|
return typeNameProp.initializer.text;
|
|
5751
5755
|
}
|
|
5752
5756
|
function extractEnclosingExtensionId(call, checker) {
|
|
5753
|
-
for (let node = call.parent; !
|
|
5754
|
-
if (
|
|
5757
|
+
for (let node = call.parent; !ts7.isSourceFile(node); node = node.parent) {
|
|
5758
|
+
if (ts7.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5755
5759
|
return extractExtensionIdFromCallArg(node);
|
|
5756
5760
|
}
|
|
5757
5761
|
}
|
|
@@ -5760,24 +5764,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5760
5764
|
function isDefineExtensionCall(node, checker) {
|
|
5761
5765
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5762
5766
|
if (callSymbol !== void 0) {
|
|
5763
|
-
const resolved = callSymbol.flags &
|
|
5767
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5764
5768
|
const decl = resolved.declarations?.[0];
|
|
5765
5769
|
if (decl !== void 0) {
|
|
5766
5770
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5767
5771
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5768
5772
|
}
|
|
5769
5773
|
}
|
|
5770
|
-
return
|
|
5774
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5771
5775
|
}
|
|
5772
5776
|
function extractExtensionIdFromCallArg(call) {
|
|
5773
5777
|
const arg = call.arguments[0];
|
|
5774
|
-
if (arg === void 0 || !
|
|
5778
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5775
5779
|
return null;
|
|
5776
5780
|
}
|
|
5777
5781
|
const prop = arg.properties.find(
|
|
5778
|
-
(p) =>
|
|
5782
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5779
5783
|
);
|
|
5780
|
-
if (prop === void 0 || !
|
|
5784
|
+
if (prop === void 0 || !ts7.isStringLiteral(prop.initializer)) {
|
|
5781
5785
|
return null;
|
|
5782
5786
|
}
|
|
5783
5787
|
return prop.initializer.text;
|
|
@@ -5798,6 +5802,7 @@ function findRegistrationByTypeName(registry, typeName) {
|
|
|
5798
5802
|
var init_symbol_registry = __esm({
|
|
5799
5803
|
"src/extensions/symbol-registry.ts"() {
|
|
5800
5804
|
"use strict";
|
|
5805
|
+
init_ts_type_utils();
|
|
5801
5806
|
}
|
|
5802
5807
|
});
|
|
5803
5808
|
|
|
@@ -5888,7 +5893,7 @@ var init_validate = __esm({
|
|
|
5888
5893
|
});
|
|
5889
5894
|
|
|
5890
5895
|
// src/generators/class-schema.ts
|
|
5891
|
-
import * as
|
|
5896
|
+
import * as ts8 from "typescript";
|
|
5892
5897
|
function generateClassSchemas(analysis, source, options) {
|
|
5893
5898
|
const result = generateClassSchemasDetailed(analysis, source, options);
|
|
5894
5899
|
if (!result.ok || result.jsonSchema === void 0 || result.uiSchema === void 0) {
|
|
@@ -6058,7 +6063,7 @@ function generateSchemasBatch(options) {
|
|
|
6058
6063
|
return options.targets.map((target) => {
|
|
6059
6064
|
let ctx;
|
|
6060
6065
|
try {
|
|
6061
|
-
const cacheKey =
|
|
6066
|
+
const cacheKey = ts8.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
6062
6067
|
const cachedContext = contextCache.get(cacheKey);
|
|
6063
6068
|
if (cachedContext === void 0) {
|
|
6064
6069
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6227,7 +6232,7 @@ var init_class_schema = __esm({
|
|
|
6227
6232
|
});
|
|
6228
6233
|
|
|
6229
6234
|
// src/static-build.ts
|
|
6230
|
-
import * as
|
|
6235
|
+
import * as ts9 from "typescript";
|
|
6231
6236
|
function toStaticBuildContext(context) {
|
|
6232
6237
|
return context;
|
|
6233
6238
|
}
|
|
@@ -6242,7 +6247,7 @@ function getModuleSymbol(context) {
|
|
|
6242
6247
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6243
6248
|
}
|
|
6244
6249
|
function isSchemaSourceDeclaration(declaration) {
|
|
6245
|
-
return
|
|
6250
|
+
return ts9.isClassDeclaration(declaration) || ts9.isInterfaceDeclaration(declaration) || ts9.isTypeAliasDeclaration(declaration);
|
|
6246
6251
|
}
|
|
6247
6252
|
function resolveModuleExport(context, exportName = "default") {
|
|
6248
6253
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6253,7 +6258,7 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6253
6258
|
if (exportSymbol === null) {
|
|
6254
6259
|
return null;
|
|
6255
6260
|
}
|
|
6256
|
-
return exportSymbol.flags &
|
|
6261
|
+
return exportSymbol.flags & ts9.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6257
6262
|
}
|
|
6258
6263
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6259
6264
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
@@ -6266,7 +6271,7 @@ var init_static_build = __esm({
|
|
|
6266
6271
|
});
|
|
6267
6272
|
|
|
6268
6273
|
// src/generators/discovered-schema.ts
|
|
6269
|
-
import * as
|
|
6274
|
+
import * as ts10 from "typescript";
|
|
6270
6275
|
import { analyzeMetadataForNodeWithChecker as analyzeMetadataForNodeWithChecker2 } from "@formspec/analysis/internal";
|
|
6271
6276
|
import { IR_VERSION as IR_VERSION3 } from "@formspec/core/internals";
|
|
6272
6277
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
@@ -6276,17 +6281,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6276
6281
|
};
|
|
6277
6282
|
}
|
|
6278
6283
|
function isNamedTypeDeclaration(declaration) {
|
|
6279
|
-
return
|
|
6284
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6280
6285
|
}
|
|
6281
6286
|
function hasConcreteTypeArguments(type, checker) {
|
|
6282
6287
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6283
6288
|
return true;
|
|
6284
6289
|
}
|
|
6285
|
-
if ((type.flags &
|
|
6290
|
+
if ((type.flags & ts10.TypeFlags.Object) === 0) {
|
|
6286
6291
|
return false;
|
|
6287
6292
|
}
|
|
6288
6293
|
const objectType = type;
|
|
6289
|
-
if ((objectType.objectFlags &
|
|
6294
|
+
if ((objectType.objectFlags & ts10.ObjectFlags.Reference) === 0) {
|
|
6290
6295
|
return false;
|
|
6291
6296
|
}
|
|
6292
6297
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6299,13 +6304,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6299
6304
|
return declaration;
|
|
6300
6305
|
}
|
|
6301
6306
|
}
|
|
6302
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6307
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts10.isTypeAliasDeclaration);
|
|
6303
6308
|
return aliasDeclaration;
|
|
6304
6309
|
}
|
|
6305
6310
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6306
6311
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6307
6312
|
const namedNode = sourceNode;
|
|
6308
|
-
if (namedNode.name !== void 0 &&
|
|
6313
|
+
if (namedNode.name !== void 0 && ts10.isIdentifier(namedNode.name)) {
|
|
6309
6314
|
return namedNode.name.text;
|
|
6310
6315
|
}
|
|
6311
6316
|
}
|
|
@@ -6527,7 +6532,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6527
6532
|
function generateSchemasFromDeclaration(options) {
|
|
6528
6533
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6529
6534
|
const resolved = resolveStaticOptions(options);
|
|
6530
|
-
if (
|
|
6535
|
+
if (ts10.isClassDeclaration(options.declaration)) {
|
|
6531
6536
|
return generateSchemasFromAnalysis(
|
|
6532
6537
|
analyzeClassToIR(
|
|
6533
6538
|
options.declaration,
|
|
@@ -6541,7 +6546,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6541
6546
|
resolved
|
|
6542
6547
|
);
|
|
6543
6548
|
}
|
|
6544
|
-
if (
|
|
6549
|
+
if (ts10.isInterfaceDeclaration(options.declaration)) {
|
|
6545
6550
|
return generateSchemasFromAnalysis(
|
|
6546
6551
|
analyzeInterfaceToIR(
|
|
6547
6552
|
options.declaration,
|
|
@@ -6555,7 +6560,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6555
6560
|
resolved
|
|
6556
6561
|
);
|
|
6557
6562
|
}
|
|
6558
|
-
if (
|
|
6563
|
+
if (ts10.isTypeAliasDeclaration(options.declaration)) {
|
|
6559
6564
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6560
6565
|
options.declaration,
|
|
6561
6566
|
options.context.checker,
|
|
@@ -6614,7 +6619,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6614
6619
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6615
6620
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6616
6621
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6617
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6622
|
+
const fallbackName = options.declaration.name !== void 0 && ts10.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6618
6623
|
return generateSchemasFromResolvedType({
|
|
6619
6624
|
...options,
|
|
6620
6625
|
type,
|
|
@@ -6661,14 +6666,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6661
6666
|
if (typeNode === void 0) {
|
|
6662
6667
|
return void 0;
|
|
6663
6668
|
}
|
|
6664
|
-
if (
|
|
6669
|
+
if (ts10.isParenthesizedTypeNode(typeNode)) {
|
|
6665
6670
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6666
6671
|
return unwrapped ?? typeNode;
|
|
6667
6672
|
}
|
|
6668
6673
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6669
6674
|
}
|
|
6670
6675
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6671
|
-
return
|
|
6676
|
+
return ts10.isTypeReferenceNode(typeNode) && ts10.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6672
6677
|
}
|
|
6673
6678
|
var init_discovered_schema = __esm({
|
|
6674
6679
|
"src/generators/discovered-schema.ts"() {
|