@formspec/build 0.1.0-alpha.51 → 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/index.cjs
CHANGED
|
@@ -2219,21 +2219,21 @@ var jsonSchema7Schema = import_zod3.z.lazy(
|
|
|
2219
2219
|
);
|
|
2220
2220
|
|
|
2221
2221
|
// src/generators/class-schema.ts
|
|
2222
|
-
var
|
|
2222
|
+
var ts9 = __toESM(require("typescript"), 1);
|
|
2223
2223
|
|
|
2224
2224
|
// src/analyzer/program.ts
|
|
2225
|
-
var
|
|
2225
|
+
var ts7 = __toESM(require("typescript"), 1);
|
|
2226
2226
|
var path = __toESM(require("path"), 1);
|
|
2227
2227
|
|
|
2228
2228
|
// src/analyzer/class-analyzer.ts
|
|
2229
|
-
var
|
|
2229
|
+
var ts6 = __toESM(require("typescript"), 1);
|
|
2230
2230
|
var import_internal4 = require("@formspec/analysis/internal");
|
|
2231
2231
|
|
|
2232
2232
|
// src/analyzer/jsdoc-constraints.ts
|
|
2233
|
-
var
|
|
2233
|
+
var ts5 = __toESM(require("typescript"), 1);
|
|
2234
2234
|
|
|
2235
2235
|
// src/analyzer/tsdoc-parser.ts
|
|
2236
|
-
var
|
|
2236
|
+
var ts4 = __toESM(require("typescript"), 1);
|
|
2237
2237
|
var import_internal3 = require("@formspec/analysis/internal");
|
|
2238
2238
|
var import_internals4 = require("@formspec/core/internals");
|
|
2239
2239
|
var import_internals5 = require("@formspec/core/internals");
|
|
@@ -2355,6 +2355,14 @@ function customTypeIdFromLookup(result) {
|
|
|
2355
2355
|
return `${result.extensionId}/${result.registration.typeName}`;
|
|
2356
2356
|
}
|
|
2357
2357
|
|
|
2358
|
+
// src/analyzer/builtin-brands.ts
|
|
2359
|
+
var ts3 = __toESM(require("typescript"), 1);
|
|
2360
|
+
function isIntegerBrandedType(type) {
|
|
2361
|
+
if (!type.isIntersection()) return false;
|
|
2362
|
+
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2363
|
+
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2358
2366
|
// src/analyzer/tsdoc-parser.ts
|
|
2359
2367
|
function sharedTagValueOptions(options) {
|
|
2360
2368
|
return {
|
|
@@ -2362,7 +2370,7 @@ function sharedTagValueOptions(options) {
|
|
|
2362
2370
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2363
2371
|
};
|
|
2364
2372
|
}
|
|
2365
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
2373
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts4.TypeFormatFlags.NoTruncation | ts4.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2366
2374
|
function getExtensionTypeNames(registry) {
|
|
2367
2375
|
if (registry === void 0) {
|
|
2368
2376
|
return /* @__PURE__ */ new Set();
|
|
@@ -2376,23 +2384,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2376
2384
|
function collectImportedNames(sourceFile) {
|
|
2377
2385
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2378
2386
|
for (const statement of sourceFile.statements) {
|
|
2379
|
-
if (
|
|
2387
|
+
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2380
2388
|
const clause = statement.importClause;
|
|
2381
2389
|
if (clause.name !== void 0) {
|
|
2382
2390
|
importedNames.add(clause.name.text);
|
|
2383
2391
|
}
|
|
2384
2392
|
if (clause.namedBindings !== void 0) {
|
|
2385
|
-
if (
|
|
2393
|
+
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
2386
2394
|
for (const specifier of clause.namedBindings.elements) {
|
|
2387
2395
|
importedNames.add(specifier.name.text);
|
|
2388
2396
|
}
|
|
2389
|
-
} else if (
|
|
2397
|
+
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
2390
2398
|
importedNames.add(clause.namedBindings.name.text);
|
|
2391
2399
|
}
|
|
2392
2400
|
}
|
|
2393
2401
|
continue;
|
|
2394
2402
|
}
|
|
2395
|
-
if (
|
|
2403
|
+
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
2396
2404
|
importedNames.add(statement.name.text);
|
|
2397
2405
|
}
|
|
2398
2406
|
}
|
|
@@ -2400,13 +2408,13 @@ function collectImportedNames(sourceFile) {
|
|
|
2400
2408
|
}
|
|
2401
2409
|
function isNonReferenceIdentifier(node) {
|
|
2402
2410
|
const parent = node.parent;
|
|
2403
|
-
if ((
|
|
2411
|
+
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) {
|
|
2404
2412
|
return true;
|
|
2405
2413
|
}
|
|
2406
|
-
if ((
|
|
2414
|
+
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2407
2415
|
return true;
|
|
2408
2416
|
}
|
|
2409
|
-
if (
|
|
2417
|
+
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
2410
2418
|
return true;
|
|
2411
2419
|
}
|
|
2412
2420
|
return false;
|
|
@@ -2420,11 +2428,11 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
2420
2428
|
if (referencesImportedName) {
|
|
2421
2429
|
return;
|
|
2422
2430
|
}
|
|
2423
|
-
if (
|
|
2431
|
+
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2424
2432
|
referencesImportedName = true;
|
|
2425
2433
|
return;
|
|
2426
2434
|
}
|
|
2427
|
-
|
|
2435
|
+
ts4.forEachChild(node, visit);
|
|
2428
2436
|
};
|
|
2429
2437
|
visit(statement);
|
|
2430
2438
|
return referencesImportedName;
|
|
@@ -2435,9 +2443,9 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
2435
2443
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2436
2444
|
);
|
|
2437
2445
|
return sourceFile.statements.filter((statement) => {
|
|
2438
|
-
if (
|
|
2439
|
-
if (
|
|
2440
|
-
if (
|
|
2446
|
+
if (ts4.isImportDeclaration(statement)) return false;
|
|
2447
|
+
if (ts4.isImportEqualsDeclaration(statement)) return false;
|
|
2448
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
2441
2449
|
return false;
|
|
2442
2450
|
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2443
2451
|
return false;
|
|
@@ -2535,7 +2543,7 @@ function stripHintNullishUnion(type) {
|
|
|
2535
2543
|
return type;
|
|
2536
2544
|
}
|
|
2537
2545
|
const nonNullish = type.types.filter(
|
|
2538
|
-
(member) => (member.flags & (
|
|
2546
|
+
(member) => (member.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) === 0
|
|
2539
2547
|
);
|
|
2540
2548
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2541
2549
|
return nonNullish[0];
|
|
@@ -2551,10 +2559,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2551
2559
|
}
|
|
2552
2560
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2553
2561
|
const name = declaration.name;
|
|
2554
|
-
if (
|
|
2562
|
+
if (ts4.isComputedPropertyName(name) || ts4.isPrivateIdentifier(name)) {
|
|
2555
2563
|
return false;
|
|
2556
2564
|
}
|
|
2557
|
-
if (!
|
|
2565
|
+
if (!ts4.isIdentifier(name) && !ts4.isStringLiteral(name) && !ts4.isNumericLiteral(name)) {
|
|
2558
2566
|
return false;
|
|
2559
2567
|
}
|
|
2560
2568
|
}
|
|
@@ -2772,6 +2780,9 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2772
2780
|
}
|
|
2773
2781
|
const hasBroadening = (() => {
|
|
2774
2782
|
if (target === null) {
|
|
2783
|
+
if (isIntegerBrandedType((0, import_internal3.stripNullishUnion)(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2784
|
+
return true;
|
|
2785
|
+
}
|
|
2775
2786
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2776
2787
|
}
|
|
2777
2788
|
const registry = options?.extensionRegistry;
|
|
@@ -2924,12 +2935,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2924
2935
|
const sourceText = sourceFile.getFullText();
|
|
2925
2936
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2926
2937
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2927
|
-
const commentRanges =
|
|
2938
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2928
2939
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2929
2940
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2930
2941
|
if (commentRanges) {
|
|
2931
2942
|
for (const range of commentRanges) {
|
|
2932
|
-
if (range.kind !==
|
|
2943
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) {
|
|
2933
2944
|
continue;
|
|
2934
2945
|
}
|
|
2935
2946
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3086,10 +3097,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3086
3097
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3087
3098
|
const sourceFile = node.getSourceFile();
|
|
3088
3099
|
const sourceText = sourceFile.getFullText();
|
|
3089
|
-
const commentRanges =
|
|
3100
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3090
3101
|
if (commentRanges) {
|
|
3091
3102
|
for (const range of commentRanges) {
|
|
3092
|
-
if (range.kind !==
|
|
3103
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3093
3104
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3094
3105
|
if (!commentText.startsWith("/**")) continue;
|
|
3095
3106
|
const unified = (0, import_internal3.parseUnifiedComment)(commentText);
|
|
@@ -3114,7 +3125,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3114
3125
|
}
|
|
3115
3126
|
function collectRawTextFallbacks(node, file) {
|
|
3116
3127
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3117
|
-
for (const tag of
|
|
3128
|
+
for (const tag of ts4.getJSDocTags(node)) {
|
|
3118
3129
|
const tagName = (0, import_internals4.normalizeConstraintTagName)(tag.tagName.text);
|
|
3119
3130
|
if (!import_internal3.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3120
3131
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3169,7 +3180,7 @@ function getTagCommentText(tag) {
|
|
|
3169
3180
|
if (typeof tag.comment === "string") {
|
|
3170
3181
|
return tag.comment;
|
|
3171
3182
|
}
|
|
3172
|
-
return
|
|
3183
|
+
return ts4.getTextOfJSDocComment(tag.comment);
|
|
3173
3184
|
}
|
|
3174
3185
|
|
|
3175
3186
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3187,18 +3198,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3187
3198
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3188
3199
|
if (!initializer) return null;
|
|
3189
3200
|
let value;
|
|
3190
|
-
if (
|
|
3201
|
+
if (ts5.isStringLiteral(initializer)) {
|
|
3191
3202
|
value = initializer.text;
|
|
3192
|
-
} else if (
|
|
3203
|
+
} else if (ts5.isNumericLiteral(initializer)) {
|
|
3193
3204
|
value = Number(initializer.text);
|
|
3194
|
-
} else if (initializer.kind ===
|
|
3205
|
+
} else if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
|
|
3195
3206
|
value = true;
|
|
3196
|
-
} else if (initializer.kind ===
|
|
3207
|
+
} else if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
|
|
3197
3208
|
value = false;
|
|
3198
|
-
} else if (initializer.kind ===
|
|
3209
|
+
} else if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
|
|
3199
3210
|
value = null;
|
|
3200
|
-
} else if (
|
|
3201
|
-
if (initializer.operator ===
|
|
3211
|
+
} else if (ts5.isPrefixUnaryExpression(initializer)) {
|
|
3212
|
+
if (initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
|
|
3202
3213
|
value = -Number(initializer.operand.text);
|
|
3203
3214
|
}
|
|
3204
3215
|
}
|
|
@@ -3220,38 +3231,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3220
3231
|
|
|
3221
3232
|
// src/analyzer/class-analyzer.ts
|
|
3222
3233
|
function isObjectType(type) {
|
|
3223
|
-
return !!(type.flags &
|
|
3234
|
+
return !!(type.flags & ts6.TypeFlags.Object);
|
|
3224
3235
|
}
|
|
3225
3236
|
function isIntersectionType(type) {
|
|
3226
|
-
return !!(type.flags &
|
|
3227
|
-
}
|
|
3228
|
-
function isIntegerBrandedType(type) {
|
|
3229
|
-
if (!type.isIntersection()) {
|
|
3230
|
-
return false;
|
|
3231
|
-
}
|
|
3232
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3233
|
-
if (!hasNumberBase) {
|
|
3234
|
-
return false;
|
|
3235
|
-
}
|
|
3236
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3237
|
+
return !!(type.flags & ts6.TypeFlags.Intersection);
|
|
3237
3238
|
}
|
|
3238
3239
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3239
|
-
if (
|
|
3240
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3240
3241
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3241
3242
|
}
|
|
3242
|
-
if (
|
|
3243
|
+
if (ts6.isTypeLiteralNode(typeNode) || ts6.isTypeReferenceNode(typeNode)) {
|
|
3243
3244
|
return true;
|
|
3244
3245
|
}
|
|
3245
|
-
return
|
|
3246
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3246
3247
|
}
|
|
3247
3248
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3248
3249
|
if (isIntersectionType(type)) {
|
|
3249
3250
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3250
3251
|
}
|
|
3251
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3252
|
+
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);
|
|
3252
3253
|
}
|
|
3253
3254
|
function isTypeReference(type) {
|
|
3254
|
-
return !!(type.flags &
|
|
3255
|
+
return !!(type.flags & ts6.TypeFlags.Object) && !!(type.objectFlags & ts6.ObjectFlags.Reference);
|
|
3255
3256
|
}
|
|
3256
3257
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3257
3258
|
kind: "object",
|
|
@@ -3316,7 +3317,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3316
3317
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3317
3318
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3318
3319
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3319
|
-
const logicalName =
|
|
3320
|
+
const logicalName = ts6.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3320
3321
|
const docResult = extractJSDocParseResult(
|
|
3321
3322
|
declaration,
|
|
3322
3323
|
file,
|
|
@@ -3364,7 +3365,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3364
3365
|
const instanceMethods = [];
|
|
3365
3366
|
const staticMethods = [];
|
|
3366
3367
|
for (const member of classDecl.members) {
|
|
3367
|
-
if (
|
|
3368
|
+
if (ts6.isPropertyDeclaration(member)) {
|
|
3368
3369
|
const fieldNode = analyzeFieldToIR(
|
|
3369
3370
|
member,
|
|
3370
3371
|
checker,
|
|
@@ -3380,10 +3381,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3380
3381
|
fields.push(fieldNode);
|
|
3381
3382
|
fieldLayouts.push({});
|
|
3382
3383
|
}
|
|
3383
|
-
} else if (
|
|
3384
|
+
} else if (ts6.isMethodDeclaration(member)) {
|
|
3384
3385
|
const methodInfo = analyzeMethod(member, checker);
|
|
3385
3386
|
if (methodInfo) {
|
|
3386
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3387
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts6.SyntaxKind.StaticKeyword);
|
|
3387
3388
|
if (isStatic) {
|
|
3388
3389
|
staticMethods.push(methodInfo);
|
|
3389
3390
|
} else {
|
|
@@ -3446,7 +3447,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3446
3447
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3447
3448
|
const visiting = /* @__PURE__ */ new Set();
|
|
3448
3449
|
for (const member of interfaceDecl.members) {
|
|
3449
|
-
if (
|
|
3450
|
+
if (ts6.isPropertySignature(member)) {
|
|
3450
3451
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3451
3452
|
member,
|
|
3452
3453
|
checker,
|
|
@@ -3504,7 +3505,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3504
3505
|
if (members === null) {
|
|
3505
3506
|
const sourceFile = typeAlias.getSourceFile();
|
|
3506
3507
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3507
|
-
const kindDesc =
|
|
3508
|
+
const kindDesc = ts6.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3508
3509
|
return {
|
|
3509
3510
|
ok: false,
|
|
3510
3511
|
kind: "not-object-like",
|
|
@@ -3539,7 +3540,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3539
3540
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3540
3541
|
const visiting = /* @__PURE__ */ new Set();
|
|
3541
3542
|
for (const member of members) {
|
|
3542
|
-
if (
|
|
3543
|
+
if (ts6.isPropertySignature(member)) {
|
|
3543
3544
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3544
3545
|
member,
|
|
3545
3546
|
checker,
|
|
@@ -3606,13 +3607,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3606
3607
|
function getLeadingParsedTags(node) {
|
|
3607
3608
|
const sourceFile = node.getSourceFile();
|
|
3608
3609
|
const sourceText = sourceFile.getFullText();
|
|
3609
|
-
const commentRanges =
|
|
3610
|
+
const commentRanges = ts6.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3610
3611
|
if (commentRanges === void 0) {
|
|
3611
3612
|
return [];
|
|
3612
3613
|
}
|
|
3613
3614
|
const parsedTags = [];
|
|
3614
3615
|
for (const range of commentRanges) {
|
|
3615
|
-
if (range.kind !==
|
|
3616
|
+
if (range.kind !== ts6.SyntaxKind.MultiLineCommentTrivia) {
|
|
3616
3617
|
continue;
|
|
3617
3618
|
}
|
|
3618
3619
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3630,19 +3631,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3630
3631
|
return null;
|
|
3631
3632
|
}
|
|
3632
3633
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3633
|
-
(candidate) =>
|
|
3634
|
+
(candidate) => ts6.isPropertyDeclaration(candidate) || ts6.isPropertySignature(candidate)
|
|
3634
3635
|
) ?? propertySymbol.declarations?.[0];
|
|
3635
3636
|
return {
|
|
3636
3637
|
declaration,
|
|
3637
3638
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3638
|
-
optional: !!(propertySymbol.flags &
|
|
3639
|
+
optional: !!(propertySymbol.flags & ts6.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3639
3640
|
};
|
|
3640
3641
|
}
|
|
3641
3642
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3642
3643
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3643
3644
|
}
|
|
3644
3645
|
function isNullishSemanticType(type) {
|
|
3645
|
-
if (type.flags & (
|
|
3646
|
+
if (type.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined | ts6.TypeFlags.Void | ts6.TypeFlags.Unknown | ts6.TypeFlags.Any)) {
|
|
3646
3647
|
return true;
|
|
3647
3648
|
}
|
|
3648
3649
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3652,7 +3653,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3652
3653
|
return false;
|
|
3653
3654
|
}
|
|
3654
3655
|
seen.add(type);
|
|
3655
|
-
if (type.flags &
|
|
3656
|
+
if (type.flags & ts6.TypeFlags.StringLike) {
|
|
3656
3657
|
return true;
|
|
3657
3658
|
}
|
|
3658
3659
|
if (type.isUnion()) {
|
|
@@ -3665,13 +3666,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3665
3666
|
return false;
|
|
3666
3667
|
}
|
|
3667
3668
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3668
|
-
if (
|
|
3669
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3669
3670
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3670
3671
|
}
|
|
3671
|
-
if (
|
|
3672
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
3672
3673
|
return [...typeNode.members];
|
|
3673
3674
|
}
|
|
3674
|
-
if (
|
|
3675
|
+
if (ts6.isIntersectionTypeNode(typeNode)) {
|
|
3675
3676
|
const members = [];
|
|
3676
3677
|
for (const intersectionMember of typeNode.types) {
|
|
3677
3678
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3834,7 +3835,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3834
3835
|
}
|
|
3835
3836
|
if (propertyType.isUnion()) {
|
|
3836
3837
|
const nonNullMembers = propertyType.types.filter(
|
|
3837
|
-
(member) => !(member.flags & (
|
|
3838
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3838
3839
|
);
|
|
3839
3840
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3840
3841
|
diagnostics.push(
|
|
@@ -3883,13 +3884,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3883
3884
|
seen.add(type);
|
|
3884
3885
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3885
3886
|
if (symbol !== void 0) {
|
|
3886
|
-
const aliased = symbol.flags &
|
|
3887
|
+
const aliased = symbol.flags & ts6.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3887
3888
|
const targetSymbol = aliased ?? symbol;
|
|
3888
3889
|
const declaration = targetSymbol.declarations?.find(
|
|
3889
|
-
(candidate) =>
|
|
3890
|
+
(candidate) => ts6.isClassDeclaration(candidate) || ts6.isInterfaceDeclaration(candidate) || ts6.isTypeAliasDeclaration(candidate) || ts6.isEnumDeclaration(candidate)
|
|
3890
3891
|
);
|
|
3891
3892
|
if (declaration !== void 0) {
|
|
3892
|
-
if (
|
|
3893
|
+
if (ts6.isTypeAliasDeclaration(declaration) && ts6.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3893
3894
|
return resolveNamedDiscriminatorDeclaration(
|
|
3894
3895
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3895
3896
|
checker,
|
|
@@ -3917,7 +3918,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3917
3918
|
}
|
|
3918
3919
|
if (boundType.isUnion()) {
|
|
3919
3920
|
const nonNullMembers = boundType.types.filter(
|
|
3920
|
-
(member) => !(member.flags & (
|
|
3921
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3921
3922
|
);
|
|
3922
3923
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3923
3924
|
diagnostics.push(
|
|
@@ -3962,7 +3963,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3962
3963
|
return null;
|
|
3963
3964
|
}
|
|
3964
3965
|
function getDeclarationName(node) {
|
|
3965
|
-
if (
|
|
3966
|
+
if (ts6.isClassDeclaration(node) || ts6.isInterfaceDeclaration(node) || ts6.isTypeAliasDeclaration(node) || ts6.isEnumDeclaration(node)) {
|
|
3966
3967
|
return node.name?.text ?? "anonymous";
|
|
3967
3968
|
}
|
|
3968
3969
|
return "anonymous";
|
|
@@ -4017,11 +4018,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4017
4018
|
if (sourceTypeNode === void 0) {
|
|
4018
4019
|
return [];
|
|
4019
4020
|
}
|
|
4020
|
-
const unwrapParentheses = (typeNode) =>
|
|
4021
|
+
const unwrapParentheses = (typeNode) => ts6.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4021
4022
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4022
|
-
const referenceTypeNode =
|
|
4023
|
+
const referenceTypeNode = ts6.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4023
4024
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4024
|
-
return
|
|
4025
|
+
return ts6.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4025
4026
|
})();
|
|
4026
4027
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4027
4028
|
return [];
|
|
@@ -4076,7 +4077,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4076
4077
|
);
|
|
4077
4078
|
}
|
|
4078
4079
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4079
|
-
if (!
|
|
4080
|
+
if (!ts6.isIdentifier(prop.name)) {
|
|
4080
4081
|
return null;
|
|
4081
4082
|
}
|
|
4082
4083
|
const name = prop.name.text;
|
|
@@ -4203,7 +4204,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4203
4204
|
const seen = /* @__PURE__ */ new Set();
|
|
4204
4205
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4205
4206
|
for (const member of members) {
|
|
4206
|
-
if (!
|
|
4207
|
+
if (!ts6.isPropertySignature(member)) {
|
|
4207
4208
|
continue;
|
|
4208
4209
|
}
|
|
4209
4210
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4219,7 +4220,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4219
4220
|
return [...duplicates].sort();
|
|
4220
4221
|
}
|
|
4221
4222
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4222
|
-
if (
|
|
4223
|
+
if (ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNumericLiteral(name)) {
|
|
4223
4224
|
return name.text;
|
|
4224
4225
|
}
|
|
4225
4226
|
return null;
|
|
@@ -4317,25 +4318,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4317
4318
|
if (isIntegerBrandedType(type)) {
|
|
4318
4319
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4319
4320
|
}
|
|
4320
|
-
if (type.flags &
|
|
4321
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4321
4322
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4322
4323
|
}
|
|
4323
|
-
if (type.flags &
|
|
4324
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4324
4325
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4325
4326
|
}
|
|
4326
|
-
if (type.flags & (
|
|
4327
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4327
4328
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4328
4329
|
}
|
|
4329
|
-
if (type.flags &
|
|
4330
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4330
4331
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4331
4332
|
}
|
|
4332
|
-
if (type.flags &
|
|
4333
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4333
4334
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4334
4335
|
}
|
|
4335
|
-
if (type.flags &
|
|
4336
|
+
if (type.flags & ts6.TypeFlags.Undefined) {
|
|
4336
4337
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4337
4338
|
}
|
|
4338
|
-
if (type.flags &
|
|
4339
|
+
if (type.flags & ts6.TypeFlags.Void) {
|
|
4339
4340
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4340
4341
|
}
|
|
4341
4342
|
if (type.isStringLiteral()) {
|
|
@@ -4422,10 +4423,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4422
4423
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4423
4424
|
}
|
|
4424
4425
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4425
|
-
if (!(type.flags & (
|
|
4426
|
+
if (!(type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4426
4427
|
return null;
|
|
4427
4428
|
}
|
|
4428
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4429
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4429
4430
|
if (!aliasDecl) {
|
|
4430
4431
|
return null;
|
|
4431
4432
|
}
|
|
@@ -4475,14 +4476,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4475
4476
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4476
4477
|
}
|
|
4477
4478
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4478
|
-
const typeNode = sourceNode && (
|
|
4479
|
-
if (!typeNode || !
|
|
4479
|
+
const typeNode = sourceNode && (ts6.isPropertyDeclaration(sourceNode) || ts6.isPropertySignature(sourceNode) || ts6.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4480
|
+
if (!typeNode || !ts6.isTypeReferenceNode(typeNode)) {
|
|
4480
4481
|
return void 0;
|
|
4481
4482
|
}
|
|
4482
4483
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4483
4484
|
}
|
|
4484
4485
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4485
|
-
if (!
|
|
4486
|
+
if (!ts6.isTypeReferenceNode(typeNode)) {
|
|
4486
4487
|
return false;
|
|
4487
4488
|
}
|
|
4488
4489
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4490,10 +4491,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4490
4491
|
return false;
|
|
4491
4492
|
}
|
|
4492
4493
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4493
|
-
return !!(resolved.flags & (
|
|
4494
|
+
return !!(resolved.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null));
|
|
4494
4495
|
}
|
|
4495
4496
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4496
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4497
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration);
|
|
4497
4498
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4498
4499
|
visitedAliases.add(nestedAliasDecl);
|
|
4499
4500
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4511,19 +4512,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4511
4512
|
if (isIntegerBrandedType(type)) {
|
|
4512
4513
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4513
4514
|
}
|
|
4514
|
-
if (type.flags &
|
|
4515
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4515
4516
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4516
4517
|
}
|
|
4517
|
-
if (type.flags &
|
|
4518
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4518
4519
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4519
4520
|
}
|
|
4520
|
-
if (type.flags & (
|
|
4521
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4521
4522
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4522
4523
|
}
|
|
4523
|
-
if (type.flags &
|
|
4524
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4524
4525
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4525
4526
|
}
|
|
4526
|
-
if (type.flags &
|
|
4527
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4527
4528
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4528
4529
|
}
|
|
4529
4530
|
return resolveTypeNode(
|
|
@@ -4550,13 +4551,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4550
4551
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4551
4552
|
);
|
|
4552
4553
|
const nonNullTypes = allTypes.filter(
|
|
4553
|
-
(memberType) => !(memberType.flags & (
|
|
4554
|
+
(memberType) => !(memberType.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4554
4555
|
);
|
|
4555
4556
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4556
4557
|
memberType,
|
|
4557
4558
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4558
4559
|
}));
|
|
4559
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4560
|
+
const hasNull = allTypes.some((t) => t.flags & ts6.TypeFlags.Null);
|
|
4560
4561
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4561
4562
|
if (namedDecl) {
|
|
4562
4563
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4599,7 +4600,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4599
4600
|
const displayName = memberDisplayNames.get(String(value));
|
|
4600
4601
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4601
4602
|
});
|
|
4602
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4603
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts6.TypeFlags.BooleanLiteral);
|
|
4603
4604
|
if (isBooleanUnion2) {
|
|
4604
4605
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4605
4606
|
const result = hasNull ? {
|
|
@@ -4691,7 +4692,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4691
4692
|
if (type.getProperties().length > 0) {
|
|
4692
4693
|
return null;
|
|
4693
4694
|
}
|
|
4694
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4695
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts6.IndexKind.String);
|
|
4695
4696
|
if (!indexInfo) {
|
|
4696
4697
|
return null;
|
|
4697
4698
|
}
|
|
@@ -4739,10 +4740,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4739
4740
|
}
|
|
4740
4741
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4741
4742
|
const name = declaration.name;
|
|
4742
|
-
if (
|
|
4743
|
+
if (ts6.isComputedPropertyName(name) || ts6.isPrivateIdentifier(name)) {
|
|
4743
4744
|
return false;
|
|
4744
4745
|
}
|
|
4745
|
-
if (!
|
|
4746
|
+
if (!ts6.isIdentifier(name) && !ts6.isStringLiteral(name) && !ts6.isNumericLiteral(name)) {
|
|
4746
4747
|
return false;
|
|
4747
4748
|
}
|
|
4748
4749
|
}
|
|
@@ -4868,7 +4869,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4868
4869
|
if (!declaration) continue;
|
|
4869
4870
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4870
4871
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4871
|
-
const optional = !!(prop.flags &
|
|
4872
|
+
const optional = !!(prop.flags & ts6.SymbolFlags.Optional);
|
|
4872
4873
|
const propTypeNode = resolveTypeNode(
|
|
4873
4874
|
propType,
|
|
4874
4875
|
checker,
|
|
@@ -4881,7 +4882,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4881
4882
|
collectedDiagnostics
|
|
4882
4883
|
);
|
|
4883
4884
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4884
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
4885
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts6.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4885
4886
|
declaration,
|
|
4886
4887
|
checker,
|
|
4887
4888
|
file,
|
|
@@ -4891,7 +4892,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4891
4892
|
type,
|
|
4892
4893
|
metadataPolicy,
|
|
4893
4894
|
extensionRegistry
|
|
4894
|
-
) :
|
|
4895
|
+
) : ts6.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4895
4896
|
declaration,
|
|
4896
4897
|
checker,
|
|
4897
4898
|
file,
|
|
@@ -4919,7 +4920,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4919
4920
|
visiting.delete(type);
|
|
4920
4921
|
const objectNode = {
|
|
4921
4922
|
kind: "object",
|
|
4922
|
-
properties: namedDecl !== void 0 && (
|
|
4923
|
+
properties: namedDecl !== void 0 && (ts6.isClassDeclaration(namedDecl) || ts6.isInterfaceDeclaration(namedDecl) || ts6.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
4923
4924
|
properties,
|
|
4924
4925
|
namedDecl,
|
|
4925
4926
|
type,
|
|
@@ -4967,12 +4968,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4967
4968
|
for (const symbol of symbols) {
|
|
4968
4969
|
const declarations = symbol.declarations;
|
|
4969
4970
|
if (!declarations) continue;
|
|
4970
|
-
const classDecl = declarations.find(
|
|
4971
|
+
const classDecl = declarations.find(ts6.isClassDeclaration);
|
|
4971
4972
|
if (classDecl) {
|
|
4972
4973
|
const map = /* @__PURE__ */ new Map();
|
|
4973
4974
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
4974
4975
|
for (const member of classDecl.members) {
|
|
4975
|
-
if (
|
|
4976
|
+
if (ts6.isPropertyDeclaration(member) && ts6.isIdentifier(member.name)) {
|
|
4976
4977
|
const fieldNode = analyzeFieldToIR(
|
|
4977
4978
|
member,
|
|
4978
4979
|
checker,
|
|
@@ -4996,7 +4997,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4996
4997
|
}
|
|
4997
4998
|
return map;
|
|
4998
4999
|
}
|
|
4999
|
-
const interfaceDecl = declarations.find(
|
|
5000
|
+
const interfaceDecl = declarations.find(ts6.isInterfaceDeclaration);
|
|
5000
5001
|
if (interfaceDecl) {
|
|
5001
5002
|
return buildFieldNodeInfoMap(
|
|
5002
5003
|
interfaceDecl.members,
|
|
@@ -5010,7 +5011,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5010
5011
|
extensionRegistry
|
|
5011
5012
|
);
|
|
5012
5013
|
}
|
|
5013
|
-
const typeAliasDecl = declarations.find(
|
|
5014
|
+
const typeAliasDecl = declarations.find(ts6.isTypeAliasDeclaration);
|
|
5014
5015
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5015
5016
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5016
5017
|
return buildFieldNodeInfoMap(
|
|
@@ -5034,10 +5035,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5034
5035
|
return void 0;
|
|
5035
5036
|
}
|
|
5036
5037
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5037
|
-
if (
|
|
5038
|
+
if (ts6.isArrayTypeNode(resolvedTypeNode)) {
|
|
5038
5039
|
return resolvedTypeNode.elementType;
|
|
5039
5040
|
}
|
|
5040
|
-
if (
|
|
5041
|
+
if (ts6.isTypeReferenceNode(resolvedTypeNode) && ts6.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5041
5042
|
return resolvedTypeNode.typeArguments[0];
|
|
5042
5043
|
}
|
|
5043
5044
|
return void 0;
|
|
@@ -5048,13 +5049,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5048
5049
|
return [];
|
|
5049
5050
|
}
|
|
5050
5051
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5051
|
-
return
|
|
5052
|
+
return ts6.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5052
5053
|
}
|
|
5053
5054
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5054
|
-
if (
|
|
5055
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5055
5056
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5056
5057
|
}
|
|
5057
|
-
if (!
|
|
5058
|
+
if (!ts6.isTypeReferenceNode(typeNode) || !ts6.isIdentifier(typeNode.typeName)) {
|
|
5058
5059
|
return typeNode;
|
|
5059
5060
|
}
|
|
5060
5061
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5065,15 +5066,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5065
5066
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5066
5067
|
}
|
|
5067
5068
|
function isNullishTypeNode(typeNode) {
|
|
5068
|
-
if (typeNode.kind ===
|
|
5069
|
+
if (typeNode.kind === ts6.SyntaxKind.NullKeyword || typeNode.kind === ts6.SyntaxKind.UndefinedKeyword) {
|
|
5069
5070
|
return true;
|
|
5070
5071
|
}
|
|
5071
|
-
return
|
|
5072
|
+
return ts6.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts6.SyntaxKind.NullKeyword || typeNode.literal.kind === ts6.SyntaxKind.UndefinedKeyword);
|
|
5072
5073
|
}
|
|
5073
5074
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5074
5075
|
const map = /* @__PURE__ */ new Map();
|
|
5075
5076
|
for (const member of members) {
|
|
5076
|
-
if (
|
|
5077
|
+
if (ts6.isPropertySignature(member)) {
|
|
5077
5078
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5078
5079
|
member,
|
|
5079
5080
|
checker,
|
|
@@ -5099,7 +5100,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5099
5100
|
}
|
|
5100
5101
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5101
5102
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5102
|
-
if (!
|
|
5103
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return [];
|
|
5103
5104
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5104
5105
|
const aliasName = typeNode.typeName.getText();
|
|
5105
5106
|
throw new Error(
|
|
@@ -5108,7 +5109,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5108
5109
|
}
|
|
5109
5110
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5110
5111
|
if (!aliasDecl) return [];
|
|
5111
|
-
if (
|
|
5112
|
+
if (ts6.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5112
5113
|
const aliasFieldType = resolveTypeNode(
|
|
5113
5114
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5114
5115
|
checker,
|
|
@@ -5152,14 +5153,14 @@ function getNamedTypeName(type) {
|
|
|
5152
5153
|
const symbol = type.getSymbol();
|
|
5153
5154
|
if (symbol?.declarations) {
|
|
5154
5155
|
const decl = symbol.declarations[0];
|
|
5155
|
-
if (decl && (
|
|
5156
|
-
const name =
|
|
5156
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5157
|
+
const name = ts6.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5157
5158
|
if (name) return name;
|
|
5158
5159
|
}
|
|
5159
5160
|
}
|
|
5160
5161
|
const aliasSymbol = type.aliasSymbol;
|
|
5161
5162
|
if (aliasSymbol?.declarations) {
|
|
5162
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5163
|
+
const aliasDecl = aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5163
5164
|
if (aliasDecl) {
|
|
5164
5165
|
return aliasDecl.name.text;
|
|
5165
5166
|
}
|
|
@@ -5170,24 +5171,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5170
5171
|
const symbol = type.getSymbol();
|
|
5171
5172
|
if (symbol?.declarations) {
|
|
5172
5173
|
const decl = symbol.declarations[0];
|
|
5173
|
-
if (decl && (
|
|
5174
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5174
5175
|
return decl;
|
|
5175
5176
|
}
|
|
5176
5177
|
}
|
|
5177
5178
|
const aliasSymbol = type.aliasSymbol;
|
|
5178
5179
|
if (aliasSymbol?.declarations) {
|
|
5179
|
-
return aliasSymbol.declarations.find(
|
|
5180
|
+
return aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5180
5181
|
}
|
|
5181
5182
|
return void 0;
|
|
5182
5183
|
}
|
|
5183
5184
|
function analyzeMethod(method, checker) {
|
|
5184
|
-
if (!
|
|
5185
|
+
if (!ts6.isIdentifier(method.name)) {
|
|
5185
5186
|
return null;
|
|
5186
5187
|
}
|
|
5187
5188
|
const name = method.name.text;
|
|
5188
5189
|
const parameters = [];
|
|
5189
5190
|
for (const param of method.parameters) {
|
|
5190
|
-
if (
|
|
5191
|
+
if (ts6.isIdentifier(param.name)) {
|
|
5191
5192
|
const paramInfo = analyzeParameter(param, checker);
|
|
5192
5193
|
parameters.push(paramInfo);
|
|
5193
5194
|
}
|
|
@@ -5198,7 +5199,7 @@ function analyzeMethod(method, checker) {
|
|
|
5198
5199
|
return { name, parameters, returnTypeNode, returnType };
|
|
5199
5200
|
}
|
|
5200
5201
|
function analyzeParameter(param, checker) {
|
|
5201
|
-
const name =
|
|
5202
|
+
const name = ts6.isIdentifier(param.name) ? param.name.text : "param";
|
|
5202
5203
|
const typeNode = param.type;
|
|
5203
5204
|
const type = checker.getTypeAtLocation(param);
|
|
5204
5205
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5207,15 +5208,15 @@ function analyzeParameter(param, checker) {
|
|
|
5207
5208
|
}
|
|
5208
5209
|
function detectFormSpecReference(typeNode) {
|
|
5209
5210
|
if (!typeNode) return null;
|
|
5210
|
-
if (!
|
|
5211
|
-
const typeName =
|
|
5211
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return null;
|
|
5212
|
+
const typeName = ts6.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts6.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5212
5213
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5213
5214
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5214
|
-
if (!typeArg || !
|
|
5215
|
-
if (
|
|
5215
|
+
if (!typeArg || !ts6.isTypeQueryNode(typeArg)) return null;
|
|
5216
|
+
if (ts6.isIdentifier(typeArg.exprName)) {
|
|
5216
5217
|
return typeArg.exprName.text;
|
|
5217
5218
|
}
|
|
5218
|
-
if (
|
|
5219
|
+
if (ts6.isQualifiedName(typeArg.exprName)) {
|
|
5219
5220
|
return typeArg.exprName.right.text;
|
|
5220
5221
|
}
|
|
5221
5222
|
return null;
|
|
@@ -5237,23 +5238,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5237
5238
|
function createProgramContext(filePath, additionalFiles) {
|
|
5238
5239
|
const absolutePath = path.resolve(filePath);
|
|
5239
5240
|
const fileDir = path.dirname(absolutePath);
|
|
5240
|
-
const configPath =
|
|
5241
|
+
const configPath = ts7.findConfigFile(fileDir, ts7.sys.fileExists.bind(ts7.sys), "tsconfig.json");
|
|
5241
5242
|
let compilerOptions;
|
|
5242
5243
|
let fileNames;
|
|
5243
5244
|
if (configPath) {
|
|
5244
|
-
const configFile =
|
|
5245
|
+
const configFile = ts7.readConfigFile(configPath, ts7.sys.readFile.bind(ts7.sys));
|
|
5245
5246
|
if (configFile.error) {
|
|
5246
5247
|
throw new Error(
|
|
5247
|
-
`Error reading tsconfig.json: ${
|
|
5248
|
+
`Error reading tsconfig.json: ${ts7.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5248
5249
|
);
|
|
5249
5250
|
}
|
|
5250
|
-
const parsed =
|
|
5251
|
+
const parsed = ts7.parseJsonConfigFileContent(
|
|
5251
5252
|
configFile.config,
|
|
5252
|
-
|
|
5253
|
+
ts7.sys,
|
|
5253
5254
|
path.dirname(configPath)
|
|
5254
5255
|
);
|
|
5255
5256
|
if (parsed.errors.length > 0) {
|
|
5256
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5257
|
+
const errorMessages = parsed.errors.map((e) => ts7.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5257
5258
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5258
5259
|
}
|
|
5259
5260
|
compilerOptions = parsed.options;
|
|
@@ -5261,9 +5262,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5261
5262
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5262
5263
|
} else {
|
|
5263
5264
|
compilerOptions = {
|
|
5264
|
-
target:
|
|
5265
|
-
module:
|
|
5266
|
-
moduleResolution:
|
|
5265
|
+
target: ts7.ScriptTarget.ES2022,
|
|
5266
|
+
module: ts7.ModuleKind.NodeNext,
|
|
5267
|
+
moduleResolution: ts7.ModuleResolutionKind.NodeNext,
|
|
5267
5268
|
strict: true,
|
|
5268
5269
|
skipLibCheck: true,
|
|
5269
5270
|
declaration: true
|
|
@@ -5271,7 +5272,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5271
5272
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5272
5273
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5273
5274
|
}
|
|
5274
|
-
const program =
|
|
5275
|
+
const program = ts7.createProgram(fileNames, compilerOptions);
|
|
5275
5276
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5276
5277
|
if (!sourceFile) {
|
|
5277
5278
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5290,19 +5291,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5290
5291
|
result = node;
|
|
5291
5292
|
return;
|
|
5292
5293
|
}
|
|
5293
|
-
|
|
5294
|
+
ts7.forEachChild(node, visit);
|
|
5294
5295
|
}
|
|
5295
5296
|
visit(sourceFile);
|
|
5296
5297
|
return result;
|
|
5297
5298
|
}
|
|
5298
5299
|
function findClassByName(sourceFile, className) {
|
|
5299
|
-
return findNodeByName(sourceFile, className,
|
|
5300
|
+
return findNodeByName(sourceFile, className, ts7.isClassDeclaration, (n) => n.name?.text);
|
|
5300
5301
|
}
|
|
5301
5302
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5302
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5303
|
+
return findNodeByName(sourceFile, interfaceName, ts7.isInterfaceDeclaration, (n) => n.name.text);
|
|
5303
5304
|
}
|
|
5304
5305
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5305
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5306
|
+
return findNodeByName(sourceFile, aliasName, ts7.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5306
5307
|
}
|
|
5307
5308
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5308
5309
|
if (rootType.kind === "object") {
|
|
@@ -5342,22 +5343,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5342
5343
|
};
|
|
5343
5344
|
}
|
|
5344
5345
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5345
|
-
if (
|
|
5346
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5346
5347
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5347
5348
|
}
|
|
5348
|
-
if (
|
|
5349
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5349
5350
|
return true;
|
|
5350
5351
|
}
|
|
5351
|
-
return
|
|
5352
|
+
return ts7.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5352
5353
|
}
|
|
5353
5354
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5354
|
-
if (
|
|
5355
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5355
5356
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5356
5357
|
}
|
|
5357
|
-
if (
|
|
5358
|
+
if (ts7.isTypeLiteralNode(typeNode)) {
|
|
5358
5359
|
const propertyNames = [];
|
|
5359
5360
|
for (const member of typeNode.members) {
|
|
5360
|
-
if (!
|
|
5361
|
+
if (!ts7.isPropertySignature(member)) {
|
|
5361
5362
|
continue;
|
|
5362
5363
|
}
|
|
5363
5364
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5367,13 +5368,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5367
5368
|
}
|
|
5368
5369
|
return propertyNames;
|
|
5369
5370
|
}
|
|
5370
|
-
if (
|
|
5371
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5371
5372
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5372
5373
|
}
|
|
5373
5374
|
return null;
|
|
5374
5375
|
}
|
|
5375
5376
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5376
|
-
if (!
|
|
5377
|
+
if (!ts7.isIntersectionTypeNode(typeNode)) {
|
|
5377
5378
|
return [];
|
|
5378
5379
|
}
|
|
5379
5380
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5574,7 +5575,7 @@ function makeFileProvenance(filePath) {
|
|
|
5574
5575
|
}
|
|
5575
5576
|
|
|
5576
5577
|
// src/extensions/symbol-registry.ts
|
|
5577
|
-
var
|
|
5578
|
+
var ts8 = __toESM(require("typescript"), 1);
|
|
5578
5579
|
var path2 = __toESM(require("path"), 1);
|
|
5579
5580
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5580
5581
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5584,10 +5585,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5584
5585
|
return symbolMap;
|
|
5585
5586
|
}
|
|
5586
5587
|
function visit(node) {
|
|
5587
|
-
if (
|
|
5588
|
+
if (ts8.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5588
5589
|
processDefineCustomTypeCall(node);
|
|
5589
5590
|
}
|
|
5590
|
-
|
|
5591
|
+
ts8.forEachChild(node, visit);
|
|
5591
5592
|
}
|
|
5592
5593
|
function processDefineCustomTypeCall(call) {
|
|
5593
5594
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5624,7 +5625,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5624
5625
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5625
5626
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5626
5627
|
if (callSymbol !== void 0) {
|
|
5627
|
-
const resolved = callSymbol.flags &
|
|
5628
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5628
5629
|
const decl = resolved.declarations?.[0];
|
|
5629
5630
|
if (decl !== void 0) {
|
|
5630
5631
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5632,24 +5633,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5632
5633
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5633
5634
|
}
|
|
5634
5635
|
}
|
|
5635
|
-
return
|
|
5636
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5636
5637
|
}
|
|
5637
5638
|
function extractTypeNameFromCallArg(call) {
|
|
5638
5639
|
const arg = call.arguments[0];
|
|
5639
|
-
if (arg === void 0 || !
|
|
5640
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5640
5641
|
return null;
|
|
5641
5642
|
}
|
|
5642
5643
|
const typeNameProp = arg.properties.find(
|
|
5643
|
-
(p) =>
|
|
5644
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5644
5645
|
);
|
|
5645
|
-
if (typeNameProp === void 0 || !
|
|
5646
|
+
if (typeNameProp === void 0 || !ts8.isStringLiteral(typeNameProp.initializer)) {
|
|
5646
5647
|
return null;
|
|
5647
5648
|
}
|
|
5648
5649
|
return typeNameProp.initializer.text;
|
|
5649
5650
|
}
|
|
5650
5651
|
function extractEnclosingExtensionId(call, checker) {
|
|
5651
|
-
for (let node = call.parent; !
|
|
5652
|
-
if (
|
|
5652
|
+
for (let node = call.parent; !ts8.isSourceFile(node); node = node.parent) {
|
|
5653
|
+
if (ts8.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5653
5654
|
return extractExtensionIdFromCallArg(node);
|
|
5654
5655
|
}
|
|
5655
5656
|
}
|
|
@@ -5658,24 +5659,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5658
5659
|
function isDefineExtensionCall(node, checker) {
|
|
5659
5660
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5660
5661
|
if (callSymbol !== void 0) {
|
|
5661
|
-
const resolved = callSymbol.flags &
|
|
5662
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5662
5663
|
const decl = resolved.declarations?.[0];
|
|
5663
5664
|
if (decl !== void 0) {
|
|
5664
5665
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5665
5666
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5666
5667
|
}
|
|
5667
5668
|
}
|
|
5668
|
-
return
|
|
5669
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5669
5670
|
}
|
|
5670
5671
|
function extractExtensionIdFromCallArg(call) {
|
|
5671
5672
|
const arg = call.arguments[0];
|
|
5672
|
-
if (arg === void 0 || !
|
|
5673
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5673
5674
|
return null;
|
|
5674
5675
|
}
|
|
5675
5676
|
const prop = arg.properties.find(
|
|
5676
|
-
(p) =>
|
|
5677
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5677
5678
|
);
|
|
5678
|
-
if (prop === void 0 || !
|
|
5679
|
+
if (prop === void 0 || !ts8.isStringLiteral(prop.initializer)) {
|
|
5679
5680
|
return null;
|
|
5680
5681
|
}
|
|
5681
5682
|
return prop.initializer.text;
|
|
@@ -5937,7 +5938,7 @@ function generateSchemasBatch(options) {
|
|
|
5937
5938
|
return options.targets.map((target) => {
|
|
5938
5939
|
let ctx;
|
|
5939
5940
|
try {
|
|
5940
|
-
const cacheKey =
|
|
5941
|
+
const cacheKey = ts9.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
5941
5942
|
const cachedContext = contextCache.get(cacheKey);
|
|
5942
5943
|
if (cachedContext === void 0) {
|
|
5943
5944
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6093,7 +6094,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6093
6094
|
}
|
|
6094
6095
|
|
|
6095
6096
|
// src/static-build.ts
|
|
6096
|
-
var
|
|
6097
|
+
var ts10 = __toESM(require("typescript"), 1);
|
|
6097
6098
|
function toStaticBuildContext(context) {
|
|
6098
6099
|
return context;
|
|
6099
6100
|
}
|
|
@@ -6108,7 +6109,7 @@ function getModuleSymbol(context) {
|
|
|
6108
6109
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6109
6110
|
}
|
|
6110
6111
|
function isSchemaSourceDeclaration(declaration) {
|
|
6111
|
-
return
|
|
6112
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6112
6113
|
}
|
|
6113
6114
|
function resolveModuleExport(context, exportName = "default") {
|
|
6114
6115
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6119,14 +6120,14 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6119
6120
|
if (exportSymbol === null) {
|
|
6120
6121
|
return null;
|
|
6121
6122
|
}
|
|
6122
|
-
return exportSymbol.flags &
|
|
6123
|
+
return exportSymbol.flags & ts10.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6123
6124
|
}
|
|
6124
6125
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6125
6126
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6126
6127
|
}
|
|
6127
6128
|
|
|
6128
6129
|
// src/generators/discovered-schema.ts
|
|
6129
|
-
var
|
|
6130
|
+
var ts11 = __toESM(require("typescript"), 1);
|
|
6130
6131
|
var import_internal6 = require("@formspec/analysis/internal");
|
|
6131
6132
|
var import_internals6 = require("@formspec/core/internals");
|
|
6132
6133
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
@@ -6136,17 +6137,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6136
6137
|
};
|
|
6137
6138
|
}
|
|
6138
6139
|
function isNamedTypeDeclaration(declaration) {
|
|
6139
|
-
return
|
|
6140
|
+
return ts11.isClassDeclaration(declaration) || ts11.isInterfaceDeclaration(declaration) || ts11.isTypeAliasDeclaration(declaration);
|
|
6140
6141
|
}
|
|
6141
6142
|
function hasConcreteTypeArguments(type, checker) {
|
|
6142
6143
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6143
6144
|
return true;
|
|
6144
6145
|
}
|
|
6145
|
-
if ((type.flags &
|
|
6146
|
+
if ((type.flags & ts11.TypeFlags.Object) === 0) {
|
|
6146
6147
|
return false;
|
|
6147
6148
|
}
|
|
6148
6149
|
const objectType = type;
|
|
6149
|
-
if ((objectType.objectFlags &
|
|
6150
|
+
if ((objectType.objectFlags & ts11.ObjectFlags.Reference) === 0) {
|
|
6150
6151
|
return false;
|
|
6151
6152
|
}
|
|
6152
6153
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6159,13 +6160,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6159
6160
|
return declaration;
|
|
6160
6161
|
}
|
|
6161
6162
|
}
|
|
6162
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6163
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts11.isTypeAliasDeclaration);
|
|
6163
6164
|
return aliasDeclaration;
|
|
6164
6165
|
}
|
|
6165
6166
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6166
6167
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6167
6168
|
const namedNode = sourceNode;
|
|
6168
|
-
if (namedNode.name !== void 0 &&
|
|
6169
|
+
if (namedNode.name !== void 0 && ts11.isIdentifier(namedNode.name)) {
|
|
6169
6170
|
return namedNode.name.text;
|
|
6170
6171
|
}
|
|
6171
6172
|
}
|
|
@@ -6387,7 +6388,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6387
6388
|
function generateSchemasFromDeclaration(options) {
|
|
6388
6389
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6389
6390
|
const resolved = resolveStaticOptions(options);
|
|
6390
|
-
if (
|
|
6391
|
+
if (ts11.isClassDeclaration(options.declaration)) {
|
|
6391
6392
|
return generateSchemasFromAnalysis(
|
|
6392
6393
|
analyzeClassToIR(
|
|
6393
6394
|
options.declaration,
|
|
@@ -6401,7 +6402,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6401
6402
|
resolved
|
|
6402
6403
|
);
|
|
6403
6404
|
}
|
|
6404
|
-
if (
|
|
6405
|
+
if (ts11.isInterfaceDeclaration(options.declaration)) {
|
|
6405
6406
|
return generateSchemasFromAnalysis(
|
|
6406
6407
|
analyzeInterfaceToIR(
|
|
6407
6408
|
options.declaration,
|
|
@@ -6415,7 +6416,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6415
6416
|
resolved
|
|
6416
6417
|
);
|
|
6417
6418
|
}
|
|
6418
|
-
if (
|
|
6419
|
+
if (ts11.isTypeAliasDeclaration(options.declaration)) {
|
|
6419
6420
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6420
6421
|
options.declaration,
|
|
6421
6422
|
options.context.checker,
|
|
@@ -6474,7 +6475,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6474
6475
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6475
6476
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6476
6477
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6477
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6478
|
+
const fallbackName = options.declaration.name !== void 0 && ts11.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6478
6479
|
return generateSchemasFromResolvedType({
|
|
6479
6480
|
...options,
|
|
6480
6481
|
type,
|
|
@@ -6521,14 +6522,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6521
6522
|
if (typeNode === void 0) {
|
|
6522
6523
|
return void 0;
|
|
6523
6524
|
}
|
|
6524
|
-
if (
|
|
6525
|
+
if (ts11.isParenthesizedTypeNode(typeNode)) {
|
|
6525
6526
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6526
6527
|
return unwrapped ?? typeNode;
|
|
6527
6528
|
}
|
|
6528
6529
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6529
6530
|
}
|
|
6530
6531
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6531
|
-
return
|
|
6532
|
+
return ts11.isTypeReferenceNode(typeNode) && ts11.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6532
6533
|
}
|
|
6533
6534
|
|
|
6534
6535
|
// src/generators/mixed-authoring.ts
|