@formspec/build 0.1.0-alpha.51 → 0.1.0-alpha.53
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/browser.cjs +17 -0
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +8 -2
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +19 -0
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +21 -0
- package/dist/build-beta.d.ts +21 -0
- package/dist/build-internal.d.ts +21 -0
- package/dist/build.d.ts +21 -0
- package/dist/cli/logger.d.ts +22 -0
- package/dist/cli/logger.d.ts.map +1 -0
- package/dist/cli.cjs +326 -214
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +314 -205
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +274 -205
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +277 -205
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +219 -172
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +220 -172
- package/dist/internals.js.map +1 -1
- package/dist/json-schema/generator.d.ts +6 -1
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/ui-schema/generator.d.ts +6 -1
- package/dist/ui-schema/generator.d.ts.map +1 -1
- package/package.json +11 -5
package/dist/index.cjs
CHANGED
|
@@ -56,6 +56,10 @@ __export(index_exports, {
|
|
|
56
56
|
writeSchemas: () => writeSchemas
|
|
57
57
|
});
|
|
58
58
|
module.exports = __toCommonJS(index_exports);
|
|
59
|
+
var import_core3 = require("@formspec/core");
|
|
60
|
+
|
|
61
|
+
// src/json-schema/generator.ts
|
|
62
|
+
var import_core = require("@formspec/core");
|
|
59
63
|
|
|
60
64
|
// src/canonicalize/chain-dsl-canonicalizer.ts
|
|
61
65
|
var import_internals = require("@formspec/core/internals");
|
|
@@ -1713,10 +1717,14 @@ function assignVendorPrefixedExtensionKeywords(schema, extensionSchema, vendorPr
|
|
|
1713
1717
|
|
|
1714
1718
|
// src/json-schema/generator.ts
|
|
1715
1719
|
function generateJsonSchema(form, options) {
|
|
1720
|
+
const logger = (options?.logger ?? import_core.noopLogger).child({ stage: "ir" });
|
|
1716
1721
|
const metadata = options?.metadata;
|
|
1717
1722
|
const vendorPrefix = options?.vendorPrefix;
|
|
1718
1723
|
const enumSerialization = options?.enumSerialization;
|
|
1724
|
+
logger.debug("canonicalizing chain DSL to IR");
|
|
1719
1725
|
const ir = canonicalizeChainDSL(form, metadata !== void 0 ? { metadata } : void 0);
|
|
1726
|
+
const schemaLogger = (options?.logger ?? import_core.noopLogger).child({ stage: "schema" });
|
|
1727
|
+
schemaLogger.debug("generating JSON Schema from IR");
|
|
1720
1728
|
const internalOptions = vendorPrefix === void 0 && enumSerialization === void 0 ? void 0 : {
|
|
1721
1729
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
1722
1730
|
...enumSerialization !== void 0 && { enumSerialization }
|
|
@@ -1724,6 +1732,9 @@ function generateJsonSchema(form, options) {
|
|
|
1724
1732
|
return generateJsonSchemaFromIR(ir, internalOptions);
|
|
1725
1733
|
}
|
|
1726
1734
|
|
|
1735
|
+
// src/ui-schema/generator.ts
|
|
1736
|
+
var import_core2 = require("@formspec/core");
|
|
1737
|
+
|
|
1727
1738
|
// src/ui-schema/schema.ts
|
|
1728
1739
|
var import_zod = require("zod");
|
|
1729
1740
|
var jsonPointerSchema = import_zod.z.string();
|
|
@@ -1983,10 +1994,14 @@ function collectFieldNameMap(elements) {
|
|
|
1983
1994
|
|
|
1984
1995
|
// src/ui-schema/generator.ts
|
|
1985
1996
|
function generateUiSchema(form, options) {
|
|
1997
|
+
const logger = (options?.logger ?? import_core2.noopLogger).child({ stage: "ir" });
|
|
1998
|
+
logger.debug("canonicalizing chain DSL to IR for UI Schema generation");
|
|
1986
1999
|
const ir = canonicalizeChainDSL(
|
|
1987
2000
|
form,
|
|
1988
2001
|
options?.metadata !== void 0 ? { metadata: options.metadata } : void 0
|
|
1989
2002
|
);
|
|
2003
|
+
const schemaLogger = (options?.logger ?? import_core2.noopLogger).child({ stage: "schema" });
|
|
2004
|
+
schemaLogger.debug("generating UI Schema from IR");
|
|
1990
2005
|
return generateUiSchemaFromIR(ir);
|
|
1991
2006
|
}
|
|
1992
2007
|
|
|
@@ -2219,21 +2234,21 @@ var jsonSchema7Schema = import_zod3.z.lazy(
|
|
|
2219
2234
|
);
|
|
2220
2235
|
|
|
2221
2236
|
// src/generators/class-schema.ts
|
|
2222
|
-
var
|
|
2237
|
+
var ts9 = __toESM(require("typescript"), 1);
|
|
2223
2238
|
|
|
2224
2239
|
// src/analyzer/program.ts
|
|
2225
|
-
var
|
|
2240
|
+
var ts7 = __toESM(require("typescript"), 1);
|
|
2226
2241
|
var path = __toESM(require("path"), 1);
|
|
2227
2242
|
|
|
2228
2243
|
// src/analyzer/class-analyzer.ts
|
|
2229
|
-
var
|
|
2244
|
+
var ts6 = __toESM(require("typescript"), 1);
|
|
2230
2245
|
var import_internal4 = require("@formspec/analysis/internal");
|
|
2231
2246
|
|
|
2232
2247
|
// src/analyzer/jsdoc-constraints.ts
|
|
2233
|
-
var
|
|
2248
|
+
var ts5 = __toESM(require("typescript"), 1);
|
|
2234
2249
|
|
|
2235
2250
|
// src/analyzer/tsdoc-parser.ts
|
|
2236
|
-
var
|
|
2251
|
+
var ts4 = __toESM(require("typescript"), 1);
|
|
2237
2252
|
var import_internal3 = require("@formspec/analysis/internal");
|
|
2238
2253
|
var import_internals4 = require("@formspec/core/internals");
|
|
2239
2254
|
var import_internals5 = require("@formspec/core/internals");
|
|
@@ -2355,6 +2370,14 @@ function customTypeIdFromLookup(result) {
|
|
|
2355
2370
|
return `${result.extensionId}/${result.registration.typeName}`;
|
|
2356
2371
|
}
|
|
2357
2372
|
|
|
2373
|
+
// src/analyzer/builtin-brands.ts
|
|
2374
|
+
var ts3 = __toESM(require("typescript"), 1);
|
|
2375
|
+
function isIntegerBrandedType(type) {
|
|
2376
|
+
if (!type.isIntersection()) return false;
|
|
2377
|
+
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2378
|
+
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2358
2381
|
// src/analyzer/tsdoc-parser.ts
|
|
2359
2382
|
function sharedTagValueOptions(options) {
|
|
2360
2383
|
return {
|
|
@@ -2362,7 +2385,7 @@ function sharedTagValueOptions(options) {
|
|
|
2362
2385
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2363
2386
|
};
|
|
2364
2387
|
}
|
|
2365
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
2388
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts4.TypeFormatFlags.NoTruncation | ts4.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2366
2389
|
function getExtensionTypeNames(registry) {
|
|
2367
2390
|
if (registry === void 0) {
|
|
2368
2391
|
return /* @__PURE__ */ new Set();
|
|
@@ -2376,23 +2399,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2376
2399
|
function collectImportedNames(sourceFile) {
|
|
2377
2400
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2378
2401
|
for (const statement of sourceFile.statements) {
|
|
2379
|
-
if (
|
|
2402
|
+
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2380
2403
|
const clause = statement.importClause;
|
|
2381
2404
|
if (clause.name !== void 0) {
|
|
2382
2405
|
importedNames.add(clause.name.text);
|
|
2383
2406
|
}
|
|
2384
2407
|
if (clause.namedBindings !== void 0) {
|
|
2385
|
-
if (
|
|
2408
|
+
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
2386
2409
|
for (const specifier of clause.namedBindings.elements) {
|
|
2387
2410
|
importedNames.add(specifier.name.text);
|
|
2388
2411
|
}
|
|
2389
|
-
} else if (
|
|
2412
|
+
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
2390
2413
|
importedNames.add(clause.namedBindings.name.text);
|
|
2391
2414
|
}
|
|
2392
2415
|
}
|
|
2393
2416
|
continue;
|
|
2394
2417
|
}
|
|
2395
|
-
if (
|
|
2418
|
+
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
2396
2419
|
importedNames.add(statement.name.text);
|
|
2397
2420
|
}
|
|
2398
2421
|
}
|
|
@@ -2400,50 +2423,96 @@ function collectImportedNames(sourceFile) {
|
|
|
2400
2423
|
}
|
|
2401
2424
|
function isNonReferenceIdentifier(node) {
|
|
2402
2425
|
const parent = node.parent;
|
|
2403
|
-
if ((
|
|
2426
|
+
if ((ts4.isBindingElement(parent) || ts4.isClassDeclaration(parent) || ts4.isEnumDeclaration(parent) || ts4.isEnumMember(parent) || ts4.isFunctionDeclaration(parent) || ts4.isFunctionExpression(parent) || ts4.isImportClause(parent) || ts4.isImportEqualsDeclaration(parent) || ts4.isImportSpecifier(parent) || ts4.isInterfaceDeclaration(parent) || ts4.isMethodDeclaration(parent) || ts4.isMethodSignature(parent) || ts4.isModuleDeclaration(parent) || ts4.isNamespaceExport(parent) || ts4.isNamespaceImport(parent) || ts4.isParameter(parent) || ts4.isPropertyDeclaration(parent) || ts4.isPropertySignature(parent) || ts4.isSetAccessorDeclaration(parent) || ts4.isGetAccessorDeclaration(parent) || ts4.isTypeAliasDeclaration(parent) || ts4.isTypeParameterDeclaration(parent) || ts4.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2404
2427
|
return true;
|
|
2405
2428
|
}
|
|
2406
|
-
if ((
|
|
2429
|
+
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2407
2430
|
return true;
|
|
2408
2431
|
}
|
|
2409
|
-
if (
|
|
2432
|
+
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
2410
2433
|
return true;
|
|
2411
2434
|
}
|
|
2412
2435
|
return false;
|
|
2413
2436
|
}
|
|
2414
|
-
function
|
|
2437
|
+
function astReferencesImportedName(root, importedNames) {
|
|
2415
2438
|
if (importedNames.size === 0) {
|
|
2416
2439
|
return false;
|
|
2417
2440
|
}
|
|
2418
|
-
let
|
|
2441
|
+
let found = false;
|
|
2419
2442
|
const visit = (node) => {
|
|
2420
|
-
if (
|
|
2443
|
+
if (found) return;
|
|
2444
|
+
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2445
|
+
found = true;
|
|
2421
2446
|
return;
|
|
2422
2447
|
}
|
|
2423
|
-
|
|
2424
|
-
referencesImportedName = true;
|
|
2425
|
-
return;
|
|
2426
|
-
}
|
|
2427
|
-
ts3.forEachChild(node, visit);
|
|
2448
|
+
ts4.forEachChild(node, visit);
|
|
2428
2449
|
};
|
|
2429
|
-
visit(
|
|
2430
|
-
return
|
|
2450
|
+
visit(root);
|
|
2451
|
+
return found;
|
|
2452
|
+
}
|
|
2453
|
+
function getObjectMembers(statement) {
|
|
2454
|
+
if (ts4.isInterfaceDeclaration(statement)) {
|
|
2455
|
+
return statement.members;
|
|
2456
|
+
}
|
|
2457
|
+
if (ts4.isTypeLiteralNode(statement.type)) {
|
|
2458
|
+
return statement.type.members;
|
|
2459
|
+
}
|
|
2460
|
+
return void 0;
|
|
2461
|
+
}
|
|
2462
|
+
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
2463
|
+
const members = getObjectMembers(statement);
|
|
2464
|
+
if (members === void 0) {
|
|
2465
|
+
return null;
|
|
2466
|
+
}
|
|
2467
|
+
const replacements = [];
|
|
2468
|
+
for (const member of members) {
|
|
2469
|
+
if (!ts4.isPropertySignature(member)) {
|
|
2470
|
+
if (astReferencesImportedName(member, importedNames)) {
|
|
2471
|
+
return null;
|
|
2472
|
+
}
|
|
2473
|
+
continue;
|
|
2474
|
+
}
|
|
2475
|
+
const typeAnnotation = member.type;
|
|
2476
|
+
if (typeAnnotation === void 0) continue;
|
|
2477
|
+
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
2478
|
+
replacements.push({
|
|
2479
|
+
start: typeAnnotation.getStart(sourceFile),
|
|
2480
|
+
end: typeAnnotation.getEnd()
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
if (replacements.length === 0) {
|
|
2485
|
+
return statement.getText(sourceFile);
|
|
2486
|
+
}
|
|
2487
|
+
const stmtStart = statement.getStart(sourceFile);
|
|
2488
|
+
let result = statement.getText(sourceFile);
|
|
2489
|
+
for (const { start, end } of [...replacements].reverse()) {
|
|
2490
|
+
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
2491
|
+
}
|
|
2492
|
+
return result;
|
|
2431
2493
|
}
|
|
2432
2494
|
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
2433
2495
|
const importedNames = collectImportedNames(sourceFile);
|
|
2434
2496
|
const importedNamesToSkip = new Set(
|
|
2435
2497
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2436
2498
|
);
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
if (
|
|
2440
|
-
if (
|
|
2441
|
-
|
|
2442
|
-
if (
|
|
2443
|
-
|
|
2499
|
+
const result = [];
|
|
2500
|
+
for (const statement of sourceFile.statements) {
|
|
2501
|
+
if (ts4.isImportDeclaration(statement)) continue;
|
|
2502
|
+
if (ts4.isImportEqualsDeclaration(statement)) continue;
|
|
2503
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2504
|
+
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2505
|
+
result.push(statement.getText(sourceFile));
|
|
2506
|
+
continue;
|
|
2444
2507
|
}
|
|
2445
|
-
|
|
2446
|
-
|
|
2508
|
+
if (ts4.isInterfaceDeclaration(statement) || ts4.isTypeAliasDeclaration(statement)) {
|
|
2509
|
+
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2510
|
+
if (rewritten !== null) {
|
|
2511
|
+
result.push(rewritten);
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
return result;
|
|
2447
2516
|
}
|
|
2448
2517
|
function pushUniqueCompilerDiagnostics(target, additions) {
|
|
2449
2518
|
for (const diagnostic of additions) {
|
|
@@ -2535,7 +2604,7 @@ function stripHintNullishUnion(type) {
|
|
|
2535
2604
|
return type;
|
|
2536
2605
|
}
|
|
2537
2606
|
const nonNullish = type.types.filter(
|
|
2538
|
-
(member) => (member.flags & (
|
|
2607
|
+
(member) => (member.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) === 0
|
|
2539
2608
|
);
|
|
2540
2609
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2541
2610
|
return nonNullish[0];
|
|
@@ -2551,10 +2620,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2551
2620
|
}
|
|
2552
2621
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2553
2622
|
const name = declaration.name;
|
|
2554
|
-
if (
|
|
2623
|
+
if (ts4.isComputedPropertyName(name) || ts4.isPrivateIdentifier(name)) {
|
|
2555
2624
|
return false;
|
|
2556
2625
|
}
|
|
2557
|
-
if (!
|
|
2626
|
+
if (!ts4.isIdentifier(name) && !ts4.isStringLiteral(name) && !ts4.isNumericLiteral(name)) {
|
|
2558
2627
|
return false;
|
|
2559
2628
|
}
|
|
2560
2629
|
}
|
|
@@ -2772,6 +2841,9 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2772
2841
|
}
|
|
2773
2842
|
const hasBroadening = (() => {
|
|
2774
2843
|
if (target === null) {
|
|
2844
|
+
if (isIntegerBrandedType((0, import_internal3.stripNullishUnion)(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2845
|
+
return true;
|
|
2846
|
+
}
|
|
2775
2847
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2776
2848
|
}
|
|
2777
2849
|
const registry = options?.extensionRegistry;
|
|
@@ -2924,12 +2996,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2924
2996
|
const sourceText = sourceFile.getFullText();
|
|
2925
2997
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2926
2998
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2927
|
-
const commentRanges =
|
|
2999
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2928
3000
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2929
3001
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2930
3002
|
if (commentRanges) {
|
|
2931
3003
|
for (const range of commentRanges) {
|
|
2932
|
-
if (range.kind !==
|
|
3004
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) {
|
|
2933
3005
|
continue;
|
|
2934
3006
|
}
|
|
2935
3007
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3086,10 +3158,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3086
3158
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3087
3159
|
const sourceFile = node.getSourceFile();
|
|
3088
3160
|
const sourceText = sourceFile.getFullText();
|
|
3089
|
-
const commentRanges =
|
|
3161
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3090
3162
|
if (commentRanges) {
|
|
3091
3163
|
for (const range of commentRanges) {
|
|
3092
|
-
if (range.kind !==
|
|
3164
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3093
3165
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3094
3166
|
if (!commentText.startsWith("/**")) continue;
|
|
3095
3167
|
const unified = (0, import_internal3.parseUnifiedComment)(commentText);
|
|
@@ -3114,7 +3186,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3114
3186
|
}
|
|
3115
3187
|
function collectRawTextFallbacks(node, file) {
|
|
3116
3188
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3117
|
-
for (const tag of
|
|
3189
|
+
for (const tag of ts4.getJSDocTags(node)) {
|
|
3118
3190
|
const tagName = (0, import_internals4.normalizeConstraintTagName)(tag.tagName.text);
|
|
3119
3191
|
if (!import_internal3.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3120
3192
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3169,7 +3241,7 @@ function getTagCommentText(tag) {
|
|
|
3169
3241
|
if (typeof tag.comment === "string") {
|
|
3170
3242
|
return tag.comment;
|
|
3171
3243
|
}
|
|
3172
|
-
return
|
|
3244
|
+
return ts4.getTextOfJSDocComment(tag.comment);
|
|
3173
3245
|
}
|
|
3174
3246
|
|
|
3175
3247
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3187,18 +3259,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3187
3259
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3188
3260
|
if (!initializer) return null;
|
|
3189
3261
|
let value;
|
|
3190
|
-
if (
|
|
3262
|
+
if (ts5.isStringLiteral(initializer)) {
|
|
3191
3263
|
value = initializer.text;
|
|
3192
|
-
} else if (
|
|
3264
|
+
} else if (ts5.isNumericLiteral(initializer)) {
|
|
3193
3265
|
value = Number(initializer.text);
|
|
3194
|
-
} else if (initializer.kind ===
|
|
3266
|
+
} else if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
|
|
3195
3267
|
value = true;
|
|
3196
|
-
} else if (initializer.kind ===
|
|
3268
|
+
} else if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
|
|
3197
3269
|
value = false;
|
|
3198
|
-
} else if (initializer.kind ===
|
|
3270
|
+
} else if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
|
|
3199
3271
|
value = null;
|
|
3200
|
-
} else if (
|
|
3201
|
-
if (initializer.operator ===
|
|
3272
|
+
} else if (ts5.isPrefixUnaryExpression(initializer)) {
|
|
3273
|
+
if (initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
|
|
3202
3274
|
value = -Number(initializer.operand.text);
|
|
3203
3275
|
}
|
|
3204
3276
|
}
|
|
@@ -3220,38 +3292,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3220
3292
|
|
|
3221
3293
|
// src/analyzer/class-analyzer.ts
|
|
3222
3294
|
function isObjectType(type) {
|
|
3223
|
-
return !!(type.flags &
|
|
3295
|
+
return !!(type.flags & ts6.TypeFlags.Object);
|
|
3224
3296
|
}
|
|
3225
3297
|
function isIntersectionType(type) {
|
|
3226
|
-
return !!(type.flags &
|
|
3227
|
-
}
|
|
3228
|
-
function isIntegerBrandedType(type) {
|
|
3229
|
-
if (!type.isIntersection()) {
|
|
3230
|
-
return false;
|
|
3231
|
-
}
|
|
3232
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3233
|
-
if (!hasNumberBase) {
|
|
3234
|
-
return false;
|
|
3235
|
-
}
|
|
3236
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3298
|
+
return !!(type.flags & ts6.TypeFlags.Intersection);
|
|
3237
3299
|
}
|
|
3238
3300
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3239
|
-
if (
|
|
3301
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3240
3302
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3241
3303
|
}
|
|
3242
|
-
if (
|
|
3304
|
+
if (ts6.isTypeLiteralNode(typeNode) || ts6.isTypeReferenceNode(typeNode)) {
|
|
3243
3305
|
return true;
|
|
3244
3306
|
}
|
|
3245
|
-
return
|
|
3307
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3246
3308
|
}
|
|
3247
3309
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3248
3310
|
if (isIntersectionType(type)) {
|
|
3249
3311
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3250
3312
|
}
|
|
3251
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3313
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts6.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts6.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
3252
3314
|
}
|
|
3253
3315
|
function isTypeReference(type) {
|
|
3254
|
-
return !!(type.flags &
|
|
3316
|
+
return !!(type.flags & ts6.TypeFlags.Object) && !!(type.objectFlags & ts6.ObjectFlags.Reference);
|
|
3255
3317
|
}
|
|
3256
3318
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3257
3319
|
kind: "object",
|
|
@@ -3316,7 +3378,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3316
3378
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3317
3379
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3318
3380
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3319
|
-
const logicalName =
|
|
3381
|
+
const logicalName = ts6.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3320
3382
|
const docResult = extractJSDocParseResult(
|
|
3321
3383
|
declaration,
|
|
3322
3384
|
file,
|
|
@@ -3364,7 +3426,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3364
3426
|
const instanceMethods = [];
|
|
3365
3427
|
const staticMethods = [];
|
|
3366
3428
|
for (const member of classDecl.members) {
|
|
3367
|
-
if (
|
|
3429
|
+
if (ts6.isPropertyDeclaration(member)) {
|
|
3368
3430
|
const fieldNode = analyzeFieldToIR(
|
|
3369
3431
|
member,
|
|
3370
3432
|
checker,
|
|
@@ -3380,10 +3442,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3380
3442
|
fields.push(fieldNode);
|
|
3381
3443
|
fieldLayouts.push({});
|
|
3382
3444
|
}
|
|
3383
|
-
} else if (
|
|
3445
|
+
} else if (ts6.isMethodDeclaration(member)) {
|
|
3384
3446
|
const methodInfo = analyzeMethod(member, checker);
|
|
3385
3447
|
if (methodInfo) {
|
|
3386
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3448
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts6.SyntaxKind.StaticKeyword);
|
|
3387
3449
|
if (isStatic) {
|
|
3388
3450
|
staticMethods.push(methodInfo);
|
|
3389
3451
|
} else {
|
|
@@ -3446,7 +3508,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3446
3508
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3447
3509
|
const visiting = /* @__PURE__ */ new Set();
|
|
3448
3510
|
for (const member of interfaceDecl.members) {
|
|
3449
|
-
if (
|
|
3511
|
+
if (ts6.isPropertySignature(member)) {
|
|
3450
3512
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3451
3513
|
member,
|
|
3452
3514
|
checker,
|
|
@@ -3504,7 +3566,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3504
3566
|
if (members === null) {
|
|
3505
3567
|
const sourceFile = typeAlias.getSourceFile();
|
|
3506
3568
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3507
|
-
const kindDesc =
|
|
3569
|
+
const kindDesc = ts6.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3508
3570
|
return {
|
|
3509
3571
|
ok: false,
|
|
3510
3572
|
kind: "not-object-like",
|
|
@@ -3539,7 +3601,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3539
3601
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3540
3602
|
const visiting = /* @__PURE__ */ new Set();
|
|
3541
3603
|
for (const member of members) {
|
|
3542
|
-
if (
|
|
3604
|
+
if (ts6.isPropertySignature(member)) {
|
|
3543
3605
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3544
3606
|
member,
|
|
3545
3607
|
checker,
|
|
@@ -3606,13 +3668,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3606
3668
|
function getLeadingParsedTags(node) {
|
|
3607
3669
|
const sourceFile = node.getSourceFile();
|
|
3608
3670
|
const sourceText = sourceFile.getFullText();
|
|
3609
|
-
const commentRanges =
|
|
3671
|
+
const commentRanges = ts6.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3610
3672
|
if (commentRanges === void 0) {
|
|
3611
3673
|
return [];
|
|
3612
3674
|
}
|
|
3613
3675
|
const parsedTags = [];
|
|
3614
3676
|
for (const range of commentRanges) {
|
|
3615
|
-
if (range.kind !==
|
|
3677
|
+
if (range.kind !== ts6.SyntaxKind.MultiLineCommentTrivia) {
|
|
3616
3678
|
continue;
|
|
3617
3679
|
}
|
|
3618
3680
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3630,19 +3692,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3630
3692
|
return null;
|
|
3631
3693
|
}
|
|
3632
3694
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3633
|
-
(candidate) =>
|
|
3695
|
+
(candidate) => ts6.isPropertyDeclaration(candidate) || ts6.isPropertySignature(candidate)
|
|
3634
3696
|
) ?? propertySymbol.declarations?.[0];
|
|
3635
3697
|
return {
|
|
3636
3698
|
declaration,
|
|
3637
3699
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3638
|
-
optional: !!(propertySymbol.flags &
|
|
3700
|
+
optional: !!(propertySymbol.flags & ts6.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3639
3701
|
};
|
|
3640
3702
|
}
|
|
3641
3703
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3642
3704
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3643
3705
|
}
|
|
3644
3706
|
function isNullishSemanticType(type) {
|
|
3645
|
-
if (type.flags & (
|
|
3707
|
+
if (type.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined | ts6.TypeFlags.Void | ts6.TypeFlags.Unknown | ts6.TypeFlags.Any)) {
|
|
3646
3708
|
return true;
|
|
3647
3709
|
}
|
|
3648
3710
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3652,7 +3714,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3652
3714
|
return false;
|
|
3653
3715
|
}
|
|
3654
3716
|
seen.add(type);
|
|
3655
|
-
if (type.flags &
|
|
3717
|
+
if (type.flags & ts6.TypeFlags.StringLike) {
|
|
3656
3718
|
return true;
|
|
3657
3719
|
}
|
|
3658
3720
|
if (type.isUnion()) {
|
|
@@ -3665,13 +3727,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3665
3727
|
return false;
|
|
3666
3728
|
}
|
|
3667
3729
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3668
|
-
if (
|
|
3730
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3669
3731
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3670
3732
|
}
|
|
3671
|
-
if (
|
|
3733
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
3672
3734
|
return [...typeNode.members];
|
|
3673
3735
|
}
|
|
3674
|
-
if (
|
|
3736
|
+
if (ts6.isIntersectionTypeNode(typeNode)) {
|
|
3675
3737
|
const members = [];
|
|
3676
3738
|
for (const intersectionMember of typeNode.types) {
|
|
3677
3739
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3834,7 +3896,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3834
3896
|
}
|
|
3835
3897
|
if (propertyType.isUnion()) {
|
|
3836
3898
|
const nonNullMembers = propertyType.types.filter(
|
|
3837
|
-
(member) => !(member.flags & (
|
|
3899
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3838
3900
|
);
|
|
3839
3901
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3840
3902
|
diagnostics.push(
|
|
@@ -3883,13 +3945,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3883
3945
|
seen.add(type);
|
|
3884
3946
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3885
3947
|
if (symbol !== void 0) {
|
|
3886
|
-
const aliased = symbol.flags &
|
|
3948
|
+
const aliased = symbol.flags & ts6.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3887
3949
|
const targetSymbol = aliased ?? symbol;
|
|
3888
3950
|
const declaration = targetSymbol.declarations?.find(
|
|
3889
|
-
(candidate) =>
|
|
3951
|
+
(candidate) => ts6.isClassDeclaration(candidate) || ts6.isInterfaceDeclaration(candidate) || ts6.isTypeAliasDeclaration(candidate) || ts6.isEnumDeclaration(candidate)
|
|
3890
3952
|
);
|
|
3891
3953
|
if (declaration !== void 0) {
|
|
3892
|
-
if (
|
|
3954
|
+
if (ts6.isTypeAliasDeclaration(declaration) && ts6.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3893
3955
|
return resolveNamedDiscriminatorDeclaration(
|
|
3894
3956
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3895
3957
|
checker,
|
|
@@ -3917,7 +3979,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3917
3979
|
}
|
|
3918
3980
|
if (boundType.isUnion()) {
|
|
3919
3981
|
const nonNullMembers = boundType.types.filter(
|
|
3920
|
-
(member) => !(member.flags & (
|
|
3982
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3921
3983
|
);
|
|
3922
3984
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3923
3985
|
diagnostics.push(
|
|
@@ -3962,7 +4024,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3962
4024
|
return null;
|
|
3963
4025
|
}
|
|
3964
4026
|
function getDeclarationName(node) {
|
|
3965
|
-
if (
|
|
4027
|
+
if (ts6.isClassDeclaration(node) || ts6.isInterfaceDeclaration(node) || ts6.isTypeAliasDeclaration(node) || ts6.isEnumDeclaration(node)) {
|
|
3966
4028
|
return node.name?.text ?? "anonymous";
|
|
3967
4029
|
}
|
|
3968
4030
|
return "anonymous";
|
|
@@ -4017,11 +4079,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
4017
4079
|
if (sourceTypeNode === void 0) {
|
|
4018
4080
|
return [];
|
|
4019
4081
|
}
|
|
4020
|
-
const unwrapParentheses = (typeNode) =>
|
|
4082
|
+
const unwrapParentheses = (typeNode) => ts6.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
4021
4083
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
4022
|
-
const referenceTypeNode =
|
|
4084
|
+
const referenceTypeNode = ts6.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
4023
4085
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
4024
|
-
return
|
|
4086
|
+
return ts6.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
4025
4087
|
})();
|
|
4026
4088
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
4027
4089
|
return [];
|
|
@@ -4076,7 +4138,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4076
4138
|
);
|
|
4077
4139
|
}
|
|
4078
4140
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4079
|
-
if (!
|
|
4141
|
+
if (!ts6.isIdentifier(prop.name)) {
|
|
4080
4142
|
return null;
|
|
4081
4143
|
}
|
|
4082
4144
|
const name = prop.name.text;
|
|
@@ -4203,7 +4265,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4203
4265
|
const seen = /* @__PURE__ */ new Set();
|
|
4204
4266
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4205
4267
|
for (const member of members) {
|
|
4206
|
-
if (!
|
|
4268
|
+
if (!ts6.isPropertySignature(member)) {
|
|
4207
4269
|
continue;
|
|
4208
4270
|
}
|
|
4209
4271
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4219,7 +4281,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4219
4281
|
return [...duplicates].sort();
|
|
4220
4282
|
}
|
|
4221
4283
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4222
|
-
if (
|
|
4284
|
+
if (ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNumericLiteral(name)) {
|
|
4223
4285
|
return name.text;
|
|
4224
4286
|
}
|
|
4225
4287
|
return null;
|
|
@@ -4317,25 +4379,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4317
4379
|
if (isIntegerBrandedType(type)) {
|
|
4318
4380
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4319
4381
|
}
|
|
4320
|
-
if (type.flags &
|
|
4382
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4321
4383
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4322
4384
|
}
|
|
4323
|
-
if (type.flags &
|
|
4385
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4324
4386
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4325
4387
|
}
|
|
4326
|
-
if (type.flags & (
|
|
4388
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4327
4389
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4328
4390
|
}
|
|
4329
|
-
if (type.flags &
|
|
4391
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4330
4392
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4331
4393
|
}
|
|
4332
|
-
if (type.flags &
|
|
4394
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4333
4395
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4334
4396
|
}
|
|
4335
|
-
if (type.flags &
|
|
4397
|
+
if (type.flags & ts6.TypeFlags.Undefined) {
|
|
4336
4398
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4337
4399
|
}
|
|
4338
|
-
if (type.flags &
|
|
4400
|
+
if (type.flags & ts6.TypeFlags.Void) {
|
|
4339
4401
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4340
4402
|
}
|
|
4341
4403
|
if (type.isStringLiteral()) {
|
|
@@ -4422,10 +4484,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4422
4484
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4423
4485
|
}
|
|
4424
4486
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4425
|
-
if (!(type.flags & (
|
|
4487
|
+
if (!(type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4426
4488
|
return null;
|
|
4427
4489
|
}
|
|
4428
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4490
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4429
4491
|
if (!aliasDecl) {
|
|
4430
4492
|
return null;
|
|
4431
4493
|
}
|
|
@@ -4475,14 +4537,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4475
4537
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4476
4538
|
}
|
|
4477
4539
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4478
|
-
const typeNode = sourceNode && (
|
|
4479
|
-
if (!typeNode || !
|
|
4540
|
+
const typeNode = sourceNode && (ts6.isPropertyDeclaration(sourceNode) || ts6.isPropertySignature(sourceNode) || ts6.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4541
|
+
if (!typeNode || !ts6.isTypeReferenceNode(typeNode)) {
|
|
4480
4542
|
return void 0;
|
|
4481
4543
|
}
|
|
4482
4544
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4483
4545
|
}
|
|
4484
4546
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4485
|
-
if (!
|
|
4547
|
+
if (!ts6.isTypeReferenceNode(typeNode)) {
|
|
4486
4548
|
return false;
|
|
4487
4549
|
}
|
|
4488
4550
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4490,10 +4552,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4490
4552
|
return false;
|
|
4491
4553
|
}
|
|
4492
4554
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4493
|
-
return !!(resolved.flags & (
|
|
4555
|
+
return !!(resolved.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null));
|
|
4494
4556
|
}
|
|
4495
4557
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4496
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4558
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration);
|
|
4497
4559
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4498
4560
|
visitedAliases.add(nestedAliasDecl);
|
|
4499
4561
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4511,19 +4573,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4511
4573
|
if (isIntegerBrandedType(type)) {
|
|
4512
4574
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4513
4575
|
}
|
|
4514
|
-
if (type.flags &
|
|
4576
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4515
4577
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4516
4578
|
}
|
|
4517
|
-
if (type.flags &
|
|
4579
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4518
4580
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4519
4581
|
}
|
|
4520
|
-
if (type.flags & (
|
|
4582
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4521
4583
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4522
4584
|
}
|
|
4523
|
-
if (type.flags &
|
|
4585
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4524
4586
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4525
4587
|
}
|
|
4526
|
-
if (type.flags &
|
|
4588
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4527
4589
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4528
4590
|
}
|
|
4529
4591
|
return resolveTypeNode(
|
|
@@ -4550,13 +4612,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4550
4612
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4551
4613
|
);
|
|
4552
4614
|
const nonNullTypes = allTypes.filter(
|
|
4553
|
-
(memberType) => !(memberType.flags & (
|
|
4615
|
+
(memberType) => !(memberType.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4554
4616
|
);
|
|
4555
4617
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4556
4618
|
memberType,
|
|
4557
4619
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4558
4620
|
}));
|
|
4559
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4621
|
+
const hasNull = allTypes.some((t) => t.flags & ts6.TypeFlags.Null);
|
|
4560
4622
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4561
4623
|
if (namedDecl) {
|
|
4562
4624
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4599,7 +4661,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4599
4661
|
const displayName = memberDisplayNames.get(String(value));
|
|
4600
4662
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4601
4663
|
});
|
|
4602
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4664
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts6.TypeFlags.BooleanLiteral);
|
|
4603
4665
|
if (isBooleanUnion2) {
|
|
4604
4666
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4605
4667
|
const result = hasNull ? {
|
|
@@ -4691,7 +4753,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4691
4753
|
if (type.getProperties().length > 0) {
|
|
4692
4754
|
return null;
|
|
4693
4755
|
}
|
|
4694
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4756
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts6.IndexKind.String);
|
|
4695
4757
|
if (!indexInfo) {
|
|
4696
4758
|
return null;
|
|
4697
4759
|
}
|
|
@@ -4739,10 +4801,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4739
4801
|
}
|
|
4740
4802
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4741
4803
|
const name = declaration.name;
|
|
4742
|
-
if (
|
|
4804
|
+
if (ts6.isComputedPropertyName(name) || ts6.isPrivateIdentifier(name)) {
|
|
4743
4805
|
return false;
|
|
4744
4806
|
}
|
|
4745
|
-
if (!
|
|
4807
|
+
if (!ts6.isIdentifier(name) && !ts6.isStringLiteral(name) && !ts6.isNumericLiteral(name)) {
|
|
4746
4808
|
return false;
|
|
4747
4809
|
}
|
|
4748
4810
|
}
|
|
@@ -4868,7 +4930,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4868
4930
|
if (!declaration) continue;
|
|
4869
4931
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4870
4932
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4871
|
-
const optional = !!(prop.flags &
|
|
4933
|
+
const optional = !!(prop.flags & ts6.SymbolFlags.Optional);
|
|
4872
4934
|
const propTypeNode = resolveTypeNode(
|
|
4873
4935
|
propType,
|
|
4874
4936
|
checker,
|
|
@@ -4881,7 +4943,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4881
4943
|
collectedDiagnostics
|
|
4882
4944
|
);
|
|
4883
4945
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4884
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
4946
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts6.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4885
4947
|
declaration,
|
|
4886
4948
|
checker,
|
|
4887
4949
|
file,
|
|
@@ -4891,7 +4953,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4891
4953
|
type,
|
|
4892
4954
|
metadataPolicy,
|
|
4893
4955
|
extensionRegistry
|
|
4894
|
-
) :
|
|
4956
|
+
) : ts6.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4895
4957
|
declaration,
|
|
4896
4958
|
checker,
|
|
4897
4959
|
file,
|
|
@@ -4919,7 +4981,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4919
4981
|
visiting.delete(type);
|
|
4920
4982
|
const objectNode = {
|
|
4921
4983
|
kind: "object",
|
|
4922
|
-
properties: namedDecl !== void 0 && (
|
|
4984
|
+
properties: namedDecl !== void 0 && (ts6.isClassDeclaration(namedDecl) || ts6.isInterfaceDeclaration(namedDecl) || ts6.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
4923
4985
|
properties,
|
|
4924
4986
|
namedDecl,
|
|
4925
4987
|
type,
|
|
@@ -4967,12 +5029,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4967
5029
|
for (const symbol of symbols) {
|
|
4968
5030
|
const declarations = symbol.declarations;
|
|
4969
5031
|
if (!declarations) continue;
|
|
4970
|
-
const classDecl = declarations.find(
|
|
5032
|
+
const classDecl = declarations.find(ts6.isClassDeclaration);
|
|
4971
5033
|
if (classDecl) {
|
|
4972
5034
|
const map = /* @__PURE__ */ new Map();
|
|
4973
5035
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
4974
5036
|
for (const member of classDecl.members) {
|
|
4975
|
-
if (
|
|
5037
|
+
if (ts6.isPropertyDeclaration(member) && ts6.isIdentifier(member.name)) {
|
|
4976
5038
|
const fieldNode = analyzeFieldToIR(
|
|
4977
5039
|
member,
|
|
4978
5040
|
checker,
|
|
@@ -4996,7 +5058,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4996
5058
|
}
|
|
4997
5059
|
return map;
|
|
4998
5060
|
}
|
|
4999
|
-
const interfaceDecl = declarations.find(
|
|
5061
|
+
const interfaceDecl = declarations.find(ts6.isInterfaceDeclaration);
|
|
5000
5062
|
if (interfaceDecl) {
|
|
5001
5063
|
return buildFieldNodeInfoMap(
|
|
5002
5064
|
interfaceDecl.members,
|
|
@@ -5010,7 +5072,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
5010
5072
|
extensionRegistry
|
|
5011
5073
|
);
|
|
5012
5074
|
}
|
|
5013
|
-
const typeAliasDecl = declarations.find(
|
|
5075
|
+
const typeAliasDecl = declarations.find(ts6.isTypeAliasDeclaration);
|
|
5014
5076
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
5015
5077
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
5016
5078
|
return buildFieldNodeInfoMap(
|
|
@@ -5034,10 +5096,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5034
5096
|
return void 0;
|
|
5035
5097
|
}
|
|
5036
5098
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5037
|
-
if (
|
|
5099
|
+
if (ts6.isArrayTypeNode(resolvedTypeNode)) {
|
|
5038
5100
|
return resolvedTypeNode.elementType;
|
|
5039
5101
|
}
|
|
5040
|
-
if (
|
|
5102
|
+
if (ts6.isTypeReferenceNode(resolvedTypeNode) && ts6.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5041
5103
|
return resolvedTypeNode.typeArguments[0];
|
|
5042
5104
|
}
|
|
5043
5105
|
return void 0;
|
|
@@ -5048,13 +5110,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5048
5110
|
return [];
|
|
5049
5111
|
}
|
|
5050
5112
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5051
|
-
return
|
|
5113
|
+
return ts6.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5052
5114
|
}
|
|
5053
5115
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5054
|
-
if (
|
|
5116
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5055
5117
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5056
5118
|
}
|
|
5057
|
-
if (!
|
|
5119
|
+
if (!ts6.isTypeReferenceNode(typeNode) || !ts6.isIdentifier(typeNode.typeName)) {
|
|
5058
5120
|
return typeNode;
|
|
5059
5121
|
}
|
|
5060
5122
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5065,15 +5127,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5065
5127
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5066
5128
|
}
|
|
5067
5129
|
function isNullishTypeNode(typeNode) {
|
|
5068
|
-
if (typeNode.kind ===
|
|
5130
|
+
if (typeNode.kind === ts6.SyntaxKind.NullKeyword || typeNode.kind === ts6.SyntaxKind.UndefinedKeyword) {
|
|
5069
5131
|
return true;
|
|
5070
5132
|
}
|
|
5071
|
-
return
|
|
5133
|
+
return ts6.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts6.SyntaxKind.NullKeyword || typeNode.literal.kind === ts6.SyntaxKind.UndefinedKeyword);
|
|
5072
5134
|
}
|
|
5073
5135
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5074
5136
|
const map = /* @__PURE__ */ new Map();
|
|
5075
5137
|
for (const member of members) {
|
|
5076
|
-
if (
|
|
5138
|
+
if (ts6.isPropertySignature(member)) {
|
|
5077
5139
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5078
5140
|
member,
|
|
5079
5141
|
checker,
|
|
@@ -5099,7 +5161,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5099
5161
|
}
|
|
5100
5162
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5101
5163
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5102
|
-
if (!
|
|
5164
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return [];
|
|
5103
5165
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5104
5166
|
const aliasName = typeNode.typeName.getText();
|
|
5105
5167
|
throw new Error(
|
|
@@ -5108,7 +5170,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5108
5170
|
}
|
|
5109
5171
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5110
5172
|
if (!aliasDecl) return [];
|
|
5111
|
-
if (
|
|
5173
|
+
if (ts6.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5112
5174
|
const aliasFieldType = resolveTypeNode(
|
|
5113
5175
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5114
5176
|
checker,
|
|
@@ -5152,14 +5214,14 @@ function getNamedTypeName(type) {
|
|
|
5152
5214
|
const symbol = type.getSymbol();
|
|
5153
5215
|
if (symbol?.declarations) {
|
|
5154
5216
|
const decl = symbol.declarations[0];
|
|
5155
|
-
if (decl && (
|
|
5156
|
-
const name =
|
|
5217
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5218
|
+
const name = ts6.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5157
5219
|
if (name) return name;
|
|
5158
5220
|
}
|
|
5159
5221
|
}
|
|
5160
5222
|
const aliasSymbol = type.aliasSymbol;
|
|
5161
5223
|
if (aliasSymbol?.declarations) {
|
|
5162
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5224
|
+
const aliasDecl = aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5163
5225
|
if (aliasDecl) {
|
|
5164
5226
|
return aliasDecl.name.text;
|
|
5165
5227
|
}
|
|
@@ -5170,24 +5232,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5170
5232
|
const symbol = type.getSymbol();
|
|
5171
5233
|
if (symbol?.declarations) {
|
|
5172
5234
|
const decl = symbol.declarations[0];
|
|
5173
|
-
if (decl && (
|
|
5235
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5174
5236
|
return decl;
|
|
5175
5237
|
}
|
|
5176
5238
|
}
|
|
5177
5239
|
const aliasSymbol = type.aliasSymbol;
|
|
5178
5240
|
if (aliasSymbol?.declarations) {
|
|
5179
|
-
return aliasSymbol.declarations.find(
|
|
5241
|
+
return aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5180
5242
|
}
|
|
5181
5243
|
return void 0;
|
|
5182
5244
|
}
|
|
5183
5245
|
function analyzeMethod(method, checker) {
|
|
5184
|
-
if (!
|
|
5246
|
+
if (!ts6.isIdentifier(method.name)) {
|
|
5185
5247
|
return null;
|
|
5186
5248
|
}
|
|
5187
5249
|
const name = method.name.text;
|
|
5188
5250
|
const parameters = [];
|
|
5189
5251
|
for (const param of method.parameters) {
|
|
5190
|
-
if (
|
|
5252
|
+
if (ts6.isIdentifier(param.name)) {
|
|
5191
5253
|
const paramInfo = analyzeParameter(param, checker);
|
|
5192
5254
|
parameters.push(paramInfo);
|
|
5193
5255
|
}
|
|
@@ -5198,7 +5260,7 @@ function analyzeMethod(method, checker) {
|
|
|
5198
5260
|
return { name, parameters, returnTypeNode, returnType };
|
|
5199
5261
|
}
|
|
5200
5262
|
function analyzeParameter(param, checker) {
|
|
5201
|
-
const name =
|
|
5263
|
+
const name = ts6.isIdentifier(param.name) ? param.name.text : "param";
|
|
5202
5264
|
const typeNode = param.type;
|
|
5203
5265
|
const type = checker.getTypeAtLocation(param);
|
|
5204
5266
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5207,15 +5269,15 @@ function analyzeParameter(param, checker) {
|
|
|
5207
5269
|
}
|
|
5208
5270
|
function detectFormSpecReference(typeNode) {
|
|
5209
5271
|
if (!typeNode) return null;
|
|
5210
|
-
if (!
|
|
5211
|
-
const typeName =
|
|
5272
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return null;
|
|
5273
|
+
const typeName = ts6.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts6.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5212
5274
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5213
5275
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5214
|
-
if (!typeArg || !
|
|
5215
|
-
if (
|
|
5276
|
+
if (!typeArg || !ts6.isTypeQueryNode(typeArg)) return null;
|
|
5277
|
+
if (ts6.isIdentifier(typeArg.exprName)) {
|
|
5216
5278
|
return typeArg.exprName.text;
|
|
5217
5279
|
}
|
|
5218
|
-
if (
|
|
5280
|
+
if (ts6.isQualifiedName(typeArg.exprName)) {
|
|
5219
5281
|
return typeArg.exprName.right.text;
|
|
5220
5282
|
}
|
|
5221
5283
|
return null;
|
|
@@ -5237,23 +5299,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5237
5299
|
function createProgramContext(filePath, additionalFiles) {
|
|
5238
5300
|
const absolutePath = path.resolve(filePath);
|
|
5239
5301
|
const fileDir = path.dirname(absolutePath);
|
|
5240
|
-
const configPath =
|
|
5302
|
+
const configPath = ts7.findConfigFile(fileDir, ts7.sys.fileExists.bind(ts7.sys), "tsconfig.json");
|
|
5241
5303
|
let compilerOptions;
|
|
5242
5304
|
let fileNames;
|
|
5243
5305
|
if (configPath) {
|
|
5244
|
-
const configFile =
|
|
5306
|
+
const configFile = ts7.readConfigFile(configPath, ts7.sys.readFile.bind(ts7.sys));
|
|
5245
5307
|
if (configFile.error) {
|
|
5246
5308
|
throw new Error(
|
|
5247
|
-
`Error reading tsconfig.json: ${
|
|
5309
|
+
`Error reading tsconfig.json: ${ts7.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5248
5310
|
);
|
|
5249
5311
|
}
|
|
5250
|
-
const parsed =
|
|
5312
|
+
const parsed = ts7.parseJsonConfigFileContent(
|
|
5251
5313
|
configFile.config,
|
|
5252
|
-
|
|
5314
|
+
ts7.sys,
|
|
5253
5315
|
path.dirname(configPath)
|
|
5254
5316
|
);
|
|
5255
5317
|
if (parsed.errors.length > 0) {
|
|
5256
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5318
|
+
const errorMessages = parsed.errors.map((e) => ts7.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5257
5319
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5258
5320
|
}
|
|
5259
5321
|
compilerOptions = parsed.options;
|
|
@@ -5261,9 +5323,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5261
5323
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5262
5324
|
} else {
|
|
5263
5325
|
compilerOptions = {
|
|
5264
|
-
target:
|
|
5265
|
-
module:
|
|
5266
|
-
moduleResolution:
|
|
5326
|
+
target: ts7.ScriptTarget.ES2022,
|
|
5327
|
+
module: ts7.ModuleKind.NodeNext,
|
|
5328
|
+
moduleResolution: ts7.ModuleResolutionKind.NodeNext,
|
|
5267
5329
|
strict: true,
|
|
5268
5330
|
skipLibCheck: true,
|
|
5269
5331
|
declaration: true
|
|
@@ -5271,7 +5333,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5271
5333
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5272
5334
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5273
5335
|
}
|
|
5274
|
-
const program =
|
|
5336
|
+
const program = ts7.createProgram(fileNames, compilerOptions);
|
|
5275
5337
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5276
5338
|
if (!sourceFile) {
|
|
5277
5339
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5290,19 +5352,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5290
5352
|
result = node;
|
|
5291
5353
|
return;
|
|
5292
5354
|
}
|
|
5293
|
-
|
|
5355
|
+
ts7.forEachChild(node, visit);
|
|
5294
5356
|
}
|
|
5295
5357
|
visit(sourceFile);
|
|
5296
5358
|
return result;
|
|
5297
5359
|
}
|
|
5298
5360
|
function findClassByName(sourceFile, className) {
|
|
5299
|
-
return findNodeByName(sourceFile, className,
|
|
5361
|
+
return findNodeByName(sourceFile, className, ts7.isClassDeclaration, (n) => n.name?.text);
|
|
5300
5362
|
}
|
|
5301
5363
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5302
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5364
|
+
return findNodeByName(sourceFile, interfaceName, ts7.isInterfaceDeclaration, (n) => n.name.text);
|
|
5303
5365
|
}
|
|
5304
5366
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5305
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5367
|
+
return findNodeByName(sourceFile, aliasName, ts7.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5306
5368
|
}
|
|
5307
5369
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5308
5370
|
if (rootType.kind === "object") {
|
|
@@ -5342,22 +5404,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5342
5404
|
};
|
|
5343
5405
|
}
|
|
5344
5406
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5345
|
-
if (
|
|
5407
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5346
5408
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5347
5409
|
}
|
|
5348
|
-
if (
|
|
5410
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5349
5411
|
return true;
|
|
5350
5412
|
}
|
|
5351
|
-
return
|
|
5413
|
+
return ts7.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5352
5414
|
}
|
|
5353
5415
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5354
|
-
if (
|
|
5416
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5355
5417
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5356
5418
|
}
|
|
5357
|
-
if (
|
|
5419
|
+
if (ts7.isTypeLiteralNode(typeNode)) {
|
|
5358
5420
|
const propertyNames = [];
|
|
5359
5421
|
for (const member of typeNode.members) {
|
|
5360
|
-
if (!
|
|
5422
|
+
if (!ts7.isPropertySignature(member)) {
|
|
5361
5423
|
continue;
|
|
5362
5424
|
}
|
|
5363
5425
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5367,13 +5429,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5367
5429
|
}
|
|
5368
5430
|
return propertyNames;
|
|
5369
5431
|
}
|
|
5370
|
-
if (
|
|
5432
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5371
5433
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5372
5434
|
}
|
|
5373
5435
|
return null;
|
|
5374
5436
|
}
|
|
5375
5437
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5376
|
-
if (!
|
|
5438
|
+
if (!ts7.isIntersectionTypeNode(typeNode)) {
|
|
5377
5439
|
return [];
|
|
5378
5440
|
}
|
|
5379
5441
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5574,7 +5636,7 @@ function makeFileProvenance(filePath) {
|
|
|
5574
5636
|
}
|
|
5575
5637
|
|
|
5576
5638
|
// src/extensions/symbol-registry.ts
|
|
5577
|
-
var
|
|
5639
|
+
var ts8 = __toESM(require("typescript"), 1);
|
|
5578
5640
|
var path2 = __toESM(require("path"), 1);
|
|
5579
5641
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5580
5642
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5584,10 +5646,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5584
5646
|
return symbolMap;
|
|
5585
5647
|
}
|
|
5586
5648
|
function visit(node) {
|
|
5587
|
-
if (
|
|
5649
|
+
if (ts8.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5588
5650
|
processDefineCustomTypeCall(node);
|
|
5589
5651
|
}
|
|
5590
|
-
|
|
5652
|
+
ts8.forEachChild(node, visit);
|
|
5591
5653
|
}
|
|
5592
5654
|
function processDefineCustomTypeCall(call) {
|
|
5593
5655
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5624,7 +5686,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5624
5686
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5625
5687
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5626
5688
|
if (callSymbol !== void 0) {
|
|
5627
|
-
const resolved = callSymbol.flags &
|
|
5689
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5628
5690
|
const decl = resolved.declarations?.[0];
|
|
5629
5691
|
if (decl !== void 0) {
|
|
5630
5692
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5632,24 +5694,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5632
5694
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5633
5695
|
}
|
|
5634
5696
|
}
|
|
5635
|
-
return
|
|
5697
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5636
5698
|
}
|
|
5637
5699
|
function extractTypeNameFromCallArg(call) {
|
|
5638
5700
|
const arg = call.arguments[0];
|
|
5639
|
-
if (arg === void 0 || !
|
|
5701
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5640
5702
|
return null;
|
|
5641
5703
|
}
|
|
5642
5704
|
const typeNameProp = arg.properties.find(
|
|
5643
|
-
(p) =>
|
|
5705
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5644
5706
|
);
|
|
5645
|
-
if (typeNameProp === void 0 || !
|
|
5707
|
+
if (typeNameProp === void 0 || !ts8.isStringLiteral(typeNameProp.initializer)) {
|
|
5646
5708
|
return null;
|
|
5647
5709
|
}
|
|
5648
5710
|
return typeNameProp.initializer.text;
|
|
5649
5711
|
}
|
|
5650
5712
|
function extractEnclosingExtensionId(call, checker) {
|
|
5651
|
-
for (let node = call.parent; !
|
|
5652
|
-
if (
|
|
5713
|
+
for (let node = call.parent; !ts8.isSourceFile(node); node = node.parent) {
|
|
5714
|
+
if (ts8.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5653
5715
|
return extractExtensionIdFromCallArg(node);
|
|
5654
5716
|
}
|
|
5655
5717
|
}
|
|
@@ -5658,24 +5720,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5658
5720
|
function isDefineExtensionCall(node, checker) {
|
|
5659
5721
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5660
5722
|
if (callSymbol !== void 0) {
|
|
5661
|
-
const resolved = callSymbol.flags &
|
|
5723
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5662
5724
|
const decl = resolved.declarations?.[0];
|
|
5663
5725
|
if (decl !== void 0) {
|
|
5664
5726
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5665
5727
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5666
5728
|
}
|
|
5667
5729
|
}
|
|
5668
|
-
return
|
|
5730
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5669
5731
|
}
|
|
5670
5732
|
function extractExtensionIdFromCallArg(call) {
|
|
5671
5733
|
const arg = call.arguments[0];
|
|
5672
|
-
if (arg === void 0 || !
|
|
5734
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5673
5735
|
return null;
|
|
5674
5736
|
}
|
|
5675
5737
|
const prop = arg.properties.find(
|
|
5676
|
-
(p) =>
|
|
5738
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5677
5739
|
);
|
|
5678
|
-
if (prop === void 0 || !
|
|
5740
|
+
if (prop === void 0 || !ts8.isStringLiteral(prop.initializer)) {
|
|
5679
5741
|
return null;
|
|
5680
5742
|
}
|
|
5681
5743
|
return prop.initializer.text;
|
|
@@ -5937,7 +5999,7 @@ function generateSchemasBatch(options) {
|
|
|
5937
5999
|
return options.targets.map((target) => {
|
|
5938
6000
|
let ctx;
|
|
5939
6001
|
try {
|
|
5940
|
-
const cacheKey =
|
|
6002
|
+
const cacheKey = ts9.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
5941
6003
|
const cachedContext = contextCache.get(cacheKey);
|
|
5942
6004
|
if (cachedContext === void 0) {
|
|
5943
6005
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6093,7 +6155,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6093
6155
|
}
|
|
6094
6156
|
|
|
6095
6157
|
// src/static-build.ts
|
|
6096
|
-
var
|
|
6158
|
+
var ts10 = __toESM(require("typescript"), 1);
|
|
6097
6159
|
function toStaticBuildContext(context) {
|
|
6098
6160
|
return context;
|
|
6099
6161
|
}
|
|
@@ -6108,7 +6170,7 @@ function getModuleSymbol(context) {
|
|
|
6108
6170
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6109
6171
|
}
|
|
6110
6172
|
function isSchemaSourceDeclaration(declaration) {
|
|
6111
|
-
return
|
|
6173
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6112
6174
|
}
|
|
6113
6175
|
function resolveModuleExport(context, exportName = "default") {
|
|
6114
6176
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6119,14 +6181,14 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6119
6181
|
if (exportSymbol === null) {
|
|
6120
6182
|
return null;
|
|
6121
6183
|
}
|
|
6122
|
-
return exportSymbol.flags &
|
|
6184
|
+
return exportSymbol.flags & ts10.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6123
6185
|
}
|
|
6124
6186
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6125
6187
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6126
6188
|
}
|
|
6127
6189
|
|
|
6128
6190
|
// src/generators/discovered-schema.ts
|
|
6129
|
-
var
|
|
6191
|
+
var ts11 = __toESM(require("typescript"), 1);
|
|
6130
6192
|
var import_internal6 = require("@formspec/analysis/internal");
|
|
6131
6193
|
var import_internals6 = require("@formspec/core/internals");
|
|
6132
6194
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
@@ -6136,17 +6198,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6136
6198
|
};
|
|
6137
6199
|
}
|
|
6138
6200
|
function isNamedTypeDeclaration(declaration) {
|
|
6139
|
-
return
|
|
6201
|
+
return ts11.isClassDeclaration(declaration) || ts11.isInterfaceDeclaration(declaration) || ts11.isTypeAliasDeclaration(declaration);
|
|
6140
6202
|
}
|
|
6141
6203
|
function hasConcreteTypeArguments(type, checker) {
|
|
6142
6204
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6143
6205
|
return true;
|
|
6144
6206
|
}
|
|
6145
|
-
if ((type.flags &
|
|
6207
|
+
if ((type.flags & ts11.TypeFlags.Object) === 0) {
|
|
6146
6208
|
return false;
|
|
6147
6209
|
}
|
|
6148
6210
|
const objectType = type;
|
|
6149
|
-
if ((objectType.objectFlags &
|
|
6211
|
+
if ((objectType.objectFlags & ts11.ObjectFlags.Reference) === 0) {
|
|
6150
6212
|
return false;
|
|
6151
6213
|
}
|
|
6152
6214
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6159,13 +6221,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6159
6221
|
return declaration;
|
|
6160
6222
|
}
|
|
6161
6223
|
}
|
|
6162
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6224
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts11.isTypeAliasDeclaration);
|
|
6163
6225
|
return aliasDeclaration;
|
|
6164
6226
|
}
|
|
6165
6227
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6166
6228
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6167
6229
|
const namedNode = sourceNode;
|
|
6168
|
-
if (namedNode.name !== void 0 &&
|
|
6230
|
+
if (namedNode.name !== void 0 && ts11.isIdentifier(namedNode.name)) {
|
|
6169
6231
|
return namedNode.name.text;
|
|
6170
6232
|
}
|
|
6171
6233
|
}
|
|
@@ -6387,7 +6449,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6387
6449
|
function generateSchemasFromDeclaration(options) {
|
|
6388
6450
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6389
6451
|
const resolved = resolveStaticOptions(options);
|
|
6390
|
-
if (
|
|
6452
|
+
if (ts11.isClassDeclaration(options.declaration)) {
|
|
6391
6453
|
return generateSchemasFromAnalysis(
|
|
6392
6454
|
analyzeClassToIR(
|
|
6393
6455
|
options.declaration,
|
|
@@ -6401,7 +6463,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6401
6463
|
resolved
|
|
6402
6464
|
);
|
|
6403
6465
|
}
|
|
6404
|
-
if (
|
|
6466
|
+
if (ts11.isInterfaceDeclaration(options.declaration)) {
|
|
6405
6467
|
return generateSchemasFromAnalysis(
|
|
6406
6468
|
analyzeInterfaceToIR(
|
|
6407
6469
|
options.declaration,
|
|
@@ -6415,7 +6477,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6415
6477
|
resolved
|
|
6416
6478
|
);
|
|
6417
6479
|
}
|
|
6418
|
-
if (
|
|
6480
|
+
if (ts11.isTypeAliasDeclaration(options.declaration)) {
|
|
6419
6481
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6420
6482
|
options.declaration,
|
|
6421
6483
|
options.context.checker,
|
|
@@ -6474,7 +6536,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6474
6536
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6475
6537
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6476
6538
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6477
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6539
|
+
const fallbackName = options.declaration.name !== void 0 && ts11.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6478
6540
|
return generateSchemasFromResolvedType({
|
|
6479
6541
|
...options,
|
|
6480
6542
|
type,
|
|
@@ -6521,14 +6583,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6521
6583
|
if (typeNode === void 0) {
|
|
6522
6584
|
return void 0;
|
|
6523
6585
|
}
|
|
6524
|
-
if (
|
|
6586
|
+
if (ts11.isParenthesizedTypeNode(typeNode)) {
|
|
6525
6587
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6526
6588
|
return unwrapped ?? typeNode;
|
|
6527
6589
|
}
|
|
6528
6590
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6529
6591
|
}
|
|
6530
6592
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6531
|
-
return
|
|
6593
|
+
return ts11.isTypeReferenceNode(typeNode) && ts11.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6532
6594
|
}
|
|
6533
6595
|
|
|
6534
6596
|
// src/generators/mixed-authoring.ts
|
|
@@ -6727,6 +6789,8 @@ function annotationKey(annotation) {
|
|
|
6727
6789
|
|
|
6728
6790
|
// src/index.ts
|
|
6729
6791
|
function buildFormSchemas(form, options) {
|
|
6792
|
+
const logger = options?.logger ?? import_core3.noopLogger;
|
|
6793
|
+
logger.debug("buildFormSchemas: starting schema generation");
|
|
6730
6794
|
return {
|
|
6731
6795
|
jsonSchema: generateJsonSchema(form, options),
|
|
6732
6796
|
uiSchema: generateUiSchema(form, options)
|
|
@@ -6739,12 +6803,15 @@ function writeSchemas(form, options) {
|
|
|
6739
6803
|
indent = 2,
|
|
6740
6804
|
vendorPrefix,
|
|
6741
6805
|
enumSerialization,
|
|
6742
|
-
metadata
|
|
6806
|
+
metadata,
|
|
6807
|
+
logger: rawLogger
|
|
6743
6808
|
} = options;
|
|
6744
|
-
const
|
|
6809
|
+
const logger = (rawLogger ?? import_core3.noopLogger).child({ stage: "write" });
|
|
6810
|
+
const buildOptions = vendorPrefix === void 0 && enumSerialization === void 0 && metadata === void 0 ? { logger: rawLogger } : {
|
|
6745
6811
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
6746
6812
|
...enumSerialization !== void 0 && { enumSerialization },
|
|
6747
|
-
...metadata !== void 0 && { metadata }
|
|
6813
|
+
...metadata !== void 0 && { metadata },
|
|
6814
|
+
logger: rawLogger
|
|
6748
6815
|
};
|
|
6749
6816
|
const { jsonSchema, uiSchema: uiSchema2 } = buildFormSchemas(form, buildOptions);
|
|
6750
6817
|
if (!fs.existsSync(outDir)) {
|
|
@@ -6752,7 +6819,9 @@ function writeSchemas(form, options) {
|
|
|
6752
6819
|
}
|
|
6753
6820
|
const jsonSchemaPath = path3.join(outDir, `${name}-schema.json`);
|
|
6754
6821
|
const uiSchemaPath = path3.join(outDir, `${name}-uischema.json`);
|
|
6822
|
+
logger.debug("writing JSON Schema", { path: jsonSchemaPath });
|
|
6755
6823
|
fs.writeFileSync(jsonSchemaPath, JSON.stringify(jsonSchema, null, indent));
|
|
6824
|
+
logger.debug("writing UI Schema", { path: uiSchemaPath });
|
|
6756
6825
|
fs.writeFileSync(uiSchemaPath, JSON.stringify(uiSchema2, null, indent));
|
|
6757
6826
|
return { jsonSchemaPath, uiSchemaPath };
|
|
6758
6827
|
}
|