@formspec/build 0.1.0-alpha.50 → 0.1.0-alpha.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/builtin-brands.d.ts +13 -0
- package/dist/analyzer/builtin-brands.d.ts.map +1 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/cli.cjs +206 -196
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +198 -188
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +189 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +190 -188
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +159 -158
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +160 -158
- package/dist/internals.js.map +1 -1
- package/package.json +4 -4
package/dist/cli.cjs
CHANGED
|
@@ -2420,6 +2420,21 @@ var init_resolve_custom_type = __esm({
|
|
|
2420
2420
|
}
|
|
2421
2421
|
});
|
|
2422
2422
|
|
|
2423
|
+
// src/analyzer/builtin-brands.ts
|
|
2424
|
+
function isIntegerBrandedType(type) {
|
|
2425
|
+
if (!type.isIntersection()) return false;
|
|
2426
|
+
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2427
|
+
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2428
|
+
}
|
|
2429
|
+
var ts3;
|
|
2430
|
+
var init_builtin_brands = __esm({
|
|
2431
|
+
"src/analyzer/builtin-brands.ts"() {
|
|
2432
|
+
"use strict";
|
|
2433
|
+
ts3 = __toESM(require("typescript"), 1);
|
|
2434
|
+
init_ts_type_utils();
|
|
2435
|
+
}
|
|
2436
|
+
});
|
|
2437
|
+
|
|
2423
2438
|
// src/analyzer/tsdoc-parser.ts
|
|
2424
2439
|
function sharedTagValueOptions(options) {
|
|
2425
2440
|
return {
|
|
@@ -2440,23 +2455,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2440
2455
|
function collectImportedNames(sourceFile) {
|
|
2441
2456
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2442
2457
|
for (const statement of sourceFile.statements) {
|
|
2443
|
-
if (
|
|
2458
|
+
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2444
2459
|
const clause = statement.importClause;
|
|
2445
2460
|
if (clause.name !== void 0) {
|
|
2446
2461
|
importedNames.add(clause.name.text);
|
|
2447
2462
|
}
|
|
2448
2463
|
if (clause.namedBindings !== void 0) {
|
|
2449
|
-
if (
|
|
2464
|
+
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
2450
2465
|
for (const specifier of clause.namedBindings.elements) {
|
|
2451
2466
|
importedNames.add(specifier.name.text);
|
|
2452
2467
|
}
|
|
2453
|
-
} else if (
|
|
2468
|
+
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
2454
2469
|
importedNames.add(clause.namedBindings.name.text);
|
|
2455
2470
|
}
|
|
2456
2471
|
}
|
|
2457
2472
|
continue;
|
|
2458
2473
|
}
|
|
2459
|
-
if (
|
|
2474
|
+
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
2460
2475
|
importedNames.add(statement.name.text);
|
|
2461
2476
|
}
|
|
2462
2477
|
}
|
|
@@ -2464,13 +2479,13 @@ function collectImportedNames(sourceFile) {
|
|
|
2464
2479
|
}
|
|
2465
2480
|
function isNonReferenceIdentifier(node) {
|
|
2466
2481
|
const parent = node.parent;
|
|
2467
|
-
if ((
|
|
2482
|
+
if ((ts4.isBindingElement(parent) || ts4.isClassDeclaration(parent) || ts4.isEnumDeclaration(parent) || ts4.isEnumMember(parent) || ts4.isFunctionDeclaration(parent) || ts4.isFunctionExpression(parent) || ts4.isImportClause(parent) || ts4.isImportEqualsDeclaration(parent) || ts4.isImportSpecifier(parent) || ts4.isInterfaceDeclaration(parent) || ts4.isMethodDeclaration(parent) || ts4.isMethodSignature(parent) || ts4.isModuleDeclaration(parent) || ts4.isNamespaceExport(parent) || ts4.isNamespaceImport(parent) || ts4.isParameter(parent) || ts4.isPropertyDeclaration(parent) || ts4.isPropertySignature(parent) || ts4.isSetAccessorDeclaration(parent) || ts4.isGetAccessorDeclaration(parent) || ts4.isTypeAliasDeclaration(parent) || ts4.isTypeParameterDeclaration(parent) || ts4.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2468
2483
|
return true;
|
|
2469
2484
|
}
|
|
2470
|
-
if ((
|
|
2485
|
+
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2471
2486
|
return true;
|
|
2472
2487
|
}
|
|
2473
|
-
if (
|
|
2488
|
+
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
2474
2489
|
return true;
|
|
2475
2490
|
}
|
|
2476
2491
|
return false;
|
|
@@ -2484,11 +2499,11 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
2484
2499
|
if (referencesImportedName) {
|
|
2485
2500
|
return;
|
|
2486
2501
|
}
|
|
2487
|
-
if (
|
|
2502
|
+
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2488
2503
|
referencesImportedName = true;
|
|
2489
2504
|
return;
|
|
2490
2505
|
}
|
|
2491
|
-
|
|
2506
|
+
ts4.forEachChild(node, visit);
|
|
2492
2507
|
};
|
|
2493
2508
|
visit(statement);
|
|
2494
2509
|
return referencesImportedName;
|
|
@@ -2499,9 +2514,9 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
2499
2514
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2500
2515
|
);
|
|
2501
2516
|
return sourceFile.statements.filter((statement) => {
|
|
2502
|
-
if (
|
|
2503
|
-
if (
|
|
2504
|
-
if (
|
|
2517
|
+
if (ts4.isImportDeclaration(statement)) return false;
|
|
2518
|
+
if (ts4.isImportEqualsDeclaration(statement)) return false;
|
|
2519
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
2505
2520
|
return false;
|
|
2506
2521
|
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2507
2522
|
return false;
|
|
@@ -2597,7 +2612,7 @@ function stripHintNullishUnion(type) {
|
|
|
2597
2612
|
return type;
|
|
2598
2613
|
}
|
|
2599
2614
|
const nonNullish = type.types.filter(
|
|
2600
|
-
(member) => (member.flags & (
|
|
2615
|
+
(member) => (member.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) === 0
|
|
2601
2616
|
);
|
|
2602
2617
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2603
2618
|
return nonNullish[0];
|
|
@@ -2613,10 +2628,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2613
2628
|
}
|
|
2614
2629
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2615
2630
|
const name = declaration.name;
|
|
2616
|
-
if (
|
|
2631
|
+
if (ts4.isComputedPropertyName(name) || ts4.isPrivateIdentifier(name)) {
|
|
2617
2632
|
return false;
|
|
2618
2633
|
}
|
|
2619
|
-
if (!
|
|
2634
|
+
if (!ts4.isIdentifier(name) && !ts4.isStringLiteral(name) && !ts4.isNumericLiteral(name)) {
|
|
2620
2635
|
return false;
|
|
2621
2636
|
}
|
|
2622
2637
|
}
|
|
@@ -2834,6 +2849,9 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2834
2849
|
}
|
|
2835
2850
|
const hasBroadening = (() => {
|
|
2836
2851
|
if (target === null) {
|
|
2852
|
+
if (isIntegerBrandedType((0, import_internal3.stripNullishUnion)(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2853
|
+
return true;
|
|
2854
|
+
}
|
|
2837
2855
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2838
2856
|
}
|
|
2839
2857
|
const registry = options?.extensionRegistry;
|
|
@@ -2985,12 +3003,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2985
3003
|
const sourceText = sourceFile.getFullText();
|
|
2986
3004
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2987
3005
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2988
|
-
const commentRanges =
|
|
3006
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2989
3007
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2990
3008
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2991
3009
|
if (commentRanges) {
|
|
2992
3010
|
for (const range of commentRanges) {
|
|
2993
|
-
if (range.kind !==
|
|
3011
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) {
|
|
2994
3012
|
continue;
|
|
2995
3013
|
}
|
|
2996
3014
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3147,10 +3165,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3147
3165
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3148
3166
|
const sourceFile = node.getSourceFile();
|
|
3149
3167
|
const sourceText = sourceFile.getFullText();
|
|
3150
|
-
const commentRanges =
|
|
3168
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3151
3169
|
if (commentRanges) {
|
|
3152
3170
|
for (const range of commentRanges) {
|
|
3153
|
-
if (range.kind !==
|
|
3171
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3154
3172
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3155
3173
|
if (!commentText.startsWith("/**")) continue;
|
|
3156
3174
|
const unified = (0, import_internal3.parseUnifiedComment)(commentText);
|
|
@@ -3175,7 +3193,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3175
3193
|
}
|
|
3176
3194
|
function collectRawTextFallbacks(node, file) {
|
|
3177
3195
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3178
|
-
for (const tag of
|
|
3196
|
+
for (const tag of ts4.getJSDocTags(node)) {
|
|
3179
3197
|
const tagName = (0, import_internals4.normalizeConstraintTagName)(tag.tagName.text);
|
|
3180
3198
|
if (!import_internal3.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3181
3199
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3230,18 +3248,19 @@ function getTagCommentText(tag) {
|
|
|
3230
3248
|
if (typeof tag.comment === "string") {
|
|
3231
3249
|
return tag.comment;
|
|
3232
3250
|
}
|
|
3233
|
-
return
|
|
3251
|
+
return ts4.getTextOfJSDocComment(tag.comment);
|
|
3234
3252
|
}
|
|
3235
|
-
var
|
|
3253
|
+
var ts4, import_internal3, import_internals4, import_internals5, SYNTHETIC_TYPE_FORMAT_FLAGS, MAX_HINT_CANDIDATES, MAX_HINT_DEPTH, parseResultCache;
|
|
3236
3254
|
var init_tsdoc_parser = __esm({
|
|
3237
3255
|
"src/analyzer/tsdoc-parser.ts"() {
|
|
3238
3256
|
"use strict";
|
|
3239
|
-
|
|
3257
|
+
ts4 = __toESM(require("typescript"), 1);
|
|
3240
3258
|
import_internal3 = require("@formspec/analysis/internal");
|
|
3241
3259
|
import_internals4 = require("@formspec/core/internals");
|
|
3242
3260
|
import_internals5 = require("@formspec/core/internals");
|
|
3243
3261
|
init_resolve_custom_type();
|
|
3244
|
-
|
|
3262
|
+
init_builtin_brands();
|
|
3263
|
+
SYNTHETIC_TYPE_FORMAT_FLAGS = ts4.TypeFormatFlags.NoTruncation | ts4.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
3245
3264
|
MAX_HINT_CANDIDATES = 5;
|
|
3246
3265
|
MAX_HINT_DEPTH = 3;
|
|
3247
3266
|
parseResultCache = /* @__PURE__ */ new Map();
|
|
@@ -3263,18 +3282,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3263
3282
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3264
3283
|
if (!initializer) return null;
|
|
3265
3284
|
let value;
|
|
3266
|
-
if (
|
|
3285
|
+
if (ts5.isStringLiteral(initializer)) {
|
|
3267
3286
|
value = initializer.text;
|
|
3268
|
-
} else if (
|
|
3287
|
+
} else if (ts5.isNumericLiteral(initializer)) {
|
|
3269
3288
|
value = Number(initializer.text);
|
|
3270
|
-
} else if (initializer.kind ===
|
|
3289
|
+
} else if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
|
|
3271
3290
|
value = true;
|
|
3272
|
-
} else if (initializer.kind ===
|
|
3291
|
+
} else if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
|
|
3273
3292
|
value = false;
|
|
3274
|
-
} else if (initializer.kind ===
|
|
3293
|
+
} else if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
|
|
3275
3294
|
value = null;
|
|
3276
|
-
} else if (
|
|
3277
|
-
if (initializer.operator ===
|
|
3295
|
+
} else if (ts5.isPrefixUnaryExpression(initializer)) {
|
|
3296
|
+
if (initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
|
|
3278
3297
|
value = -Number(initializer.operand.text);
|
|
3279
3298
|
}
|
|
3280
3299
|
}
|
|
@@ -3293,49 +3312,39 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3293
3312
|
}
|
|
3294
3313
|
};
|
|
3295
3314
|
}
|
|
3296
|
-
var
|
|
3315
|
+
var ts5;
|
|
3297
3316
|
var init_jsdoc_constraints = __esm({
|
|
3298
3317
|
"src/analyzer/jsdoc-constraints.ts"() {
|
|
3299
3318
|
"use strict";
|
|
3300
|
-
|
|
3319
|
+
ts5 = __toESM(require("typescript"), 1);
|
|
3301
3320
|
init_tsdoc_parser();
|
|
3302
3321
|
}
|
|
3303
3322
|
});
|
|
3304
3323
|
|
|
3305
3324
|
// src/analyzer/class-analyzer.ts
|
|
3306
3325
|
function isObjectType(type) {
|
|
3307
|
-
return !!(type.flags &
|
|
3326
|
+
return !!(type.flags & ts6.TypeFlags.Object);
|
|
3308
3327
|
}
|
|
3309
3328
|
function isIntersectionType(type) {
|
|
3310
|
-
return !!(type.flags &
|
|
3311
|
-
}
|
|
3312
|
-
function isIntegerBrandedType(type) {
|
|
3313
|
-
if (!type.isIntersection()) {
|
|
3314
|
-
return false;
|
|
3315
|
-
}
|
|
3316
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3317
|
-
if (!hasNumberBase) {
|
|
3318
|
-
return false;
|
|
3319
|
-
}
|
|
3320
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3329
|
+
return !!(type.flags & ts6.TypeFlags.Intersection);
|
|
3321
3330
|
}
|
|
3322
3331
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3323
|
-
if (
|
|
3332
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3324
3333
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3325
3334
|
}
|
|
3326
|
-
if (
|
|
3335
|
+
if (ts6.isTypeLiteralNode(typeNode) || ts6.isTypeReferenceNode(typeNode)) {
|
|
3327
3336
|
return true;
|
|
3328
3337
|
}
|
|
3329
|
-
return
|
|
3338
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3330
3339
|
}
|
|
3331
3340
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3332
3341
|
if (isIntersectionType(type)) {
|
|
3333
3342
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3334
3343
|
}
|
|
3335
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3344
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts6.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts6.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
3336
3345
|
}
|
|
3337
3346
|
function isTypeReference(type) {
|
|
3338
|
-
return !!(type.flags &
|
|
3347
|
+
return !!(type.flags & ts6.TypeFlags.Object) && !!(type.objectFlags & ts6.ObjectFlags.Reference);
|
|
3339
3348
|
}
|
|
3340
3349
|
function makeParseOptions(extensionRegistry, fieldType, checker, subjectType, hostType) {
|
|
3341
3350
|
if (extensionRegistry === void 0 && fieldType === void 0 && checker === void 0 && subjectType === void 0 && hostType === void 0) {
|
|
@@ -3395,7 +3404,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3395
3404
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3396
3405
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3397
3406
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3398
|
-
const logicalName =
|
|
3407
|
+
const logicalName = ts6.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3399
3408
|
const docResult = extractJSDocParseResult(
|
|
3400
3409
|
declaration,
|
|
3401
3410
|
file,
|
|
@@ -3443,7 +3452,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3443
3452
|
const instanceMethods = [];
|
|
3444
3453
|
const staticMethods = [];
|
|
3445
3454
|
for (const member of classDecl.members) {
|
|
3446
|
-
if (
|
|
3455
|
+
if (ts6.isPropertyDeclaration(member)) {
|
|
3447
3456
|
const fieldNode = analyzeFieldToIR(
|
|
3448
3457
|
member,
|
|
3449
3458
|
checker,
|
|
@@ -3459,10 +3468,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3459
3468
|
fields.push(fieldNode);
|
|
3460
3469
|
fieldLayouts.push({});
|
|
3461
3470
|
}
|
|
3462
|
-
} else if (
|
|
3471
|
+
} else if (ts6.isMethodDeclaration(member)) {
|
|
3463
3472
|
const methodInfo = analyzeMethod(member, checker);
|
|
3464
3473
|
if (methodInfo) {
|
|
3465
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3474
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts6.SyntaxKind.StaticKeyword);
|
|
3466
3475
|
if (isStatic) {
|
|
3467
3476
|
staticMethods.push(methodInfo);
|
|
3468
3477
|
} else {
|
|
@@ -3525,7 +3534,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3525
3534
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3526
3535
|
const visiting = /* @__PURE__ */ new Set();
|
|
3527
3536
|
for (const member of interfaceDecl.members) {
|
|
3528
|
-
if (
|
|
3537
|
+
if (ts6.isPropertySignature(member)) {
|
|
3529
3538
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3530
3539
|
member,
|
|
3531
3540
|
checker,
|
|
@@ -3583,7 +3592,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3583
3592
|
if (members === null) {
|
|
3584
3593
|
const sourceFile = typeAlias.getSourceFile();
|
|
3585
3594
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3586
|
-
const kindDesc =
|
|
3595
|
+
const kindDesc = ts6.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3587
3596
|
return {
|
|
3588
3597
|
ok: false,
|
|
3589
3598
|
kind: "not-object-like",
|
|
@@ -3618,7 +3627,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3618
3627
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3619
3628
|
const visiting = /* @__PURE__ */ new Set();
|
|
3620
3629
|
for (const member of members) {
|
|
3621
|
-
if (
|
|
3630
|
+
if (ts6.isPropertySignature(member)) {
|
|
3622
3631
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3623
3632
|
member,
|
|
3624
3633
|
checker,
|
|
@@ -3685,13 +3694,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3685
3694
|
function getLeadingParsedTags(node) {
|
|
3686
3695
|
const sourceFile = node.getSourceFile();
|
|
3687
3696
|
const sourceText = sourceFile.getFullText();
|
|
3688
|
-
const commentRanges =
|
|
3697
|
+
const commentRanges = ts6.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3689
3698
|
if (commentRanges === void 0) {
|
|
3690
3699
|
return [];
|
|
3691
3700
|
}
|
|
3692
3701
|
const parsedTags = [];
|
|
3693
3702
|
for (const range of commentRanges) {
|
|
3694
|
-
if (range.kind !==
|
|
3703
|
+
if (range.kind !== ts6.SyntaxKind.MultiLineCommentTrivia) {
|
|
3695
3704
|
continue;
|
|
3696
3705
|
}
|
|
3697
3706
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3709,19 +3718,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3709
3718
|
return null;
|
|
3710
3719
|
}
|
|
3711
3720
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3712
|
-
(candidate) =>
|
|
3721
|
+
(candidate) => ts6.isPropertyDeclaration(candidate) || ts6.isPropertySignature(candidate)
|
|
3713
3722
|
) ?? propertySymbol.declarations?.[0];
|
|
3714
3723
|
return {
|
|
3715
3724
|
declaration,
|
|
3716
3725
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3717
|
-
optional: !!(propertySymbol.flags &
|
|
3726
|
+
optional: !!(propertySymbol.flags & ts6.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3718
3727
|
};
|
|
3719
3728
|
}
|
|
3720
3729
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3721
3730
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3722
3731
|
}
|
|
3723
3732
|
function isNullishSemanticType(type) {
|
|
3724
|
-
if (type.flags & (
|
|
3733
|
+
if (type.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined | ts6.TypeFlags.Void | ts6.TypeFlags.Unknown | ts6.TypeFlags.Any)) {
|
|
3725
3734
|
return true;
|
|
3726
3735
|
}
|
|
3727
3736
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3731,7 +3740,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3731
3740
|
return false;
|
|
3732
3741
|
}
|
|
3733
3742
|
seen.add(type);
|
|
3734
|
-
if (type.flags &
|
|
3743
|
+
if (type.flags & ts6.TypeFlags.StringLike) {
|
|
3735
3744
|
return true;
|
|
3736
3745
|
}
|
|
3737
3746
|
if (type.isUnion()) {
|
|
@@ -3744,13 +3753,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3744
3753
|
return false;
|
|
3745
3754
|
}
|
|
3746
3755
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3747
|
-
if (
|
|
3756
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3748
3757
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3749
3758
|
}
|
|
3750
|
-
if (
|
|
3759
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
3751
3760
|
return [...typeNode.members];
|
|
3752
3761
|
}
|
|
3753
|
-
if (
|
|
3762
|
+
if (ts6.isIntersectionTypeNode(typeNode)) {
|
|
3754
3763
|
const members = [];
|
|
3755
3764
|
for (const intersectionMember of typeNode.types) {
|
|
3756
3765
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3913,7 +3922,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3913
3922
|
}
|
|
3914
3923
|
if (propertyType.isUnion()) {
|
|
3915
3924
|
const nonNullMembers = propertyType.types.filter(
|
|
3916
|
-
(member) => !(member.flags & (
|
|
3925
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3917
3926
|
);
|
|
3918
3927
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3919
3928
|
diagnostics.push(
|
|
@@ -3962,13 +3971,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3962
3971
|
seen.add(type);
|
|
3963
3972
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3964
3973
|
if (symbol !== void 0) {
|
|
3965
|
-
const aliased = symbol.flags &
|
|
3974
|
+
const aliased = symbol.flags & ts6.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3966
3975
|
const targetSymbol = aliased ?? symbol;
|
|
3967
3976
|
const declaration = targetSymbol.declarations?.find(
|
|
3968
|
-
(candidate) =>
|
|
3977
|
+
(candidate) => ts6.isClassDeclaration(candidate) || ts6.isInterfaceDeclaration(candidate) || ts6.isTypeAliasDeclaration(candidate) || ts6.isEnumDeclaration(candidate)
|
|
3969
3978
|
);
|
|
3970
3979
|
if (declaration !== void 0) {
|
|
3971
|
-
if (
|
|
3980
|
+
if (ts6.isTypeAliasDeclaration(declaration) && ts6.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3972
3981
|
return resolveNamedDiscriminatorDeclaration(
|
|
3973
3982
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3974
3983
|
checker,
|
|
@@ -3996,7 +4005,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3996
4005
|
}
|
|
3997
4006
|
if (boundType.isUnion()) {
|
|
3998
4007
|
const nonNullMembers = boundType.types.filter(
|
|
3999
|
-
(member) => !(member.flags & (
|
|
4008
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4000
4009
|
);
|
|
4001
4010
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
4002
4011
|
diagnostics.push(
|
|
@@ -4041,7 +4050,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
4041
4050
|
return null;
|
|
4042
4051
|
}
|
|
4043
4052
|
function getDeclarationName(node) {
|
|
4044
|
-
if (
|
|
4053
|
+
if (ts6.isClassDeclaration(node) || ts6.isInterfaceDeclaration(node) || ts6.isTypeAliasDeclaration(node) || ts6.isEnumDeclaration(node)) {
|
|
4045
4054
|
return node.name?.text ?? "anonymous";
|
|
4046
4055
|
}
|
|
4047
4056
|
return "anonymous";
|
|
@@ -4096,11 +4105,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4096
4105
|
if (sourceTypeNode === void 0) {
|
|
4097
4106
|
return [];
|
|
4098
4107
|
}
|
|
4099
|
-
const unwrapParentheses = (typeNode) =>
|
|
4108
|
+
const unwrapParentheses = (typeNode) => ts6.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4100
4109
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4101
|
-
const referenceTypeNode =
|
|
4110
|
+
const referenceTypeNode = ts6.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4102
4111
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4103
|
-
return
|
|
4112
|
+
return ts6.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4104
4113
|
})();
|
|
4105
4114
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4106
4115
|
return [];
|
|
@@ -4155,7 +4164,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4155
4164
|
);
|
|
4156
4165
|
}
|
|
4157
4166
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4158
|
-
if (!
|
|
4167
|
+
if (!ts6.isIdentifier(prop.name)) {
|
|
4159
4168
|
return null;
|
|
4160
4169
|
}
|
|
4161
4170
|
const name = prop.name.text;
|
|
@@ -4282,7 +4291,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4282
4291
|
const seen = /* @__PURE__ */ new Set();
|
|
4283
4292
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4284
4293
|
for (const member of members) {
|
|
4285
|
-
if (!
|
|
4294
|
+
if (!ts6.isPropertySignature(member)) {
|
|
4286
4295
|
continue;
|
|
4287
4296
|
}
|
|
4288
4297
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4298,7 +4307,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4298
4307
|
return [...duplicates].sort();
|
|
4299
4308
|
}
|
|
4300
4309
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4301
|
-
if (
|
|
4310
|
+
if (ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNumericLiteral(name)) {
|
|
4302
4311
|
return name.text;
|
|
4303
4312
|
}
|
|
4304
4313
|
return null;
|
|
@@ -4396,25 +4405,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4396
4405
|
if (isIntegerBrandedType(type)) {
|
|
4397
4406
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4398
4407
|
}
|
|
4399
|
-
if (type.flags &
|
|
4408
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4400
4409
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4401
4410
|
}
|
|
4402
|
-
if (type.flags &
|
|
4411
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4403
4412
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4404
4413
|
}
|
|
4405
|
-
if (type.flags & (
|
|
4414
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4406
4415
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4407
4416
|
}
|
|
4408
|
-
if (type.flags &
|
|
4417
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4409
4418
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4410
4419
|
}
|
|
4411
|
-
if (type.flags &
|
|
4420
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4412
4421
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4413
4422
|
}
|
|
4414
|
-
if (type.flags &
|
|
4423
|
+
if (type.flags & ts6.TypeFlags.Undefined) {
|
|
4415
4424
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4416
4425
|
}
|
|
4417
|
-
if (type.flags &
|
|
4426
|
+
if (type.flags & ts6.TypeFlags.Void) {
|
|
4418
4427
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4419
4428
|
}
|
|
4420
4429
|
if (type.isStringLiteral()) {
|
|
@@ -4501,10 +4510,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4501
4510
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4502
4511
|
}
|
|
4503
4512
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4504
|
-
if (!(type.flags & (
|
|
4513
|
+
if (!(type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4505
4514
|
return null;
|
|
4506
4515
|
}
|
|
4507
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4516
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4508
4517
|
if (!aliasDecl) {
|
|
4509
4518
|
return null;
|
|
4510
4519
|
}
|
|
@@ -4554,14 +4563,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4554
4563
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4555
4564
|
}
|
|
4556
4565
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4557
|
-
const typeNode = sourceNode && (
|
|
4558
|
-
if (!typeNode || !
|
|
4566
|
+
const typeNode = sourceNode && (ts6.isPropertyDeclaration(sourceNode) || ts6.isPropertySignature(sourceNode) || ts6.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4567
|
+
if (!typeNode || !ts6.isTypeReferenceNode(typeNode)) {
|
|
4559
4568
|
return void 0;
|
|
4560
4569
|
}
|
|
4561
4570
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4562
4571
|
}
|
|
4563
4572
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4564
|
-
if (!
|
|
4573
|
+
if (!ts6.isTypeReferenceNode(typeNode)) {
|
|
4565
4574
|
return false;
|
|
4566
4575
|
}
|
|
4567
4576
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4569,10 +4578,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4569
4578
|
return false;
|
|
4570
4579
|
}
|
|
4571
4580
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4572
|
-
return !!(resolved.flags & (
|
|
4581
|
+
return !!(resolved.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null));
|
|
4573
4582
|
}
|
|
4574
4583
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4575
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4584
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration);
|
|
4576
4585
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4577
4586
|
visitedAliases.add(nestedAliasDecl);
|
|
4578
4587
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4590,19 +4599,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4590
4599
|
if (isIntegerBrandedType(type)) {
|
|
4591
4600
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4592
4601
|
}
|
|
4593
|
-
if (type.flags &
|
|
4602
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4594
4603
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4595
4604
|
}
|
|
4596
|
-
if (type.flags &
|
|
4605
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4597
4606
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4598
4607
|
}
|
|
4599
|
-
if (type.flags & (
|
|
4608
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4600
4609
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4601
4610
|
}
|
|
4602
|
-
if (type.flags &
|
|
4611
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4603
4612
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4604
4613
|
}
|
|
4605
|
-
if (type.flags &
|
|
4614
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4606
4615
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4607
4616
|
}
|
|
4608
4617
|
return resolveTypeNode(
|
|
@@ -4629,13 +4638,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4629
4638
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4630
4639
|
);
|
|
4631
4640
|
const nonNullTypes = allTypes.filter(
|
|
4632
|
-
(memberType) => !(memberType.flags & (
|
|
4641
|
+
(memberType) => !(memberType.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4633
4642
|
);
|
|
4634
4643
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4635
4644
|
memberType,
|
|
4636
4645
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4637
4646
|
}));
|
|
4638
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4647
|
+
const hasNull = allTypes.some((t) => t.flags & ts6.TypeFlags.Null);
|
|
4639
4648
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4640
4649
|
if (namedDecl) {
|
|
4641
4650
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4678,7 +4687,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4678
4687
|
const displayName = memberDisplayNames.get(String(value));
|
|
4679
4688
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4680
4689
|
});
|
|
4681
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4690
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts6.TypeFlags.BooleanLiteral);
|
|
4682
4691
|
if (isBooleanUnion2) {
|
|
4683
4692
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4684
4693
|
const result = hasNull ? {
|
|
@@ -4770,7 +4779,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4770
4779
|
if (type.getProperties().length > 0) {
|
|
4771
4780
|
return null;
|
|
4772
4781
|
}
|
|
4773
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4782
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts6.IndexKind.String);
|
|
4774
4783
|
if (!indexInfo) {
|
|
4775
4784
|
return null;
|
|
4776
4785
|
}
|
|
@@ -4818,10 +4827,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4818
4827
|
}
|
|
4819
4828
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4820
4829
|
const name = declaration.name;
|
|
4821
|
-
if (
|
|
4830
|
+
if (ts6.isComputedPropertyName(name) || ts6.isPrivateIdentifier(name)) {
|
|
4822
4831
|
return false;
|
|
4823
4832
|
}
|
|
4824
|
-
if (!
|
|
4833
|
+
if (!ts6.isIdentifier(name) && !ts6.isStringLiteral(name) && !ts6.isNumericLiteral(name)) {
|
|
4825
4834
|
return false;
|
|
4826
4835
|
}
|
|
4827
4836
|
}
|
|
@@ -4947,7 +4956,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4947
4956
|
if (!declaration) continue;
|
|
4948
4957
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4949
4958
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4950
|
-
const optional = !!(prop.flags &
|
|
4959
|
+
const optional = !!(prop.flags & ts6.SymbolFlags.Optional);
|
|
4951
4960
|
const propTypeNode = resolveTypeNode(
|
|
4952
4961
|
propType,
|
|
4953
4962
|
checker,
|
|
@@ -4960,7 +4969,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4960
4969
|
collectedDiagnostics
|
|
4961
4970
|
);
|
|
4962
4971
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4963
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
4972
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts6.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4964
4973
|
declaration,
|
|
4965
4974
|
checker,
|
|
4966
4975
|
file,
|
|
@@ -4970,7 +4979,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4970
4979
|
type,
|
|
4971
4980
|
metadataPolicy,
|
|
4972
4981
|
extensionRegistry
|
|
4973
|
-
) :
|
|
4982
|
+
) : ts6.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4974
4983
|
declaration,
|
|
4975
4984
|
checker,
|
|
4976
4985
|
file,
|
|
@@ -4998,7 +5007,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4998
5007
|
visiting.delete(type);
|
|
4999
5008
|
const objectNode = {
|
|
5000
5009
|
kind: "object",
|
|
5001
|
-
properties: namedDecl !== void 0 && (
|
|
5010
|
+
properties: namedDecl !== void 0 && (ts6.isClassDeclaration(namedDecl) || ts6.isInterfaceDeclaration(namedDecl) || ts6.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
5002
5011
|
properties,
|
|
5003
5012
|
namedDecl,
|
|
5004
5013
|
type,
|
|
@@ -5046,12 +5055,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5046
5055
|
for (const symbol of symbols) {
|
|
5047
5056
|
const declarations = symbol.declarations;
|
|
5048
5057
|
if (!declarations) continue;
|
|
5049
|
-
const classDecl = declarations.find(
|
|
5058
|
+
const classDecl = declarations.find(ts6.isClassDeclaration);
|
|
5050
5059
|
if (classDecl) {
|
|
5051
5060
|
const map = /* @__PURE__ */ new Map();
|
|
5052
5061
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
5053
5062
|
for (const member of classDecl.members) {
|
|
5054
|
-
if (
|
|
5063
|
+
if (ts6.isPropertyDeclaration(member) && ts6.isIdentifier(member.name)) {
|
|
5055
5064
|
const fieldNode = analyzeFieldToIR(
|
|
5056
5065
|
member,
|
|
5057
5066
|
checker,
|
|
@@ -5075,7 +5084,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5075
5084
|
}
|
|
5076
5085
|
return map;
|
|
5077
5086
|
}
|
|
5078
|
-
const interfaceDecl = declarations.find(
|
|
5087
|
+
const interfaceDecl = declarations.find(ts6.isInterfaceDeclaration);
|
|
5079
5088
|
if (interfaceDecl) {
|
|
5080
5089
|
return buildFieldNodeInfoMap(
|
|
5081
5090
|
interfaceDecl.members,
|
|
@@ -5089,7 +5098,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5089
5098
|
extensionRegistry
|
|
5090
5099
|
);
|
|
5091
5100
|
}
|
|
5092
|
-
const typeAliasDecl = declarations.find(
|
|
5101
|
+
const typeAliasDecl = declarations.find(ts6.isTypeAliasDeclaration);
|
|
5093
5102
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5094
5103
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5095
5104
|
return buildFieldNodeInfoMap(
|
|
@@ -5113,10 +5122,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5113
5122
|
return void 0;
|
|
5114
5123
|
}
|
|
5115
5124
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5116
|
-
if (
|
|
5125
|
+
if (ts6.isArrayTypeNode(resolvedTypeNode)) {
|
|
5117
5126
|
return resolvedTypeNode.elementType;
|
|
5118
5127
|
}
|
|
5119
|
-
if (
|
|
5128
|
+
if (ts6.isTypeReferenceNode(resolvedTypeNode) && ts6.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5120
5129
|
return resolvedTypeNode.typeArguments[0];
|
|
5121
5130
|
}
|
|
5122
5131
|
return void 0;
|
|
@@ -5127,13 +5136,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5127
5136
|
return [];
|
|
5128
5137
|
}
|
|
5129
5138
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5130
|
-
return
|
|
5139
|
+
return ts6.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5131
5140
|
}
|
|
5132
5141
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5133
|
-
if (
|
|
5142
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5134
5143
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5135
5144
|
}
|
|
5136
|
-
if (!
|
|
5145
|
+
if (!ts6.isTypeReferenceNode(typeNode) || !ts6.isIdentifier(typeNode.typeName)) {
|
|
5137
5146
|
return typeNode;
|
|
5138
5147
|
}
|
|
5139
5148
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5144,15 +5153,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5144
5153
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5145
5154
|
}
|
|
5146
5155
|
function isNullishTypeNode(typeNode) {
|
|
5147
|
-
if (typeNode.kind ===
|
|
5156
|
+
if (typeNode.kind === ts6.SyntaxKind.NullKeyword || typeNode.kind === ts6.SyntaxKind.UndefinedKeyword) {
|
|
5148
5157
|
return true;
|
|
5149
5158
|
}
|
|
5150
|
-
return
|
|
5159
|
+
return ts6.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts6.SyntaxKind.NullKeyword || typeNode.literal.kind === ts6.SyntaxKind.UndefinedKeyword);
|
|
5151
5160
|
}
|
|
5152
5161
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5153
5162
|
const map = /* @__PURE__ */ new Map();
|
|
5154
5163
|
for (const member of members) {
|
|
5155
|
-
if (
|
|
5164
|
+
if (ts6.isPropertySignature(member)) {
|
|
5156
5165
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5157
5166
|
member,
|
|
5158
5167
|
checker,
|
|
@@ -5177,7 +5186,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5177
5186
|
return map;
|
|
5178
5187
|
}
|
|
5179
5188
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5180
|
-
if (!
|
|
5189
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return [];
|
|
5181
5190
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5182
5191
|
const aliasName = typeNode.typeName.getText();
|
|
5183
5192
|
throw new Error(
|
|
@@ -5186,7 +5195,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5186
5195
|
}
|
|
5187
5196
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5188
5197
|
if (!aliasDecl) return [];
|
|
5189
|
-
if (
|
|
5198
|
+
if (ts6.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5190
5199
|
const aliasFieldType = resolveTypeNode(
|
|
5191
5200
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5192
5201
|
checker,
|
|
@@ -5230,14 +5239,14 @@ function getNamedTypeName(type) {
|
|
|
5230
5239
|
const symbol = type.getSymbol();
|
|
5231
5240
|
if (symbol?.declarations) {
|
|
5232
5241
|
const decl = symbol.declarations[0];
|
|
5233
|
-
if (decl && (
|
|
5234
|
-
const name =
|
|
5242
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5243
|
+
const name = ts6.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5235
5244
|
if (name) return name;
|
|
5236
5245
|
}
|
|
5237
5246
|
}
|
|
5238
5247
|
const aliasSymbol = type.aliasSymbol;
|
|
5239
5248
|
if (aliasSymbol?.declarations) {
|
|
5240
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5249
|
+
const aliasDecl = aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5241
5250
|
if (aliasDecl) {
|
|
5242
5251
|
return aliasDecl.name.text;
|
|
5243
5252
|
}
|
|
@@ -5248,24 +5257,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5248
5257
|
const symbol = type.getSymbol();
|
|
5249
5258
|
if (symbol?.declarations) {
|
|
5250
5259
|
const decl = symbol.declarations[0];
|
|
5251
|
-
if (decl && (
|
|
5260
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5252
5261
|
return decl;
|
|
5253
5262
|
}
|
|
5254
5263
|
}
|
|
5255
5264
|
const aliasSymbol = type.aliasSymbol;
|
|
5256
5265
|
if (aliasSymbol?.declarations) {
|
|
5257
|
-
return aliasSymbol.declarations.find(
|
|
5266
|
+
return aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5258
5267
|
}
|
|
5259
5268
|
return void 0;
|
|
5260
5269
|
}
|
|
5261
5270
|
function analyzeMethod(method, checker) {
|
|
5262
|
-
if (!
|
|
5271
|
+
if (!ts6.isIdentifier(method.name)) {
|
|
5263
5272
|
return null;
|
|
5264
5273
|
}
|
|
5265
5274
|
const name = method.name.text;
|
|
5266
5275
|
const parameters = [];
|
|
5267
5276
|
for (const param of method.parameters) {
|
|
5268
|
-
if (
|
|
5277
|
+
if (ts6.isIdentifier(param.name)) {
|
|
5269
5278
|
const paramInfo = analyzeParameter(param, checker);
|
|
5270
5279
|
parameters.push(paramInfo);
|
|
5271
5280
|
}
|
|
@@ -5276,7 +5285,7 @@ function analyzeMethod(method, checker) {
|
|
|
5276
5285
|
return { name, parameters, returnTypeNode, returnType };
|
|
5277
5286
|
}
|
|
5278
5287
|
function analyzeParameter(param, checker) {
|
|
5279
|
-
const name =
|
|
5288
|
+
const name = ts6.isIdentifier(param.name) ? param.name.text : "param";
|
|
5280
5289
|
const typeNode = param.type;
|
|
5281
5290
|
const type = checker.getTypeAtLocation(param);
|
|
5282
5291
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5285,29 +5294,30 @@ function analyzeParameter(param, checker) {
|
|
|
5285
5294
|
}
|
|
5286
5295
|
function detectFormSpecReference(typeNode) {
|
|
5287
5296
|
if (!typeNode) return null;
|
|
5288
|
-
if (!
|
|
5289
|
-
const typeName =
|
|
5297
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return null;
|
|
5298
|
+
const typeName = ts6.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts6.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5290
5299
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5291
5300
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5292
|
-
if (!typeArg || !
|
|
5293
|
-
if (
|
|
5301
|
+
if (!typeArg || !ts6.isTypeQueryNode(typeArg)) return null;
|
|
5302
|
+
if (ts6.isIdentifier(typeArg.exprName)) {
|
|
5294
5303
|
return typeArg.exprName.text;
|
|
5295
5304
|
}
|
|
5296
|
-
if (
|
|
5305
|
+
if (ts6.isQualifiedName(typeArg.exprName)) {
|
|
5297
5306
|
return typeArg.exprName.right.text;
|
|
5298
5307
|
}
|
|
5299
5308
|
return null;
|
|
5300
5309
|
}
|
|
5301
|
-
var
|
|
5310
|
+
var ts6, import_internal4, RESOLVING_TYPE_PLACEHOLDER, MAX_ALIAS_CHAIN_DEPTH;
|
|
5302
5311
|
var init_class_analyzer = __esm({
|
|
5303
5312
|
"src/analyzer/class-analyzer.ts"() {
|
|
5304
5313
|
"use strict";
|
|
5305
|
-
|
|
5314
|
+
ts6 = __toESM(require("typescript"), 1);
|
|
5306
5315
|
import_internal4 = require("@formspec/analysis/internal");
|
|
5307
5316
|
init_jsdoc_constraints();
|
|
5308
5317
|
init_tsdoc_parser();
|
|
5309
5318
|
init_resolve_custom_type();
|
|
5310
5319
|
init_ts_type_utils();
|
|
5320
|
+
init_builtin_brands();
|
|
5311
5321
|
init_metadata();
|
|
5312
5322
|
RESOLVING_TYPE_PLACEHOLDER = {
|
|
5313
5323
|
kind: "object",
|
|
@@ -5334,23 +5344,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5334
5344
|
function createProgramContext(filePath, additionalFiles) {
|
|
5335
5345
|
const absolutePath = path.resolve(filePath);
|
|
5336
5346
|
const fileDir = path.dirname(absolutePath);
|
|
5337
|
-
const configPath =
|
|
5347
|
+
const configPath = ts7.findConfigFile(fileDir, ts7.sys.fileExists.bind(ts7.sys), "tsconfig.json");
|
|
5338
5348
|
let compilerOptions;
|
|
5339
5349
|
let fileNames;
|
|
5340
5350
|
if (configPath) {
|
|
5341
|
-
const configFile =
|
|
5351
|
+
const configFile = ts7.readConfigFile(configPath, ts7.sys.readFile.bind(ts7.sys));
|
|
5342
5352
|
if (configFile.error) {
|
|
5343
5353
|
throw new Error(
|
|
5344
|
-
`Error reading tsconfig.json: ${
|
|
5354
|
+
`Error reading tsconfig.json: ${ts7.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5345
5355
|
);
|
|
5346
5356
|
}
|
|
5347
|
-
const parsed =
|
|
5357
|
+
const parsed = ts7.parseJsonConfigFileContent(
|
|
5348
5358
|
configFile.config,
|
|
5349
|
-
|
|
5359
|
+
ts7.sys,
|
|
5350
5360
|
path.dirname(configPath)
|
|
5351
5361
|
);
|
|
5352
5362
|
if (parsed.errors.length > 0) {
|
|
5353
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5363
|
+
const errorMessages = parsed.errors.map((e) => ts7.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5354
5364
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5355
5365
|
}
|
|
5356
5366
|
compilerOptions = parsed.options;
|
|
@@ -5358,9 +5368,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5358
5368
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5359
5369
|
} else {
|
|
5360
5370
|
compilerOptions = {
|
|
5361
|
-
target:
|
|
5362
|
-
module:
|
|
5363
|
-
moduleResolution:
|
|
5371
|
+
target: ts7.ScriptTarget.ES2022,
|
|
5372
|
+
module: ts7.ModuleKind.NodeNext,
|
|
5373
|
+
moduleResolution: ts7.ModuleResolutionKind.NodeNext,
|
|
5364
5374
|
strict: true,
|
|
5365
5375
|
skipLibCheck: true,
|
|
5366
5376
|
declaration: true
|
|
@@ -5368,7 +5378,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5368
5378
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5369
5379
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5370
5380
|
}
|
|
5371
|
-
const program =
|
|
5381
|
+
const program = ts7.createProgram(fileNames, compilerOptions);
|
|
5372
5382
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5373
5383
|
if (!sourceFile) {
|
|
5374
5384
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5387,19 +5397,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5387
5397
|
result = node;
|
|
5388
5398
|
return;
|
|
5389
5399
|
}
|
|
5390
|
-
|
|
5400
|
+
ts7.forEachChild(node, visit);
|
|
5391
5401
|
}
|
|
5392
5402
|
visit(sourceFile);
|
|
5393
5403
|
return result;
|
|
5394
5404
|
}
|
|
5395
5405
|
function findClassByName(sourceFile, className) {
|
|
5396
|
-
return findNodeByName(sourceFile, className,
|
|
5406
|
+
return findNodeByName(sourceFile, className, ts7.isClassDeclaration, (n) => n.name?.text);
|
|
5397
5407
|
}
|
|
5398
5408
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5399
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5409
|
+
return findNodeByName(sourceFile, interfaceName, ts7.isInterfaceDeclaration, (n) => n.name.text);
|
|
5400
5410
|
}
|
|
5401
5411
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5402
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5412
|
+
return findNodeByName(sourceFile, aliasName, ts7.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5403
5413
|
}
|
|
5404
5414
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5405
5415
|
if (rootType.kind === "object") {
|
|
@@ -5439,22 +5449,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5439
5449
|
};
|
|
5440
5450
|
}
|
|
5441
5451
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5442
|
-
if (
|
|
5452
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5443
5453
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5444
5454
|
}
|
|
5445
|
-
if (
|
|
5455
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5446
5456
|
return true;
|
|
5447
5457
|
}
|
|
5448
|
-
return
|
|
5458
|
+
return ts7.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5449
5459
|
}
|
|
5450
5460
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5451
|
-
if (
|
|
5461
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5452
5462
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5453
5463
|
}
|
|
5454
|
-
if (
|
|
5464
|
+
if (ts7.isTypeLiteralNode(typeNode)) {
|
|
5455
5465
|
const propertyNames = [];
|
|
5456
5466
|
for (const member of typeNode.members) {
|
|
5457
|
-
if (!
|
|
5467
|
+
if (!ts7.isPropertySignature(member)) {
|
|
5458
5468
|
continue;
|
|
5459
5469
|
}
|
|
5460
5470
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5464,13 +5474,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5464
5474
|
}
|
|
5465
5475
|
return propertyNames;
|
|
5466
5476
|
}
|
|
5467
|
-
if (
|
|
5477
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5468
5478
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5469
5479
|
}
|
|
5470
5480
|
return null;
|
|
5471
5481
|
}
|
|
5472
5482
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5473
|
-
if (!
|
|
5483
|
+
if (!ts7.isIntersectionTypeNode(typeNode)) {
|
|
5474
5484
|
return [];
|
|
5475
5485
|
}
|
|
5476
5486
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5669,11 +5679,11 @@ function makeFileProvenance(filePath) {
|
|
|
5669
5679
|
column: 0
|
|
5670
5680
|
};
|
|
5671
5681
|
}
|
|
5672
|
-
var
|
|
5682
|
+
var ts7, path;
|
|
5673
5683
|
var init_program = __esm({
|
|
5674
5684
|
"src/analyzer/program.ts"() {
|
|
5675
5685
|
"use strict";
|
|
5676
|
-
|
|
5686
|
+
ts7 = __toESM(require("typescript"), 1);
|
|
5677
5687
|
path = __toESM(require("path"), 1);
|
|
5678
5688
|
init_class_analyzer();
|
|
5679
5689
|
}
|
|
@@ -5688,10 +5698,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5688
5698
|
return symbolMap;
|
|
5689
5699
|
}
|
|
5690
5700
|
function visit(node) {
|
|
5691
|
-
if (
|
|
5701
|
+
if (ts8.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5692
5702
|
processDefineCustomTypeCall(node);
|
|
5693
5703
|
}
|
|
5694
|
-
|
|
5704
|
+
ts8.forEachChild(node, visit);
|
|
5695
5705
|
}
|
|
5696
5706
|
function processDefineCustomTypeCall(call) {
|
|
5697
5707
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5728,7 +5738,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5728
5738
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5729
5739
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5730
5740
|
if (callSymbol !== void 0) {
|
|
5731
|
-
const resolved = callSymbol.flags &
|
|
5741
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5732
5742
|
const decl = resolved.declarations?.[0];
|
|
5733
5743
|
if (decl !== void 0) {
|
|
5734
5744
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5736,24 +5746,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5736
5746
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5737
5747
|
}
|
|
5738
5748
|
}
|
|
5739
|
-
return
|
|
5749
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5740
5750
|
}
|
|
5741
5751
|
function extractTypeNameFromCallArg(call) {
|
|
5742
5752
|
const arg = call.arguments[0];
|
|
5743
|
-
if (arg === void 0 || !
|
|
5753
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5744
5754
|
return null;
|
|
5745
5755
|
}
|
|
5746
5756
|
const typeNameProp = arg.properties.find(
|
|
5747
|
-
(p) =>
|
|
5757
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5748
5758
|
);
|
|
5749
|
-
if (typeNameProp === void 0 || !
|
|
5759
|
+
if (typeNameProp === void 0 || !ts8.isStringLiteral(typeNameProp.initializer)) {
|
|
5750
5760
|
return null;
|
|
5751
5761
|
}
|
|
5752
5762
|
return typeNameProp.initializer.text;
|
|
5753
5763
|
}
|
|
5754
5764
|
function extractEnclosingExtensionId(call, checker) {
|
|
5755
|
-
for (let node = call.parent; !
|
|
5756
|
-
if (
|
|
5765
|
+
for (let node = call.parent; !ts8.isSourceFile(node); node = node.parent) {
|
|
5766
|
+
if (ts8.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5757
5767
|
return extractExtensionIdFromCallArg(node);
|
|
5758
5768
|
}
|
|
5759
5769
|
}
|
|
@@ -5762,24 +5772,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5762
5772
|
function isDefineExtensionCall(node, checker) {
|
|
5763
5773
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5764
5774
|
if (callSymbol !== void 0) {
|
|
5765
|
-
const resolved = callSymbol.flags &
|
|
5775
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5766
5776
|
const decl = resolved.declarations?.[0];
|
|
5767
5777
|
if (decl !== void 0) {
|
|
5768
5778
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5769
5779
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5770
5780
|
}
|
|
5771
5781
|
}
|
|
5772
|
-
return
|
|
5782
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5773
5783
|
}
|
|
5774
5784
|
function extractExtensionIdFromCallArg(call) {
|
|
5775
5785
|
const arg = call.arguments[0];
|
|
5776
|
-
if (arg === void 0 || !
|
|
5786
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5777
5787
|
return null;
|
|
5778
5788
|
}
|
|
5779
5789
|
const prop = arg.properties.find(
|
|
5780
|
-
(p) =>
|
|
5790
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5781
5791
|
);
|
|
5782
|
-
if (prop === void 0 || !
|
|
5792
|
+
if (prop === void 0 || !ts8.isStringLiteral(prop.initializer)) {
|
|
5783
5793
|
return null;
|
|
5784
5794
|
}
|
|
5785
5795
|
return prop.initializer.text;
|
|
@@ -5797,11 +5807,11 @@ function findRegistrationByTypeName(registry, typeName) {
|
|
|
5797
5807
|
}
|
|
5798
5808
|
return void 0;
|
|
5799
5809
|
}
|
|
5800
|
-
var
|
|
5810
|
+
var ts8, path2;
|
|
5801
5811
|
var init_symbol_registry = __esm({
|
|
5802
5812
|
"src/extensions/symbol-registry.ts"() {
|
|
5803
5813
|
"use strict";
|
|
5804
|
-
|
|
5814
|
+
ts8 = __toESM(require("typescript"), 1);
|
|
5805
5815
|
path2 = __toESM(require("path"), 1);
|
|
5806
5816
|
init_ts_type_utils();
|
|
5807
5817
|
}
|
|
@@ -6064,7 +6074,7 @@ function generateSchemasBatch(options) {
|
|
|
6064
6074
|
return options.targets.map((target) => {
|
|
6065
6075
|
let ctx;
|
|
6066
6076
|
try {
|
|
6067
|
-
const cacheKey =
|
|
6077
|
+
const cacheKey = ts9.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
6068
6078
|
const cachedContext = contextCache.get(cacheKey);
|
|
6069
6079
|
if (cachedContext === void 0) {
|
|
6070
6080
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6218,11 +6228,11 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6218
6228
|
relatedLocations: []
|
|
6219
6229
|
};
|
|
6220
6230
|
}
|
|
6221
|
-
var
|
|
6231
|
+
var ts9;
|
|
6222
6232
|
var init_class_schema = __esm({
|
|
6223
6233
|
"src/generators/class-schema.ts"() {
|
|
6224
6234
|
"use strict";
|
|
6225
|
-
|
|
6235
|
+
ts9 = __toESM(require("typescript"), 1);
|
|
6226
6236
|
init_program();
|
|
6227
6237
|
init_class_analyzer();
|
|
6228
6238
|
init_canonicalize();
|
|
@@ -6249,7 +6259,7 @@ function getModuleSymbol(context) {
|
|
|
6249
6259
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6250
6260
|
}
|
|
6251
6261
|
function isSchemaSourceDeclaration(declaration) {
|
|
6252
|
-
return
|
|
6262
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6253
6263
|
}
|
|
6254
6264
|
function resolveModuleExport(context, exportName = "default") {
|
|
6255
6265
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6260,16 +6270,16 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6260
6270
|
if (exportSymbol === null) {
|
|
6261
6271
|
return null;
|
|
6262
6272
|
}
|
|
6263
|
-
return exportSymbol.flags &
|
|
6273
|
+
return exportSymbol.flags & ts10.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6264
6274
|
}
|
|
6265
6275
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6266
6276
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6267
6277
|
}
|
|
6268
|
-
var
|
|
6278
|
+
var ts10;
|
|
6269
6279
|
var init_static_build = __esm({
|
|
6270
6280
|
"src/static-build.ts"() {
|
|
6271
6281
|
"use strict";
|
|
6272
|
-
|
|
6282
|
+
ts10 = __toESM(require("typescript"), 1);
|
|
6273
6283
|
init_program();
|
|
6274
6284
|
}
|
|
6275
6285
|
});
|
|
@@ -6282,17 +6292,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6282
6292
|
};
|
|
6283
6293
|
}
|
|
6284
6294
|
function isNamedTypeDeclaration(declaration) {
|
|
6285
|
-
return
|
|
6295
|
+
return ts11.isClassDeclaration(declaration) || ts11.isInterfaceDeclaration(declaration) || ts11.isTypeAliasDeclaration(declaration);
|
|
6286
6296
|
}
|
|
6287
6297
|
function hasConcreteTypeArguments(type, checker) {
|
|
6288
6298
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6289
6299
|
return true;
|
|
6290
6300
|
}
|
|
6291
|
-
if ((type.flags &
|
|
6301
|
+
if ((type.flags & ts11.TypeFlags.Object) === 0) {
|
|
6292
6302
|
return false;
|
|
6293
6303
|
}
|
|
6294
6304
|
const objectType = type;
|
|
6295
|
-
if ((objectType.objectFlags &
|
|
6305
|
+
if ((objectType.objectFlags & ts11.ObjectFlags.Reference) === 0) {
|
|
6296
6306
|
return false;
|
|
6297
6307
|
}
|
|
6298
6308
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6305,13 +6315,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6305
6315
|
return declaration;
|
|
6306
6316
|
}
|
|
6307
6317
|
}
|
|
6308
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6318
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts11.isTypeAliasDeclaration);
|
|
6309
6319
|
return aliasDeclaration;
|
|
6310
6320
|
}
|
|
6311
6321
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6312
6322
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6313
6323
|
const namedNode = sourceNode;
|
|
6314
|
-
if (namedNode.name !== void 0 &&
|
|
6324
|
+
if (namedNode.name !== void 0 && ts11.isIdentifier(namedNode.name)) {
|
|
6315
6325
|
return namedNode.name.text;
|
|
6316
6326
|
}
|
|
6317
6327
|
}
|
|
@@ -6533,7 +6543,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6533
6543
|
function generateSchemasFromDeclaration(options) {
|
|
6534
6544
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6535
6545
|
const resolved = resolveStaticOptions(options);
|
|
6536
|
-
if (
|
|
6546
|
+
if (ts11.isClassDeclaration(options.declaration)) {
|
|
6537
6547
|
return generateSchemasFromAnalysis(
|
|
6538
6548
|
analyzeClassToIR(
|
|
6539
6549
|
options.declaration,
|
|
@@ -6547,7 +6557,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6547
6557
|
resolved
|
|
6548
6558
|
);
|
|
6549
6559
|
}
|
|
6550
|
-
if (
|
|
6560
|
+
if (ts11.isInterfaceDeclaration(options.declaration)) {
|
|
6551
6561
|
return generateSchemasFromAnalysis(
|
|
6552
6562
|
analyzeInterfaceToIR(
|
|
6553
6563
|
options.declaration,
|
|
@@ -6561,7 +6571,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6561
6571
|
resolved
|
|
6562
6572
|
);
|
|
6563
6573
|
}
|
|
6564
|
-
if (
|
|
6574
|
+
if (ts11.isTypeAliasDeclaration(options.declaration)) {
|
|
6565
6575
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6566
6576
|
options.declaration,
|
|
6567
6577
|
options.context.checker,
|
|
@@ -6620,7 +6630,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6620
6630
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6621
6631
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6622
6632
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6623
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6633
|
+
const fallbackName = options.declaration.name !== void 0 && ts11.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6624
6634
|
return generateSchemasFromResolvedType({
|
|
6625
6635
|
...options,
|
|
6626
6636
|
type,
|
|
@@ -6667,20 +6677,20 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6667
6677
|
if (typeNode === void 0) {
|
|
6668
6678
|
return void 0;
|
|
6669
6679
|
}
|
|
6670
|
-
if (
|
|
6680
|
+
if (ts11.isParenthesizedTypeNode(typeNode)) {
|
|
6671
6681
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6672
6682
|
return unwrapped ?? typeNode;
|
|
6673
6683
|
}
|
|
6674
6684
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6675
6685
|
}
|
|
6676
6686
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6677
|
-
return
|
|
6687
|
+
return ts11.isTypeReferenceNode(typeNode) && ts11.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6678
6688
|
}
|
|
6679
|
-
var
|
|
6689
|
+
var ts11, import_internal6, import_internals6;
|
|
6680
6690
|
var init_discovered_schema = __esm({
|
|
6681
6691
|
"src/generators/discovered-schema.ts"() {
|
|
6682
6692
|
"use strict";
|
|
6683
|
-
|
|
6693
|
+
ts11 = __toESM(require("typescript"), 1);
|
|
6684
6694
|
import_internal6 = require("@formspec/analysis/internal");
|
|
6685
6695
|
init_class_analyzer();
|
|
6686
6696
|
init_class_schema();
|