@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.js
CHANGED
|
@@ -2166,24 +2166,24 @@ var jsonSchema7Schema = z3.lazy(
|
|
|
2166
2166
|
);
|
|
2167
2167
|
|
|
2168
2168
|
// src/generators/class-schema.ts
|
|
2169
|
-
import * as
|
|
2169
|
+
import * as ts9 from "typescript";
|
|
2170
2170
|
|
|
2171
2171
|
// src/analyzer/program.ts
|
|
2172
|
-
import * as
|
|
2172
|
+
import * as ts7 from "typescript";
|
|
2173
2173
|
import * as path from "path";
|
|
2174
2174
|
|
|
2175
2175
|
// src/analyzer/class-analyzer.ts
|
|
2176
|
-
import * as
|
|
2176
|
+
import * as ts6 from "typescript";
|
|
2177
2177
|
import {
|
|
2178
2178
|
analyzeMetadataForNodeWithChecker,
|
|
2179
2179
|
parseCommentBlock
|
|
2180
2180
|
} from "@formspec/analysis/internal";
|
|
2181
2181
|
|
|
2182
2182
|
// src/analyzer/jsdoc-constraints.ts
|
|
2183
|
-
import * as
|
|
2183
|
+
import * as ts5 from "typescript";
|
|
2184
2184
|
|
|
2185
2185
|
// src/analyzer/tsdoc-parser.ts
|
|
2186
|
-
import * as
|
|
2186
|
+
import * as ts4 from "typescript";
|
|
2187
2187
|
import {
|
|
2188
2188
|
checkSyntheticTagApplication,
|
|
2189
2189
|
choosePreferredPayloadText,
|
|
@@ -2191,6 +2191,7 @@ import {
|
|
|
2191
2191
|
getTagDefinition as getTagDefinition2,
|
|
2192
2192
|
hasTypeSemanticCapability,
|
|
2193
2193
|
normalizeFormSpecTagName as normalizeFormSpecTagName2,
|
|
2194
|
+
stripNullishUnion as stripNullishUnion2,
|
|
2194
2195
|
parseConstraintTagValue,
|
|
2195
2196
|
parseDefaultValueTagValue,
|
|
2196
2197
|
parseTagSyntax,
|
|
@@ -2323,6 +2324,14 @@ function customTypeIdFromLookup(result) {
|
|
|
2323
2324
|
return `${result.extensionId}/${result.registration.typeName}`;
|
|
2324
2325
|
}
|
|
2325
2326
|
|
|
2327
|
+
// src/analyzer/builtin-brands.ts
|
|
2328
|
+
import * as ts3 from "typescript";
|
|
2329
|
+
function isIntegerBrandedType(type) {
|
|
2330
|
+
if (!type.isIntersection()) return false;
|
|
2331
|
+
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2332
|
+
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2326
2335
|
// src/analyzer/tsdoc-parser.ts
|
|
2327
2336
|
function sharedTagValueOptions(options) {
|
|
2328
2337
|
return {
|
|
@@ -2330,7 +2339,7 @@ function sharedTagValueOptions(options) {
|
|
|
2330
2339
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2331
2340
|
};
|
|
2332
2341
|
}
|
|
2333
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
2342
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts4.TypeFormatFlags.NoTruncation | ts4.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2334
2343
|
function getExtensionTypeNames(registry) {
|
|
2335
2344
|
if (registry === void 0) {
|
|
2336
2345
|
return /* @__PURE__ */ new Set();
|
|
@@ -2344,23 +2353,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2344
2353
|
function collectImportedNames(sourceFile) {
|
|
2345
2354
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2346
2355
|
for (const statement of sourceFile.statements) {
|
|
2347
|
-
if (
|
|
2356
|
+
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2348
2357
|
const clause = statement.importClause;
|
|
2349
2358
|
if (clause.name !== void 0) {
|
|
2350
2359
|
importedNames.add(clause.name.text);
|
|
2351
2360
|
}
|
|
2352
2361
|
if (clause.namedBindings !== void 0) {
|
|
2353
|
-
if (
|
|
2362
|
+
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
2354
2363
|
for (const specifier of clause.namedBindings.elements) {
|
|
2355
2364
|
importedNames.add(specifier.name.text);
|
|
2356
2365
|
}
|
|
2357
|
-
} else if (
|
|
2366
|
+
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
2358
2367
|
importedNames.add(clause.namedBindings.name.text);
|
|
2359
2368
|
}
|
|
2360
2369
|
}
|
|
2361
2370
|
continue;
|
|
2362
2371
|
}
|
|
2363
|
-
if (
|
|
2372
|
+
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
2364
2373
|
importedNames.add(statement.name.text);
|
|
2365
2374
|
}
|
|
2366
2375
|
}
|
|
@@ -2368,13 +2377,13 @@ function collectImportedNames(sourceFile) {
|
|
|
2368
2377
|
}
|
|
2369
2378
|
function isNonReferenceIdentifier(node) {
|
|
2370
2379
|
const parent = node.parent;
|
|
2371
|
-
if ((
|
|
2380
|
+
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) {
|
|
2372
2381
|
return true;
|
|
2373
2382
|
}
|
|
2374
|
-
if ((
|
|
2383
|
+
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2375
2384
|
return true;
|
|
2376
2385
|
}
|
|
2377
|
-
if (
|
|
2386
|
+
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
2378
2387
|
return true;
|
|
2379
2388
|
}
|
|
2380
2389
|
return false;
|
|
@@ -2388,11 +2397,11 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
2388
2397
|
if (referencesImportedName) {
|
|
2389
2398
|
return;
|
|
2390
2399
|
}
|
|
2391
|
-
if (
|
|
2400
|
+
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2392
2401
|
referencesImportedName = true;
|
|
2393
2402
|
return;
|
|
2394
2403
|
}
|
|
2395
|
-
|
|
2404
|
+
ts4.forEachChild(node, visit);
|
|
2396
2405
|
};
|
|
2397
2406
|
visit(statement);
|
|
2398
2407
|
return referencesImportedName;
|
|
@@ -2403,9 +2412,9 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
2403
2412
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2404
2413
|
);
|
|
2405
2414
|
return sourceFile.statements.filter((statement) => {
|
|
2406
|
-
if (
|
|
2407
|
-
if (
|
|
2408
|
-
if (
|
|
2415
|
+
if (ts4.isImportDeclaration(statement)) return false;
|
|
2416
|
+
if (ts4.isImportEqualsDeclaration(statement)) return false;
|
|
2417
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
2409
2418
|
return false;
|
|
2410
2419
|
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2411
2420
|
return false;
|
|
@@ -2503,7 +2512,7 @@ function stripHintNullishUnion(type) {
|
|
|
2503
2512
|
return type;
|
|
2504
2513
|
}
|
|
2505
2514
|
const nonNullish = type.types.filter(
|
|
2506
|
-
(member) => (member.flags & (
|
|
2515
|
+
(member) => (member.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) === 0
|
|
2507
2516
|
);
|
|
2508
2517
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2509
2518
|
return nonNullish[0];
|
|
@@ -2519,10 +2528,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2519
2528
|
}
|
|
2520
2529
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2521
2530
|
const name = declaration.name;
|
|
2522
|
-
if (
|
|
2531
|
+
if (ts4.isComputedPropertyName(name) || ts4.isPrivateIdentifier(name)) {
|
|
2523
2532
|
return false;
|
|
2524
2533
|
}
|
|
2525
|
-
if (!
|
|
2534
|
+
if (!ts4.isIdentifier(name) && !ts4.isStringLiteral(name) && !ts4.isNumericLiteral(name)) {
|
|
2526
2535
|
return false;
|
|
2527
2536
|
}
|
|
2528
2537
|
}
|
|
@@ -2740,6 +2749,9 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2740
2749
|
}
|
|
2741
2750
|
const hasBroadening = (() => {
|
|
2742
2751
|
if (target === null) {
|
|
2752
|
+
if (isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2753
|
+
return true;
|
|
2754
|
+
}
|
|
2743
2755
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2744
2756
|
}
|
|
2745
2757
|
const registry = options?.extensionRegistry;
|
|
@@ -2892,12 +2904,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2892
2904
|
const sourceText = sourceFile.getFullText();
|
|
2893
2905
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2894
2906
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2895
|
-
const commentRanges =
|
|
2907
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2896
2908
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2897
2909
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2898
2910
|
if (commentRanges) {
|
|
2899
2911
|
for (const range of commentRanges) {
|
|
2900
|
-
if (range.kind !==
|
|
2912
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) {
|
|
2901
2913
|
continue;
|
|
2902
2914
|
}
|
|
2903
2915
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3054,10 +3066,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3054
3066
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3055
3067
|
const sourceFile = node.getSourceFile();
|
|
3056
3068
|
const sourceText = sourceFile.getFullText();
|
|
3057
|
-
const commentRanges =
|
|
3069
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3058
3070
|
if (commentRanges) {
|
|
3059
3071
|
for (const range of commentRanges) {
|
|
3060
|
-
if (range.kind !==
|
|
3072
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3061
3073
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3062
3074
|
if (!commentText.startsWith("/**")) continue;
|
|
3063
3075
|
const unified = parseUnifiedComment(commentText);
|
|
@@ -3082,7 +3094,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3082
3094
|
}
|
|
3083
3095
|
function collectRawTextFallbacks(node, file) {
|
|
3084
3096
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3085
|
-
for (const tag of
|
|
3097
|
+
for (const tag of ts4.getJSDocTags(node)) {
|
|
3086
3098
|
const tagName = normalizeConstraintTagName2(tag.tagName.text);
|
|
3087
3099
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3088
3100
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3137,7 +3149,7 @@ function getTagCommentText(tag) {
|
|
|
3137
3149
|
if (typeof tag.comment === "string") {
|
|
3138
3150
|
return tag.comment;
|
|
3139
3151
|
}
|
|
3140
|
-
return
|
|
3152
|
+
return ts4.getTextOfJSDocComment(tag.comment);
|
|
3141
3153
|
}
|
|
3142
3154
|
|
|
3143
3155
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3155,18 +3167,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3155
3167
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3156
3168
|
if (!initializer) return null;
|
|
3157
3169
|
let value;
|
|
3158
|
-
if (
|
|
3170
|
+
if (ts5.isStringLiteral(initializer)) {
|
|
3159
3171
|
value = initializer.text;
|
|
3160
|
-
} else if (
|
|
3172
|
+
} else if (ts5.isNumericLiteral(initializer)) {
|
|
3161
3173
|
value = Number(initializer.text);
|
|
3162
|
-
} else if (initializer.kind ===
|
|
3174
|
+
} else if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
|
|
3163
3175
|
value = true;
|
|
3164
|
-
} else if (initializer.kind ===
|
|
3176
|
+
} else if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
|
|
3165
3177
|
value = false;
|
|
3166
|
-
} else if (initializer.kind ===
|
|
3178
|
+
} else if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
|
|
3167
3179
|
value = null;
|
|
3168
|
-
} else if (
|
|
3169
|
-
if (initializer.operator ===
|
|
3180
|
+
} else if (ts5.isPrefixUnaryExpression(initializer)) {
|
|
3181
|
+
if (initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
|
|
3170
3182
|
value = -Number(initializer.operand.text);
|
|
3171
3183
|
}
|
|
3172
3184
|
}
|
|
@@ -3188,38 +3200,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3188
3200
|
|
|
3189
3201
|
// src/analyzer/class-analyzer.ts
|
|
3190
3202
|
function isObjectType(type) {
|
|
3191
|
-
return !!(type.flags &
|
|
3203
|
+
return !!(type.flags & ts6.TypeFlags.Object);
|
|
3192
3204
|
}
|
|
3193
3205
|
function isIntersectionType(type) {
|
|
3194
|
-
return !!(type.flags &
|
|
3195
|
-
}
|
|
3196
|
-
function isIntegerBrandedType(type) {
|
|
3197
|
-
if (!type.isIntersection()) {
|
|
3198
|
-
return false;
|
|
3199
|
-
}
|
|
3200
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3201
|
-
if (!hasNumberBase) {
|
|
3202
|
-
return false;
|
|
3203
|
-
}
|
|
3204
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3206
|
+
return !!(type.flags & ts6.TypeFlags.Intersection);
|
|
3205
3207
|
}
|
|
3206
3208
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3207
|
-
if (
|
|
3209
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3208
3210
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3209
3211
|
}
|
|
3210
|
-
if (
|
|
3212
|
+
if (ts6.isTypeLiteralNode(typeNode) || ts6.isTypeReferenceNode(typeNode)) {
|
|
3211
3213
|
return true;
|
|
3212
3214
|
}
|
|
3213
|
-
return
|
|
3215
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3214
3216
|
}
|
|
3215
3217
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3216
3218
|
if (isIntersectionType(type)) {
|
|
3217
3219
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3218
3220
|
}
|
|
3219
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3221
|
+
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);
|
|
3220
3222
|
}
|
|
3221
3223
|
function isTypeReference(type) {
|
|
3222
|
-
return !!(type.flags &
|
|
3224
|
+
return !!(type.flags & ts6.TypeFlags.Object) && !!(type.objectFlags & ts6.ObjectFlags.Reference);
|
|
3223
3225
|
}
|
|
3224
3226
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3225
3227
|
kind: "object",
|
|
@@ -3284,7 +3286,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3284
3286
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3285
3287
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3286
3288
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3287
|
-
const logicalName =
|
|
3289
|
+
const logicalName = ts6.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3288
3290
|
const docResult = extractJSDocParseResult(
|
|
3289
3291
|
declaration,
|
|
3290
3292
|
file,
|
|
@@ -3332,7 +3334,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3332
3334
|
const instanceMethods = [];
|
|
3333
3335
|
const staticMethods = [];
|
|
3334
3336
|
for (const member of classDecl.members) {
|
|
3335
|
-
if (
|
|
3337
|
+
if (ts6.isPropertyDeclaration(member)) {
|
|
3336
3338
|
const fieldNode = analyzeFieldToIR(
|
|
3337
3339
|
member,
|
|
3338
3340
|
checker,
|
|
@@ -3348,10 +3350,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3348
3350
|
fields.push(fieldNode);
|
|
3349
3351
|
fieldLayouts.push({});
|
|
3350
3352
|
}
|
|
3351
|
-
} else if (
|
|
3353
|
+
} else if (ts6.isMethodDeclaration(member)) {
|
|
3352
3354
|
const methodInfo = analyzeMethod(member, checker);
|
|
3353
3355
|
if (methodInfo) {
|
|
3354
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3356
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts6.SyntaxKind.StaticKeyword);
|
|
3355
3357
|
if (isStatic) {
|
|
3356
3358
|
staticMethods.push(methodInfo);
|
|
3357
3359
|
} else {
|
|
@@ -3414,7 +3416,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3414
3416
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3415
3417
|
const visiting = /* @__PURE__ */ new Set();
|
|
3416
3418
|
for (const member of interfaceDecl.members) {
|
|
3417
|
-
if (
|
|
3419
|
+
if (ts6.isPropertySignature(member)) {
|
|
3418
3420
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3419
3421
|
member,
|
|
3420
3422
|
checker,
|
|
@@ -3472,7 +3474,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3472
3474
|
if (members === null) {
|
|
3473
3475
|
const sourceFile = typeAlias.getSourceFile();
|
|
3474
3476
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3475
|
-
const kindDesc =
|
|
3477
|
+
const kindDesc = ts6.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3476
3478
|
return {
|
|
3477
3479
|
ok: false,
|
|
3478
3480
|
kind: "not-object-like",
|
|
@@ -3507,7 +3509,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3507
3509
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3508
3510
|
const visiting = /* @__PURE__ */ new Set();
|
|
3509
3511
|
for (const member of members) {
|
|
3510
|
-
if (
|
|
3512
|
+
if (ts6.isPropertySignature(member)) {
|
|
3511
3513
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3512
3514
|
member,
|
|
3513
3515
|
checker,
|
|
@@ -3574,13 +3576,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3574
3576
|
function getLeadingParsedTags(node) {
|
|
3575
3577
|
const sourceFile = node.getSourceFile();
|
|
3576
3578
|
const sourceText = sourceFile.getFullText();
|
|
3577
|
-
const commentRanges =
|
|
3579
|
+
const commentRanges = ts6.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3578
3580
|
if (commentRanges === void 0) {
|
|
3579
3581
|
return [];
|
|
3580
3582
|
}
|
|
3581
3583
|
const parsedTags = [];
|
|
3582
3584
|
for (const range of commentRanges) {
|
|
3583
|
-
if (range.kind !==
|
|
3585
|
+
if (range.kind !== ts6.SyntaxKind.MultiLineCommentTrivia) {
|
|
3584
3586
|
continue;
|
|
3585
3587
|
}
|
|
3586
3588
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3598,19 +3600,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3598
3600
|
return null;
|
|
3599
3601
|
}
|
|
3600
3602
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3601
|
-
(candidate) =>
|
|
3603
|
+
(candidate) => ts6.isPropertyDeclaration(candidate) || ts6.isPropertySignature(candidate)
|
|
3602
3604
|
) ?? propertySymbol.declarations?.[0];
|
|
3603
3605
|
return {
|
|
3604
3606
|
declaration,
|
|
3605
3607
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3606
|
-
optional: !!(propertySymbol.flags &
|
|
3608
|
+
optional: !!(propertySymbol.flags & ts6.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3607
3609
|
};
|
|
3608
3610
|
}
|
|
3609
3611
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3610
3612
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3611
3613
|
}
|
|
3612
3614
|
function isNullishSemanticType(type) {
|
|
3613
|
-
if (type.flags & (
|
|
3615
|
+
if (type.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined | ts6.TypeFlags.Void | ts6.TypeFlags.Unknown | ts6.TypeFlags.Any)) {
|
|
3614
3616
|
return true;
|
|
3615
3617
|
}
|
|
3616
3618
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3620,7 +3622,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3620
3622
|
return false;
|
|
3621
3623
|
}
|
|
3622
3624
|
seen.add(type);
|
|
3623
|
-
if (type.flags &
|
|
3625
|
+
if (type.flags & ts6.TypeFlags.StringLike) {
|
|
3624
3626
|
return true;
|
|
3625
3627
|
}
|
|
3626
3628
|
if (type.isUnion()) {
|
|
@@ -3633,13 +3635,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3633
3635
|
return false;
|
|
3634
3636
|
}
|
|
3635
3637
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3636
|
-
if (
|
|
3638
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3637
3639
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3638
3640
|
}
|
|
3639
|
-
if (
|
|
3641
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
3640
3642
|
return [...typeNode.members];
|
|
3641
3643
|
}
|
|
3642
|
-
if (
|
|
3644
|
+
if (ts6.isIntersectionTypeNode(typeNode)) {
|
|
3643
3645
|
const members = [];
|
|
3644
3646
|
for (const intersectionMember of typeNode.types) {
|
|
3645
3647
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3802,7 +3804,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3802
3804
|
}
|
|
3803
3805
|
if (propertyType.isUnion()) {
|
|
3804
3806
|
const nonNullMembers = propertyType.types.filter(
|
|
3805
|
-
(member) => !(member.flags & (
|
|
3807
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3806
3808
|
);
|
|
3807
3809
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3808
3810
|
diagnostics.push(
|
|
@@ -3851,13 +3853,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3851
3853
|
seen.add(type);
|
|
3852
3854
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3853
3855
|
if (symbol !== void 0) {
|
|
3854
|
-
const aliased = symbol.flags &
|
|
3856
|
+
const aliased = symbol.flags & ts6.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3855
3857
|
const targetSymbol = aliased ?? symbol;
|
|
3856
3858
|
const declaration = targetSymbol.declarations?.find(
|
|
3857
|
-
(candidate) =>
|
|
3859
|
+
(candidate) => ts6.isClassDeclaration(candidate) || ts6.isInterfaceDeclaration(candidate) || ts6.isTypeAliasDeclaration(candidate) || ts6.isEnumDeclaration(candidate)
|
|
3858
3860
|
);
|
|
3859
3861
|
if (declaration !== void 0) {
|
|
3860
|
-
if (
|
|
3862
|
+
if (ts6.isTypeAliasDeclaration(declaration) && ts6.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3861
3863
|
return resolveNamedDiscriminatorDeclaration(
|
|
3862
3864
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3863
3865
|
checker,
|
|
@@ -3885,7 +3887,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3885
3887
|
}
|
|
3886
3888
|
if (boundType.isUnion()) {
|
|
3887
3889
|
const nonNullMembers = boundType.types.filter(
|
|
3888
|
-
(member) => !(member.flags & (
|
|
3890
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3889
3891
|
);
|
|
3890
3892
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3891
3893
|
diagnostics.push(
|
|
@@ -3930,7 +3932,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3930
3932
|
return null;
|
|
3931
3933
|
}
|
|
3932
3934
|
function getDeclarationName(node) {
|
|
3933
|
-
if (
|
|
3935
|
+
if (ts6.isClassDeclaration(node) || ts6.isInterfaceDeclaration(node) || ts6.isTypeAliasDeclaration(node) || ts6.isEnumDeclaration(node)) {
|
|
3934
3936
|
return node.name?.text ?? "anonymous";
|
|
3935
3937
|
}
|
|
3936
3938
|
return "anonymous";
|
|
@@ -3985,11 +3987,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
3985
3987
|
if (sourceTypeNode === void 0) {
|
|
3986
3988
|
return [];
|
|
3987
3989
|
}
|
|
3988
|
-
const unwrapParentheses = (typeNode) =>
|
|
3990
|
+
const unwrapParentheses = (typeNode) => ts6.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
3989
3991
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
3990
|
-
const referenceTypeNode =
|
|
3992
|
+
const referenceTypeNode = ts6.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
3991
3993
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
3992
|
-
return
|
|
3994
|
+
return ts6.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
3993
3995
|
})();
|
|
3994
3996
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
3995
3997
|
return [];
|
|
@@ -4044,7 +4046,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4044
4046
|
);
|
|
4045
4047
|
}
|
|
4046
4048
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4047
|
-
if (!
|
|
4049
|
+
if (!ts6.isIdentifier(prop.name)) {
|
|
4048
4050
|
return null;
|
|
4049
4051
|
}
|
|
4050
4052
|
const name = prop.name.text;
|
|
@@ -4171,7 +4173,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4171
4173
|
const seen = /* @__PURE__ */ new Set();
|
|
4172
4174
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4173
4175
|
for (const member of members) {
|
|
4174
|
-
if (!
|
|
4176
|
+
if (!ts6.isPropertySignature(member)) {
|
|
4175
4177
|
continue;
|
|
4176
4178
|
}
|
|
4177
4179
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4187,7 +4189,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4187
4189
|
return [...duplicates].sort();
|
|
4188
4190
|
}
|
|
4189
4191
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4190
|
-
if (
|
|
4192
|
+
if (ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNumericLiteral(name)) {
|
|
4191
4193
|
return name.text;
|
|
4192
4194
|
}
|
|
4193
4195
|
return null;
|
|
@@ -4285,25 +4287,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4285
4287
|
if (isIntegerBrandedType(type)) {
|
|
4286
4288
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4287
4289
|
}
|
|
4288
|
-
if (type.flags &
|
|
4290
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4289
4291
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4290
4292
|
}
|
|
4291
|
-
if (type.flags &
|
|
4293
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4292
4294
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4293
4295
|
}
|
|
4294
|
-
if (type.flags & (
|
|
4296
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4295
4297
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4296
4298
|
}
|
|
4297
|
-
if (type.flags &
|
|
4299
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4298
4300
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4299
4301
|
}
|
|
4300
|
-
if (type.flags &
|
|
4302
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4301
4303
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4302
4304
|
}
|
|
4303
|
-
if (type.flags &
|
|
4305
|
+
if (type.flags & ts6.TypeFlags.Undefined) {
|
|
4304
4306
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4305
4307
|
}
|
|
4306
|
-
if (type.flags &
|
|
4308
|
+
if (type.flags & ts6.TypeFlags.Void) {
|
|
4307
4309
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4308
4310
|
}
|
|
4309
4311
|
if (type.isStringLiteral()) {
|
|
@@ -4390,10 +4392,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4390
4392
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4391
4393
|
}
|
|
4392
4394
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4393
|
-
if (!(type.flags & (
|
|
4395
|
+
if (!(type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4394
4396
|
return null;
|
|
4395
4397
|
}
|
|
4396
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4398
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4397
4399
|
if (!aliasDecl) {
|
|
4398
4400
|
return null;
|
|
4399
4401
|
}
|
|
@@ -4443,14 +4445,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4443
4445
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4444
4446
|
}
|
|
4445
4447
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4446
|
-
const typeNode = sourceNode && (
|
|
4447
|
-
if (!typeNode || !
|
|
4448
|
+
const typeNode = sourceNode && (ts6.isPropertyDeclaration(sourceNode) || ts6.isPropertySignature(sourceNode) || ts6.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4449
|
+
if (!typeNode || !ts6.isTypeReferenceNode(typeNode)) {
|
|
4448
4450
|
return void 0;
|
|
4449
4451
|
}
|
|
4450
4452
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4451
4453
|
}
|
|
4452
4454
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4453
|
-
if (!
|
|
4455
|
+
if (!ts6.isTypeReferenceNode(typeNode)) {
|
|
4454
4456
|
return false;
|
|
4455
4457
|
}
|
|
4456
4458
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4458,10 +4460,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4458
4460
|
return false;
|
|
4459
4461
|
}
|
|
4460
4462
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4461
|
-
return !!(resolved.flags & (
|
|
4463
|
+
return !!(resolved.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null));
|
|
4462
4464
|
}
|
|
4463
4465
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4464
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4466
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration);
|
|
4465
4467
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4466
4468
|
visitedAliases.add(nestedAliasDecl);
|
|
4467
4469
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4479,19 +4481,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4479
4481
|
if (isIntegerBrandedType(type)) {
|
|
4480
4482
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4481
4483
|
}
|
|
4482
|
-
if (type.flags &
|
|
4484
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4483
4485
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4484
4486
|
}
|
|
4485
|
-
if (type.flags &
|
|
4487
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4486
4488
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4487
4489
|
}
|
|
4488
|
-
if (type.flags & (
|
|
4490
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4489
4491
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4490
4492
|
}
|
|
4491
|
-
if (type.flags &
|
|
4493
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4492
4494
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4493
4495
|
}
|
|
4494
|
-
if (type.flags &
|
|
4496
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4495
4497
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4496
4498
|
}
|
|
4497
4499
|
return resolveTypeNode(
|
|
@@ -4518,13 +4520,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4518
4520
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4519
4521
|
);
|
|
4520
4522
|
const nonNullTypes = allTypes.filter(
|
|
4521
|
-
(memberType) => !(memberType.flags & (
|
|
4523
|
+
(memberType) => !(memberType.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4522
4524
|
);
|
|
4523
4525
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4524
4526
|
memberType,
|
|
4525
4527
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4526
4528
|
}));
|
|
4527
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4529
|
+
const hasNull = allTypes.some((t) => t.flags & ts6.TypeFlags.Null);
|
|
4528
4530
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4529
4531
|
if (namedDecl) {
|
|
4530
4532
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4567,7 +4569,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4567
4569
|
const displayName = memberDisplayNames.get(String(value));
|
|
4568
4570
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4569
4571
|
});
|
|
4570
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4572
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts6.TypeFlags.BooleanLiteral);
|
|
4571
4573
|
if (isBooleanUnion2) {
|
|
4572
4574
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4573
4575
|
const result = hasNull ? {
|
|
@@ -4659,7 +4661,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4659
4661
|
if (type.getProperties().length > 0) {
|
|
4660
4662
|
return null;
|
|
4661
4663
|
}
|
|
4662
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4664
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts6.IndexKind.String);
|
|
4663
4665
|
if (!indexInfo) {
|
|
4664
4666
|
return null;
|
|
4665
4667
|
}
|
|
@@ -4707,10 +4709,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4707
4709
|
}
|
|
4708
4710
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4709
4711
|
const name = declaration.name;
|
|
4710
|
-
if (
|
|
4712
|
+
if (ts6.isComputedPropertyName(name) || ts6.isPrivateIdentifier(name)) {
|
|
4711
4713
|
return false;
|
|
4712
4714
|
}
|
|
4713
|
-
if (!
|
|
4715
|
+
if (!ts6.isIdentifier(name) && !ts6.isStringLiteral(name) && !ts6.isNumericLiteral(name)) {
|
|
4714
4716
|
return false;
|
|
4715
4717
|
}
|
|
4716
4718
|
}
|
|
@@ -4836,7 +4838,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4836
4838
|
if (!declaration) continue;
|
|
4837
4839
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4838
4840
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4839
|
-
const optional = !!(prop.flags &
|
|
4841
|
+
const optional = !!(prop.flags & ts6.SymbolFlags.Optional);
|
|
4840
4842
|
const propTypeNode = resolveTypeNode(
|
|
4841
4843
|
propType,
|
|
4842
4844
|
checker,
|
|
@@ -4849,7 +4851,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4849
4851
|
collectedDiagnostics
|
|
4850
4852
|
);
|
|
4851
4853
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4852
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
4854
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts6.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4853
4855
|
declaration,
|
|
4854
4856
|
checker,
|
|
4855
4857
|
file,
|
|
@@ -4859,7 +4861,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4859
4861
|
type,
|
|
4860
4862
|
metadataPolicy,
|
|
4861
4863
|
extensionRegistry
|
|
4862
|
-
) :
|
|
4864
|
+
) : ts6.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4863
4865
|
declaration,
|
|
4864
4866
|
checker,
|
|
4865
4867
|
file,
|
|
@@ -4887,7 +4889,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4887
4889
|
visiting.delete(type);
|
|
4888
4890
|
const objectNode = {
|
|
4889
4891
|
kind: "object",
|
|
4890
|
-
properties: namedDecl !== void 0 && (
|
|
4892
|
+
properties: namedDecl !== void 0 && (ts6.isClassDeclaration(namedDecl) || ts6.isInterfaceDeclaration(namedDecl) || ts6.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
4891
4893
|
properties,
|
|
4892
4894
|
namedDecl,
|
|
4893
4895
|
type,
|
|
@@ -4935,12 +4937,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4935
4937
|
for (const symbol of symbols) {
|
|
4936
4938
|
const declarations = symbol.declarations;
|
|
4937
4939
|
if (!declarations) continue;
|
|
4938
|
-
const classDecl = declarations.find(
|
|
4940
|
+
const classDecl = declarations.find(ts6.isClassDeclaration);
|
|
4939
4941
|
if (classDecl) {
|
|
4940
4942
|
const map = /* @__PURE__ */ new Map();
|
|
4941
4943
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
4942
4944
|
for (const member of classDecl.members) {
|
|
4943
|
-
if (
|
|
4945
|
+
if (ts6.isPropertyDeclaration(member) && ts6.isIdentifier(member.name)) {
|
|
4944
4946
|
const fieldNode = analyzeFieldToIR(
|
|
4945
4947
|
member,
|
|
4946
4948
|
checker,
|
|
@@ -4964,7 +4966,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4964
4966
|
}
|
|
4965
4967
|
return map;
|
|
4966
4968
|
}
|
|
4967
|
-
const interfaceDecl = declarations.find(
|
|
4969
|
+
const interfaceDecl = declarations.find(ts6.isInterfaceDeclaration);
|
|
4968
4970
|
if (interfaceDecl) {
|
|
4969
4971
|
return buildFieldNodeInfoMap(
|
|
4970
4972
|
interfaceDecl.members,
|
|
@@ -4978,7 +4980,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4978
4980
|
extensionRegistry
|
|
4979
4981
|
);
|
|
4980
4982
|
}
|
|
4981
|
-
const typeAliasDecl = declarations.find(
|
|
4983
|
+
const typeAliasDecl = declarations.find(ts6.isTypeAliasDeclaration);
|
|
4982
4984
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
4983
4985
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
4984
4986
|
return buildFieldNodeInfoMap(
|
|
@@ -5002,10 +5004,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5002
5004
|
return void 0;
|
|
5003
5005
|
}
|
|
5004
5006
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5005
|
-
if (
|
|
5007
|
+
if (ts6.isArrayTypeNode(resolvedTypeNode)) {
|
|
5006
5008
|
return resolvedTypeNode.elementType;
|
|
5007
5009
|
}
|
|
5008
|
-
if (
|
|
5010
|
+
if (ts6.isTypeReferenceNode(resolvedTypeNode) && ts6.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5009
5011
|
return resolvedTypeNode.typeArguments[0];
|
|
5010
5012
|
}
|
|
5011
5013
|
return void 0;
|
|
@@ -5016,13 +5018,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5016
5018
|
return [];
|
|
5017
5019
|
}
|
|
5018
5020
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5019
|
-
return
|
|
5021
|
+
return ts6.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5020
5022
|
}
|
|
5021
5023
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5022
|
-
if (
|
|
5024
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5023
5025
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5024
5026
|
}
|
|
5025
|
-
if (!
|
|
5027
|
+
if (!ts6.isTypeReferenceNode(typeNode) || !ts6.isIdentifier(typeNode.typeName)) {
|
|
5026
5028
|
return typeNode;
|
|
5027
5029
|
}
|
|
5028
5030
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5033,15 +5035,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5033
5035
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5034
5036
|
}
|
|
5035
5037
|
function isNullishTypeNode(typeNode) {
|
|
5036
|
-
if (typeNode.kind ===
|
|
5038
|
+
if (typeNode.kind === ts6.SyntaxKind.NullKeyword || typeNode.kind === ts6.SyntaxKind.UndefinedKeyword) {
|
|
5037
5039
|
return true;
|
|
5038
5040
|
}
|
|
5039
|
-
return
|
|
5041
|
+
return ts6.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts6.SyntaxKind.NullKeyword || typeNode.literal.kind === ts6.SyntaxKind.UndefinedKeyword);
|
|
5040
5042
|
}
|
|
5041
5043
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5042
5044
|
const map = /* @__PURE__ */ new Map();
|
|
5043
5045
|
for (const member of members) {
|
|
5044
|
-
if (
|
|
5046
|
+
if (ts6.isPropertySignature(member)) {
|
|
5045
5047
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5046
5048
|
member,
|
|
5047
5049
|
checker,
|
|
@@ -5067,7 +5069,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5067
5069
|
}
|
|
5068
5070
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5069
5071
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5070
|
-
if (!
|
|
5072
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return [];
|
|
5071
5073
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5072
5074
|
const aliasName = typeNode.typeName.getText();
|
|
5073
5075
|
throw new Error(
|
|
@@ -5076,7 +5078,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5076
5078
|
}
|
|
5077
5079
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5078
5080
|
if (!aliasDecl) return [];
|
|
5079
|
-
if (
|
|
5081
|
+
if (ts6.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5080
5082
|
const aliasFieldType = resolveTypeNode(
|
|
5081
5083
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5082
5084
|
checker,
|
|
@@ -5120,14 +5122,14 @@ function getNamedTypeName(type) {
|
|
|
5120
5122
|
const symbol = type.getSymbol();
|
|
5121
5123
|
if (symbol?.declarations) {
|
|
5122
5124
|
const decl = symbol.declarations[0];
|
|
5123
|
-
if (decl && (
|
|
5124
|
-
const name =
|
|
5125
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5126
|
+
const name = ts6.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5125
5127
|
if (name) return name;
|
|
5126
5128
|
}
|
|
5127
5129
|
}
|
|
5128
5130
|
const aliasSymbol = type.aliasSymbol;
|
|
5129
5131
|
if (aliasSymbol?.declarations) {
|
|
5130
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5132
|
+
const aliasDecl = aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5131
5133
|
if (aliasDecl) {
|
|
5132
5134
|
return aliasDecl.name.text;
|
|
5133
5135
|
}
|
|
@@ -5138,24 +5140,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5138
5140
|
const symbol = type.getSymbol();
|
|
5139
5141
|
if (symbol?.declarations) {
|
|
5140
5142
|
const decl = symbol.declarations[0];
|
|
5141
|
-
if (decl && (
|
|
5143
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5142
5144
|
return decl;
|
|
5143
5145
|
}
|
|
5144
5146
|
}
|
|
5145
5147
|
const aliasSymbol = type.aliasSymbol;
|
|
5146
5148
|
if (aliasSymbol?.declarations) {
|
|
5147
|
-
return aliasSymbol.declarations.find(
|
|
5149
|
+
return aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5148
5150
|
}
|
|
5149
5151
|
return void 0;
|
|
5150
5152
|
}
|
|
5151
5153
|
function analyzeMethod(method, checker) {
|
|
5152
|
-
if (!
|
|
5154
|
+
if (!ts6.isIdentifier(method.name)) {
|
|
5153
5155
|
return null;
|
|
5154
5156
|
}
|
|
5155
5157
|
const name = method.name.text;
|
|
5156
5158
|
const parameters = [];
|
|
5157
5159
|
for (const param of method.parameters) {
|
|
5158
|
-
if (
|
|
5160
|
+
if (ts6.isIdentifier(param.name)) {
|
|
5159
5161
|
const paramInfo = analyzeParameter(param, checker);
|
|
5160
5162
|
parameters.push(paramInfo);
|
|
5161
5163
|
}
|
|
@@ -5166,7 +5168,7 @@ function analyzeMethod(method, checker) {
|
|
|
5166
5168
|
return { name, parameters, returnTypeNode, returnType };
|
|
5167
5169
|
}
|
|
5168
5170
|
function analyzeParameter(param, checker) {
|
|
5169
|
-
const name =
|
|
5171
|
+
const name = ts6.isIdentifier(param.name) ? param.name.text : "param";
|
|
5170
5172
|
const typeNode = param.type;
|
|
5171
5173
|
const type = checker.getTypeAtLocation(param);
|
|
5172
5174
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5175,15 +5177,15 @@ function analyzeParameter(param, checker) {
|
|
|
5175
5177
|
}
|
|
5176
5178
|
function detectFormSpecReference(typeNode) {
|
|
5177
5179
|
if (!typeNode) return null;
|
|
5178
|
-
if (!
|
|
5179
|
-
const typeName =
|
|
5180
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return null;
|
|
5181
|
+
const typeName = ts6.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts6.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5180
5182
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5181
5183
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5182
|
-
if (!typeArg || !
|
|
5183
|
-
if (
|
|
5184
|
+
if (!typeArg || !ts6.isTypeQueryNode(typeArg)) return null;
|
|
5185
|
+
if (ts6.isIdentifier(typeArg.exprName)) {
|
|
5184
5186
|
return typeArg.exprName.text;
|
|
5185
5187
|
}
|
|
5186
|
-
if (
|
|
5188
|
+
if (ts6.isQualifiedName(typeArg.exprName)) {
|
|
5187
5189
|
return typeArg.exprName.right.text;
|
|
5188
5190
|
}
|
|
5189
5191
|
return null;
|
|
@@ -5205,23 +5207,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5205
5207
|
function createProgramContext(filePath, additionalFiles) {
|
|
5206
5208
|
const absolutePath = path.resolve(filePath);
|
|
5207
5209
|
const fileDir = path.dirname(absolutePath);
|
|
5208
|
-
const configPath =
|
|
5210
|
+
const configPath = ts7.findConfigFile(fileDir, ts7.sys.fileExists.bind(ts7.sys), "tsconfig.json");
|
|
5209
5211
|
let compilerOptions;
|
|
5210
5212
|
let fileNames;
|
|
5211
5213
|
if (configPath) {
|
|
5212
|
-
const configFile =
|
|
5214
|
+
const configFile = ts7.readConfigFile(configPath, ts7.sys.readFile.bind(ts7.sys));
|
|
5213
5215
|
if (configFile.error) {
|
|
5214
5216
|
throw new Error(
|
|
5215
|
-
`Error reading tsconfig.json: ${
|
|
5217
|
+
`Error reading tsconfig.json: ${ts7.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5216
5218
|
);
|
|
5217
5219
|
}
|
|
5218
|
-
const parsed =
|
|
5220
|
+
const parsed = ts7.parseJsonConfigFileContent(
|
|
5219
5221
|
configFile.config,
|
|
5220
|
-
|
|
5222
|
+
ts7.sys,
|
|
5221
5223
|
path.dirname(configPath)
|
|
5222
5224
|
);
|
|
5223
5225
|
if (parsed.errors.length > 0) {
|
|
5224
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5226
|
+
const errorMessages = parsed.errors.map((e) => ts7.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5225
5227
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5226
5228
|
}
|
|
5227
5229
|
compilerOptions = parsed.options;
|
|
@@ -5229,9 +5231,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5229
5231
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5230
5232
|
} else {
|
|
5231
5233
|
compilerOptions = {
|
|
5232
|
-
target:
|
|
5233
|
-
module:
|
|
5234
|
-
moduleResolution:
|
|
5234
|
+
target: ts7.ScriptTarget.ES2022,
|
|
5235
|
+
module: ts7.ModuleKind.NodeNext,
|
|
5236
|
+
moduleResolution: ts7.ModuleResolutionKind.NodeNext,
|
|
5235
5237
|
strict: true,
|
|
5236
5238
|
skipLibCheck: true,
|
|
5237
5239
|
declaration: true
|
|
@@ -5239,7 +5241,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5239
5241
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5240
5242
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5241
5243
|
}
|
|
5242
|
-
const program =
|
|
5244
|
+
const program = ts7.createProgram(fileNames, compilerOptions);
|
|
5243
5245
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5244
5246
|
if (!sourceFile) {
|
|
5245
5247
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5258,19 +5260,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5258
5260
|
result = node;
|
|
5259
5261
|
return;
|
|
5260
5262
|
}
|
|
5261
|
-
|
|
5263
|
+
ts7.forEachChild(node, visit);
|
|
5262
5264
|
}
|
|
5263
5265
|
visit(sourceFile);
|
|
5264
5266
|
return result;
|
|
5265
5267
|
}
|
|
5266
5268
|
function findClassByName(sourceFile, className) {
|
|
5267
|
-
return findNodeByName(sourceFile, className,
|
|
5269
|
+
return findNodeByName(sourceFile, className, ts7.isClassDeclaration, (n) => n.name?.text);
|
|
5268
5270
|
}
|
|
5269
5271
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5270
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5272
|
+
return findNodeByName(sourceFile, interfaceName, ts7.isInterfaceDeclaration, (n) => n.name.text);
|
|
5271
5273
|
}
|
|
5272
5274
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5273
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5275
|
+
return findNodeByName(sourceFile, aliasName, ts7.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5274
5276
|
}
|
|
5275
5277
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5276
5278
|
if (rootType.kind === "object") {
|
|
@@ -5310,22 +5312,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5310
5312
|
};
|
|
5311
5313
|
}
|
|
5312
5314
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5313
|
-
if (
|
|
5315
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5314
5316
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5315
5317
|
}
|
|
5316
|
-
if (
|
|
5318
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5317
5319
|
return true;
|
|
5318
5320
|
}
|
|
5319
|
-
return
|
|
5321
|
+
return ts7.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5320
5322
|
}
|
|
5321
5323
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5322
|
-
if (
|
|
5324
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5323
5325
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5324
5326
|
}
|
|
5325
|
-
if (
|
|
5327
|
+
if (ts7.isTypeLiteralNode(typeNode)) {
|
|
5326
5328
|
const propertyNames = [];
|
|
5327
5329
|
for (const member of typeNode.members) {
|
|
5328
|
-
if (!
|
|
5330
|
+
if (!ts7.isPropertySignature(member)) {
|
|
5329
5331
|
continue;
|
|
5330
5332
|
}
|
|
5331
5333
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5335,13 +5337,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5335
5337
|
}
|
|
5336
5338
|
return propertyNames;
|
|
5337
5339
|
}
|
|
5338
|
-
if (
|
|
5340
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5339
5341
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5340
5342
|
}
|
|
5341
5343
|
return null;
|
|
5342
5344
|
}
|
|
5343
5345
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5344
|
-
if (!
|
|
5346
|
+
if (!ts7.isIntersectionTypeNode(typeNode)) {
|
|
5345
5347
|
return [];
|
|
5346
5348
|
}
|
|
5347
5349
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5542,7 +5544,7 @@ function makeFileProvenance(filePath) {
|
|
|
5542
5544
|
}
|
|
5543
5545
|
|
|
5544
5546
|
// src/extensions/symbol-registry.ts
|
|
5545
|
-
import * as
|
|
5547
|
+
import * as ts8 from "typescript";
|
|
5546
5548
|
import * as path2 from "path";
|
|
5547
5549
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5548
5550
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5552,10 +5554,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5552
5554
|
return symbolMap;
|
|
5553
5555
|
}
|
|
5554
5556
|
function visit(node) {
|
|
5555
|
-
if (
|
|
5557
|
+
if (ts8.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5556
5558
|
processDefineCustomTypeCall(node);
|
|
5557
5559
|
}
|
|
5558
|
-
|
|
5560
|
+
ts8.forEachChild(node, visit);
|
|
5559
5561
|
}
|
|
5560
5562
|
function processDefineCustomTypeCall(call) {
|
|
5561
5563
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5592,7 +5594,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5592
5594
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5593
5595
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5594
5596
|
if (callSymbol !== void 0) {
|
|
5595
|
-
const resolved = callSymbol.flags &
|
|
5597
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5596
5598
|
const decl = resolved.declarations?.[0];
|
|
5597
5599
|
if (decl !== void 0) {
|
|
5598
5600
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5600,24 +5602,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5600
5602
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5601
5603
|
}
|
|
5602
5604
|
}
|
|
5603
|
-
return
|
|
5605
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5604
5606
|
}
|
|
5605
5607
|
function extractTypeNameFromCallArg(call) {
|
|
5606
5608
|
const arg = call.arguments[0];
|
|
5607
|
-
if (arg === void 0 || !
|
|
5609
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5608
5610
|
return null;
|
|
5609
5611
|
}
|
|
5610
5612
|
const typeNameProp = arg.properties.find(
|
|
5611
|
-
(p) =>
|
|
5613
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5612
5614
|
);
|
|
5613
|
-
if (typeNameProp === void 0 || !
|
|
5615
|
+
if (typeNameProp === void 0 || !ts8.isStringLiteral(typeNameProp.initializer)) {
|
|
5614
5616
|
return null;
|
|
5615
5617
|
}
|
|
5616
5618
|
return typeNameProp.initializer.text;
|
|
5617
5619
|
}
|
|
5618
5620
|
function extractEnclosingExtensionId(call, checker) {
|
|
5619
|
-
for (let node = call.parent; !
|
|
5620
|
-
if (
|
|
5621
|
+
for (let node = call.parent; !ts8.isSourceFile(node); node = node.parent) {
|
|
5622
|
+
if (ts8.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5621
5623
|
return extractExtensionIdFromCallArg(node);
|
|
5622
5624
|
}
|
|
5623
5625
|
}
|
|
@@ -5626,24 +5628,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5626
5628
|
function isDefineExtensionCall(node, checker) {
|
|
5627
5629
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5628
5630
|
if (callSymbol !== void 0) {
|
|
5629
|
-
const resolved = callSymbol.flags &
|
|
5631
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5630
5632
|
const decl = resolved.declarations?.[0];
|
|
5631
5633
|
if (decl !== void 0) {
|
|
5632
5634
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5633
5635
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5634
5636
|
}
|
|
5635
5637
|
}
|
|
5636
|
-
return
|
|
5638
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5637
5639
|
}
|
|
5638
5640
|
function extractExtensionIdFromCallArg(call) {
|
|
5639
5641
|
const arg = call.arguments[0];
|
|
5640
|
-
if (arg === void 0 || !
|
|
5642
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5641
5643
|
return null;
|
|
5642
5644
|
}
|
|
5643
5645
|
const prop = arg.properties.find(
|
|
5644
|
-
(p) =>
|
|
5646
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5645
5647
|
);
|
|
5646
|
-
if (prop === void 0 || !
|
|
5648
|
+
if (prop === void 0 || !ts8.isStringLiteral(prop.initializer)) {
|
|
5647
5649
|
return null;
|
|
5648
5650
|
}
|
|
5649
5651
|
return prop.initializer.text;
|
|
@@ -5905,7 +5907,7 @@ function generateSchemasBatch(options) {
|
|
|
5905
5907
|
return options.targets.map((target) => {
|
|
5906
5908
|
let ctx;
|
|
5907
5909
|
try {
|
|
5908
|
-
const cacheKey =
|
|
5910
|
+
const cacheKey = ts9.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
5909
5911
|
const cachedContext = contextCache.get(cacheKey);
|
|
5910
5912
|
if (cachedContext === void 0) {
|
|
5911
5913
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6061,7 +6063,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6061
6063
|
}
|
|
6062
6064
|
|
|
6063
6065
|
// src/static-build.ts
|
|
6064
|
-
import * as
|
|
6066
|
+
import * as ts10 from "typescript";
|
|
6065
6067
|
function toStaticBuildContext(context) {
|
|
6066
6068
|
return context;
|
|
6067
6069
|
}
|
|
@@ -6076,7 +6078,7 @@ function getModuleSymbol(context) {
|
|
|
6076
6078
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6077
6079
|
}
|
|
6078
6080
|
function isSchemaSourceDeclaration(declaration) {
|
|
6079
|
-
return
|
|
6081
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6080
6082
|
}
|
|
6081
6083
|
function resolveModuleExport(context, exportName = "default") {
|
|
6082
6084
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6087,14 +6089,14 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6087
6089
|
if (exportSymbol === null) {
|
|
6088
6090
|
return null;
|
|
6089
6091
|
}
|
|
6090
|
-
return exportSymbol.flags &
|
|
6092
|
+
return exportSymbol.flags & ts10.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6091
6093
|
}
|
|
6092
6094
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6093
6095
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6094
6096
|
}
|
|
6095
6097
|
|
|
6096
6098
|
// src/generators/discovered-schema.ts
|
|
6097
|
-
import * as
|
|
6099
|
+
import * as ts11 from "typescript";
|
|
6098
6100
|
import { analyzeMetadataForNodeWithChecker as analyzeMetadataForNodeWithChecker2 } from "@formspec/analysis/internal";
|
|
6099
6101
|
import { IR_VERSION as IR_VERSION3 } from "@formspec/core/internals";
|
|
6100
6102
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
@@ -6104,17 +6106,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6104
6106
|
};
|
|
6105
6107
|
}
|
|
6106
6108
|
function isNamedTypeDeclaration(declaration) {
|
|
6107
|
-
return
|
|
6109
|
+
return ts11.isClassDeclaration(declaration) || ts11.isInterfaceDeclaration(declaration) || ts11.isTypeAliasDeclaration(declaration);
|
|
6108
6110
|
}
|
|
6109
6111
|
function hasConcreteTypeArguments(type, checker) {
|
|
6110
6112
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6111
6113
|
return true;
|
|
6112
6114
|
}
|
|
6113
|
-
if ((type.flags &
|
|
6115
|
+
if ((type.flags & ts11.TypeFlags.Object) === 0) {
|
|
6114
6116
|
return false;
|
|
6115
6117
|
}
|
|
6116
6118
|
const objectType = type;
|
|
6117
|
-
if ((objectType.objectFlags &
|
|
6119
|
+
if ((objectType.objectFlags & ts11.ObjectFlags.Reference) === 0) {
|
|
6118
6120
|
return false;
|
|
6119
6121
|
}
|
|
6120
6122
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6127,13 +6129,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6127
6129
|
return declaration;
|
|
6128
6130
|
}
|
|
6129
6131
|
}
|
|
6130
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6132
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts11.isTypeAliasDeclaration);
|
|
6131
6133
|
return aliasDeclaration;
|
|
6132
6134
|
}
|
|
6133
6135
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6134
6136
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6135
6137
|
const namedNode = sourceNode;
|
|
6136
|
-
if (namedNode.name !== void 0 &&
|
|
6138
|
+
if (namedNode.name !== void 0 && ts11.isIdentifier(namedNode.name)) {
|
|
6137
6139
|
return namedNode.name.text;
|
|
6138
6140
|
}
|
|
6139
6141
|
}
|
|
@@ -6355,7 +6357,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6355
6357
|
function generateSchemasFromDeclaration(options) {
|
|
6356
6358
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6357
6359
|
const resolved = resolveStaticOptions(options);
|
|
6358
|
-
if (
|
|
6360
|
+
if (ts11.isClassDeclaration(options.declaration)) {
|
|
6359
6361
|
return generateSchemasFromAnalysis(
|
|
6360
6362
|
analyzeClassToIR(
|
|
6361
6363
|
options.declaration,
|
|
@@ -6369,7 +6371,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6369
6371
|
resolved
|
|
6370
6372
|
);
|
|
6371
6373
|
}
|
|
6372
|
-
if (
|
|
6374
|
+
if (ts11.isInterfaceDeclaration(options.declaration)) {
|
|
6373
6375
|
return generateSchemasFromAnalysis(
|
|
6374
6376
|
analyzeInterfaceToIR(
|
|
6375
6377
|
options.declaration,
|
|
@@ -6383,7 +6385,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6383
6385
|
resolved
|
|
6384
6386
|
);
|
|
6385
6387
|
}
|
|
6386
|
-
if (
|
|
6388
|
+
if (ts11.isTypeAliasDeclaration(options.declaration)) {
|
|
6387
6389
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6388
6390
|
options.declaration,
|
|
6389
6391
|
options.context.checker,
|
|
@@ -6442,7 +6444,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6442
6444
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6443
6445
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6444
6446
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6445
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6447
|
+
const fallbackName = options.declaration.name !== void 0 && ts11.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6446
6448
|
return generateSchemasFromResolvedType({
|
|
6447
6449
|
...options,
|
|
6448
6450
|
type,
|
|
@@ -6489,14 +6491,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6489
6491
|
if (typeNode === void 0) {
|
|
6490
6492
|
return void 0;
|
|
6491
6493
|
}
|
|
6492
|
-
if (
|
|
6494
|
+
if (ts11.isParenthesizedTypeNode(typeNode)) {
|
|
6493
6495
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6494
6496
|
return unwrapped ?? typeNode;
|
|
6495
6497
|
}
|
|
6496
6498
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6497
6499
|
}
|
|
6498
6500
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6499
|
-
return
|
|
6501
|
+
return ts11.isTypeReferenceNode(typeNode) && ts11.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6500
6502
|
}
|
|
6501
6503
|
|
|
6502
6504
|
// src/generators/mixed-authoring.ts
|