@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.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { noopLogger as noopLogger3 } from "@formspec/core";
|
|
3
|
+
|
|
4
|
+
// src/json-schema/generator.ts
|
|
5
|
+
import { noopLogger } from "@formspec/core";
|
|
6
|
+
|
|
1
7
|
// src/canonicalize/chain-dsl-canonicalizer.ts
|
|
2
8
|
import { IR_VERSION, _getFormSpecMetadataPolicy } from "@formspec/core/internals";
|
|
3
9
|
|
|
@@ -1654,10 +1660,14 @@ function assignVendorPrefixedExtensionKeywords(schema, extensionSchema, vendorPr
|
|
|
1654
1660
|
|
|
1655
1661
|
// src/json-schema/generator.ts
|
|
1656
1662
|
function generateJsonSchema(form, options) {
|
|
1663
|
+
const logger = (options?.logger ?? noopLogger).child({ stage: "ir" });
|
|
1657
1664
|
const metadata = options?.metadata;
|
|
1658
1665
|
const vendorPrefix = options?.vendorPrefix;
|
|
1659
1666
|
const enumSerialization = options?.enumSerialization;
|
|
1667
|
+
logger.debug("canonicalizing chain DSL to IR");
|
|
1660
1668
|
const ir = canonicalizeChainDSL(form, metadata !== void 0 ? { metadata } : void 0);
|
|
1669
|
+
const schemaLogger = (options?.logger ?? noopLogger).child({ stage: "schema" });
|
|
1670
|
+
schemaLogger.debug("generating JSON Schema from IR");
|
|
1661
1671
|
const internalOptions = vendorPrefix === void 0 && enumSerialization === void 0 ? void 0 : {
|
|
1662
1672
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
1663
1673
|
...enumSerialization !== void 0 && { enumSerialization }
|
|
@@ -1665,6 +1675,9 @@ function generateJsonSchema(form, options) {
|
|
|
1665
1675
|
return generateJsonSchemaFromIR(ir, internalOptions);
|
|
1666
1676
|
}
|
|
1667
1677
|
|
|
1678
|
+
// src/ui-schema/generator.ts
|
|
1679
|
+
import { noopLogger as noopLogger2 } from "@formspec/core";
|
|
1680
|
+
|
|
1668
1681
|
// src/ui-schema/schema.ts
|
|
1669
1682
|
import { z } from "zod";
|
|
1670
1683
|
var jsonPointerSchema = z.string();
|
|
@@ -1924,10 +1937,14 @@ function collectFieldNameMap(elements) {
|
|
|
1924
1937
|
|
|
1925
1938
|
// src/ui-schema/generator.ts
|
|
1926
1939
|
function generateUiSchema(form, options) {
|
|
1940
|
+
const logger = (options?.logger ?? noopLogger2).child({ stage: "ir" });
|
|
1941
|
+
logger.debug("canonicalizing chain DSL to IR for UI Schema generation");
|
|
1927
1942
|
const ir = canonicalizeChainDSL(
|
|
1928
1943
|
form,
|
|
1929
1944
|
options?.metadata !== void 0 ? { metadata: options.metadata } : void 0
|
|
1930
1945
|
);
|
|
1946
|
+
const schemaLogger = (options?.logger ?? noopLogger2).child({ stage: "schema" });
|
|
1947
|
+
schemaLogger.debug("generating UI Schema from IR");
|
|
1931
1948
|
return generateUiSchemaFromIR(ir);
|
|
1932
1949
|
}
|
|
1933
1950
|
|
|
@@ -2166,24 +2183,24 @@ var jsonSchema7Schema = z3.lazy(
|
|
|
2166
2183
|
);
|
|
2167
2184
|
|
|
2168
2185
|
// src/generators/class-schema.ts
|
|
2169
|
-
import * as
|
|
2186
|
+
import * as ts9 from "typescript";
|
|
2170
2187
|
|
|
2171
2188
|
// src/analyzer/program.ts
|
|
2172
|
-
import * as
|
|
2189
|
+
import * as ts7 from "typescript";
|
|
2173
2190
|
import * as path from "path";
|
|
2174
2191
|
|
|
2175
2192
|
// src/analyzer/class-analyzer.ts
|
|
2176
|
-
import * as
|
|
2193
|
+
import * as ts6 from "typescript";
|
|
2177
2194
|
import {
|
|
2178
2195
|
analyzeMetadataForNodeWithChecker,
|
|
2179
2196
|
parseCommentBlock
|
|
2180
2197
|
} from "@formspec/analysis/internal";
|
|
2181
2198
|
|
|
2182
2199
|
// src/analyzer/jsdoc-constraints.ts
|
|
2183
|
-
import * as
|
|
2200
|
+
import * as ts5 from "typescript";
|
|
2184
2201
|
|
|
2185
2202
|
// src/analyzer/tsdoc-parser.ts
|
|
2186
|
-
import * as
|
|
2203
|
+
import * as ts4 from "typescript";
|
|
2187
2204
|
import {
|
|
2188
2205
|
checkSyntheticTagApplication,
|
|
2189
2206
|
choosePreferredPayloadText,
|
|
@@ -2191,6 +2208,7 @@ import {
|
|
|
2191
2208
|
getTagDefinition as getTagDefinition2,
|
|
2192
2209
|
hasTypeSemanticCapability,
|
|
2193
2210
|
normalizeFormSpecTagName as normalizeFormSpecTagName2,
|
|
2211
|
+
stripNullishUnion as stripNullishUnion2,
|
|
2194
2212
|
parseConstraintTagValue,
|
|
2195
2213
|
parseDefaultValueTagValue,
|
|
2196
2214
|
parseTagSyntax,
|
|
@@ -2323,6 +2341,14 @@ function customTypeIdFromLookup(result) {
|
|
|
2323
2341
|
return `${result.extensionId}/${result.registration.typeName}`;
|
|
2324
2342
|
}
|
|
2325
2343
|
|
|
2344
|
+
// src/analyzer/builtin-brands.ts
|
|
2345
|
+
import * as ts3 from "typescript";
|
|
2346
|
+
function isIntegerBrandedType(type) {
|
|
2347
|
+
if (!type.isIntersection()) return false;
|
|
2348
|
+
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
2349
|
+
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2326
2352
|
// src/analyzer/tsdoc-parser.ts
|
|
2327
2353
|
function sharedTagValueOptions(options) {
|
|
2328
2354
|
return {
|
|
@@ -2330,7 +2356,7 @@ function sharedTagValueOptions(options) {
|
|
|
2330
2356
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2331
2357
|
};
|
|
2332
2358
|
}
|
|
2333
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
2359
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts4.TypeFormatFlags.NoTruncation | ts4.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2334
2360
|
function getExtensionTypeNames(registry) {
|
|
2335
2361
|
if (registry === void 0) {
|
|
2336
2362
|
return /* @__PURE__ */ new Set();
|
|
@@ -2344,23 +2370,23 @@ function getExtensionTypeNames(registry) {
|
|
|
2344
2370
|
function collectImportedNames(sourceFile) {
|
|
2345
2371
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2346
2372
|
for (const statement of sourceFile.statements) {
|
|
2347
|
-
if (
|
|
2373
|
+
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
2348
2374
|
const clause = statement.importClause;
|
|
2349
2375
|
if (clause.name !== void 0) {
|
|
2350
2376
|
importedNames.add(clause.name.text);
|
|
2351
2377
|
}
|
|
2352
2378
|
if (clause.namedBindings !== void 0) {
|
|
2353
|
-
if (
|
|
2379
|
+
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
2354
2380
|
for (const specifier of clause.namedBindings.elements) {
|
|
2355
2381
|
importedNames.add(specifier.name.text);
|
|
2356
2382
|
}
|
|
2357
|
-
} else if (
|
|
2383
|
+
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
2358
2384
|
importedNames.add(clause.namedBindings.name.text);
|
|
2359
2385
|
}
|
|
2360
2386
|
}
|
|
2361
2387
|
continue;
|
|
2362
2388
|
}
|
|
2363
|
-
if (
|
|
2389
|
+
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
2364
2390
|
importedNames.add(statement.name.text);
|
|
2365
2391
|
}
|
|
2366
2392
|
}
|
|
@@ -2368,50 +2394,96 @@ function collectImportedNames(sourceFile) {
|
|
|
2368
2394
|
}
|
|
2369
2395
|
function isNonReferenceIdentifier(node) {
|
|
2370
2396
|
const parent = node.parent;
|
|
2371
|
-
if ((
|
|
2397
|
+
if ((ts4.isBindingElement(parent) || ts4.isClassDeclaration(parent) || ts4.isEnumDeclaration(parent) || ts4.isEnumMember(parent) || ts4.isFunctionDeclaration(parent) || ts4.isFunctionExpression(parent) || ts4.isImportClause(parent) || ts4.isImportEqualsDeclaration(parent) || ts4.isImportSpecifier(parent) || ts4.isInterfaceDeclaration(parent) || ts4.isMethodDeclaration(parent) || ts4.isMethodSignature(parent) || ts4.isModuleDeclaration(parent) || ts4.isNamespaceExport(parent) || ts4.isNamespaceImport(parent) || ts4.isParameter(parent) || ts4.isPropertyDeclaration(parent) || ts4.isPropertySignature(parent) || ts4.isSetAccessorDeclaration(parent) || ts4.isGetAccessorDeclaration(parent) || ts4.isTypeAliasDeclaration(parent) || ts4.isTypeParameterDeclaration(parent) || ts4.isVariableDeclaration(parent)) && parent.name === node) {
|
|
2372
2398
|
return true;
|
|
2373
2399
|
}
|
|
2374
|
-
if ((
|
|
2400
|
+
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2375
2401
|
return true;
|
|
2376
2402
|
}
|
|
2377
|
-
if (
|
|
2403
|
+
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
2378
2404
|
return true;
|
|
2379
2405
|
}
|
|
2380
2406
|
return false;
|
|
2381
2407
|
}
|
|
2382
|
-
function
|
|
2408
|
+
function astReferencesImportedName(root, importedNames) {
|
|
2383
2409
|
if (importedNames.size === 0) {
|
|
2384
2410
|
return false;
|
|
2385
2411
|
}
|
|
2386
|
-
let
|
|
2412
|
+
let found = false;
|
|
2387
2413
|
const visit = (node) => {
|
|
2388
|
-
if (
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2392
|
-
referencesImportedName = true;
|
|
2414
|
+
if (found) return;
|
|
2415
|
+
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2416
|
+
found = true;
|
|
2393
2417
|
return;
|
|
2394
2418
|
}
|
|
2395
|
-
|
|
2419
|
+
ts4.forEachChild(node, visit);
|
|
2396
2420
|
};
|
|
2397
|
-
visit(
|
|
2398
|
-
return
|
|
2421
|
+
visit(root);
|
|
2422
|
+
return found;
|
|
2423
|
+
}
|
|
2424
|
+
function getObjectMembers(statement) {
|
|
2425
|
+
if (ts4.isInterfaceDeclaration(statement)) {
|
|
2426
|
+
return statement.members;
|
|
2427
|
+
}
|
|
2428
|
+
if (ts4.isTypeLiteralNode(statement.type)) {
|
|
2429
|
+
return statement.type.members;
|
|
2430
|
+
}
|
|
2431
|
+
return void 0;
|
|
2432
|
+
}
|
|
2433
|
+
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
2434
|
+
const members = getObjectMembers(statement);
|
|
2435
|
+
if (members === void 0) {
|
|
2436
|
+
return null;
|
|
2437
|
+
}
|
|
2438
|
+
const replacements = [];
|
|
2439
|
+
for (const member of members) {
|
|
2440
|
+
if (!ts4.isPropertySignature(member)) {
|
|
2441
|
+
if (astReferencesImportedName(member, importedNames)) {
|
|
2442
|
+
return null;
|
|
2443
|
+
}
|
|
2444
|
+
continue;
|
|
2445
|
+
}
|
|
2446
|
+
const typeAnnotation = member.type;
|
|
2447
|
+
if (typeAnnotation === void 0) continue;
|
|
2448
|
+
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
2449
|
+
replacements.push({
|
|
2450
|
+
start: typeAnnotation.getStart(sourceFile),
|
|
2451
|
+
end: typeAnnotation.getEnd()
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
if (replacements.length === 0) {
|
|
2456
|
+
return statement.getText(sourceFile);
|
|
2457
|
+
}
|
|
2458
|
+
const stmtStart = statement.getStart(sourceFile);
|
|
2459
|
+
let result = statement.getText(sourceFile);
|
|
2460
|
+
for (const { start, end } of [...replacements].reverse()) {
|
|
2461
|
+
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
2462
|
+
}
|
|
2463
|
+
return result;
|
|
2399
2464
|
}
|
|
2400
2465
|
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
2401
2466
|
const importedNames = collectImportedNames(sourceFile);
|
|
2402
2467
|
const importedNamesToSkip = new Set(
|
|
2403
2468
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2404
2469
|
);
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
if (
|
|
2408
|
-
if (
|
|
2409
|
-
|
|
2410
|
-
if (
|
|
2411
|
-
|
|
2470
|
+
const result = [];
|
|
2471
|
+
for (const statement of sourceFile.statements) {
|
|
2472
|
+
if (ts4.isImportDeclaration(statement)) continue;
|
|
2473
|
+
if (ts4.isImportEqualsDeclaration(statement)) continue;
|
|
2474
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2475
|
+
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2476
|
+
result.push(statement.getText(sourceFile));
|
|
2477
|
+
continue;
|
|
2412
2478
|
}
|
|
2413
|
-
|
|
2414
|
-
|
|
2479
|
+
if (ts4.isInterfaceDeclaration(statement) || ts4.isTypeAliasDeclaration(statement)) {
|
|
2480
|
+
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2481
|
+
if (rewritten !== null) {
|
|
2482
|
+
result.push(rewritten);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
return result;
|
|
2415
2487
|
}
|
|
2416
2488
|
function pushUniqueCompilerDiagnostics(target, additions) {
|
|
2417
2489
|
for (const diagnostic of additions) {
|
|
@@ -2503,7 +2575,7 @@ function stripHintNullishUnion(type) {
|
|
|
2503
2575
|
return type;
|
|
2504
2576
|
}
|
|
2505
2577
|
const nonNullish = type.types.filter(
|
|
2506
|
-
(member) => (member.flags & (
|
|
2578
|
+
(member) => (member.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) === 0
|
|
2507
2579
|
);
|
|
2508
2580
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
2509
2581
|
return nonNullish[0];
|
|
@@ -2519,10 +2591,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
2519
2591
|
}
|
|
2520
2592
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
2521
2593
|
const name = declaration.name;
|
|
2522
|
-
if (
|
|
2594
|
+
if (ts4.isComputedPropertyName(name) || ts4.isPrivateIdentifier(name)) {
|
|
2523
2595
|
return false;
|
|
2524
2596
|
}
|
|
2525
|
-
if (!
|
|
2597
|
+
if (!ts4.isIdentifier(name) && !ts4.isStringLiteral(name) && !ts4.isNumericLiteral(name)) {
|
|
2526
2598
|
return false;
|
|
2527
2599
|
}
|
|
2528
2600
|
}
|
|
@@ -2740,6 +2812,9 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2740
2812
|
}
|
|
2741
2813
|
const hasBroadening = (() => {
|
|
2742
2814
|
if (target === null) {
|
|
2815
|
+
if (isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
2816
|
+
return true;
|
|
2817
|
+
}
|
|
2743
2818
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
2744
2819
|
}
|
|
2745
2820
|
const registry = options?.extensionRegistry;
|
|
@@ -2892,12 +2967,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2892
2967
|
const sourceText = sourceFile.getFullText();
|
|
2893
2968
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2894
2969
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2895
|
-
const commentRanges =
|
|
2970
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2896
2971
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2897
2972
|
const extensionTagNames = getExtensionTagNames(options);
|
|
2898
2973
|
if (commentRanges) {
|
|
2899
2974
|
for (const range of commentRanges) {
|
|
2900
|
-
if (range.kind !==
|
|
2975
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) {
|
|
2901
2976
|
continue;
|
|
2902
2977
|
}
|
|
2903
2978
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -3054,10 +3129,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
3054
3129
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3055
3130
|
const sourceFile = node.getSourceFile();
|
|
3056
3131
|
const sourceText = sourceFile.getFullText();
|
|
3057
|
-
const commentRanges =
|
|
3132
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3058
3133
|
if (commentRanges) {
|
|
3059
3134
|
for (const range of commentRanges) {
|
|
3060
|
-
if (range.kind !==
|
|
3135
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
3061
3136
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
3062
3137
|
if (!commentText.startsWith("/**")) continue;
|
|
3063
3138
|
const unified = parseUnifiedComment(commentText);
|
|
@@ -3082,7 +3157,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
3082
3157
|
}
|
|
3083
3158
|
function collectRawTextFallbacks(node, file) {
|
|
3084
3159
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
3085
|
-
for (const tag of
|
|
3160
|
+
for (const tag of ts4.getJSDocTags(node)) {
|
|
3086
3161
|
const tagName = normalizeConstraintTagName2(tag.tagName.text);
|
|
3087
3162
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
3088
3163
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -3137,7 +3212,7 @@ function getTagCommentText(tag) {
|
|
|
3137
3212
|
if (typeof tag.comment === "string") {
|
|
3138
3213
|
return tag.comment;
|
|
3139
3214
|
}
|
|
3140
|
-
return
|
|
3215
|
+
return ts4.getTextOfJSDocComment(tag.comment);
|
|
3141
3216
|
}
|
|
3142
3217
|
|
|
3143
3218
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -3155,18 +3230,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
3155
3230
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
3156
3231
|
if (!initializer) return null;
|
|
3157
3232
|
let value;
|
|
3158
|
-
if (
|
|
3233
|
+
if (ts5.isStringLiteral(initializer)) {
|
|
3159
3234
|
value = initializer.text;
|
|
3160
|
-
} else if (
|
|
3235
|
+
} else if (ts5.isNumericLiteral(initializer)) {
|
|
3161
3236
|
value = Number(initializer.text);
|
|
3162
|
-
} else if (initializer.kind ===
|
|
3237
|
+
} else if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
|
|
3163
3238
|
value = true;
|
|
3164
|
-
} else if (initializer.kind ===
|
|
3239
|
+
} else if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
|
|
3165
3240
|
value = false;
|
|
3166
|
-
} else if (initializer.kind ===
|
|
3241
|
+
} else if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
|
|
3167
3242
|
value = null;
|
|
3168
|
-
} else if (
|
|
3169
|
-
if (initializer.operator ===
|
|
3243
|
+
} else if (ts5.isPrefixUnaryExpression(initializer)) {
|
|
3244
|
+
if (initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
|
|
3170
3245
|
value = -Number(initializer.operand.text);
|
|
3171
3246
|
}
|
|
3172
3247
|
}
|
|
@@ -3188,38 +3263,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
3188
3263
|
|
|
3189
3264
|
// src/analyzer/class-analyzer.ts
|
|
3190
3265
|
function isObjectType(type) {
|
|
3191
|
-
return !!(type.flags &
|
|
3266
|
+
return !!(type.flags & ts6.TypeFlags.Object);
|
|
3192
3267
|
}
|
|
3193
3268
|
function isIntersectionType(type) {
|
|
3194
|
-
return !!(type.flags &
|
|
3195
|
-
}
|
|
3196
|
-
function isIntegerBrandedType(type) {
|
|
3197
|
-
if (!type.isIntersection()) {
|
|
3198
|
-
return false;
|
|
3199
|
-
}
|
|
3200
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
3201
|
-
if (!hasNumberBase) {
|
|
3202
|
-
return false;
|
|
3203
|
-
}
|
|
3204
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
3269
|
+
return !!(type.flags & ts6.TypeFlags.Intersection);
|
|
3205
3270
|
}
|
|
3206
3271
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
3207
|
-
if (
|
|
3272
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3208
3273
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
3209
3274
|
}
|
|
3210
|
-
if (
|
|
3275
|
+
if (ts6.isTypeLiteralNode(typeNode) || ts6.isTypeReferenceNode(typeNode)) {
|
|
3211
3276
|
return true;
|
|
3212
3277
|
}
|
|
3213
|
-
return
|
|
3278
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
3214
3279
|
}
|
|
3215
3280
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
3216
3281
|
if (isIntersectionType(type)) {
|
|
3217
3282
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
3218
3283
|
}
|
|
3219
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
3284
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts6.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts6.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
3220
3285
|
}
|
|
3221
3286
|
function isTypeReference(type) {
|
|
3222
|
-
return !!(type.flags &
|
|
3287
|
+
return !!(type.flags & ts6.TypeFlags.Object) && !!(type.objectFlags & ts6.ObjectFlags.Reference);
|
|
3223
3288
|
}
|
|
3224
3289
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
3225
3290
|
kind: "object",
|
|
@@ -3284,7 +3349,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
3284
3349
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3285
3350
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3286
3351
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
3287
|
-
const logicalName =
|
|
3352
|
+
const logicalName = ts6.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
3288
3353
|
const docResult = extractJSDocParseResult(
|
|
3289
3354
|
declaration,
|
|
3290
3355
|
file,
|
|
@@ -3332,7 +3397,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3332
3397
|
const instanceMethods = [];
|
|
3333
3398
|
const staticMethods = [];
|
|
3334
3399
|
for (const member of classDecl.members) {
|
|
3335
|
-
if (
|
|
3400
|
+
if (ts6.isPropertyDeclaration(member)) {
|
|
3336
3401
|
const fieldNode = analyzeFieldToIR(
|
|
3337
3402
|
member,
|
|
3338
3403
|
checker,
|
|
@@ -3348,10 +3413,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3348
3413
|
fields.push(fieldNode);
|
|
3349
3414
|
fieldLayouts.push({});
|
|
3350
3415
|
}
|
|
3351
|
-
} else if (
|
|
3416
|
+
} else if (ts6.isMethodDeclaration(member)) {
|
|
3352
3417
|
const methodInfo = analyzeMethod(member, checker);
|
|
3353
3418
|
if (methodInfo) {
|
|
3354
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
3419
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts6.SyntaxKind.StaticKeyword);
|
|
3355
3420
|
if (isStatic) {
|
|
3356
3421
|
staticMethods.push(methodInfo);
|
|
3357
3422
|
} else {
|
|
@@ -3414,7 +3479,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3414
3479
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
3415
3480
|
const visiting = /* @__PURE__ */ new Set();
|
|
3416
3481
|
for (const member of interfaceDecl.members) {
|
|
3417
|
-
if (
|
|
3482
|
+
if (ts6.isPropertySignature(member)) {
|
|
3418
3483
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3419
3484
|
member,
|
|
3420
3485
|
checker,
|
|
@@ -3472,7 +3537,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3472
3537
|
if (members === null) {
|
|
3473
3538
|
const sourceFile = typeAlias.getSourceFile();
|
|
3474
3539
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
3475
|
-
const kindDesc =
|
|
3540
|
+
const kindDesc = ts6.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
3476
3541
|
return {
|
|
3477
3542
|
ok: false,
|
|
3478
3543
|
kind: "not-object-like",
|
|
@@ -3507,7 +3572,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3507
3572
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
3508
3573
|
const visiting = /* @__PURE__ */ new Set();
|
|
3509
3574
|
for (const member of members) {
|
|
3510
|
-
if (
|
|
3575
|
+
if (ts6.isPropertySignature(member)) {
|
|
3511
3576
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3512
3577
|
member,
|
|
3513
3578
|
checker,
|
|
@@ -3574,13 +3639,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
3574
3639
|
function getLeadingParsedTags(node) {
|
|
3575
3640
|
const sourceFile = node.getSourceFile();
|
|
3576
3641
|
const sourceText = sourceFile.getFullText();
|
|
3577
|
-
const commentRanges =
|
|
3642
|
+
const commentRanges = ts6.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3578
3643
|
if (commentRanges === void 0) {
|
|
3579
3644
|
return [];
|
|
3580
3645
|
}
|
|
3581
3646
|
const parsedTags = [];
|
|
3582
3647
|
for (const range of commentRanges) {
|
|
3583
|
-
if (range.kind !==
|
|
3648
|
+
if (range.kind !== ts6.SyntaxKind.MultiLineCommentTrivia) {
|
|
3584
3649
|
continue;
|
|
3585
3650
|
}
|
|
3586
3651
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -3598,19 +3663,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
3598
3663
|
return null;
|
|
3599
3664
|
}
|
|
3600
3665
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
3601
|
-
(candidate) =>
|
|
3666
|
+
(candidate) => ts6.isPropertyDeclaration(candidate) || ts6.isPropertySignature(candidate)
|
|
3602
3667
|
) ?? propertySymbol.declarations?.[0];
|
|
3603
3668
|
return {
|
|
3604
3669
|
declaration,
|
|
3605
3670
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
3606
|
-
optional: !!(propertySymbol.flags &
|
|
3671
|
+
optional: !!(propertySymbol.flags & ts6.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
3607
3672
|
};
|
|
3608
3673
|
}
|
|
3609
3674
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
3610
3675
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
3611
3676
|
}
|
|
3612
3677
|
function isNullishSemanticType(type) {
|
|
3613
|
-
if (type.flags & (
|
|
3678
|
+
if (type.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined | ts6.TypeFlags.Void | ts6.TypeFlags.Unknown | ts6.TypeFlags.Any)) {
|
|
3614
3679
|
return true;
|
|
3615
3680
|
}
|
|
3616
3681
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -3620,7 +3685,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3620
3685
|
return false;
|
|
3621
3686
|
}
|
|
3622
3687
|
seen.add(type);
|
|
3623
|
-
if (type.flags &
|
|
3688
|
+
if (type.flags & ts6.TypeFlags.StringLike) {
|
|
3624
3689
|
return true;
|
|
3625
3690
|
}
|
|
3626
3691
|
if (type.isUnion()) {
|
|
@@ -3633,13 +3698,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
3633
3698
|
return false;
|
|
3634
3699
|
}
|
|
3635
3700
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
3636
|
-
if (
|
|
3701
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3637
3702
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
3638
3703
|
}
|
|
3639
|
-
if (
|
|
3704
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
3640
3705
|
return [...typeNode.members];
|
|
3641
3706
|
}
|
|
3642
|
-
if (
|
|
3707
|
+
if (ts6.isIntersectionTypeNode(typeNode)) {
|
|
3643
3708
|
const members = [];
|
|
3644
3709
|
for (const intersectionMember of typeNode.types) {
|
|
3645
3710
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -3802,7 +3867,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
3802
3867
|
}
|
|
3803
3868
|
if (propertyType.isUnion()) {
|
|
3804
3869
|
const nonNullMembers = propertyType.types.filter(
|
|
3805
|
-
(member) => !(member.flags & (
|
|
3870
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3806
3871
|
);
|
|
3807
3872
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3808
3873
|
diagnostics.push(
|
|
@@ -3851,13 +3916,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
3851
3916
|
seen.add(type);
|
|
3852
3917
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
3853
3918
|
if (symbol !== void 0) {
|
|
3854
|
-
const aliased = symbol.flags &
|
|
3919
|
+
const aliased = symbol.flags & ts6.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
3855
3920
|
const targetSymbol = aliased ?? symbol;
|
|
3856
3921
|
const declaration = targetSymbol.declarations?.find(
|
|
3857
|
-
(candidate) =>
|
|
3922
|
+
(candidate) => ts6.isClassDeclaration(candidate) || ts6.isInterfaceDeclaration(candidate) || ts6.isTypeAliasDeclaration(candidate) || ts6.isEnumDeclaration(candidate)
|
|
3858
3923
|
);
|
|
3859
3924
|
if (declaration !== void 0) {
|
|
3860
|
-
if (
|
|
3925
|
+
if (ts6.isTypeAliasDeclaration(declaration) && ts6.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
3861
3926
|
return resolveNamedDiscriminatorDeclaration(
|
|
3862
3927
|
checker.getTypeFromTypeNode(declaration.type),
|
|
3863
3928
|
checker,
|
|
@@ -3885,7 +3950,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3885
3950
|
}
|
|
3886
3951
|
if (boundType.isUnion()) {
|
|
3887
3952
|
const nonNullMembers = boundType.types.filter(
|
|
3888
|
-
(member) => !(member.flags & (
|
|
3953
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3889
3954
|
);
|
|
3890
3955
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
3891
3956
|
diagnostics.push(
|
|
@@ -3930,7 +3995,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
3930
3995
|
return null;
|
|
3931
3996
|
}
|
|
3932
3997
|
function getDeclarationName(node) {
|
|
3933
|
-
if (
|
|
3998
|
+
if (ts6.isClassDeclaration(node) || ts6.isInterfaceDeclaration(node) || ts6.isTypeAliasDeclaration(node) || ts6.isEnumDeclaration(node)) {
|
|
3934
3999
|
return node.name?.text ?? "anonymous";
|
|
3935
4000
|
}
|
|
3936
4001
|
return "anonymous";
|
|
@@ -3985,11 +4050,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
3985
4050
|
if (sourceTypeNode === void 0) {
|
|
3986
4051
|
return [];
|
|
3987
4052
|
}
|
|
3988
|
-
const unwrapParentheses = (typeNode) =>
|
|
4053
|
+
const unwrapParentheses = (typeNode) => ts6.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
3989
4054
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
3990
|
-
const referenceTypeNode =
|
|
4055
|
+
const referenceTypeNode = ts6.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
3991
4056
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
3992
|
-
return
|
|
4057
|
+
return ts6.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
3993
4058
|
})();
|
|
3994
4059
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
3995
4060
|
return [];
|
|
@@ -4044,7 +4109,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
4044
4109
|
);
|
|
4045
4110
|
}
|
|
4046
4111
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
4047
|
-
if (!
|
|
4112
|
+
if (!ts6.isIdentifier(prop.name)) {
|
|
4048
4113
|
return null;
|
|
4049
4114
|
}
|
|
4050
4115
|
const name = prop.name.text;
|
|
@@ -4171,7 +4236,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4171
4236
|
const seen = /* @__PURE__ */ new Set();
|
|
4172
4237
|
const duplicates = /* @__PURE__ */ new Set();
|
|
4173
4238
|
for (const member of members) {
|
|
4174
|
-
if (!
|
|
4239
|
+
if (!ts6.isPropertySignature(member)) {
|
|
4175
4240
|
continue;
|
|
4176
4241
|
}
|
|
4177
4242
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4187,7 +4252,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
4187
4252
|
return [...duplicates].sort();
|
|
4188
4253
|
}
|
|
4189
4254
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
4190
|
-
if (
|
|
4255
|
+
if (ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNumericLiteral(name)) {
|
|
4191
4256
|
return name.text;
|
|
4192
4257
|
}
|
|
4193
4258
|
return null;
|
|
@@ -4285,25 +4350,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4285
4350
|
if (isIntegerBrandedType(type)) {
|
|
4286
4351
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4287
4352
|
}
|
|
4288
|
-
if (type.flags &
|
|
4353
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4289
4354
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4290
4355
|
}
|
|
4291
|
-
if (type.flags &
|
|
4356
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4292
4357
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4293
4358
|
}
|
|
4294
|
-
if (type.flags & (
|
|
4359
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4295
4360
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4296
4361
|
}
|
|
4297
|
-
if (type.flags &
|
|
4362
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4298
4363
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4299
4364
|
}
|
|
4300
|
-
if (type.flags &
|
|
4365
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4301
4366
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4302
4367
|
}
|
|
4303
|
-
if (type.flags &
|
|
4368
|
+
if (type.flags & ts6.TypeFlags.Undefined) {
|
|
4304
4369
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4305
4370
|
}
|
|
4306
|
-
if (type.flags &
|
|
4371
|
+
if (type.flags & ts6.TypeFlags.Void) {
|
|
4307
4372
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4308
4373
|
}
|
|
4309
4374
|
if (type.isStringLiteral()) {
|
|
@@ -4390,10 +4455,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
4390
4455
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4391
4456
|
}
|
|
4392
4457
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4393
|
-
if (!(type.flags & (
|
|
4458
|
+
if (!(type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
4394
4459
|
return null;
|
|
4395
4460
|
}
|
|
4396
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4461
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
4397
4462
|
if (!aliasDecl) {
|
|
4398
4463
|
return null;
|
|
4399
4464
|
}
|
|
@@ -4443,14 +4508,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
4443
4508
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
4444
4509
|
}
|
|
4445
4510
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
4446
|
-
const typeNode = sourceNode && (
|
|
4447
|
-
if (!typeNode || !
|
|
4511
|
+
const typeNode = sourceNode && (ts6.isPropertyDeclaration(sourceNode) || ts6.isPropertySignature(sourceNode) || ts6.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
4512
|
+
if (!typeNode || !ts6.isTypeReferenceNode(typeNode)) {
|
|
4448
4513
|
return void 0;
|
|
4449
4514
|
}
|
|
4450
4515
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
4451
4516
|
}
|
|
4452
4517
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
4453
|
-
if (!
|
|
4518
|
+
if (!ts6.isTypeReferenceNode(typeNode)) {
|
|
4454
4519
|
return false;
|
|
4455
4520
|
}
|
|
4456
4521
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -4458,10 +4523,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4458
4523
|
return false;
|
|
4459
4524
|
}
|
|
4460
4525
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4461
|
-
return !!(resolved.flags & (
|
|
4526
|
+
return !!(resolved.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null));
|
|
4462
4527
|
}
|
|
4463
4528
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
4464
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
4529
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration);
|
|
4465
4530
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
4466
4531
|
visitedAliases.add(nestedAliasDecl);
|
|
4467
4532
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4479,19 +4544,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4479
4544
|
if (isIntegerBrandedType(type)) {
|
|
4480
4545
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
4481
4546
|
}
|
|
4482
|
-
if (type.flags &
|
|
4547
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
4483
4548
|
return { kind: "primitive", primitiveKind: "string" };
|
|
4484
4549
|
}
|
|
4485
|
-
if (type.flags &
|
|
4550
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
4486
4551
|
return { kind: "primitive", primitiveKind: "number" };
|
|
4487
4552
|
}
|
|
4488
|
-
if (type.flags & (
|
|
4553
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
4489
4554
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
4490
4555
|
}
|
|
4491
|
-
if (type.flags &
|
|
4556
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
4492
4557
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
4493
4558
|
}
|
|
4494
|
-
if (type.flags &
|
|
4559
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
4495
4560
|
return { kind: "primitive", primitiveKind: "null" };
|
|
4496
4561
|
}
|
|
4497
4562
|
return resolveTypeNode(
|
|
@@ -4518,13 +4583,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4518
4583
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
4519
4584
|
);
|
|
4520
4585
|
const nonNullTypes = allTypes.filter(
|
|
4521
|
-
(memberType) => !(memberType.flags & (
|
|
4586
|
+
(memberType) => !(memberType.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
4522
4587
|
);
|
|
4523
4588
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
4524
4589
|
memberType,
|
|
4525
4590
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
4526
4591
|
}));
|
|
4527
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
4592
|
+
const hasNull = allTypes.some((t) => t.flags & ts6.TypeFlags.Null);
|
|
4528
4593
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
4529
4594
|
if (namedDecl) {
|
|
4530
4595
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -4567,7 +4632,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4567
4632
|
const displayName = memberDisplayNames.get(String(value));
|
|
4568
4633
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
4569
4634
|
});
|
|
4570
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
4635
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts6.TypeFlags.BooleanLiteral);
|
|
4571
4636
|
if (isBooleanUnion2) {
|
|
4572
4637
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
4573
4638
|
const result = hasNull ? {
|
|
@@ -4659,7 +4724,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
4659
4724
|
if (type.getProperties().length > 0) {
|
|
4660
4725
|
return null;
|
|
4661
4726
|
}
|
|
4662
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
4727
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts6.IndexKind.String);
|
|
4663
4728
|
if (!indexInfo) {
|
|
4664
4729
|
return null;
|
|
4665
4730
|
}
|
|
@@ -4707,10 +4772,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4707
4772
|
}
|
|
4708
4773
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
4709
4774
|
const name = declaration.name;
|
|
4710
|
-
if (
|
|
4775
|
+
if (ts6.isComputedPropertyName(name) || ts6.isPrivateIdentifier(name)) {
|
|
4711
4776
|
return false;
|
|
4712
4777
|
}
|
|
4713
|
-
if (!
|
|
4778
|
+
if (!ts6.isIdentifier(name) && !ts6.isStringLiteral(name) && !ts6.isNumericLiteral(name)) {
|
|
4714
4779
|
return false;
|
|
4715
4780
|
}
|
|
4716
4781
|
}
|
|
@@ -4836,7 +4901,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4836
4901
|
if (!declaration) continue;
|
|
4837
4902
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
4838
4903
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
4839
|
-
const optional = !!(prop.flags &
|
|
4904
|
+
const optional = !!(prop.flags & ts6.SymbolFlags.Optional);
|
|
4840
4905
|
const propTypeNode = resolveTypeNode(
|
|
4841
4906
|
propType,
|
|
4842
4907
|
checker,
|
|
@@ -4849,7 +4914,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4849
4914
|
collectedDiagnostics
|
|
4850
4915
|
);
|
|
4851
4916
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
4852
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
4917
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts6.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
4853
4918
|
declaration,
|
|
4854
4919
|
checker,
|
|
4855
4920
|
file,
|
|
@@ -4859,7 +4924,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4859
4924
|
type,
|
|
4860
4925
|
metadataPolicy,
|
|
4861
4926
|
extensionRegistry
|
|
4862
|
-
) :
|
|
4927
|
+
) : ts6.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
4863
4928
|
declaration,
|
|
4864
4929
|
checker,
|
|
4865
4930
|
file,
|
|
@@ -4887,7 +4952,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4887
4952
|
visiting.delete(type);
|
|
4888
4953
|
const objectNode = {
|
|
4889
4954
|
kind: "object",
|
|
4890
|
-
properties: namedDecl !== void 0 && (
|
|
4955
|
+
properties: namedDecl !== void 0 && (ts6.isClassDeclaration(namedDecl) || ts6.isInterfaceDeclaration(namedDecl) || ts6.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
4891
4956
|
properties,
|
|
4892
4957
|
namedDecl,
|
|
4893
4958
|
type,
|
|
@@ -4935,12 +5000,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4935
5000
|
for (const symbol of symbols) {
|
|
4936
5001
|
const declarations = symbol.declarations;
|
|
4937
5002
|
if (!declarations) continue;
|
|
4938
|
-
const classDecl = declarations.find(
|
|
5003
|
+
const classDecl = declarations.find(ts6.isClassDeclaration);
|
|
4939
5004
|
if (classDecl) {
|
|
4940
5005
|
const map = /* @__PURE__ */ new Map();
|
|
4941
5006
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
4942
5007
|
for (const member of classDecl.members) {
|
|
4943
|
-
if (
|
|
5008
|
+
if (ts6.isPropertyDeclaration(member) && ts6.isIdentifier(member.name)) {
|
|
4944
5009
|
const fieldNode = analyzeFieldToIR(
|
|
4945
5010
|
member,
|
|
4946
5011
|
checker,
|
|
@@ -4964,7 +5029,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4964
5029
|
}
|
|
4965
5030
|
return map;
|
|
4966
5031
|
}
|
|
4967
|
-
const interfaceDecl = declarations.find(
|
|
5032
|
+
const interfaceDecl = declarations.find(ts6.isInterfaceDeclaration);
|
|
4968
5033
|
if (interfaceDecl) {
|
|
4969
5034
|
return buildFieldNodeInfoMap(
|
|
4970
5035
|
interfaceDecl.members,
|
|
@@ -4978,7 +5043,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
4978
5043
|
extensionRegistry
|
|
4979
5044
|
);
|
|
4980
5045
|
}
|
|
4981
|
-
const typeAliasDecl = declarations.find(
|
|
5046
|
+
const typeAliasDecl = declarations.find(ts6.isTypeAliasDeclaration);
|
|
4982
5047
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
4983
5048
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
4984
5049
|
return buildFieldNodeInfoMap(
|
|
@@ -5002,10 +5067,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
5002
5067
|
return void 0;
|
|
5003
5068
|
}
|
|
5004
5069
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5005
|
-
if (
|
|
5070
|
+
if (ts6.isArrayTypeNode(resolvedTypeNode)) {
|
|
5006
5071
|
return resolvedTypeNode.elementType;
|
|
5007
5072
|
}
|
|
5008
|
-
if (
|
|
5073
|
+
if (ts6.isTypeReferenceNode(resolvedTypeNode) && ts6.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
5009
5074
|
return resolvedTypeNode.typeArguments[0];
|
|
5010
5075
|
}
|
|
5011
5076
|
return void 0;
|
|
@@ -5016,13 +5081,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
5016
5081
|
return [];
|
|
5017
5082
|
}
|
|
5018
5083
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
5019
|
-
return
|
|
5084
|
+
return ts6.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
5020
5085
|
}
|
|
5021
5086
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
5022
|
-
if (
|
|
5087
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
5023
5088
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
5024
5089
|
}
|
|
5025
|
-
if (!
|
|
5090
|
+
if (!ts6.isTypeReferenceNode(typeNode) || !ts6.isIdentifier(typeNode.typeName)) {
|
|
5026
5091
|
return typeNode;
|
|
5027
5092
|
}
|
|
5028
5093
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -5033,15 +5098,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
5033
5098
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
5034
5099
|
}
|
|
5035
5100
|
function isNullishTypeNode(typeNode) {
|
|
5036
|
-
if (typeNode.kind ===
|
|
5101
|
+
if (typeNode.kind === ts6.SyntaxKind.NullKeyword || typeNode.kind === ts6.SyntaxKind.UndefinedKeyword) {
|
|
5037
5102
|
return true;
|
|
5038
5103
|
}
|
|
5039
|
-
return
|
|
5104
|
+
return ts6.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts6.SyntaxKind.NullKeyword || typeNode.literal.kind === ts6.SyntaxKind.UndefinedKeyword);
|
|
5040
5105
|
}
|
|
5041
5106
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
5042
5107
|
const map = /* @__PURE__ */ new Map();
|
|
5043
5108
|
for (const member of members) {
|
|
5044
|
-
if (
|
|
5109
|
+
if (ts6.isPropertySignature(member)) {
|
|
5045
5110
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
5046
5111
|
member,
|
|
5047
5112
|
checker,
|
|
@@ -5067,7 +5132,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
5067
5132
|
}
|
|
5068
5133
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
5069
5134
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
5070
|
-
if (!
|
|
5135
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return [];
|
|
5071
5136
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
5072
5137
|
const aliasName = typeNode.typeName.getText();
|
|
5073
5138
|
throw new Error(
|
|
@@ -5076,7 +5141,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
5076
5141
|
}
|
|
5077
5142
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
5078
5143
|
if (!aliasDecl) return [];
|
|
5079
|
-
if (
|
|
5144
|
+
if (ts6.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
5080
5145
|
const aliasFieldType = resolveTypeNode(
|
|
5081
5146
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
5082
5147
|
checker,
|
|
@@ -5120,14 +5185,14 @@ function getNamedTypeName(type) {
|
|
|
5120
5185
|
const symbol = type.getSymbol();
|
|
5121
5186
|
if (symbol?.declarations) {
|
|
5122
5187
|
const decl = symbol.declarations[0];
|
|
5123
|
-
if (decl && (
|
|
5124
|
-
const name =
|
|
5188
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5189
|
+
const name = ts6.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
5125
5190
|
if (name) return name;
|
|
5126
5191
|
}
|
|
5127
5192
|
}
|
|
5128
5193
|
const aliasSymbol = type.aliasSymbol;
|
|
5129
5194
|
if (aliasSymbol?.declarations) {
|
|
5130
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
5195
|
+
const aliasDecl = aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5131
5196
|
if (aliasDecl) {
|
|
5132
5197
|
return aliasDecl.name.text;
|
|
5133
5198
|
}
|
|
@@ -5138,24 +5203,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
5138
5203
|
const symbol = type.getSymbol();
|
|
5139
5204
|
if (symbol?.declarations) {
|
|
5140
5205
|
const decl = symbol.declarations[0];
|
|
5141
|
-
if (decl && (
|
|
5206
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
5142
5207
|
return decl;
|
|
5143
5208
|
}
|
|
5144
5209
|
}
|
|
5145
5210
|
const aliasSymbol = type.aliasSymbol;
|
|
5146
5211
|
if (aliasSymbol?.declarations) {
|
|
5147
|
-
return aliasSymbol.declarations.find(
|
|
5212
|
+
return aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
5148
5213
|
}
|
|
5149
5214
|
return void 0;
|
|
5150
5215
|
}
|
|
5151
5216
|
function analyzeMethod(method, checker) {
|
|
5152
|
-
if (!
|
|
5217
|
+
if (!ts6.isIdentifier(method.name)) {
|
|
5153
5218
|
return null;
|
|
5154
5219
|
}
|
|
5155
5220
|
const name = method.name.text;
|
|
5156
5221
|
const parameters = [];
|
|
5157
5222
|
for (const param of method.parameters) {
|
|
5158
|
-
if (
|
|
5223
|
+
if (ts6.isIdentifier(param.name)) {
|
|
5159
5224
|
const paramInfo = analyzeParameter(param, checker);
|
|
5160
5225
|
parameters.push(paramInfo);
|
|
5161
5226
|
}
|
|
@@ -5166,7 +5231,7 @@ function analyzeMethod(method, checker) {
|
|
|
5166
5231
|
return { name, parameters, returnTypeNode, returnType };
|
|
5167
5232
|
}
|
|
5168
5233
|
function analyzeParameter(param, checker) {
|
|
5169
|
-
const name =
|
|
5234
|
+
const name = ts6.isIdentifier(param.name) ? param.name.text : "param";
|
|
5170
5235
|
const typeNode = param.type;
|
|
5171
5236
|
const type = checker.getTypeAtLocation(param);
|
|
5172
5237
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -5175,15 +5240,15 @@ function analyzeParameter(param, checker) {
|
|
|
5175
5240
|
}
|
|
5176
5241
|
function detectFormSpecReference(typeNode) {
|
|
5177
5242
|
if (!typeNode) return null;
|
|
5178
|
-
if (!
|
|
5179
|
-
const typeName =
|
|
5243
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return null;
|
|
5244
|
+
const typeName = ts6.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts6.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
5180
5245
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
5181
5246
|
const typeArg = typeNode.typeArguments?.[0];
|
|
5182
|
-
if (!typeArg || !
|
|
5183
|
-
if (
|
|
5247
|
+
if (!typeArg || !ts6.isTypeQueryNode(typeArg)) return null;
|
|
5248
|
+
if (ts6.isIdentifier(typeArg.exprName)) {
|
|
5184
5249
|
return typeArg.exprName.text;
|
|
5185
5250
|
}
|
|
5186
|
-
if (
|
|
5251
|
+
if (ts6.isQualifiedName(typeArg.exprName)) {
|
|
5187
5252
|
return typeArg.exprName.right.text;
|
|
5188
5253
|
}
|
|
5189
5254
|
return null;
|
|
@@ -5205,23 +5270,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
5205
5270
|
function createProgramContext(filePath, additionalFiles) {
|
|
5206
5271
|
const absolutePath = path.resolve(filePath);
|
|
5207
5272
|
const fileDir = path.dirname(absolutePath);
|
|
5208
|
-
const configPath =
|
|
5273
|
+
const configPath = ts7.findConfigFile(fileDir, ts7.sys.fileExists.bind(ts7.sys), "tsconfig.json");
|
|
5209
5274
|
let compilerOptions;
|
|
5210
5275
|
let fileNames;
|
|
5211
5276
|
if (configPath) {
|
|
5212
|
-
const configFile =
|
|
5277
|
+
const configFile = ts7.readConfigFile(configPath, ts7.sys.readFile.bind(ts7.sys));
|
|
5213
5278
|
if (configFile.error) {
|
|
5214
5279
|
throw new Error(
|
|
5215
|
-
`Error reading tsconfig.json: ${
|
|
5280
|
+
`Error reading tsconfig.json: ${ts7.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
5216
5281
|
);
|
|
5217
5282
|
}
|
|
5218
|
-
const parsed =
|
|
5283
|
+
const parsed = ts7.parseJsonConfigFileContent(
|
|
5219
5284
|
configFile.config,
|
|
5220
|
-
|
|
5285
|
+
ts7.sys,
|
|
5221
5286
|
path.dirname(configPath)
|
|
5222
5287
|
);
|
|
5223
5288
|
if (parsed.errors.length > 0) {
|
|
5224
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
5289
|
+
const errorMessages = parsed.errors.map((e) => ts7.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
5225
5290
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
5226
5291
|
}
|
|
5227
5292
|
compilerOptions = parsed.options;
|
|
@@ -5229,9 +5294,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5229
5294
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
5230
5295
|
} else {
|
|
5231
5296
|
compilerOptions = {
|
|
5232
|
-
target:
|
|
5233
|
-
module:
|
|
5234
|
-
moduleResolution:
|
|
5297
|
+
target: ts7.ScriptTarget.ES2022,
|
|
5298
|
+
module: ts7.ModuleKind.NodeNext,
|
|
5299
|
+
moduleResolution: ts7.ModuleResolutionKind.NodeNext,
|
|
5235
5300
|
strict: true,
|
|
5236
5301
|
skipLibCheck: true,
|
|
5237
5302
|
declaration: true
|
|
@@ -5239,7 +5304,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
5239
5304
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
5240
5305
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
5241
5306
|
}
|
|
5242
|
-
const program =
|
|
5307
|
+
const program = ts7.createProgram(fileNames, compilerOptions);
|
|
5243
5308
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
5244
5309
|
if (!sourceFile) {
|
|
5245
5310
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -5258,19 +5323,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
5258
5323
|
result = node;
|
|
5259
5324
|
return;
|
|
5260
5325
|
}
|
|
5261
|
-
|
|
5326
|
+
ts7.forEachChild(node, visit);
|
|
5262
5327
|
}
|
|
5263
5328
|
visit(sourceFile);
|
|
5264
5329
|
return result;
|
|
5265
5330
|
}
|
|
5266
5331
|
function findClassByName(sourceFile, className) {
|
|
5267
|
-
return findNodeByName(sourceFile, className,
|
|
5332
|
+
return findNodeByName(sourceFile, className, ts7.isClassDeclaration, (n) => n.name?.text);
|
|
5268
5333
|
}
|
|
5269
5334
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
5270
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
5335
|
+
return findNodeByName(sourceFile, interfaceName, ts7.isInterfaceDeclaration, (n) => n.name.text);
|
|
5271
5336
|
}
|
|
5272
5337
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
5273
|
-
return findNodeByName(sourceFile, aliasName,
|
|
5338
|
+
return findNodeByName(sourceFile, aliasName, ts7.isTypeAliasDeclaration, (n) => n.name.text);
|
|
5274
5339
|
}
|
|
5275
5340
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
5276
5341
|
if (rootType.kind === "object") {
|
|
@@ -5310,22 +5375,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
5310
5375
|
};
|
|
5311
5376
|
}
|
|
5312
5377
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
5313
|
-
if (
|
|
5378
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5314
5379
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
5315
5380
|
}
|
|
5316
|
-
if (
|
|
5381
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5317
5382
|
return true;
|
|
5318
5383
|
}
|
|
5319
|
-
return
|
|
5384
|
+
return ts7.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
5320
5385
|
}
|
|
5321
5386
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
5322
|
-
if (
|
|
5387
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
5323
5388
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
5324
5389
|
}
|
|
5325
|
-
if (
|
|
5390
|
+
if (ts7.isTypeLiteralNode(typeNode)) {
|
|
5326
5391
|
const propertyNames = [];
|
|
5327
5392
|
for (const member of typeNode.members) {
|
|
5328
|
-
if (!
|
|
5393
|
+
if (!ts7.isPropertySignature(member)) {
|
|
5329
5394
|
continue;
|
|
5330
5395
|
}
|
|
5331
5396
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -5335,13 +5400,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
5335
5400
|
}
|
|
5336
5401
|
return propertyNames;
|
|
5337
5402
|
}
|
|
5338
|
-
if (
|
|
5403
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
5339
5404
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
5340
5405
|
}
|
|
5341
5406
|
return null;
|
|
5342
5407
|
}
|
|
5343
5408
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
5344
|
-
if (!
|
|
5409
|
+
if (!ts7.isIntersectionTypeNode(typeNode)) {
|
|
5345
5410
|
return [];
|
|
5346
5411
|
}
|
|
5347
5412
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5542,7 +5607,7 @@ function makeFileProvenance(filePath) {
|
|
|
5542
5607
|
}
|
|
5543
5608
|
|
|
5544
5609
|
// src/extensions/symbol-registry.ts
|
|
5545
|
-
import * as
|
|
5610
|
+
import * as ts8 from "typescript";
|
|
5546
5611
|
import * as path2 from "path";
|
|
5547
5612
|
function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistry) {
|
|
5548
5613
|
const symbolMap = /* @__PURE__ */ new Map();
|
|
@@ -5552,10 +5617,10 @@ function buildSymbolMapFromConfig(configPath, program, checker, extensionRegistr
|
|
|
5552
5617
|
return symbolMap;
|
|
5553
5618
|
}
|
|
5554
5619
|
function visit(node) {
|
|
5555
|
-
if (
|
|
5620
|
+
if (ts8.isCallExpression(node) && isDefineCustomTypeCall(node, checker)) {
|
|
5556
5621
|
processDefineCustomTypeCall(node);
|
|
5557
5622
|
}
|
|
5558
|
-
|
|
5623
|
+
ts8.forEachChild(node, visit);
|
|
5559
5624
|
}
|
|
5560
5625
|
function processDefineCustomTypeCall(call) {
|
|
5561
5626
|
const typeArgNode = call.typeArguments?.[0];
|
|
@@ -5592,7 +5657,7 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5592
5657
|
if (node.typeArguments === void 0 || node.typeArguments.length === 0) return false;
|
|
5593
5658
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5594
5659
|
if (callSymbol !== void 0) {
|
|
5595
|
-
const resolved = callSymbol.flags &
|
|
5660
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5596
5661
|
const decl = resolved.declarations?.[0];
|
|
5597
5662
|
if (decl !== void 0) {
|
|
5598
5663
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
@@ -5600,24 +5665,24 @@ function isDefineCustomTypeCall(node, checker) {
|
|
|
5600
5665
|
(sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5601
5666
|
}
|
|
5602
5667
|
}
|
|
5603
|
-
return
|
|
5668
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineCustomType";
|
|
5604
5669
|
}
|
|
5605
5670
|
function extractTypeNameFromCallArg(call) {
|
|
5606
5671
|
const arg = call.arguments[0];
|
|
5607
|
-
if (arg === void 0 || !
|
|
5672
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5608
5673
|
return null;
|
|
5609
5674
|
}
|
|
5610
5675
|
const typeNameProp = arg.properties.find(
|
|
5611
|
-
(p) =>
|
|
5676
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "typeName"
|
|
5612
5677
|
);
|
|
5613
|
-
if (typeNameProp === void 0 || !
|
|
5678
|
+
if (typeNameProp === void 0 || !ts8.isStringLiteral(typeNameProp.initializer)) {
|
|
5614
5679
|
return null;
|
|
5615
5680
|
}
|
|
5616
5681
|
return typeNameProp.initializer.text;
|
|
5617
5682
|
}
|
|
5618
5683
|
function extractEnclosingExtensionId(call, checker) {
|
|
5619
|
-
for (let node = call.parent; !
|
|
5620
|
-
if (
|
|
5684
|
+
for (let node = call.parent; !ts8.isSourceFile(node); node = node.parent) {
|
|
5685
|
+
if (ts8.isCallExpression(node) && isDefineExtensionCall(node, checker)) {
|
|
5621
5686
|
return extractExtensionIdFromCallArg(node);
|
|
5622
5687
|
}
|
|
5623
5688
|
}
|
|
@@ -5626,24 +5691,24 @@ function extractEnclosingExtensionId(call, checker) {
|
|
|
5626
5691
|
function isDefineExtensionCall(node, checker) {
|
|
5627
5692
|
const callSymbol = checker.getSymbolAtLocation(node.expression);
|
|
5628
5693
|
if (callSymbol !== void 0) {
|
|
5629
|
-
const resolved = callSymbol.flags &
|
|
5694
|
+
const resolved = callSymbol.flags & ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(callSymbol) : callSymbol;
|
|
5630
5695
|
const decl = resolved.declarations?.[0];
|
|
5631
5696
|
if (decl !== void 0) {
|
|
5632
5697
|
const sourceFile = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
5633
5698
|
return resolved.name === "defineExtension" && (sourceFile.includes("@formspec/core") || sourceFile.includes("/packages/core/"));
|
|
5634
5699
|
}
|
|
5635
5700
|
}
|
|
5636
|
-
return
|
|
5701
|
+
return ts8.isIdentifier(node.expression) && node.expression.text === "defineExtension";
|
|
5637
5702
|
}
|
|
5638
5703
|
function extractExtensionIdFromCallArg(call) {
|
|
5639
5704
|
const arg = call.arguments[0];
|
|
5640
|
-
if (arg === void 0 || !
|
|
5705
|
+
if (arg === void 0 || !ts8.isObjectLiteralExpression(arg)) {
|
|
5641
5706
|
return null;
|
|
5642
5707
|
}
|
|
5643
5708
|
const prop = arg.properties.find(
|
|
5644
|
-
(p) =>
|
|
5709
|
+
(p) => ts8.isPropertyAssignment(p) && ts8.isIdentifier(p.name) && p.name.text === "extensionId"
|
|
5645
5710
|
);
|
|
5646
|
-
if (prop === void 0 || !
|
|
5711
|
+
if (prop === void 0 || !ts8.isStringLiteral(prop.initializer)) {
|
|
5647
5712
|
return null;
|
|
5648
5713
|
}
|
|
5649
5714
|
return prop.initializer.text;
|
|
@@ -5905,7 +5970,7 @@ function generateSchemasBatch(options) {
|
|
|
5905
5970
|
return options.targets.map((target) => {
|
|
5906
5971
|
let ctx;
|
|
5907
5972
|
try {
|
|
5908
|
-
const cacheKey =
|
|
5973
|
+
const cacheKey = ts9.sys.useCaseSensitiveFileNames ? target.filePath : target.filePath.toLowerCase();
|
|
5909
5974
|
const cachedContext = contextCache.get(cacheKey);
|
|
5910
5975
|
if (cachedContext === void 0) {
|
|
5911
5976
|
const additionalFiles = options.configPath !== void 0 ? [options.configPath] : void 0;
|
|
@@ -6061,7 +6126,7 @@ function createProgramContextFailureDiagnostic(filePath, error) {
|
|
|
6061
6126
|
}
|
|
6062
6127
|
|
|
6063
6128
|
// src/static-build.ts
|
|
6064
|
-
import * as
|
|
6129
|
+
import * as ts10 from "typescript";
|
|
6065
6130
|
function toStaticBuildContext(context) {
|
|
6066
6131
|
return context;
|
|
6067
6132
|
}
|
|
@@ -6076,7 +6141,7 @@ function getModuleSymbol(context) {
|
|
|
6076
6141
|
return context.checker.getSymbolAtLocation(context.sourceFile) ?? sourceFileWithSymbol.symbol;
|
|
6077
6142
|
}
|
|
6078
6143
|
function isSchemaSourceDeclaration(declaration) {
|
|
6079
|
-
return
|
|
6144
|
+
return ts10.isClassDeclaration(declaration) || ts10.isInterfaceDeclaration(declaration) || ts10.isTypeAliasDeclaration(declaration);
|
|
6080
6145
|
}
|
|
6081
6146
|
function resolveModuleExport(context, exportName = "default") {
|
|
6082
6147
|
const moduleSymbol = getModuleSymbol(context);
|
|
@@ -6087,14 +6152,14 @@ function resolveModuleExport(context, exportName = "default") {
|
|
|
6087
6152
|
if (exportSymbol === null) {
|
|
6088
6153
|
return null;
|
|
6089
6154
|
}
|
|
6090
|
-
return exportSymbol.flags &
|
|
6155
|
+
return exportSymbol.flags & ts10.SymbolFlags.Alias ? context.checker.getAliasedSymbol(exportSymbol) : exportSymbol;
|
|
6091
6156
|
}
|
|
6092
6157
|
function resolveModuleExportDeclaration(context, exportName = "default") {
|
|
6093
6158
|
return resolveModuleExport(context, exportName)?.declarations?.find(isSchemaSourceDeclaration) ?? null;
|
|
6094
6159
|
}
|
|
6095
6160
|
|
|
6096
6161
|
// src/generators/discovered-schema.ts
|
|
6097
|
-
import * as
|
|
6162
|
+
import * as ts11 from "typescript";
|
|
6098
6163
|
import { analyzeMetadataForNodeWithChecker as analyzeMetadataForNodeWithChecker2 } from "@formspec/analysis/internal";
|
|
6099
6164
|
import { IR_VERSION as IR_VERSION3 } from "@formspec/core/internals";
|
|
6100
6165
|
function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
@@ -6104,17 +6169,17 @@ function toDiscoveredTypeSchemas(result, resolvedMetadata) {
|
|
|
6104
6169
|
};
|
|
6105
6170
|
}
|
|
6106
6171
|
function isNamedTypeDeclaration(declaration) {
|
|
6107
|
-
return
|
|
6172
|
+
return ts11.isClassDeclaration(declaration) || ts11.isInterfaceDeclaration(declaration) || ts11.isTypeAliasDeclaration(declaration);
|
|
6108
6173
|
}
|
|
6109
6174
|
function hasConcreteTypeArguments(type, checker) {
|
|
6110
6175
|
if ("aliasTypeArguments" in type && Array.isArray(type.aliasTypeArguments) && type.aliasTypeArguments.length > 0) {
|
|
6111
6176
|
return true;
|
|
6112
6177
|
}
|
|
6113
|
-
if ((type.flags &
|
|
6178
|
+
if ((type.flags & ts11.TypeFlags.Object) === 0) {
|
|
6114
6179
|
return false;
|
|
6115
6180
|
}
|
|
6116
6181
|
const objectType = type;
|
|
6117
|
-
if ((objectType.objectFlags &
|
|
6182
|
+
if ((objectType.objectFlags & ts11.ObjectFlags.Reference) === 0) {
|
|
6118
6183
|
return false;
|
|
6119
6184
|
}
|
|
6120
6185
|
return checker.getTypeArguments(objectType).length > 0;
|
|
@@ -6127,13 +6192,13 @@ function getNamedTypeDeclaration2(type) {
|
|
|
6127
6192
|
return declaration;
|
|
6128
6193
|
}
|
|
6129
6194
|
}
|
|
6130
|
-
const aliasDeclaration = type.aliasSymbol?.declarations?.find(
|
|
6195
|
+
const aliasDeclaration = type.aliasSymbol?.declarations?.find(ts11.isTypeAliasDeclaration);
|
|
6131
6196
|
return aliasDeclaration;
|
|
6132
6197
|
}
|
|
6133
6198
|
function getFallbackName(sourceNode, fallback = "AnonymousType") {
|
|
6134
6199
|
if (sourceNode !== void 0 && "name" in sourceNode) {
|
|
6135
6200
|
const namedNode = sourceNode;
|
|
6136
|
-
if (namedNode.name !== void 0 &&
|
|
6201
|
+
if (namedNode.name !== void 0 && ts11.isIdentifier(namedNode.name)) {
|
|
6137
6202
|
return namedNode.name.text;
|
|
6138
6203
|
}
|
|
6139
6204
|
}
|
|
@@ -6355,7 +6420,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
6355
6420
|
function generateSchemasFromDeclaration(options) {
|
|
6356
6421
|
const filePath = options.declaration.getSourceFile().fileName;
|
|
6357
6422
|
const resolved = resolveStaticOptions(options);
|
|
6358
|
-
if (
|
|
6423
|
+
if (ts11.isClassDeclaration(options.declaration)) {
|
|
6359
6424
|
return generateSchemasFromAnalysis(
|
|
6360
6425
|
analyzeClassToIR(
|
|
6361
6426
|
options.declaration,
|
|
@@ -6369,7 +6434,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6369
6434
|
resolved
|
|
6370
6435
|
);
|
|
6371
6436
|
}
|
|
6372
|
-
if (
|
|
6437
|
+
if (ts11.isInterfaceDeclaration(options.declaration)) {
|
|
6373
6438
|
return generateSchemasFromAnalysis(
|
|
6374
6439
|
analyzeInterfaceToIR(
|
|
6375
6440
|
options.declaration,
|
|
@@ -6383,7 +6448,7 @@ function generateSchemasFromDeclaration(options) {
|
|
|
6383
6448
|
resolved
|
|
6384
6449
|
);
|
|
6385
6450
|
}
|
|
6386
|
-
if (
|
|
6451
|
+
if (ts11.isTypeAliasDeclaration(options.declaration)) {
|
|
6387
6452
|
const analyzedAlias = analyzeTypeAliasToIR(
|
|
6388
6453
|
options.declaration,
|
|
6389
6454
|
options.context.checker,
|
|
@@ -6442,7 +6507,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
6442
6507
|
const returnType = signature !== void 0 ? options.context.checker.getReturnTypeOfSignature(signature) : options.context.checker.getTypeAtLocation(options.declaration);
|
|
6443
6508
|
const type = unwrapPromiseType(options.context.checker, returnType);
|
|
6444
6509
|
const sourceNode = type !== returnType ? unwrapPromiseTypeNode(options.declaration.type) ?? options.declaration.type ?? options.declaration : options.declaration.type ?? options.declaration;
|
|
6445
|
-
const fallbackName = options.declaration.name !== void 0 &&
|
|
6510
|
+
const fallbackName = options.declaration.name !== void 0 && ts11.isIdentifier(options.declaration.name) ? `${options.declaration.name.text}ReturnType` : "ReturnType";
|
|
6446
6511
|
return generateSchemasFromResolvedType({
|
|
6447
6512
|
...options,
|
|
6448
6513
|
type,
|
|
@@ -6489,14 +6554,14 @@ function unwrapPromiseTypeNode(typeNode) {
|
|
|
6489
6554
|
if (typeNode === void 0) {
|
|
6490
6555
|
return void 0;
|
|
6491
6556
|
}
|
|
6492
|
-
if (
|
|
6557
|
+
if (ts11.isParenthesizedTypeNode(typeNode)) {
|
|
6493
6558
|
const unwrapped = unwrapPromiseTypeNode(typeNode.type);
|
|
6494
6559
|
return unwrapped ?? typeNode;
|
|
6495
6560
|
}
|
|
6496
6561
|
return isPromiseTypeReferenceNode(typeNode) ? typeNode.typeArguments[0] : typeNode;
|
|
6497
6562
|
}
|
|
6498
6563
|
function isPromiseTypeReferenceNode(typeNode) {
|
|
6499
|
-
return
|
|
6564
|
+
return ts11.isTypeReferenceNode(typeNode) && ts11.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0;
|
|
6500
6565
|
}
|
|
6501
6566
|
|
|
6502
6567
|
// src/generators/mixed-authoring.ts
|
|
@@ -6695,6 +6760,8 @@ function annotationKey(annotation) {
|
|
|
6695
6760
|
|
|
6696
6761
|
// src/index.ts
|
|
6697
6762
|
function buildFormSchemas(form, options) {
|
|
6763
|
+
const logger = options?.logger ?? noopLogger3;
|
|
6764
|
+
logger.debug("buildFormSchemas: starting schema generation");
|
|
6698
6765
|
return {
|
|
6699
6766
|
jsonSchema: generateJsonSchema(form, options),
|
|
6700
6767
|
uiSchema: generateUiSchema(form, options)
|
|
@@ -6707,12 +6774,15 @@ function writeSchemas(form, options) {
|
|
|
6707
6774
|
indent = 2,
|
|
6708
6775
|
vendorPrefix,
|
|
6709
6776
|
enumSerialization,
|
|
6710
|
-
metadata
|
|
6777
|
+
metadata,
|
|
6778
|
+
logger: rawLogger
|
|
6711
6779
|
} = options;
|
|
6712
|
-
const
|
|
6780
|
+
const logger = (rawLogger ?? noopLogger3).child({ stage: "write" });
|
|
6781
|
+
const buildOptions = vendorPrefix === void 0 && enumSerialization === void 0 && metadata === void 0 ? { logger: rawLogger } : {
|
|
6713
6782
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
6714
6783
|
...enumSerialization !== void 0 && { enumSerialization },
|
|
6715
|
-
...metadata !== void 0 && { metadata }
|
|
6784
|
+
...metadata !== void 0 && { metadata },
|
|
6785
|
+
logger: rawLogger
|
|
6716
6786
|
};
|
|
6717
6787
|
const { jsonSchema, uiSchema: uiSchema2 } = buildFormSchemas(form, buildOptions);
|
|
6718
6788
|
if (!fs.existsSync(outDir)) {
|
|
@@ -6720,7 +6790,9 @@ function writeSchemas(form, options) {
|
|
|
6720
6790
|
}
|
|
6721
6791
|
const jsonSchemaPath = path3.join(outDir, `${name}-schema.json`);
|
|
6722
6792
|
const uiSchemaPath = path3.join(outDir, `${name}-uischema.json`);
|
|
6793
|
+
logger.debug("writing JSON Schema", { path: jsonSchemaPath });
|
|
6723
6794
|
fs.writeFileSync(jsonSchemaPath, JSON.stringify(jsonSchema, null, indent));
|
|
6795
|
+
logger.debug("writing UI Schema", { path: uiSchemaPath });
|
|
6724
6796
|
fs.writeFileSync(uiSchemaPath, JSON.stringify(uiSchema2, null, indent));
|
|
6725
6797
|
return { jsonSchemaPath, uiSchemaPath };
|
|
6726
6798
|
}
|