@formspec/build 0.1.0-alpha.49 → 0.1.0-alpha.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/cli.cjs +381 -374
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +339 -334
- package/dist/cli.js.map +1 -1
- package/dist/extensions/resolve-custom-type.d.ts +37 -0
- package/dist/extensions/resolve-custom-type.d.ts.map +1 -0
- package/dist/extensions/symbol-registry.d.ts.map +1 -1
- package/dist/extensions/ts-type-utils.d.ts +40 -0
- package/dist/extensions/ts-type-utils.d.ts.map +1 -0
- package/dist/index.cjs +359 -365
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +328 -334
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +332 -333
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +297 -298
- package/dist/internals.js.map +1 -1
- package/package.json +2 -2
package/dist/index.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 ts8 from "typescript";
|
|
2170
2170
|
|
|
2171
2171
|
// src/analyzer/program.ts
|
|
2172
|
-
import * as
|
|
2172
|
+
import * as ts6 from "typescript";
|
|
2173
2173
|
import * as path from "path";
|
|
2174
2174
|
|
|
2175
2175
|
// src/analyzer/class-analyzer.ts
|
|
2176
|
-
import * as
|
|
2176
|
+
import * as ts5 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 ts4 from "typescript";
|
|
2184
2184
|
|
|
2185
2185
|
// src/analyzer/tsdoc-parser.ts
|
|
2186
|
-
import * as
|
|
2186
|
+
import * as ts3 from "typescript";
|
|
2187
2187
|
import {
|
|
2188
2188
|
checkSyntheticTagApplication,
|
|
2189
2189
|
choosePreferredPayloadText,
|
|
@@ -2205,13 +2205,132 @@ import {
|
|
|
2205
2205
|
isBuiltinConstraintName
|
|
2206
2206
|
} from "@formspec/core/internals";
|
|
2207
2207
|
import "@formspec/core/internals";
|
|
2208
|
+
|
|
2209
|
+
// src/extensions/resolve-custom-type.ts
|
|
2210
|
+
import * as ts2 from "typescript";
|
|
2211
|
+
import { stripNullishUnion } from "@formspec/analysis/internal";
|
|
2212
|
+
|
|
2213
|
+
// src/extensions/ts-type-utils.ts
|
|
2214
|
+
import * as ts from "typescript";
|
|
2215
|
+
function collectBrandIdentifiers(type) {
|
|
2216
|
+
if (!type.isIntersection()) {
|
|
2217
|
+
return [];
|
|
2218
|
+
}
|
|
2219
|
+
const brands = [];
|
|
2220
|
+
for (const prop of type.getProperties()) {
|
|
2221
|
+
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
2222
|
+
if (decl === void 0) continue;
|
|
2223
|
+
if (!ts.isPropertySignature(decl) && !ts.isPropertyDeclaration(decl)) continue;
|
|
2224
|
+
if (!ts.isComputedPropertyName(decl.name)) continue;
|
|
2225
|
+
if (!ts.isIdentifier(decl.name.expression)) continue;
|
|
2226
|
+
brands.push(decl.name.expression.text);
|
|
2227
|
+
}
|
|
2228
|
+
return brands;
|
|
2229
|
+
}
|
|
2230
|
+
function resolveCanonicalSymbol(type, checker) {
|
|
2231
|
+
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
2232
|
+
if (raw === void 0) return void 0;
|
|
2233
|
+
return raw.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
2234
|
+
}
|
|
2235
|
+
function extractTypeNodeFromSource(sourceNode) {
|
|
2236
|
+
if (ts.isPropertyDeclaration(sourceNode) || ts.isPropertySignature(sourceNode) || ts.isParameter(sourceNode) || ts.isTypeAliasDeclaration(sourceNode)) {
|
|
2237
|
+
return sourceNode.type;
|
|
2238
|
+
}
|
|
2239
|
+
if (ts.isTypeNode(sourceNode)) {
|
|
2240
|
+
return sourceNode;
|
|
2241
|
+
}
|
|
2242
|
+
return void 0;
|
|
2243
|
+
}
|
|
2244
|
+
function resolveAliasedSymbol(symbol, checker) {
|
|
2245
|
+
if (symbol === void 0) return void 0;
|
|
2246
|
+
return symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
2247
|
+
}
|
|
2248
|
+
function getTypeAliasDeclarationFromTypeReference(typeNode, checker) {
|
|
2249
|
+
const symbol = checker.getSymbolAtLocation(typeNode.typeName);
|
|
2250
|
+
return resolveAliasedSymbol(symbol, checker)?.declarations?.find(ts.isTypeAliasDeclaration);
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
// src/extensions/resolve-custom-type.ts
|
|
2254
|
+
function getTypeNodeRegistrationName(typeNode) {
|
|
2255
|
+
if (ts2.isTypeReferenceNode(typeNode)) {
|
|
2256
|
+
return ts2.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : typeNode.typeName.right.text;
|
|
2257
|
+
}
|
|
2258
|
+
if (ts2.isParenthesizedTypeNode(typeNode)) {
|
|
2259
|
+
return getTypeNodeRegistrationName(typeNode.type);
|
|
2260
|
+
}
|
|
2261
|
+
if (typeNode.kind === ts2.SyntaxKind.BigIntKeyword || typeNode.kind === ts2.SyntaxKind.StringKeyword || typeNode.kind === ts2.SyntaxKind.NumberKeyword || typeNode.kind === ts2.SyntaxKind.BooleanKeyword) {
|
|
2262
|
+
return typeNode.getText();
|
|
2263
|
+
}
|
|
2264
|
+
return null;
|
|
2265
|
+
}
|
|
2266
|
+
function resolveByNameFromTypeNode(typeNode, registry, checker) {
|
|
2267
|
+
if (ts2.isParenthesizedTypeNode(typeNode)) {
|
|
2268
|
+
return resolveByNameFromTypeNode(typeNode.type, registry, checker);
|
|
2269
|
+
}
|
|
2270
|
+
const typeName = getTypeNodeRegistrationName(typeNode);
|
|
2271
|
+
if (typeName !== null) {
|
|
2272
|
+
const byName = registry.findTypeByName(typeName);
|
|
2273
|
+
if (byName !== void 0) {
|
|
2274
|
+
return byName;
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
if (ts2.isTypeReferenceNode(typeNode) && ts2.isIdentifier(typeNode.typeName)) {
|
|
2278
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
2279
|
+
if (aliasDecl !== void 0) {
|
|
2280
|
+
return resolveByNameFromTypeNode(aliasDecl.type, registry, checker);
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
return null;
|
|
2284
|
+
}
|
|
2285
|
+
function resolveCustomTypeFromTsType(type, checker, registry, sourceNode) {
|
|
2286
|
+
if (registry === void 0) {
|
|
2287
|
+
return null;
|
|
2288
|
+
}
|
|
2289
|
+
const stripped = stripNullishUnion(type);
|
|
2290
|
+
if (sourceNode !== void 0) {
|
|
2291
|
+
const typeNode = extractTypeNodeFromSource(sourceNode);
|
|
2292
|
+
if (typeNode !== void 0) {
|
|
2293
|
+
const byName = resolveByNameFromTypeNode(typeNode, registry, checker);
|
|
2294
|
+
if (byName !== null) {
|
|
2295
|
+
return byName;
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
} else {
|
|
2299
|
+
const typeName = (stripped.aliasSymbol ?? stripped.getSymbol())?.getName();
|
|
2300
|
+
if (typeName !== void 0) {
|
|
2301
|
+
const byName = registry.findTypeByName(typeName);
|
|
2302
|
+
if (byName !== void 0) {
|
|
2303
|
+
return byName;
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
const canonical = resolveCanonicalSymbol(stripped, checker);
|
|
2308
|
+
if (canonical !== void 0) {
|
|
2309
|
+
const bySymbol = registry.findTypeBySymbol(canonical);
|
|
2310
|
+
if (bySymbol !== void 0) {
|
|
2311
|
+
return bySymbol;
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
for (const brand of collectBrandIdentifiers(stripped)) {
|
|
2315
|
+
const byBrand = registry.findTypeByBrand(brand);
|
|
2316
|
+
if (byBrand !== void 0) {
|
|
2317
|
+
return byBrand;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
return null;
|
|
2321
|
+
}
|
|
2322
|
+
function customTypeIdFromLookup(result) {
|
|
2323
|
+
return `${result.extensionId}/${result.registration.typeName}`;
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
// src/analyzer/tsdoc-parser.ts
|
|
2208
2327
|
function sharedTagValueOptions(options) {
|
|
2209
2328
|
return {
|
|
2210
2329
|
...options?.extensionRegistry !== void 0 ? { registry: options.extensionRegistry } : {},
|
|
2211
2330
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2212
2331
|
};
|
|
2213
2332
|
}
|
|
2214
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
2333
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2215
2334
|
function getExtensionTypeNames(registry) {
|
|
2216
2335
|
if (registry === void 0) {
|
|
2217
2336
|
return /* @__PURE__ */ new Set();
|
|
@@ -2225,23 +2344,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2225
2344
|
function collectImportedNames(sourceFile) {
|
|
2226
2345
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2227
2346
|
for (const statement of sourceFile.statements) {
|
|
2228
|
-
if (
|
|
2347
|
+
if (ts3.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2229
2348
|
const clause = statement.importClause;
|
|
2230
2349
|
if (clause.name !== void 0) {
|
|
2231
2350
|
importedNames.add(clause.name.text);
|
|
2232
2351
|
}
|
|
2233
2352
|
if (clause.namedBindings !== void 0) {
|
|
2234
|
-
if (
|
|
2353
|
+
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
2235
2354
|
for (const specifier of clause.namedBindings.elements) {
|
|
2236
2355
|
importedNames.add(specifier.name.text);
|
|
2237
2356
|
}
|
|
2238
|
-
} else if (
|
|
2357
|
+
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
2239
2358
|
importedNames.add(clause.namedBindings.name.text);
|
|
2240
2359
|
}
|
|
2241
2360
|
}
|
|
2242
2361
|
continue;
|
|
2243
2362
|
}
|
|
2244
|
-
if (
|
|
2363
|
+
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
2245
2364
|
importedNames.add(statement.name.text);
|
|
2246
2365
|
}
|
|
2247
2366
|
}
|
|
@@ -2249,13 +2368,13 @@ function collectImportedNames(sourceFile) {
|
|
|
2249
2368
|
}
|
|
2250
2369
|
function isNonReferenceIdentifier(node) {
|
|
2251
2370
|
const parent = node.parent;
|
|
2252
|
-
if ((
|
|
2371
|
+
if ((ts3.isBindingElement(parent) || ts3.isClassDeclaration(parent) || ts3.isEnumDeclaration(parent) || ts3.isEnumMember(parent) || ts3.isFunctionDeclaration(parent) || ts3.isFunctionExpression(parent) || ts3.isImportClause(parent) || ts3.isImportEqualsDeclaration(parent) || ts3.isImportSpecifier(parent) || ts3.isInterfaceDeclaration(parent) || ts3.isMethodDeclaration(parent) || ts3.isMethodSignature(parent) || ts3.isModuleDeclaration(parent) || ts3.isNamespaceExport(parent) || ts3.isNamespaceImport(parent) || ts3.isParameter(parent) || ts3.isPropertyDeclaration(parent) || ts3.isPropertySignature(parent) || ts3.isSetAccessorDeclaration(parent) || ts3.isGetAccessorDeclaration(parent) || ts3.isTypeAliasDeclaration(parent) || ts3.isTypeParameterDeclaration(parent) || ts3.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2253
2372
|
return true;
|
|
2254
2373
|
}
|
|
2255
|
-
if ((
|
|
2374
|
+
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2256
2375
|
return true;
|
|
2257
2376
|
}
|
|
2258
|
-
if (
|
|
2377
|
+
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
2259
2378
|
return true;
|
|
2260
2379
|
}
|
|
2261
2380
|
return false;
|
|
@@ -2269,11 +2388,11 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
2269
2388
|
if (referencesImportedName) {
|
|
2270
2389
|
return;
|
|
2271
2390
|
}
|
|
2272
|
-
if (
|
|
2391
|
+
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2273
2392
|
referencesImportedName = true;
|
|
2274
2393
|
return;
|
|
2275
2394
|
}
|
|
2276
|
-
|
|
2395
|
+
ts3.forEachChild(node, visit);
|
|
2277
2396
|
};
|
|
2278
2397
|
visit(statement);
|
|
2279
2398
|
return referencesImportedName;
|
|
@@ -2284,9 +2403,9 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
2284
2403
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2285
2404
|
);
|
|
2286
2405
|
return sourceFile.statements.filter((statement) => {
|
|
2287
|
-
if (
|
|
2288
|
-
if (
|
|
2289
|
-
if (
|
|
2406
|
+
if (ts3.isImportDeclaration(statement)) return false;
|
|
2407
|
+
if (ts3.isImportEqualsDeclaration(statement)) return false;
|
|
2408
|
+
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
2290
2409
|
return false;
|
|
2291
2410
|
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2292
2411
|
return false;
|
|
@@ -2384,7 +2503,7 @@ function stripHintNullishUnion(type) {
|
|
|
2384
2503
|
return type;
|
|
2385
2504
|
}
|
|
2386
2505
|
const nonNullish = type.types.filter(
|
|
2387
|
-
(member) => (member.flags & (
|
|
2506
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
2388
2507
|
);
|
|
2389
2508
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2390
2509
|
return nonNullish[0];
|
|
@@ -2400,10 +2519,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2400
2519
|
}
|
|
2401
2520
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2402
2521
|
const name = declaration.name;
|
|
2403
|
-
if (
|
|
2522
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
2404
2523
|
return false;
|
|
2405
2524
|
}
|
|
2406
|
-
if (!
|
|
2525
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
2407
2526
|
return false;
|
|
2408
2527
|
}
|
|
2409
2528
|
}
|
|
@@ -2575,7 +2694,8 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2575
2694
|
];
|
|
2576
2695
|
}
|
|
2577
2696
|
const target = parsedTag?.target ?? null;
|
|
2578
|
-
|
|
2697
|
+
let evaluatedType = subjectType;
|
|
2698
|
+
let targetLabel = node.getText(sourceFile);
|
|
2579
2699
|
if (target !== null) {
|
|
2580
2700
|
if (target.kind !== "path") {
|
|
2581
2701
|
return [
|
|
@@ -2615,29 +2735,30 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2615
2735
|
)
|
|
2616
2736
|
];
|
|
2617
2737
|
}
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
`Target "${target.rawText}": constraint "${tagName}" is only valid on ${capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`,
|
|
2625
|
-
provenance
|
|
2626
|
-
)
|
|
2627
|
-
];
|
|
2738
|
+
evaluatedType = resolution.type;
|
|
2739
|
+
targetLabel = target.rawText;
|
|
2740
|
+
}
|
|
2741
|
+
const hasBroadening = (() => {
|
|
2742
|
+
if (target === null) {
|
|
2743
|
+
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2628
2744
|
}
|
|
2629
|
-
|
|
2745
|
+
const registry = options?.extensionRegistry;
|
|
2746
|
+
if (registry === void 0) return false;
|
|
2747
|
+
const resolved = resolveCustomTypeFromTsType(evaluatedType, checker, registry);
|
|
2748
|
+
return resolved !== null && registry.findBuiltinConstraintBroadening(customTypeIdFromLookup(resolved), tagName) !== void 0;
|
|
2749
|
+
})();
|
|
2750
|
+
if (!hasBroadening) {
|
|
2630
2751
|
const requiredCapability = definition.capabilities[0];
|
|
2631
|
-
if (requiredCapability !== void 0 && !supportsConstraintCapability(
|
|
2632
|
-
const actualType = checker.typeToString(
|
|
2633
|
-
const baseMessage = `Target "${
|
|
2634
|
-
const hint = buildPathTargetHint(
|
|
2752
|
+
if (requiredCapability !== void 0 && !supportsConstraintCapability(evaluatedType, checker, requiredCapability)) {
|
|
2753
|
+
const actualType = checker.typeToString(evaluatedType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2754
|
+
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`;
|
|
2755
|
+
const hint = target === null ? buildPathTargetHint(
|
|
2635
2756
|
subjectType,
|
|
2636
2757
|
checker,
|
|
2637
2758
|
requiredCapability,
|
|
2638
2759
|
tagName,
|
|
2639
2760
|
parsedTag?.argumentText
|
|
2640
|
-
);
|
|
2761
|
+
) : null;
|
|
2641
2762
|
return [
|
|
2642
2763
|
makeDiagnostic(
|
|
2643
2764
|
"TYPE_MISMATCH",
|
|
@@ -2771,12 +2892,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2771
2892
|
const sourceText = sourceFile.getFullText();
|
|
2772
2893
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2773
2894
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2774
|
-
const commentRanges =
|
|
2895
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2775
2896
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2776
2897
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2777
2898
|
if (commentRanges) {
|
|
2778
2899
|
for (const range of commentRanges) {
|
|
2779
|
-
if (range.kind !==
|
|
2900
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
2780
2901
|
continue;
|
|
2781
2902
|
}
|
|
2782
2903
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -2933,10 +3054,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
2933
3054
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
2934
3055
|
const sourceFile = node.getSourceFile();
|
|
2935
3056
|
const sourceText = sourceFile.getFullText();
|
|
2936
|
-
const commentRanges =
|
|
3057
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2937
3058
|
if (commentRanges) {
|
|
2938
3059
|
for (const range of commentRanges) {
|
|
2939
|
-
if (range.kind !==
|
|
3060
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
2940
3061
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
2941
3062
|
if (!commentText.startsWith("/**")) continue;
|
|
2942
3063
|
const unified = parseUnifiedComment(commentText);
|
|
@@ -2961,7 +3082,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
2961
3082
|
}
|
|
2962
3083
|
function collectRawTextFallbacks(node, file) {
|
|
2963
3084
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
2964
|
-
for (const tag of
|
|
3085
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
2965
3086
|
const tagName = normalizeConstraintTagName2(tag.tagName.text);
|
|
2966
3087
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
2967
3088
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3016,7 +3137,7 @@ function getTagCommentText(tag) {
|
|
|
3016
3137
|
if (typeof tag.comment === "string") {
|
|
3017
3138
|
return tag.comment;
|
|
3018
3139
|
}
|
|
3019
|
-
return
|
|
3140
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
3020
3141
|
}
|
|
3021
3142
|
|
|
3022
3143
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3034,18 +3155,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3034
3155
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3035
3156
|
if (!initializer) return null;
|
|
3036
3157
|
let value;
|
|
3037
|
-
if (
|
|
3158
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
3038
3159
|
value = initializer.text;
|
|
3039
|
-
} else if (
|
|
3160
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
3040
3161
|
value = Number(initializer.text);
|
|
3041
|
-
} else if (initializer.kind ===
|
|
3162
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
3042
3163
|
value = true;
|
|
3043
|
-
} else if (initializer.kind ===
|
|
3164
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
3044
3165
|
value = false;
|
|
3045
|
-
} else if (initializer.kind ===
|
|
3166
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
3046
3167
|
value = null;
|
|
3047
|
-
} else if (
|
|
3048
|
-
if (initializer.operator ===
|
|
3168
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
3169
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
3049
3170
|
value = -Number(initializer.operand.text);
|
|
3050
3171
|
}
|
|
3051
3172
|
}
|
|
@@ -3067,93 +3188,38 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3067
3188
|
|
|
3068
3189
|
// src/analyzer/class-analyzer.ts
|
|
3069
3190
|
function isObjectType(type) {
|
|
3070
|
-
return !!(type.flags &
|
|
3191
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
3071
3192
|
}
|
|
3072
3193
|
function isIntersectionType(type) {
|
|
3073
|
-
return !!(type.flags &
|
|
3074
|
-
}
|
|
3075
|
-
function collectBrandIdentifiers(type) {
|
|
3076
|
-
if (!type.isIntersection()) {
|
|
3077
|
-
return [];
|
|
3078
|
-
}
|
|
3079
|
-
const brands = [];
|
|
3080
|
-
for (const prop of type.getProperties()) {
|
|
3081
|
-
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
3082
|
-
if (decl === void 0) continue;
|
|
3083
|
-
if (!ts3.isPropertySignature(decl) && !ts3.isPropertyDeclaration(decl)) continue;
|
|
3084
|
-
if (!ts3.isComputedPropertyName(decl.name)) continue;
|
|
3085
|
-
if (!ts3.isIdentifier(decl.name.expression)) continue;
|
|
3086
|
-
brands.push(decl.name.expression.text);
|
|
3087
|
-
}
|
|
3088
|
-
return brands;
|
|
3089
|
-
}
|
|
3090
|
-
function resolveCanonicalSymbol(type, checker) {
|
|
3091
|
-
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
3092
|
-
if (raw === void 0) return void 0;
|
|
3093
|
-
return raw.flags & ts3.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
3094
|
-
}
|
|
3095
|
-
function resolveSymbolBasedCustomType(type, extensionRegistry, checker) {
|
|
3096
|
-
if (extensionRegistry === void 0) {
|
|
3097
|
-
return null;
|
|
3098
|
-
}
|
|
3099
|
-
const canonical = resolveCanonicalSymbol(type, checker);
|
|
3100
|
-
if (canonical === void 0) {
|
|
3101
|
-
return null;
|
|
3102
|
-
}
|
|
3103
|
-
const registration = extensionRegistry.findTypeBySymbol(canonical);
|
|
3104
|
-
if (registration === void 0) {
|
|
3105
|
-
return null;
|
|
3106
|
-
}
|
|
3107
|
-
return {
|
|
3108
|
-
kind: "custom",
|
|
3109
|
-
typeId: `${registration.extensionId}/${registration.registration.typeName}`,
|
|
3110
|
-
payload: null
|
|
3111
|
-
};
|
|
3194
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
3112
3195
|
}
|
|
3113
3196
|
function isIntegerBrandedType(type) {
|
|
3114
3197
|
if (!type.isIntersection()) {
|
|
3115
3198
|
return false;
|
|
3116
3199
|
}
|
|
3117
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags &
|
|
3200
|
+
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3118
3201
|
if (!hasNumberBase) {
|
|
3119
3202
|
return false;
|
|
3120
3203
|
}
|
|
3121
3204
|
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3122
3205
|
}
|
|
3123
|
-
function resolveBrandedCustomType(type, extensionRegistry) {
|
|
3124
|
-
if (extensionRegistry === void 0) {
|
|
3125
|
-
return null;
|
|
3126
|
-
}
|
|
3127
|
-
for (const brand of collectBrandIdentifiers(type)) {
|
|
3128
|
-
const registration = extensionRegistry.findTypeByBrand(brand);
|
|
3129
|
-
if (registration === void 0) {
|
|
3130
|
-
continue;
|
|
3131
|
-
}
|
|
3132
|
-
return {
|
|
3133
|
-
kind: "custom",
|
|
3134
|
-
typeId: `${registration.extensionId}/${registration.registration.typeName}`,
|
|
3135
|
-
payload: null
|
|
3136
|
-
};
|
|
3137
|
-
}
|
|
3138
|
-
return null;
|
|
3139
|
-
}
|
|
3140
3206
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3141
|
-
if (
|
|
3207
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3142
3208
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3143
3209
|
}
|
|
3144
|
-
if (
|
|
3210
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
3145
3211
|
return true;
|
|
3146
3212
|
}
|
|
3147
|
-
return
|
|
3213
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3148
3214
|
}
|
|
3149
3215
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3150
3216
|
if (isIntersectionType(type)) {
|
|
3151
3217
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3152
3218
|
}
|
|
3153
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3219
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts5.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts5.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
3154
3220
|
}
|
|
3155
3221
|
function isTypeReference(type) {
|
|
3156
|
-
return !!(type.flags &
|
|
3222
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
3157
3223
|
}
|
|
3158
3224
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3159
3225
|
kind: "object",
|
|
@@ -3218,7 +3284,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3218
3284
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3219
3285
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3220
3286
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3221
|
-
const logicalName =
|
|
3287
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3222
3288
|
const docResult = extractJSDocParseResult(
|
|
3223
3289
|
declaration,
|
|
3224
3290
|
file,
|
|
@@ -3266,7 +3332,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3266
3332
|
const instanceMethods = [];
|
|
3267
3333
|
const staticMethods = [];
|
|
3268
3334
|
for (const member of classDecl.members) {
|
|
3269
|
-
if (
|
|
3335
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
3270
3336
|
const fieldNode = analyzeFieldToIR(
|
|
3271
3337
|
member,
|
|
3272
3338
|
checker,
|
|
@@ -3282,10 +3348,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3282
3348
|
fields.push(fieldNode);
|
|
3283
3349
|
fieldLayouts.push({});
|
|
3284
3350
|
}
|
|
3285
|
-
} else if (
|
|
3351
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
3286
3352
|
const methodInfo = analyzeMethod(member, checker);
|
|
3287
3353
|
if (methodInfo) {
|
|
3288
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3354
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
3289
3355
|
if (isStatic) {
|
|
3290
3356
|
staticMethods.push(methodInfo);
|
|
3291
3357
|
} else {
|
|
@@ -3348,7 +3414,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3348
3414
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3349
3415
|
const visiting = /* @__PURE__ */ new Set();
|
|
3350
3416
|
for (const member of interfaceDecl.members) {
|
|
3351
|
-
if (
|
|
3417
|
+
if (ts5.isPropertySignature(member)) {
|
|
3352
3418
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3353
3419
|
member,
|
|
3354
3420
|
checker,
|
|
@@ -3406,7 +3472,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3406
3472
|
if (members === null) {
|
|
3407
3473
|
const sourceFile = typeAlias.getSourceFile();
|
|
3408
3474
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3409
|
-
const kindDesc =
|
|
3475
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3410
3476
|
return {
|
|
3411
3477
|
ok: false,
|
|
3412
3478
|
kind: "not-object-like",
|
|
@@ -3441,7 +3507,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3441
3507
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3442
3508
|
const visiting = /* @__PURE__ */ new Set();
|
|
3443
3509
|
for (const member of members) {
|
|
3444
|
-
if (
|
|
3510
|
+
if (ts5.isPropertySignature(member)) {
|
|
3445
3511
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3446
3512
|
member,
|
|
3447
3513
|
checker,
|
|
@@ -3508,13 +3574,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3508
3574
|
function getLeadingParsedTags(node) {
|
|
3509
3575
|
const sourceFile = node.getSourceFile();
|
|
3510
3576
|
const sourceText = sourceFile.getFullText();
|
|
3511
|
-
const commentRanges =
|
|
3577
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3512
3578
|
if (commentRanges === void 0) {
|
|
3513
3579
|
return [];
|
|
3514
3580
|
}
|
|
3515
3581
|
const parsedTags = [];
|
|
3516
3582
|
for (const range of commentRanges) {
|
|
3517
|
-
if (range.kind !==
|
|
3583
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
3518
3584
|
continue;
|
|
3519
3585
|
}
|
|
3520
3586
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3532,19 +3598,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3532
3598
|
return null;
|
|
3533
3599
|
}
|
|
3534
3600
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3535
|
-
(candidate) =>
|
|
3601
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
3536
3602
|
) ?? propertySymbol.declarations?.[0];
|
|
3537
3603
|
return {
|
|
3538
3604
|
declaration,
|
|
3539
3605
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3540
|
-
optional: !!(propertySymbol.flags &
|
|
3606
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3541
3607
|
};
|
|
3542
3608
|
}
|
|
3543
3609
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3544
3610
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3545
3611
|
}
|
|
3546
3612
|
function isNullishSemanticType(type) {
|
|
3547
|
-
if (type.flags & (
|
|
3613
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
3548
3614
|
return true;
|
|
3549
3615
|
}
|
|
3550
3616
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3554,7 +3620,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3554
3620
|
return false;
|
|
3555
3621
|
}
|
|
3556
3622
|
seen.add(type);
|
|
3557
|
-
if (type.flags &
|
|
3623
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
3558
3624
|
return true;
|
|
3559
3625
|
}
|
|
3560
3626
|
if (type.isUnion()) {
|
|
@@ -3567,13 +3633,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3567
3633
|
return false;
|
|
3568
3634
|
}
|
|
3569
3635
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3570
|
-
if (
|
|
3636
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3571
3637
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3572
3638
|
}
|
|
3573
|
-
if (
|
|
3639
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
3574
3640
|
return [...typeNode.members];
|
|
3575
3641
|
}
|
|
3576
|
-
if (
|
|
3642
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
3577
3643
|
const members = [];
|
|
3578
3644
|
for (const intersectionMember of typeNode.types) {
|
|
3579
3645
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3736,7 +3802,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3736
3802
|
}
|
|
3737
3803
|
if (propertyType.isUnion()) {
|
|
3738
3804
|
const nonNullMembers = propertyType.types.filter(
|
|
3739
|
-
(member) => !(member.flags & (
|
|
3805
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3740
3806
|
);
|
|
3741
3807
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3742
3808
|
diagnostics.push(
|
|
@@ -3785,13 +3851,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3785
3851
|
seen.add(type);
|
|
3786
3852
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3787
3853
|
if (symbol !== void 0) {
|
|
3788
|
-
const aliased = symbol.flags &
|
|
3854
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3789
3855
|
const targetSymbol = aliased ?? symbol;
|
|
3790
3856
|
const declaration = targetSymbol.declarations?.find(
|
|
3791
|
-
(candidate) =>
|
|
3857
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
3792
3858
|
);
|
|
3793
3859
|
if (declaration !== void 0) {
|
|
3794
|
-
if (
|
|
3860
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3795
3861
|
return resolveNamedDiscriminatorDeclaration(
|
|
3796
3862
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3797
3863
|
checker,
|
|
@@ -3819,7 +3885,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3819
3885
|
}
|
|
3820
3886
|
if (boundType.isUnion()) {
|
|
3821
3887
|
const nonNullMembers = boundType.types.filter(
|
|
3822
|
-
(member) => !(member.flags & (
|
|
3888
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3823
3889
|
);
|
|
3824
3890
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3825
3891
|
diagnostics.push(
|
|
@@ -3864,7 +3930,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3864
3930
|
return null;
|
|
3865
3931
|
}
|
|
3866
3932
|
function getDeclarationName(node) {
|
|
3867
|
-
if (
|
|
3933
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
3868
3934
|
return node.name?.text ?? "anonymous";
|
|
3869
3935
|
}
|
|
3870
3936
|
return "anonymous";
|
|
@@ -3919,11 +3985,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
3919
3985
|
if (sourceTypeNode === void 0) {
|
|
3920
3986
|
return [];
|
|
3921
3987
|
}
|
|
3922
|
-
const unwrapParentheses = (typeNode) =>
|
|
3988
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
3923
3989
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
3924
|
-
const referenceTypeNode =
|
|
3990
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
3925
3991
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
3926
|
-
return
|
|
3992
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
3927
3993
|
})();
|
|
3928
3994
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
3929
3995
|
return [];
|
|
@@ -3978,7 +4044,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
3978
4044
|
);
|
|
3979
4045
|
}
|
|
3980
4046
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
3981
|
-
if (!
|
|
4047
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
3982
4048
|
return null;
|
|
3983
4049
|
}
|
|
3984
4050
|
const name = prop.name.text;
|
|
@@ -4105,7 +4171,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4105
4171
|
const seen = /* @__PURE__ */ new Set();
|
|
4106
4172
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4107
4173
|
for (const member of members) {
|
|
4108
|
-
if (!
|
|
4174
|
+
if (!ts5.isPropertySignature(member)) {
|
|
4109
4175
|
continue;
|
|
4110
4176
|
}
|
|
4111
4177
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4121,7 +4187,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4121
4187
|
return [...duplicates].sort();
|
|
4122
4188
|
}
|
|
4123
4189
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4124
|
-
if (
|
|
4190
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
4125
4191
|
return name.text;
|
|
4126
4192
|
}
|
|
4127
4193
|
return null;
|
|
@@ -4188,74 +4254,20 @@ function parseEnumMemberDisplayName(value) {
|
|
|
4188
4254
|
if (label === "") return null;
|
|
4189
4255
|
return { value: match[1], label };
|
|
4190
4256
|
}
|
|
4191
|
-
function
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
return resolveRegisteredCustomTypeFromTypeNode(typeNode, extensionRegistry, checker);
|
|
4200
|
-
}
|
|
4201
|
-
function resolveRegisteredCustomTypeFromTypeNode(typeNode, extensionRegistry, checker) {
|
|
4202
|
-
if (ts3.isParenthesizedTypeNode(typeNode)) {
|
|
4203
|
-
return resolveRegisteredCustomTypeFromTypeNode(typeNode.type, extensionRegistry, checker);
|
|
4204
|
-
}
|
|
4205
|
-
const typeName = getTypeNodeRegistrationName(typeNode);
|
|
4206
|
-
if (typeName === null) {
|
|
4207
|
-
return null;
|
|
4208
|
-
}
|
|
4209
|
-
const registration = extensionRegistry.findTypeByName(typeName);
|
|
4210
|
-
if (registration !== void 0) {
|
|
4257
|
+
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4258
|
+
const customTypeLookup = resolveCustomTypeFromTsType(
|
|
4259
|
+
type,
|
|
4260
|
+
checker,
|
|
4261
|
+
extensionRegistry,
|
|
4262
|
+
sourceNode
|
|
4263
|
+
);
|
|
4264
|
+
if (customTypeLookup !== null) {
|
|
4211
4265
|
return {
|
|
4212
4266
|
kind: "custom",
|
|
4213
|
-
typeId:
|
|
4267
|
+
typeId: customTypeIdFromLookup(customTypeLookup),
|
|
4214
4268
|
payload: null
|
|
4215
4269
|
};
|
|
4216
4270
|
}
|
|
4217
|
-
if (ts3.isTypeReferenceNode(typeNode) && ts3.isIdentifier(typeNode.typeName)) {
|
|
4218
|
-
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4219
|
-
if (aliasDecl !== void 0) {
|
|
4220
|
-
return resolveRegisteredCustomTypeFromTypeNode(aliasDecl.type, extensionRegistry, checker);
|
|
4221
|
-
}
|
|
4222
|
-
}
|
|
4223
|
-
return null;
|
|
4224
|
-
}
|
|
4225
|
-
function extractTypeNodeFromSource(sourceNode) {
|
|
4226
|
-
if (ts3.isPropertyDeclaration(sourceNode) || ts3.isPropertySignature(sourceNode) || ts3.isParameter(sourceNode) || ts3.isTypeAliasDeclaration(sourceNode)) {
|
|
4227
|
-
return sourceNode.type;
|
|
4228
|
-
}
|
|
4229
|
-
if (ts3.isTypeNode(sourceNode)) {
|
|
4230
|
-
return sourceNode;
|
|
4231
|
-
}
|
|
4232
|
-
return void 0;
|
|
4233
|
-
}
|
|
4234
|
-
function getTypeNodeRegistrationName(typeNode) {
|
|
4235
|
-
if (ts3.isTypeReferenceNode(typeNode)) {
|
|
4236
|
-
return ts3.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : typeNode.typeName.right.text;
|
|
4237
|
-
}
|
|
4238
|
-
if (ts3.isParenthesizedTypeNode(typeNode)) {
|
|
4239
|
-
return getTypeNodeRegistrationName(typeNode.type);
|
|
4240
|
-
}
|
|
4241
|
-
if (typeNode.kind === ts3.SyntaxKind.BigIntKeyword || typeNode.kind === ts3.SyntaxKind.StringKeyword || typeNode.kind === ts3.SyntaxKind.NumberKeyword || typeNode.kind === ts3.SyntaxKind.BooleanKeyword) {
|
|
4242
|
-
return typeNode.getText();
|
|
4243
|
-
}
|
|
4244
|
-
return null;
|
|
4245
|
-
}
|
|
4246
|
-
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4247
|
-
const customType = resolveRegisteredCustomType(sourceNode, extensionRegistry, checker);
|
|
4248
|
-
if (customType) {
|
|
4249
|
-
return customType;
|
|
4250
|
-
}
|
|
4251
|
-
const symbolCustomType = resolveSymbolBasedCustomType(type, extensionRegistry, checker);
|
|
4252
|
-
if (symbolCustomType) {
|
|
4253
|
-
return symbolCustomType;
|
|
4254
|
-
}
|
|
4255
|
-
const brandedCustomType = resolveBrandedCustomType(type, extensionRegistry);
|
|
4256
|
-
if (brandedCustomType) {
|
|
4257
|
-
return brandedCustomType;
|
|
4258
|
-
}
|
|
4259
4271
|
const primitiveAlias = tryResolveNamedPrimitiveAlias(
|
|
4260
4272
|
type,
|
|
4261
4273
|
checker,
|
|
@@ -4273,25 +4285,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4273
4285
|
if (isIntegerBrandedType(type)) {
|
|
4274
4286
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4275
4287
|
}
|
|
4276
|
-
if (type.flags &
|
|
4288
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4277
4289
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4278
4290
|
}
|
|
4279
|
-
if (type.flags &
|
|
4291
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4280
4292
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4281
4293
|
}
|
|
4282
|
-
if (type.flags & (
|
|
4294
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4283
4295
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4284
4296
|
}
|
|
4285
|
-
if (type.flags &
|
|
4297
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4286
4298
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4287
4299
|
}
|
|
4288
|
-
if (type.flags &
|
|
4300
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4289
4301
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4290
4302
|
}
|
|
4291
|
-
if (type.flags &
|
|
4303
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
4292
4304
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4293
4305
|
}
|
|
4294
|
-
if (type.flags &
|
|
4306
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
4295
4307
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4296
4308
|
}
|
|
4297
4309
|
if (type.isStringLiteral()) {
|
|
@@ -4378,10 +4390,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4378
4390
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4379
4391
|
}
|
|
4380
4392
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4381
|
-
if (!(type.flags & (
|
|
4393
|
+
if (!(type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4382
4394
|
return null;
|
|
4383
4395
|
}
|
|
4384
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4396
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4385
4397
|
if (!aliasDecl) {
|
|
4386
4398
|
return null;
|
|
4387
4399
|
}
|
|
@@ -4431,14 +4443,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4431
4443
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4432
4444
|
}
|
|
4433
4445
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4434
|
-
const typeNode = sourceNode && (
|
|
4435
|
-
if (!typeNode || !
|
|
4446
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4447
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
4436
4448
|
return void 0;
|
|
4437
4449
|
}
|
|
4438
4450
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4439
4451
|
}
|
|
4440
4452
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4441
|
-
if (!
|
|
4453
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
4442
4454
|
return false;
|
|
4443
4455
|
}
|
|
4444
4456
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4446,10 +4458,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4446
4458
|
return false;
|
|
4447
4459
|
}
|
|
4448
4460
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4449
|
-
return !!(resolved.flags & (
|
|
4461
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
4450
4462
|
}
|
|
4451
4463
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4452
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4464
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
4453
4465
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4454
4466
|
visitedAliases.add(nestedAliasDecl);
|
|
4455
4467
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4467,19 +4479,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4467
4479
|
if (isIntegerBrandedType(type)) {
|
|
4468
4480
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4469
4481
|
}
|
|
4470
|
-
if (type.flags &
|
|
4482
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
4471
4483
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4472
4484
|
}
|
|
4473
|
-
if (type.flags &
|
|
4485
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
4474
4486
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4475
4487
|
}
|
|
4476
|
-
if (type.flags & (
|
|
4488
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
4477
4489
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4478
4490
|
}
|
|
4479
|
-
if (type.flags &
|
|
4491
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
4480
4492
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4481
4493
|
}
|
|
4482
|
-
if (type.flags &
|
|
4494
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
4483
4495
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4484
4496
|
}
|
|
4485
4497
|
return resolveTypeNode(
|
|
@@ -4506,13 +4518,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4506
4518
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4507
4519
|
);
|
|
4508
4520
|
const nonNullTypes = allTypes.filter(
|
|
4509
|
-
(memberType) => !(memberType.flags & (
|
|
4521
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
4510
4522
|
);
|
|
4511
4523
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4512
4524
|
memberType,
|
|
4513
4525
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4514
4526
|
}));
|
|
4515
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4527
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
4516
4528
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4517
4529
|
if (namedDecl) {
|
|
4518
4530
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4555,7 +4567,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4555
4567
|
const displayName = memberDisplayNames.get(String(value));
|
|
4556
4568
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4557
4569
|
});
|
|
4558
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4570
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
4559
4571
|
if (isBooleanUnion2) {
|
|
4560
4572
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4561
4573
|
const result = hasNull ? {
|
|
@@ -4647,7 +4659,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4647
4659
|
if (type.getProperties().length > 0) {
|
|
4648
4660
|
return null;
|
|
4649
4661
|
}
|
|
4650
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4662
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
4651
4663
|
if (!indexInfo) {
|
|
4652
4664
|
return null;
|
|
4653
4665
|
}
|
|
@@ -4695,10 +4707,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4695
4707
|
}
|
|
4696
4708
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4697
4709
|
const name = declaration.name;
|
|
4698
|
-
if (
|
|
4710
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
4699
4711
|
return false;
|
|
4700
4712
|
}
|
|
4701
|
-
if (!
|
|
4713
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
4702
4714
|
return false;
|
|
4703
4715
|
}
|
|
4704
4716
|
}
|
|
@@ -4824,7 +4836,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4824
4836
|
if (!declaration) continue;
|
|
4825
4837
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4826
4838
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4827
|
-
const optional = !!(prop.flags &
|
|
4839
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
4828
4840
|
const propTypeNode = resolveTypeNode(
|
|
4829
4841
|
propType,
|
|
4830
4842
|
checker,
|
|
@@ -4837,7 +4849,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4837
4849
|
collectedDiagnostics
|
|
4838
4850
|
);
|
|
4839
4851
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4840
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
4852
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4841
4853
|
declaration,
|
|
4842
4854
|
checker,
|
|
4843
4855
|
file,
|
|
@@ -4847,7 +4859,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4847
4859
|
type,
|
|
4848
4860
|
metadataPolicy,
|
|
4849
4861
|
extensionRegistry
|
|
4850
|
-
) :
|
|
4862
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4851
4863
|
declaration,
|
|
4852
4864
|
checker,
|
|
4853
4865
|
file,
|
|
@@ -4875,7 +4887,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4875
4887
|
visiting.delete(type);
|
|
4876
4888
|
const objectNode = {
|
|
4877
4889
|
kind: "object",
|
|
4878
|
-
properties: namedDecl !== void 0 && (
|
|
4890
|
+
properties: namedDecl !== void 0 && (ts5.isClassDeclaration(namedDecl) || ts5.isInterfaceDeclaration(namedDecl) || ts5.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
4879
4891
|
properties,
|
|
4880
4892
|
namedDecl,
|
|
4881
4893
|
type,
|
|
@@ -4923,12 +4935,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4923
4935
|
for (const symbol of symbols) {
|
|
4924
4936
|
const declarations = symbol.declarations;
|
|
4925
4937
|
if (!declarations) continue;
|
|
4926
|
-
const classDecl = declarations.find(
|
|
4938
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
4927
4939
|
if (classDecl) {
|
|
4928
4940
|
const map = /* @__PURE__ */ new Map();
|
|
4929
4941
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
4930
4942
|
for (const member of classDecl.members) {
|
|
4931
|
-
if (
|
|
4943
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
4932
4944
|
const fieldNode = analyzeFieldToIR(
|
|
4933
4945
|
member,
|
|
4934
4946
|
checker,
|
|
@@ -4952,7 +4964,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4952
4964
|
}
|
|
4953
4965
|
return map;
|
|
4954
4966
|
}
|
|
4955
|
-
const interfaceDecl = declarations.find(
|
|
4967
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
4956
4968
|
if (interfaceDecl) {
|
|
4957
4969
|
return buildFieldNodeInfoMap(
|
|
4958
4970
|
interfaceDecl.members,
|
|
@@ -4966,7 +4978,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4966
4978
|
extensionRegistry
|
|
4967
4979
|
);
|
|
4968
4980
|
}
|
|
4969
|
-
const typeAliasDecl = declarations.find(
|
|
4981
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
4970
4982
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
4971
4983
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
4972
4984
|
return buildFieldNodeInfoMap(
|
|
@@ -4990,10 +5002,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
4990
5002
|
return void 0;
|
|
4991
5003
|
}
|
|
4992
5004
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
4993
|
-
if (
|
|
5005
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
4994
5006
|
return resolvedTypeNode.elementType;
|
|
4995
5007
|
}
|
|
4996
|
-
if (
|
|
5008
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
4997
5009
|
return resolvedTypeNode.typeArguments[0];
|
|
4998
5010
|
}
|
|
4999
5011
|
return void 0;
|
|
@@ -5004,13 +5016,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5004
5016
|
return [];
|
|
5005
5017
|
}
|
|
5006
5018
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5007
|
-
return
|
|
5019
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5008
5020
|
}
|
|
5009
5021
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5010
|
-
if (
|
|
5022
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
5011
5023
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5012
5024
|
}
|
|
5013
|
-
if (!
|
|
5025
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
5014
5026
|
return typeNode;
|
|
5015
5027
|
}
|
|
5016
5028
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5021,15 +5033,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5021
5033
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5022
5034
|
}
|
|
5023
5035
|
function isNullishTypeNode(typeNode) {
|
|
5024
|
-
if (typeNode.kind ===
|
|
5036
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
5025
5037
|
return true;
|
|
5026
5038
|
}
|
|
5027
|
-
return
|
|
5039
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
5028
5040
|
}
|
|
5029
5041
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5030
5042
|
const map = /* @__PURE__ */ new Map();
|
|
5031
5043
|
for (const member of members) {
|
|
5032
|
-
if (
|
|
5044
|
+
if (ts5.isPropertySignature(member)) {
|
|
5033
5045
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5034
5046
|
member,
|
|
5035
5047
|
checker,
|
|
@@ -5055,17 +5067,16 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5055
5067
|
}
|
|
5056
5068
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5057
5069
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5058
|
-
if (!
|
|
5070
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
5059
5071
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5060
5072
|
const aliasName = typeNode.typeName.getText();
|
|
5061
5073
|
throw new Error(
|
|
5062
5074
|
`Type alias chain exceeds maximum depth of ${String(MAX_ALIAS_CHAIN_DEPTH)} at alias "${aliasName}" in ${file}. Simplify the alias chain or check for circular references.`
|
|
5063
5075
|
);
|
|
5064
5076
|
}
|
|
5065
|
-
const
|
|
5066
|
-
const aliasDecl = getAliasedTypeAliasDeclaration(symbol, checker);
|
|
5077
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5067
5078
|
if (!aliasDecl) return [];
|
|
5068
|
-
if (
|
|
5079
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5069
5080
|
const aliasFieldType = resolveTypeNode(
|
|
5070
5081
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5071
5082
|
checker,
|
|
@@ -5086,18 +5097,6 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5086
5097
|
);
|
|
5087
5098
|
return constraints;
|
|
5088
5099
|
}
|
|
5089
|
-
function getAliasedSymbol(symbol, checker) {
|
|
5090
|
-
if (symbol === void 0) {
|
|
5091
|
-
return void 0;
|
|
5092
|
-
}
|
|
5093
|
-
return symbol.flags & ts3.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
5094
|
-
}
|
|
5095
|
-
function getAliasedTypeAliasDeclaration(symbol, checker) {
|
|
5096
|
-
return getAliasedSymbol(symbol, checker)?.declarations?.find(ts3.isTypeAliasDeclaration);
|
|
5097
|
-
}
|
|
5098
|
-
function getTypeAliasDeclarationFromTypeReference(typeNode, checker) {
|
|
5099
|
-
return getAliasedTypeAliasDeclaration(checker.getSymbolAtLocation(typeNode.typeName), checker);
|
|
5100
|
-
}
|
|
5101
5100
|
function provenanceForNode(node, file) {
|
|
5102
5101
|
const sourceFile = node.getSourceFile();
|
|
5103
5102
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
@@ -5121,14 +5120,14 @@ function getNamedTypeName(type) {
|
|
|
5121
5120
|
const symbol = type.getSymbol();
|
|
5122
5121
|
if (symbol?.declarations) {
|
|
5123
5122
|
const decl = symbol.declarations[0];
|
|
5124
|
-
if (decl && (
|
|
5125
|
-
const name =
|
|
5123
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5124
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5126
5125
|
if (name) return name;
|
|
5127
5126
|
}
|
|
5128
5127
|
}
|
|
5129
5128
|
const aliasSymbol = type.aliasSymbol;
|
|
5130
5129
|
if (aliasSymbol?.declarations) {
|
|
5131
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5130
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5132
5131
|
if (aliasDecl) {
|
|
5133
5132
|
return aliasDecl.name.text;
|
|
5134
5133
|
}
|
|
@@ -5139,24 +5138,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5139
5138
|
const symbol = type.getSymbol();
|
|
5140
5139
|
if (symbol?.declarations) {
|
|
5141
5140
|
const decl = symbol.declarations[0];
|
|
5142
|
-
if (decl && (
|
|
5141
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
5143
5142
|
return decl;
|
|
5144
5143
|
}
|
|
5145
5144
|
}
|
|
5146
5145
|
const aliasSymbol = type.aliasSymbol;
|
|
5147
5146
|
if (aliasSymbol?.declarations) {
|
|
5148
|
-
return aliasSymbol.declarations.find(
|
|
5147
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
5149
5148
|
}
|
|
5150
5149
|
return void 0;
|
|
5151
5150
|
}
|
|
5152
5151
|
function analyzeMethod(method, checker) {
|
|
5153
|
-
if (!
|
|
5152
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
5154
5153
|
return null;
|
|
5155
5154
|
}
|
|
5156
5155
|
const name = method.name.text;
|
|
5157
5156
|
const parameters = [];
|
|
5158
5157
|
for (const param of method.parameters) {
|
|
5159
|
-
if (
|
|
5158
|
+
if (ts5.isIdentifier(param.name)) {
|
|
5160
5159
|
const paramInfo = analyzeParameter(param, checker);
|
|
5161
5160
|
parameters.push(paramInfo);
|
|
5162
5161
|
}
|
|
@@ -5167,7 +5166,7 @@ function analyzeMethod(method, checker) {
|
|
|
5167
5166
|
return { name, parameters, returnTypeNode, returnType };
|
|
5168
5167
|
}
|
|
5169
5168
|
function analyzeParameter(param, checker) {
|
|
5170
|
-
const name =
|
|
5169
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
5171
5170
|
const typeNode = param.type;
|
|
5172
5171
|
const type = checker.getTypeAtLocation(param);
|
|
5173
5172
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5176,15 +5175,15 @@ function analyzeParameter(param, checker) {
|
|
|
5176
5175
|
}
|
|
5177
5176
|
function detectFormSpecReference(typeNode) {
|
|
5178
5177
|
if (!typeNode) return null;
|
|
5179
|
-
if (!
|
|
5180
|
-
const typeName =
|
|
5178
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
5179
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5181
5180
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5182
5181
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5183
|
-
if (!typeArg || !
|
|
5184
|
-
if (
|
|
5182
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
5183
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
5185
5184
|
return typeArg.exprName.text;
|
|
5186
5185
|
}
|
|
5187
|
-
if (
|
|
5186
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
5188
5187
|
return typeArg.exprName.right.text;
|
|
5189
5188
|
}
|
|
5190
5189
|
return null;
|
|
@@ -5206,23 +5205,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5206
5205
|
function createProgramContext(filePath, additionalFiles) {
|
|
5207
5206
|
const absolutePath = path.resolve(filePath);
|
|
5208
5207
|
const fileDir = path.dirname(absolutePath);
|
|
5209
|
-
const configPath =
|
|
5208
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
5210
5209
|
let compilerOptions;
|
|
5211
5210
|
let fileNames;
|
|
5212
5211
|
if (configPath) {
|
|
5213
|
-
const configFile =
|
|
5212
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
5214
5213
|
if (configFile.error) {
|
|
5215
5214
|
throw new Error(
|
|
5216
|
-
`Error reading tsconfig.json: ${
|
|
5215
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5217
5216
|
);
|
|
5218
5217
|
}
|
|
5219
|
-
const parsed =
|
|
5218
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
5220
5219
|
configFile.config,
|
|
5221
|
-
|
|
5220
|
+
ts6.sys,
|
|
5222
5221
|
path.dirname(configPath)
|
|
5223
5222
|
);
|
|
5224
5223
|
if (parsed.errors.length > 0) {
|
|
5225
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5224
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5226
5225
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5227
5226
|
}
|
|
5228
5227
|
compilerOptions = parsed.options;
|
|
@@ -5230,9 +5229,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5230
5229
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5231
5230
|
} else {
|
|
5232
5231
|
compilerOptions = {
|
|
5233
|
-
target:
|
|
5234
|
-
module:
|
|
5235
|
-
moduleResolution:
|
|
5232
|
+
target: ts6.ScriptTarget.ES2022,
|
|
5233
|
+
module: ts6.ModuleKind.NodeNext,
|
|
5234
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
5236
5235
|
strict: true,
|
|
5237
5236
|
skipLibCheck: true,
|
|
5238
5237
|
declaration: true
|
|
@@ -5240,7 +5239,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5240
5239
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5241
5240
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5242
5241
|
}
|
|
5243
|
-
const program =
|
|
5242
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
5244
5243
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5245
5244
|
if (!sourceFile) {
|
|
5246
5245
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5259,19 +5258,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5259
5258
|
result = node;
|
|
5260
5259
|
return;
|
|
5261
5260
|
}
|
|
5262
|
-
|
|
5261
|
+
ts6.forEachChild(node, visit);
|
|
5263
5262
|
}
|
|
5264
5263
|
visit(sourceFile);
|
|
5265
5264
|
return result;
|
|
5266
5265
|
}
|
|
5267
5266
|
function findClassByName(sourceFile, className) {
|
|
5268
|
-
return findNodeByName(sourceFile, className,
|
|
5267
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
5269
5268
|
}
|
|
5270
5269
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5271
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5270
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
5272
5271
|
}
|
|
5273
5272
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5274
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5273
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5275
5274
|
}
|
|
5276
5275
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5277
5276
|
if (rootType.kind === "object") {
|
|
@@ -5311,22 +5310,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5311
5310
|
};
|
|
5312
5311
|
}
|
|
5313
5312
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5314
|
-
if (
|
|
5313
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5315
5314
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5316
5315
|
}
|
|
5317
|
-
if (
|
|
5316
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5318
5317
|
return true;
|
|
5319
5318
|
}
|
|
5320
|
-
return
|
|
5319
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5321
5320
|
}
|
|
5322
5321
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5323
|
-
if (
|
|
5322
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5324
5323
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5325
5324
|
}
|
|
5326
|
-
if (
|
|
5325
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
5327
5326
|
const propertyNames = [];
|
|
5328
5327
|
for (const member of typeNode.members) {
|
|
5329
|
-
if (!
|
|
5328
|
+
if (!ts6.isPropertySignature(member)) {
|
|
5330
5329
|
continue;
|
|
5331
5330
|
}
|
|
5332
5331
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5336,13 +5335,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5336
5335
|
}
|
|
5337
5336
|
return propertyNames;
|
|
5338
5337
|
}
|
|
5339
|
-
if (
|
|
5338
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
5340
5339
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5341
5340
|
}
|
|
5342
5341
|
return null;
|
|
5343
5342
|
}
|
|
5344
5343
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5345
|
-
if (!
|
|
5344
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
5346
5345
|
return [];
|
|
5347
5346
|
}
|
|
5348
5347
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5543,7 +5542,7 @@ function makeFileProvenance(filePath) {
|
|
|
5543
5542
|
}
|
|
5544
5543
|
|
|
5545
5544
|
// src/extensions/symbol-registry.ts
|
|
5546
|
-
import * as
|
|
5545
|
+
import * as ts7 from "typescript";
|
|
5547
5546
|
import * as path2 from "path";
|
|
5548
5547
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5549
5548
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5553,10 +5552,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5553
5552
|
return symbolMap;
|
|
5554
5553
|
}
|
|
5555
5554
|
function visit(node) {
|
|
5556
|
-
if (
|
|
5555
|
+
if (ts7.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5557
5556
|
processDefineCustomTypeCall(node);
|
|
5558
5557
|
}
|
|
5559
|
-
|
|
5558
|
+
ts7.forEachChild(node, visit);
|
|
5560
5559
|
}
|
|
5561
5560
|
function processDefineCustomTypeCall(call) {
|
|
5562
5561
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5564,7 +5563,7 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5564
5563
|
return;
|
|
5565
5564
|
}
|
|
5566
5565
|
const resolvedType = checker.getTypeFromTypeNode(typeArgNode);
|
|
5567
|
-
const canonical =
|
|
5566
|
+
const canonical = resolveCanonicalSymbol(resolvedType, checker);
|
|
5568
5567
|
if (canonical === void 0) {
|
|
5569
5568
|
return;
|
|
5570
5569
|
}
|
|
@@ -5593,7 +5592,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5593
5592
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5594
5593
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5595
5594
|
if (callSymbol !== void 0) {
|
|
5596
|
-
const resolved = callSymbol.flags &
|
|
5595
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5597
5596
|
const decl = resolved.declarations?.[0];
|
|
5598
5597
|
if (decl !== void 0) {
|
|
5599
5598
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5601,29 +5600,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5601
5600
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5602
5601
|
}
|
|
5603
5602
|
}
|
|
5604
|
-
return
|
|
5605
|
-
}
|
|
5606
|
-
function resolveCanonicalSymbol2(type, checker) {
|
|
5607
|
-
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
5608
|
-
if (raw === void 0) return void 0;
|
|
5609
|
-
return raw.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
5603
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5610
5604
|
}
|
|
5611
5605
|
function extractTypeNameFromCallArg(call) {
|
|
5612
5606
|
const arg = call.arguments[0];
|
|
5613
|
-
if (arg === void 0 || !
|
|
5607
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5614
5608
|
return null;
|
|
5615
5609
|
}
|
|
5616
5610
|
const typeNameProp = arg.properties.find(
|
|
5617
|
-
(p) =>
|
|
5611
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5618
5612
|
);
|
|
5619
|
-
if (typeNameProp === void 0 || !
|
|
5613
|
+
if (typeNameProp === void 0 || !ts7.isStringLiteral(typeNameProp.initializer)) {
|
|
5620
5614
|
return null;
|
|
5621
5615
|
}
|
|
5622
5616
|
return typeNameProp.initializer.text;
|
|
5623
5617
|
}
|
|
5624
5618
|
function extractEnclosingExtensionId(call, checker) {
|
|
5625
|
-
for (let node = call.parent; !
|
|
5626
|
-
if (
|
|
5619
|
+
for (let node = call.parent; !ts7.isSourceFile(node); node = node.parent) {
|
|
5620
|
+
if (ts7.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5627
5621
|
return extractExtensionIdFromCallArg(node);
|
|
5628
5622
|
}
|
|
5629
5623
|
}
|
|
@@ -5632,24 +5626,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5632
5626
|
function isDefineExtensionCall(node, checker) {
|
|
5633
5627
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5634
5628
|
if (callSymbol !== void 0) {
|
|
5635
|
-
const resolved = callSymbol.flags &
|
|
5629
|
+
const resolved = callSymbol.flags & ts7.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5636
5630
|
const decl = resolved.declarations?.[0];
|
|
5637
5631
|
if (decl !== void 0) {
|
|
5638
5632
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5639
5633
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5640
5634
|
}
|
|
5641
5635
|
}
|
|
5642
|
-
return
|
|
5636
|
+
return ts7.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5643
5637
|
}
|
|
5644
5638
|
function extractExtensionIdFromCallArg(call) {
|
|
5645
5639
|
const arg = call.arguments[0];
|
|
5646
|
-
if (arg === void 0 || !
|
|
5640
|
+
if (arg === void 0 || !ts7.isObjectLiteralExpression(arg)) {
|
|
5647
5641
|
return null;
|
|
5648
5642
|
}
|
|
5649
5643
|
const prop = arg.properties.find(
|
|
5650
|
-
(p) =>
|
|
5644
|
+
(p) => ts7.isPropertyAssignment(p) && ts7.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5651
5645
|
);
|
|
5652
|
-
if (prop === void 0 || !
|
|
5646
|
+
if (prop === void 0 || !ts7.isStringLiteral(prop.initializer)) {
|
|
5653
5647
|
return null;
|
|
5654
5648
|
}
|
|
5655
5649
|
return prop.initializer.text;
|
|
@@ -5911,7 +5905,7 @@ function generateSchemasBatch(options) {
|
|
|
5911
5905
|
return options.targets.map((target) => {
|
|
5912
5906
|
let ctx;
|
|
5913
5907
|
try {
|
|
5914
|
-
const cacheKey =
|
|
5908
|
+
const cacheKey = ts8.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
5915
5909
|
const cachedContext = contextCache.get(cacheKey);
|
|
5916
5910
|
if (cachedContext === void 0) {
|
|
5917
5911
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6067,7 +6061,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6067
6061
|
}
|
|
6068
6062
|
|
|
6069
6063
|
// src/static-build.ts
|
|
6070
|
-
import * as
|
|
6064
|
+
import * as ts9 from "typescript";
|
|
6071
6065
|
function toStaticBuildContext(context) {
|
|
6072
6066
|
return context;
|
|
6073
6067
|
}
|
|
@@ -6082,7 +6076,7 @@ function getModuleSymbol(context) {
|
|
|
6082
6076
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6083
6077
|
}
|
|
6084
6078
|
function isSchemaSourceDeclaration(declaration) {
|
|
6085
|
-
return
|
|
6079
|
+
return ts9.isClassDeclaration(declaration) || ts9.isInterfaceDeclaration(declaration) || ts9.isTypeAliasDeclaration(declaration);
|
|
6086
6080
|
}
|
|
6087
6081
|
function resolveModuleExport(context, exportName = "default") {
|
|
6088
6082
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6093,14 +6087,14 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6093
6087
|
if (exportSymbol === null) {
|
|
6094
6088
|
return null;
|
|
6095
6089
|
}
|
|
6096
|
-
return exportSymbol.flags &
|
|
6090
|
+
return exportSymbol.flags & ts9.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6097
6091
|
}
|
|
6098
6092
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6099
6093
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6100
6094
|
}
|
|
6101
6095
|
|
|
6102
6096
|
// src/generators/discovered-schema.ts
|
|
6103
|
-
import * as
|
|
6097
|
+
import * as ts10 from "typescript";
|
|
6104
6098
|
import { analyzeMetadataForNodeWithChecker as analyzeMetadataForNodeWithChecker2 } from "@formspec/analysis/internal";
|
|
6105
6099
|
import { IR_VERSION as IR_VERSION3 } from "@formspec/core/internals";
|
|
6106
6100
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
@@ -6110,17 +6104,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6110
6104
|
};
|
|
6111
6105
|
}
|
|
6112
6106
|
function isNamedTypeDeclaration(declaration) {
|
|
6113
|
-
return
|
|
6107
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6114
6108
|
}
|
|
6115
6109
|
function hasConcreteTypeArguments(type, checker) {
|
|
6116
6110
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6117
6111
|
return true;
|
|
6118
6112
|
}
|
|
6119
|
-
if ((type.flags &
|
|
6113
|
+
if ((type.flags & ts10.TypeFlags.Object) === 0) {
|
|
6120
6114
|
return false;
|
|
6121
6115
|
}
|
|
6122
6116
|
const objectType = type;
|
|
6123
|
-
if ((objectType.objectFlags &
|
|
6117
|
+
if ((objectType.objectFlags & ts10.ObjectFlags.Reference) === 0) {
|
|
6124
6118
|
return false;
|
|
6125
6119
|
}
|
|
6126
6120
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6133,13 +6127,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6133
6127
|
return declaration;
|
|
6134
6128
|
}
|
|
6135
6129
|
}
|
|
6136
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6130
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts10.isTypeAliasDeclaration);
|
|
6137
6131
|
return aliasDeclaration;
|
|
6138
6132
|
}
|
|
6139
6133
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6140
6134
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6141
6135
|
const namedNode = sourceNode;
|
|
6142
|
-
if (namedNode.name !== void 0 &&
|
|
6136
|
+
if (namedNode.name !== void 0 && ts10.isIdentifier(namedNode.name)) {
|
|
6143
6137
|
return namedNode.name.text;
|
|
6144
6138
|
}
|
|
6145
6139
|
}
|
|
@@ -6361,7 +6355,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6361
6355
|
function generateSchemasFromDeclaration(options) {
|
|
6362
6356
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6363
6357
|
const resolved = resolveStaticOptions(options);
|
|
6364
|
-
if (
|
|
6358
|
+
if (ts10.isClassDeclaration(options.declaration)) {
|
|
6365
6359
|
return generateSchemasFromAnalysis(
|
|
6366
6360
|
analyzeClassToIR(
|
|
6367
6361
|
options.declaration,
|
|
@@ -6375,7 +6369,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6375
6369
|
resolved
|
|
6376
6370
|
);
|
|
6377
6371
|
}
|
|
6378
|
-
if (
|
|
6372
|
+
if (ts10.isInterfaceDeclaration(options.declaration)) {
|
|
6379
6373
|
return generateSchemasFromAnalysis(
|
|
6380
6374
|
analyzeInterfaceToIR(
|
|
6381
6375
|
options.declaration,
|
|
@@ -6389,7 +6383,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6389
6383
|
resolved
|
|
6390
6384
|
);
|
|
6391
6385
|
}
|
|
6392
|
-
if (
|
|
6386
|
+
if (ts10.isTypeAliasDeclaration(options.declaration)) {
|
|
6393
6387
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6394
6388
|
options.declaration,
|
|
6395
6389
|
options.context.checker,
|
|
@@ -6448,7 +6442,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6448
6442
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6449
6443
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6450
6444
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6451
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6445
|
+
const fallbackName = options.declaration.name !== void 0 && ts10.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6452
6446
|
return generateSchemasFromResolvedType({
|
|
6453
6447
|
...options,
|
|
6454
6448
|
type,
|
|
@@ -6495,14 +6489,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6495
6489
|
if (typeNode === void 0) {
|
|
6496
6490
|
return void 0;
|
|
6497
6491
|
}
|
|
6498
|
-
if (
|
|
6492
|
+
if (ts10.isParenthesizedTypeNode(typeNode)) {
|
|
6499
6493
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6500
6494
|
return unwrapped ?? typeNode;
|
|
6501
6495
|
}
|
|
6502
6496
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6503
6497
|
}
|
|
6504
6498
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6505
|
-
return
|
|
6499
|
+
return ts10.isTypeReferenceNode(typeNode) && ts10.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6506
6500
|
}
|
|
6507
6501
|
|
|
6508
6502
|
// src/generators/mixed-authoring.ts
|