@formspec/build 0.1.0-alpha.58 → 0.1.0-alpha.59
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 +10 -7
- package/dist/analyzer/builtin-brands.d.ts.map +1 -1
- package/dist/analyzer/class-analyzer.d.ts +29 -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 +126 -31
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +129 -32
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +431 -12
- package/dist/build-beta.d.ts +399 -12
- package/dist/build-internal.d.ts +460 -12
- package/dist/build.d.ts +399 -12
- package/dist/cli.cjs +590 -338
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +547 -289
- package/dist/cli.js.map +1 -1
- package/dist/extensions/registry.d.ts +19 -1
- package/dist/extensions/registry.d.ts.map +1 -1
- package/dist/extensions/resolve-custom-type.d.ts.map +1 -1
- package/dist/extensions/ts-type-utils.d.ts +0 -11
- package/dist/extensions/ts-type-utils.d.ts.map +1 -1
- package/dist/generators/class-schema.d.ts.map +1 -1
- package/dist/index.cjs +580 -327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +546 -287
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +554 -301
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +515 -256
- package/dist/internals.js.map +1 -1
- package/package.json +5 -5
package/dist/internals.js
CHANGED
|
@@ -791,21 +791,21 @@ function wrapInConditional(field, layout, provenance) {
|
|
|
791
791
|
}
|
|
792
792
|
|
|
793
793
|
// src/analyzer/program.ts
|
|
794
|
-
import * as
|
|
794
|
+
import * as ts6 from "typescript";
|
|
795
795
|
import * as path from "path";
|
|
796
796
|
|
|
797
797
|
// src/analyzer/class-analyzer.ts
|
|
798
|
-
import * as
|
|
798
|
+
import * as ts5 from "typescript";
|
|
799
799
|
import {
|
|
800
800
|
analyzeMetadataForNodeWithChecker,
|
|
801
801
|
parseCommentBlock
|
|
802
802
|
} from "@formspec/analysis/internal";
|
|
803
803
|
|
|
804
804
|
// src/analyzer/jsdoc-constraints.ts
|
|
805
|
-
import * as
|
|
805
|
+
import * as ts4 from "typescript";
|
|
806
806
|
|
|
807
807
|
// src/analyzer/tsdoc-parser.ts
|
|
808
|
-
import * as
|
|
808
|
+
import * as ts3 from "typescript";
|
|
809
809
|
import {
|
|
810
810
|
checkSyntheticTagApplication,
|
|
811
811
|
choosePreferredPayloadText,
|
|
@@ -832,25 +832,10 @@ import { noopLogger } from "@formspec/core";
|
|
|
832
832
|
|
|
833
833
|
// src/extensions/resolve-custom-type.ts
|
|
834
834
|
import * as ts2 from "typescript";
|
|
835
|
-
import { stripNullishUnion } from "@formspec/analysis/internal";
|
|
835
|
+
import { _collectBrandIdentifiers, stripNullishUnion } from "@formspec/analysis/internal";
|
|
836
836
|
|
|
837
837
|
// src/extensions/ts-type-utils.ts
|
|
838
838
|
import * as ts from "typescript";
|
|
839
|
-
function collectBrandIdentifiers(type) {
|
|
840
|
-
if (!type.isIntersection()) {
|
|
841
|
-
return [];
|
|
842
|
-
}
|
|
843
|
-
const brands = [];
|
|
844
|
-
for (const prop of type.getProperties()) {
|
|
845
|
-
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
846
|
-
if (decl === void 0) continue;
|
|
847
|
-
if (!ts.isPropertySignature(decl) && !ts.isPropertyDeclaration(decl)) continue;
|
|
848
|
-
if (!ts.isComputedPropertyName(decl.name)) continue;
|
|
849
|
-
if (!ts.isIdentifier(decl.name.expression)) continue;
|
|
850
|
-
brands.push(decl.name.expression.text);
|
|
851
|
-
}
|
|
852
|
-
return brands;
|
|
853
|
-
}
|
|
854
839
|
function resolveCanonicalSymbol(type, checker) {
|
|
855
840
|
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
856
841
|
if (raw === void 0) return void 0;
|
|
@@ -935,7 +920,7 @@ function resolveCustomTypeFromTsType(type, checker, registry, sourceNode) {
|
|
|
935
920
|
return bySymbol;
|
|
936
921
|
}
|
|
937
922
|
}
|
|
938
|
-
for (const brand of
|
|
923
|
+
for (const brand of _collectBrandIdentifiers(stripped)) {
|
|
939
924
|
const byBrand = registry.findTypeByBrand(brand);
|
|
940
925
|
if (byBrand !== void 0) {
|
|
941
926
|
return byBrand;
|
|
@@ -948,19 +933,18 @@ function customTypeIdFromLookup(result) {
|
|
|
948
933
|
}
|
|
949
934
|
|
|
950
935
|
// src/analyzer/builtin-brands.ts
|
|
951
|
-
import
|
|
952
|
-
function isIntegerBrandedType(type) {
|
|
953
|
-
if (!type.isIntersection()) return false;
|
|
954
|
-
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
955
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
956
|
-
}
|
|
936
|
+
import { _isIntegerBrandedType } from "@formspec/analysis/internal";
|
|
957
937
|
|
|
958
938
|
// src/analyzer/tsdoc-parser.ts
|
|
959
939
|
import {
|
|
940
|
+
_emitSetupDiagnostics,
|
|
941
|
+
_mapSetupDiagnosticCode,
|
|
960
942
|
getBuildLogger,
|
|
961
943
|
getBroadeningLogger,
|
|
962
944
|
getSyntheticLogger,
|
|
963
945
|
getTypedParserLogger,
|
|
946
|
+
extractEffectiveArgumentText,
|
|
947
|
+
mapTypedParserDiagnosticCode,
|
|
964
948
|
parseTagArgument,
|
|
965
949
|
describeTypeKind,
|
|
966
950
|
elapsedMicros,
|
|
@@ -973,7 +957,7 @@ function sharedTagValueOptions(options) {
|
|
|
973
957
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
974
958
|
};
|
|
975
959
|
}
|
|
976
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
960
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
977
961
|
function getExtensionTypeNames(registry) {
|
|
978
962
|
if (registry === void 0) {
|
|
979
963
|
return /* @__PURE__ */ new Set();
|
|
@@ -987,23 +971,23 @@ function getExtensionTypeNames(registry) {
|
|
|
987
971
|
function collectImportedNames(sourceFile) {
|
|
988
972
|
const importedNames = /* @__PURE__ */ new Set();
|
|
989
973
|
for (const statement of sourceFile.statements) {
|
|
990
|
-
if (
|
|
974
|
+
if (ts3.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
991
975
|
const clause = statement.importClause;
|
|
992
976
|
if (clause.name !== void 0) {
|
|
993
977
|
importedNames.add(clause.name.text);
|
|
994
978
|
}
|
|
995
979
|
if (clause.namedBindings !== void 0) {
|
|
996
|
-
if (
|
|
980
|
+
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
997
981
|
for (const specifier of clause.namedBindings.elements) {
|
|
998
982
|
importedNames.add(specifier.name.text);
|
|
999
983
|
}
|
|
1000
|
-
} else if (
|
|
984
|
+
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
1001
985
|
importedNames.add(clause.namedBindings.name.text);
|
|
1002
986
|
}
|
|
1003
987
|
}
|
|
1004
988
|
continue;
|
|
1005
989
|
}
|
|
1006
|
-
if (
|
|
990
|
+
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
1007
991
|
importedNames.add(statement.name.text);
|
|
1008
992
|
}
|
|
1009
993
|
}
|
|
@@ -1011,13 +995,13 @@ function collectImportedNames(sourceFile) {
|
|
|
1011
995
|
}
|
|
1012
996
|
function isNonReferenceIdentifier(node) {
|
|
1013
997
|
const parent = node.parent;
|
|
1014
|
-
if ((
|
|
998
|
+
if ((ts3.isBindingElement(parent) || ts3.isClassDeclaration(parent) || ts3.isEnumDeclaration(parent) || ts3.isEnumMember(parent) || ts3.isFunctionDeclaration(parent) || ts3.isFunctionExpression(parent) || ts3.isImportClause(parent) || ts3.isImportEqualsDeclaration(parent) || ts3.isImportSpecifier(parent) || ts3.isInterfaceDeclaration(parent) || ts3.isMethodDeclaration(parent) || ts3.isMethodSignature(parent) || ts3.isModuleDeclaration(parent) || ts3.isNamespaceExport(parent) || ts3.isNamespaceImport(parent) || ts3.isParameter(parent) || ts3.isPropertyDeclaration(parent) || ts3.isPropertySignature(parent) || ts3.isSetAccessorDeclaration(parent) || ts3.isGetAccessorDeclaration(parent) || ts3.isTypeAliasDeclaration(parent) || ts3.isTypeParameterDeclaration(parent) || ts3.isVariableDeclaration(parent)) && parent.name === node) {
|
|
1015
999
|
return true;
|
|
1016
1000
|
}
|
|
1017
|
-
if ((
|
|
1001
|
+
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
1018
1002
|
return true;
|
|
1019
1003
|
}
|
|
1020
|
-
if (
|
|
1004
|
+
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
1021
1005
|
return true;
|
|
1022
1006
|
}
|
|
1023
1007
|
return false;
|
|
@@ -1029,20 +1013,20 @@ function astReferencesImportedName(root, importedNames) {
|
|
|
1029
1013
|
let found = false;
|
|
1030
1014
|
const visit = (node) => {
|
|
1031
1015
|
if (found) return;
|
|
1032
|
-
if (
|
|
1016
|
+
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
1033
1017
|
found = true;
|
|
1034
1018
|
return;
|
|
1035
1019
|
}
|
|
1036
|
-
|
|
1020
|
+
ts3.forEachChild(node, visit);
|
|
1037
1021
|
};
|
|
1038
1022
|
visit(root);
|
|
1039
1023
|
return found;
|
|
1040
1024
|
}
|
|
1041
1025
|
function getObjectMembers(statement) {
|
|
1042
|
-
if (
|
|
1026
|
+
if (ts3.isInterfaceDeclaration(statement)) {
|
|
1043
1027
|
return statement.members;
|
|
1044
1028
|
}
|
|
1045
|
-
if (
|
|
1029
|
+
if (ts3.isTypeLiteralNode(statement.type)) {
|
|
1046
1030
|
return statement.type.members;
|
|
1047
1031
|
}
|
|
1048
1032
|
return void 0;
|
|
@@ -1054,7 +1038,7 @@ function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
|
1054
1038
|
}
|
|
1055
1039
|
const replacements = [];
|
|
1056
1040
|
for (const member of members) {
|
|
1057
|
-
if (!
|
|
1041
|
+
if (!ts3.isPropertySignature(member)) {
|
|
1058
1042
|
if (astReferencesImportedName(member, importedNames)) {
|
|
1059
1043
|
return null;
|
|
1060
1044
|
}
|
|
@@ -1086,14 +1070,14 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
1086
1070
|
);
|
|
1087
1071
|
const result = [];
|
|
1088
1072
|
for (const statement of sourceFile.statements) {
|
|
1089
|
-
if (
|
|
1090
|
-
if (
|
|
1091
|
-
if (
|
|
1073
|
+
if (ts3.isImportDeclaration(statement)) continue;
|
|
1074
|
+
if (ts3.isImportEqualsDeclaration(statement)) continue;
|
|
1075
|
+
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
1092
1076
|
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
1093
1077
|
result.push(statement.getText(sourceFile));
|
|
1094
1078
|
continue;
|
|
1095
1079
|
}
|
|
1096
|
-
if (
|
|
1080
|
+
if (ts3.isInterfaceDeclaration(statement) || ts3.isTypeAliasDeclaration(statement)) {
|
|
1097
1081
|
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
1098
1082
|
if (rewritten !== null) {
|
|
1099
1083
|
result.push(rewritten);
|
|
@@ -1196,7 +1180,7 @@ function stripHintNullishUnion(type) {
|
|
|
1196
1180
|
return type;
|
|
1197
1181
|
}
|
|
1198
1182
|
const nonNullish = type.types.filter(
|
|
1199
|
-
(member) => (member.flags & (
|
|
1183
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
1200
1184
|
);
|
|
1201
1185
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
1202
1186
|
return nonNullish[0];
|
|
@@ -1212,10 +1196,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
1212
1196
|
}
|
|
1213
1197
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
1214
1198
|
const name = declaration.name;
|
|
1215
|
-
if (
|
|
1199
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
1216
1200
|
return false;
|
|
1217
1201
|
}
|
|
1218
|
-
if (!
|
|
1202
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
1219
1203
|
return false;
|
|
1220
1204
|
}
|
|
1221
1205
|
}
|
|
@@ -1461,7 +1445,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1461
1445
|
}
|
|
1462
1446
|
const hasBroadening = (() => {
|
|
1463
1447
|
if (target === null) {
|
|
1464
|
-
if (
|
|
1448
|
+
if (_isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
1465
1449
|
return true;
|
|
1466
1450
|
}
|
|
1467
1451
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
@@ -1492,10 +1476,10 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1492
1476
|
]);
|
|
1493
1477
|
}
|
|
1494
1478
|
}
|
|
1495
|
-
const effectiveArgumentText = parsedTag !== null ? parseTagSyntax(tagName, rawText).argumentText : rawText;
|
|
1496
1479
|
if (hasBroadening) {
|
|
1497
1480
|
return emit("bypass", []);
|
|
1498
1481
|
}
|
|
1482
|
+
const effectiveArgumentText = extractEffectiveArgumentText(tagName, rawText, parsedTag);
|
|
1499
1483
|
const typedParseResult = parseTagArgument(tagName, effectiveArgumentText, "build");
|
|
1500
1484
|
if (!typedParseResult.ok) {
|
|
1501
1485
|
if (typedParserTraceEnabled) {
|
|
@@ -1508,23 +1492,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1508
1492
|
diagnosticCode: typedParseResult.diagnostic.code
|
|
1509
1493
|
});
|
|
1510
1494
|
}
|
|
1511
|
-
|
|
1512
|
-
switch (typedParseResult.diagnostic.code) {
|
|
1513
|
-
case "MISSING_TAG_ARGUMENT":
|
|
1514
|
-
mappedCode = "MISSING_TAG_ARGUMENT";
|
|
1515
|
-
break;
|
|
1516
|
-
case "INVALID_TAG_ARGUMENT":
|
|
1517
|
-
mappedCode = "INVALID_TAG_ARGUMENT";
|
|
1518
|
-
break;
|
|
1519
|
-
case "UNKNOWN_TAG":
|
|
1520
|
-
throw new Error(
|
|
1521
|
-
`Unexpected UNKNOWN_TAG from parseTagArgument("${tagName}") \u2014 tag was resolved via getTagDefinition.`
|
|
1522
|
-
);
|
|
1523
|
-
default: {
|
|
1524
|
-
const _exhaustive = typedParseResult.diagnostic.code;
|
|
1525
|
-
throw new Error(`Unknown diagnostic code: ${String(_exhaustive)}`);
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1495
|
+
const mappedCode = mapTypedParserDiagnosticCode(typedParseResult.diagnostic.code, tagName);
|
|
1528
1496
|
return emit("C-reject", [
|
|
1529
1497
|
makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
|
|
1530
1498
|
]);
|
|
@@ -1581,13 +1549,13 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1581
1549
|
} : {}
|
|
1582
1550
|
});
|
|
1583
1551
|
if (result.diagnostics.length === 0) {
|
|
1584
|
-
return emit("
|
|
1552
|
+
return emit("D-pass", []);
|
|
1585
1553
|
}
|
|
1586
1554
|
const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
|
|
1587
1555
|
if (setupDiagnostic !== void 0) {
|
|
1588
1556
|
return emit("C-reject", [
|
|
1589
1557
|
makeDiagnostic(
|
|
1590
|
-
setupDiagnostic.kind
|
|
1558
|
+
_mapSetupDiagnosticCode(setupDiagnostic.kind),
|
|
1591
1559
|
setupDiagnostic.message,
|
|
1592
1560
|
provenance
|
|
1593
1561
|
)
|
|
@@ -1655,6 +1623,16 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1655
1623
|
if (cached !== void 0) {
|
|
1656
1624
|
return cached;
|
|
1657
1625
|
}
|
|
1626
|
+
const setupDiags = options?.extensionRegistry?.setupDiagnostics;
|
|
1627
|
+
if (setupDiags !== void 0 && setupDiags.length > 0) {
|
|
1628
|
+
const result2 = {
|
|
1629
|
+
constraints: [],
|
|
1630
|
+
annotations: [],
|
|
1631
|
+
diagnostics: _emitSetupDiagnostics(setupDiags, file)
|
|
1632
|
+
};
|
|
1633
|
+
parseResultCache.set(cacheKey, result2);
|
|
1634
|
+
return result2;
|
|
1635
|
+
}
|
|
1658
1636
|
const constraints = [];
|
|
1659
1637
|
const annotations = [];
|
|
1660
1638
|
const diagnostics = [];
|
|
@@ -1666,12 +1644,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1666
1644
|
const sourceText = sourceFile.getFullText();
|
|
1667
1645
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
1668
1646
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
1669
|
-
const commentRanges =
|
|
1647
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1670
1648
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
1671
1649
|
const extensionTagNames = getExtensionTagNames(options);
|
|
1672
1650
|
if (commentRanges) {
|
|
1673
1651
|
for (const range of commentRanges) {
|
|
1674
|
-
if (range.kind !==
|
|
1652
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
1675
1653
|
continue;
|
|
1676
1654
|
}
|
|
1677
1655
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -1828,10 +1806,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
1828
1806
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
1829
1807
|
const sourceFile = node.getSourceFile();
|
|
1830
1808
|
const sourceText = sourceFile.getFullText();
|
|
1831
|
-
const commentRanges =
|
|
1809
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1832
1810
|
if (commentRanges) {
|
|
1833
1811
|
for (const range of commentRanges) {
|
|
1834
|
-
if (range.kind !==
|
|
1812
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
1835
1813
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
1836
1814
|
if (!commentText.startsWith("/**")) continue;
|
|
1837
1815
|
const unified = parseUnifiedComment(commentText);
|
|
@@ -1856,7 +1834,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
1856
1834
|
}
|
|
1857
1835
|
function collectRawTextFallbacks(node, file) {
|
|
1858
1836
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
1859
|
-
for (const tag of
|
|
1837
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
1860
1838
|
const tagName = normalizeConstraintTagName(tag.tagName.text);
|
|
1861
1839
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
1862
1840
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -1911,7 +1889,7 @@ function getTagCommentText(tag) {
|
|
|
1911
1889
|
if (typeof tag.comment === "string") {
|
|
1912
1890
|
return tag.comment;
|
|
1913
1891
|
}
|
|
1914
|
-
return
|
|
1892
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
1915
1893
|
}
|
|
1916
1894
|
|
|
1917
1895
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -1929,18 +1907,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
1929
1907
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
1930
1908
|
if (!initializer) return null;
|
|
1931
1909
|
let value;
|
|
1932
|
-
if (
|
|
1910
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
1933
1911
|
value = initializer.text;
|
|
1934
|
-
} else if (
|
|
1912
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
1935
1913
|
value = Number(initializer.text);
|
|
1936
|
-
} else if (initializer.kind ===
|
|
1914
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
1937
1915
|
value = true;
|
|
1938
|
-
} else if (initializer.kind ===
|
|
1916
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
1939
1917
|
value = false;
|
|
1940
|
-
} else if (initializer.kind ===
|
|
1918
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
1941
1919
|
value = null;
|
|
1942
|
-
} else if (
|
|
1943
|
-
if (initializer.operator ===
|
|
1920
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
1921
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
1944
1922
|
value = -Number(initializer.operand.text);
|
|
1945
1923
|
}
|
|
1946
1924
|
}
|
|
@@ -1962,28 +1940,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
1962
1940
|
|
|
1963
1941
|
// src/analyzer/class-analyzer.ts
|
|
1964
1942
|
function isObjectType(type) {
|
|
1965
|
-
return !!(type.flags &
|
|
1943
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
1966
1944
|
}
|
|
1967
1945
|
function isIntersectionType(type) {
|
|
1968
|
-
return !!(type.flags &
|
|
1946
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
1969
1947
|
}
|
|
1970
1948
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
1971
|
-
if (
|
|
1949
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
1972
1950
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
1973
1951
|
}
|
|
1974
|
-
if (
|
|
1952
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
1975
1953
|
return true;
|
|
1976
1954
|
}
|
|
1977
|
-
return
|
|
1955
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
1978
1956
|
}
|
|
1979
1957
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
1980
1958
|
if (isIntersectionType(type)) {
|
|
1981
1959
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
1982
1960
|
}
|
|
1983
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
1961
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts5.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts5.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
1984
1962
|
}
|
|
1985
1963
|
function isTypeReference(type) {
|
|
1986
|
-
return !!(type.flags &
|
|
1964
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
1987
1965
|
}
|
|
1988
1966
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
1989
1967
|
kind: "object",
|
|
@@ -2009,6 +1987,21 @@ function createAnalyzerMetadataPolicy(input, discriminator) {
|
|
|
2009
1987
|
discriminator
|
|
2010
1988
|
};
|
|
2011
1989
|
}
|
|
1990
|
+
var DEDUPLICATABLE_DIAGNOSTIC_CODES = /* @__PURE__ */ new Set([
|
|
1991
|
+
"SYNTHETIC_SETUP_FAILURE",
|
|
1992
|
+
"UNSUPPORTED_CUSTOM_TYPE_OVERRIDE"
|
|
1993
|
+
]);
|
|
1994
|
+
function deduplicateDiagnostics(diagnostics) {
|
|
1995
|
+
if (diagnostics.length <= 1) return diagnostics;
|
|
1996
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1997
|
+
return diagnostics.filter((d) => {
|
|
1998
|
+
if (!DEDUPLICATABLE_DIAGNOSTIC_CODES.has(d.code)) return true;
|
|
1999
|
+
const key = `${d.code}\0${d.message}`;
|
|
2000
|
+
if (seen.has(key)) return false;
|
|
2001
|
+
seen.add(key);
|
|
2002
|
+
return true;
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2012
2005
|
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
2013
2006
|
const analysis = analyzeMetadataForNodeWithChecker({
|
|
2014
2007
|
checker,
|
|
@@ -2045,10 +2038,121 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
2045
2038
|
}
|
|
2046
2039
|
return resolvedMetadata;
|
|
2047
2040
|
}
|
|
2041
|
+
var INHERITABLE_TYPE_ANNOTATION_KINDS = /* @__PURE__ */ new Set(["format"]);
|
|
2042
|
+
function getInheritableAnnotationStringValue(annotation) {
|
|
2043
|
+
if (annotation.annotationKind === "format") return annotation.value;
|
|
2044
|
+
return void 0;
|
|
2045
|
+
}
|
|
2046
|
+
function isOverridingInheritableAnnotation(annotation) {
|
|
2047
|
+
const value = getInheritableAnnotationStringValue(annotation);
|
|
2048
|
+
if (value === void 0) return true;
|
|
2049
|
+
return value.trim().length > 0;
|
|
2050
|
+
}
|
|
2051
|
+
function collectInheritedTypeAnnotations(derivedDecl, existingAnnotations, checker, extensionRegistry) {
|
|
2052
|
+
const existingKinds = new Set(
|
|
2053
|
+
existingAnnotations.filter(isOverridingInheritableAnnotation).map((a) => a.annotationKind)
|
|
2054
|
+
);
|
|
2055
|
+
const needed = /* @__PURE__ */ new Set();
|
|
2056
|
+
for (const kind of INHERITABLE_TYPE_ANNOTATION_KINDS) {
|
|
2057
|
+
if (!existingKinds.has(kind)) needed.add(kind);
|
|
2058
|
+
}
|
|
2059
|
+
if (needed.size === 0) return [];
|
|
2060
|
+
const inherited = [];
|
|
2061
|
+
const seen = /* @__PURE__ */ new Set([derivedDecl]);
|
|
2062
|
+
const queue = [];
|
|
2063
|
+
const resolveSymbolTarget = (sym) => {
|
|
2064
|
+
if ((sym.flags & ts5.SymbolFlags.Alias) === 0) return sym;
|
|
2065
|
+
try {
|
|
2066
|
+
return checker.getAliasedSymbol(sym);
|
|
2067
|
+
} catch {
|
|
2068
|
+
return sym;
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
const isObjectShapedTypeAlias = (alias) => {
|
|
2072
|
+
const type = checker.getTypeFromTypeNode(alias.type);
|
|
2073
|
+
if ((type.flags & ts5.TypeFlags.Object) !== 0) return true;
|
|
2074
|
+
if (type.isIntersection()) return true;
|
|
2075
|
+
return false;
|
|
2076
|
+
};
|
|
2077
|
+
const enqueueCandidate = (baseDecl, fromTypeAliasRhs) => {
|
|
2078
|
+
if (seen.has(baseDecl)) return;
|
|
2079
|
+
if (ts5.isClassDeclaration(baseDecl) || ts5.isInterfaceDeclaration(baseDecl)) {
|
|
2080
|
+
seen.add(baseDecl);
|
|
2081
|
+
queue.push(baseDecl);
|
|
2082
|
+
return;
|
|
2083
|
+
}
|
|
2084
|
+
if (ts5.isTypeAliasDeclaration(baseDecl)) {
|
|
2085
|
+
if (!fromTypeAliasRhs && !isObjectShapedTypeAlias(baseDecl)) return;
|
|
2086
|
+
seen.add(baseDecl);
|
|
2087
|
+
queue.push(baseDecl);
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
const enqueueBasesOf = (decl) => {
|
|
2091
|
+
if (ts5.isTypeAliasDeclaration(decl)) {
|
|
2092
|
+
const rhs = decl.type;
|
|
2093
|
+
if (!ts5.isTypeReferenceNode(rhs)) return;
|
|
2094
|
+
const sym = checker.getSymbolAtLocation(rhs.typeName);
|
|
2095
|
+
if (!sym) return;
|
|
2096
|
+
const target = resolveSymbolTarget(sym);
|
|
2097
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
2098
|
+
enqueueCandidate(
|
|
2099
|
+
baseDecl,
|
|
2100
|
+
/*fromTypeAliasRhs*/
|
|
2101
|
+
true
|
|
2102
|
+
);
|
|
2103
|
+
}
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
const heritageClauses = decl.heritageClauses;
|
|
2107
|
+
if (!heritageClauses) return;
|
|
2108
|
+
for (const clause of heritageClauses) {
|
|
2109
|
+
if (clause.token !== ts5.SyntaxKind.ExtendsKeyword) continue;
|
|
2110
|
+
for (const typeExpr of clause.types) {
|
|
2111
|
+
const sym = checker.getSymbolAtLocation(typeExpr.expression);
|
|
2112
|
+
if (!sym) continue;
|
|
2113
|
+
const target = resolveSymbolTarget(sym);
|
|
2114
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
2115
|
+
enqueueCandidate(
|
|
2116
|
+
baseDecl,
|
|
2117
|
+
/*fromTypeAliasRhs*/
|
|
2118
|
+
false
|
|
2119
|
+
);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
enqueueBasesOf(derivedDecl);
|
|
2125
|
+
for (let queueIndex = 0; queueIndex < queue.length && needed.size > 0; queueIndex++) {
|
|
2126
|
+
const baseDecl = queue[queueIndex];
|
|
2127
|
+
if (baseDecl === void 0) continue;
|
|
2128
|
+
const baseFile = baseDecl.getSourceFile().fileName;
|
|
2129
|
+
const baseAnnotations = extractJSDocAnnotationNodes(
|
|
2130
|
+
baseDecl,
|
|
2131
|
+
baseFile,
|
|
2132
|
+
makeParseOptions(extensionRegistry)
|
|
2133
|
+
);
|
|
2134
|
+
for (const annotation of baseAnnotations) {
|
|
2135
|
+
if (!needed.has(annotation.annotationKind)) continue;
|
|
2136
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
2137
|
+
inherited.push(annotation);
|
|
2138
|
+
needed.delete(annotation.annotationKind);
|
|
2139
|
+
}
|
|
2140
|
+
if (needed.size > 0) {
|
|
2141
|
+
enqueueBasesOf(baseDecl);
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
return inherited;
|
|
2145
|
+
}
|
|
2146
|
+
function extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) {
|
|
2147
|
+
const local = extractJSDocAnnotationNodes(namedDecl, file, makeParseOptions(extensionRegistry));
|
|
2148
|
+
const inherited = collectInheritedTypeAnnotations(namedDecl, local, checker, extensionRegistry);
|
|
2149
|
+
if (inherited.length === 0) return [...local];
|
|
2150
|
+
return [...local, ...inherited];
|
|
2151
|
+
}
|
|
2048
2152
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
2049
2153
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
2050
2154
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
2051
|
-
const logicalName =
|
|
2155
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
2052
2156
|
const docResult = extractJSDocParseResult(
|
|
2053
2157
|
declaration,
|
|
2054
2158
|
file,
|
|
@@ -2090,13 +2194,19 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
2090
2194
|
file,
|
|
2091
2195
|
makeParseOptions(extensionRegistry, void 0, checker, classType, classType)
|
|
2092
2196
|
);
|
|
2093
|
-
const
|
|
2197
|
+
const inheritedClassAnnotations = collectInheritedTypeAnnotations(
|
|
2198
|
+
classDecl,
|
|
2199
|
+
classDoc.annotations,
|
|
2200
|
+
checker,
|
|
2201
|
+
extensionRegistry
|
|
2202
|
+
);
|
|
2203
|
+
const annotations = [...classDoc.annotations, ...inheritedClassAnnotations];
|
|
2094
2204
|
diagnostics.push(...classDoc.diagnostics);
|
|
2095
2205
|
const visiting = /* @__PURE__ */ new Set();
|
|
2096
2206
|
const instanceMethods = [];
|
|
2097
2207
|
const staticMethods = [];
|
|
2098
2208
|
for (const member of classDecl.members) {
|
|
2099
|
-
if (
|
|
2209
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
2100
2210
|
const fieldNode = analyzeFieldToIR(
|
|
2101
2211
|
member,
|
|
2102
2212
|
checker,
|
|
@@ -2112,10 +2222,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
2112
2222
|
fields.push(fieldNode);
|
|
2113
2223
|
fieldLayouts.push({});
|
|
2114
2224
|
}
|
|
2115
|
-
} else if (
|
|
2225
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
2116
2226
|
const methodInfo = analyzeMethod(member, checker);
|
|
2117
2227
|
if (methodInfo) {
|
|
2118
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
2228
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
2119
2229
|
if (isStatic) {
|
|
2120
2230
|
staticMethods.push(methodInfo);
|
|
2121
2231
|
} else {
|
|
@@ -2147,6 +2257,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
2147
2257
|
hostType: classType
|
|
2148
2258
|
}
|
|
2149
2259
|
);
|
|
2260
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
2150
2261
|
return {
|
|
2151
2262
|
name,
|
|
2152
2263
|
...metadata !== void 0 && { metadata },
|
|
@@ -2154,7 +2265,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
2154
2265
|
fieldLayouts,
|
|
2155
2266
|
typeRegistry,
|
|
2156
2267
|
...annotations.length > 0 && { annotations },
|
|
2157
|
-
...
|
|
2268
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
2158
2269
|
instanceMethods,
|
|
2159
2270
|
staticMethods
|
|
2160
2271
|
};
|
|
@@ -2174,11 +2285,20 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
2174
2285
|
file,
|
|
2175
2286
|
makeParseOptions(extensionRegistry, void 0, checker, interfaceType, interfaceType)
|
|
2176
2287
|
);
|
|
2177
|
-
const
|
|
2288
|
+
const inheritedInterfaceAnnotations = collectInheritedTypeAnnotations(
|
|
2289
|
+
interfaceDecl,
|
|
2290
|
+
interfaceDoc.annotations,
|
|
2291
|
+
checker,
|
|
2292
|
+
extensionRegistry
|
|
2293
|
+
);
|
|
2294
|
+
const annotations = [
|
|
2295
|
+
...interfaceDoc.annotations,
|
|
2296
|
+
...inheritedInterfaceAnnotations
|
|
2297
|
+
];
|
|
2178
2298
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
2179
2299
|
const visiting = /* @__PURE__ */ new Set();
|
|
2180
2300
|
for (const member of interfaceDecl.members) {
|
|
2181
|
-
if (
|
|
2301
|
+
if (ts5.isPropertySignature(member)) {
|
|
2182
2302
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2183
2303
|
member,
|
|
2184
2304
|
checker,
|
|
@@ -2219,6 +2339,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
2219
2339
|
hostType: interfaceType
|
|
2220
2340
|
}
|
|
2221
2341
|
);
|
|
2342
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
2222
2343
|
return {
|
|
2223
2344
|
name,
|
|
2224
2345
|
...metadata !== void 0 && { metadata },
|
|
@@ -2226,7 +2347,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
2226
2347
|
fieldLayouts,
|
|
2227
2348
|
typeRegistry,
|
|
2228
2349
|
...annotations.length > 0 && { annotations },
|
|
2229
|
-
...
|
|
2350
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
2230
2351
|
instanceMethods: [],
|
|
2231
2352
|
staticMethods: []
|
|
2232
2353
|
};
|
|
@@ -2236,7 +2357,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2236
2357
|
if (members === null) {
|
|
2237
2358
|
const sourceFile = typeAlias.getSourceFile();
|
|
2238
2359
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
2239
|
-
const kindDesc =
|
|
2360
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
2240
2361
|
return {
|
|
2241
2362
|
ok: false,
|
|
2242
2363
|
kind: "not-object-like",
|
|
@@ -2271,7 +2392,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2271
2392
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
2272
2393
|
const visiting = /* @__PURE__ */ new Set();
|
|
2273
2394
|
for (const member of members) {
|
|
2274
|
-
if (
|
|
2395
|
+
if (ts5.isPropertySignature(member)) {
|
|
2275
2396
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2276
2397
|
member,
|
|
2277
2398
|
checker,
|
|
@@ -2311,6 +2432,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2311
2432
|
hostType: aliasType
|
|
2312
2433
|
}
|
|
2313
2434
|
);
|
|
2435
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
2314
2436
|
return {
|
|
2315
2437
|
ok: true,
|
|
2316
2438
|
analysis: {
|
|
@@ -2320,7 +2442,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2320
2442
|
fieldLayouts: specializedFields.map(() => ({})),
|
|
2321
2443
|
typeRegistry,
|
|
2322
2444
|
...annotations.length > 0 && { annotations },
|
|
2323
|
-
...
|
|
2445
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
2324
2446
|
instanceMethods: [],
|
|
2325
2447
|
staticMethods: []
|
|
2326
2448
|
}
|
|
@@ -2338,13 +2460,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
2338
2460
|
function getLeadingParsedTags(node) {
|
|
2339
2461
|
const sourceFile = node.getSourceFile();
|
|
2340
2462
|
const sourceText = sourceFile.getFullText();
|
|
2341
|
-
const commentRanges =
|
|
2463
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2342
2464
|
if (commentRanges === void 0) {
|
|
2343
2465
|
return [];
|
|
2344
2466
|
}
|
|
2345
2467
|
const parsedTags = [];
|
|
2346
2468
|
for (const range of commentRanges) {
|
|
2347
|
-
if (range.kind !==
|
|
2469
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
2348
2470
|
continue;
|
|
2349
2471
|
}
|
|
2350
2472
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -2362,19 +2484,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
2362
2484
|
return null;
|
|
2363
2485
|
}
|
|
2364
2486
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
2365
|
-
(candidate) =>
|
|
2487
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
2366
2488
|
) ?? propertySymbol.declarations?.[0];
|
|
2367
2489
|
return {
|
|
2368
2490
|
declaration,
|
|
2369
2491
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
2370
|
-
optional: !!(propertySymbol.flags &
|
|
2492
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
2371
2493
|
};
|
|
2372
2494
|
}
|
|
2373
2495
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
2374
2496
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
2375
2497
|
}
|
|
2376
2498
|
function isNullishSemanticType(type) {
|
|
2377
|
-
if (type.flags & (
|
|
2499
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
2378
2500
|
return true;
|
|
2379
2501
|
}
|
|
2380
2502
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -2384,7 +2506,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2384
2506
|
return false;
|
|
2385
2507
|
}
|
|
2386
2508
|
seen.add(type);
|
|
2387
|
-
if (type.flags &
|
|
2509
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
2388
2510
|
return true;
|
|
2389
2511
|
}
|
|
2390
2512
|
if (type.isUnion()) {
|
|
@@ -2397,13 +2519,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2397
2519
|
return false;
|
|
2398
2520
|
}
|
|
2399
2521
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
2400
|
-
if (
|
|
2522
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
2401
2523
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
2402
2524
|
}
|
|
2403
|
-
if (
|
|
2525
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
2404
2526
|
return [...typeNode.members];
|
|
2405
2527
|
}
|
|
2406
|
-
if (
|
|
2528
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
2407
2529
|
const members = [];
|
|
2408
2530
|
for (const intersectionMember of typeNode.types) {
|
|
2409
2531
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -2566,7 +2688,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
2566
2688
|
}
|
|
2567
2689
|
if (propertyType.isUnion()) {
|
|
2568
2690
|
const nonNullMembers = propertyType.types.filter(
|
|
2569
|
-
(member) => !(member.flags & (
|
|
2691
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
2570
2692
|
);
|
|
2571
2693
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2572
2694
|
diagnostics.push(
|
|
@@ -2615,13 +2737,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
2615
2737
|
seen.add(type);
|
|
2616
2738
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
2617
2739
|
if (symbol !== void 0) {
|
|
2618
|
-
const aliased = symbol.flags &
|
|
2740
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
2619
2741
|
const targetSymbol = aliased ?? symbol;
|
|
2620
2742
|
const declaration = targetSymbol.declarations?.find(
|
|
2621
|
-
(candidate) =>
|
|
2743
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
2622
2744
|
);
|
|
2623
2745
|
if (declaration !== void 0) {
|
|
2624
|
-
if (
|
|
2746
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
2625
2747
|
return resolveNamedDiscriminatorDeclaration(
|
|
2626
2748
|
checker.getTypeFromTypeNode(declaration.type),
|
|
2627
2749
|
checker,
|
|
@@ -2649,7 +2771,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2649
2771
|
}
|
|
2650
2772
|
if (boundType.isUnion()) {
|
|
2651
2773
|
const nonNullMembers = boundType.types.filter(
|
|
2652
|
-
(member) => !(member.flags & (
|
|
2774
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
2653
2775
|
);
|
|
2654
2776
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2655
2777
|
diagnostics.push(
|
|
@@ -2694,7 +2816,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2694
2816
|
return null;
|
|
2695
2817
|
}
|
|
2696
2818
|
function getDeclarationName(node) {
|
|
2697
|
-
if (
|
|
2819
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
2698
2820
|
return node.name?.text ?? "anonymous";
|
|
2699
2821
|
}
|
|
2700
2822
|
return "anonymous";
|
|
@@ -2749,11 +2871,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
2749
2871
|
if (sourceTypeNode === void 0) {
|
|
2750
2872
|
return [];
|
|
2751
2873
|
}
|
|
2752
|
-
const unwrapParentheses = (typeNode) =>
|
|
2874
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
2753
2875
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
2754
|
-
const referenceTypeNode =
|
|
2876
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
2755
2877
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
2756
|
-
return
|
|
2878
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
2757
2879
|
})();
|
|
2758
2880
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
2759
2881
|
return [];
|
|
@@ -2761,7 +2883,7 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
2761
2883
|
return referenceTypeNode.typeArguments.map((argumentNode) => {
|
|
2762
2884
|
const argumentType = checker.getTypeFromTypeNode(argumentNode);
|
|
2763
2885
|
const baseSymbol = argumentType.aliasSymbol ?? argumentType.getSymbol();
|
|
2764
|
-
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags &
|
|
2886
|
+
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(baseSymbol) : baseSymbol;
|
|
2765
2887
|
const argumentDecl = argumentSymbol?.declarations?.[0];
|
|
2766
2888
|
if (argumentDecl !== void 0 && argumentDecl.getSourceFile().fileName !== file) {
|
|
2767
2889
|
const argumentName = argumentSymbol?.getName() ?? baseSymbol?.getName();
|
|
@@ -2824,7 +2946,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
2824
2946
|
);
|
|
2825
2947
|
}
|
|
2826
2948
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
2827
|
-
if (!
|
|
2949
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
2828
2950
|
return null;
|
|
2829
2951
|
}
|
|
2830
2952
|
const name = prop.name.text;
|
|
@@ -2951,7 +3073,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2951
3073
|
const seen = /* @__PURE__ */ new Set();
|
|
2952
3074
|
const duplicates = /* @__PURE__ */ new Set();
|
|
2953
3075
|
for (const member of members) {
|
|
2954
|
-
if (!
|
|
3076
|
+
if (!ts5.isPropertySignature(member)) {
|
|
2955
3077
|
continue;
|
|
2956
3078
|
}
|
|
2957
3079
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -2967,7 +3089,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2967
3089
|
return [...duplicates].sort();
|
|
2968
3090
|
}
|
|
2969
3091
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
2970
|
-
if (
|
|
3092
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
2971
3093
|
return name.text;
|
|
2972
3094
|
}
|
|
2973
3095
|
return null;
|
|
@@ -3062,28 +3184,28 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
3062
3184
|
if (primitiveAlias) {
|
|
3063
3185
|
return primitiveAlias;
|
|
3064
3186
|
}
|
|
3065
|
-
if (
|
|
3187
|
+
if (_isIntegerBrandedType(type)) {
|
|
3066
3188
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
3067
3189
|
}
|
|
3068
|
-
if (type.flags &
|
|
3190
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
3069
3191
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3070
3192
|
}
|
|
3071
|
-
if (type.flags &
|
|
3193
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
3072
3194
|
return { kind: "primitive", primitiveKind: "number" };
|
|
3073
3195
|
}
|
|
3074
|
-
if (type.flags & (
|
|
3196
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
3075
3197
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
3076
3198
|
}
|
|
3077
|
-
if (type.flags &
|
|
3199
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
3078
3200
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
3079
3201
|
}
|
|
3080
|
-
if (type.flags &
|
|
3202
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
3081
3203
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3082
3204
|
}
|
|
3083
|
-
if (type.flags &
|
|
3205
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
3084
3206
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3085
3207
|
}
|
|
3086
|
-
if (type.flags &
|
|
3208
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
3087
3209
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3088
3210
|
}
|
|
3089
3211
|
if (type.isStringLiteral()) {
|
|
@@ -3170,10 +3292,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
3170
3292
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3171
3293
|
}
|
|
3172
3294
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
3173
|
-
if (!(type.flags & (
|
|
3295
|
+
if (!(type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null)) && !_isIntegerBrandedType(type)) {
|
|
3174
3296
|
return null;
|
|
3175
3297
|
}
|
|
3176
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3298
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
3177
3299
|
if (!aliasDecl) {
|
|
3178
3300
|
return null;
|
|
3179
3301
|
}
|
|
@@ -3184,11 +3306,18 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
3184
3306
|
...extractJSDocConstraintNodes(aliasDecl, file, makeParseOptions(extensionRegistry)),
|
|
3185
3307
|
...extractTypeAliasConstraintNodes(aliasDecl.type, checker, file, extensionRegistry)
|
|
3186
3308
|
];
|
|
3187
|
-
const
|
|
3309
|
+
const localAnnotations = extractJSDocAnnotationNodes(
|
|
3188
3310
|
aliasDecl,
|
|
3189
3311
|
file,
|
|
3190
3312
|
makeParseOptions(extensionRegistry)
|
|
3191
3313
|
);
|
|
3314
|
+
const inheritedAnnotations = collectInheritedTypeAnnotations(
|
|
3315
|
+
aliasDecl,
|
|
3316
|
+
localAnnotations,
|
|
3317
|
+
checker,
|
|
3318
|
+
extensionRegistry
|
|
3319
|
+
);
|
|
3320
|
+
const annotations = [...localAnnotations, ...inheritedAnnotations];
|
|
3192
3321
|
const metadata = resolveNodeMetadata(
|
|
3193
3322
|
metadataPolicy,
|
|
3194
3323
|
"type",
|
|
@@ -3223,8 +3352,8 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
3223
3352
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
3224
3353
|
}
|
|
3225
3354
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
3226
|
-
const typeNode = sourceNode && (
|
|
3227
|
-
if (!typeNode || !
|
|
3355
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
3356
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
3228
3357
|
return void 0;
|
|
3229
3358
|
}
|
|
3230
3359
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3245,7 +3374,7 @@ function resolveNamedTypeWithSourceRecovery(type, sourceNode, checker) {
|
|
|
3245
3374
|
return { typeName: refAliasDecl.name.text, namedDecl: refAliasDecl };
|
|
3246
3375
|
}
|
|
3247
3376
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
3248
|
-
if (!
|
|
3377
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
3249
3378
|
return false;
|
|
3250
3379
|
}
|
|
3251
3380
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3253,10 +3382,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
3253
3382
|
return false;
|
|
3254
3383
|
}
|
|
3255
3384
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
3256
|
-
return !!(resolved.flags & (
|
|
3385
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
3257
3386
|
}
|
|
3258
3387
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
3259
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3388
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
3260
3389
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
3261
3390
|
visitedAliases.add(nestedAliasDecl);
|
|
3262
3391
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -3271,22 +3400,22 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
3271
3400
|
visitedAliases
|
|
3272
3401
|
);
|
|
3273
3402
|
}
|
|
3274
|
-
if (
|
|
3403
|
+
if (_isIntegerBrandedType(type)) {
|
|
3275
3404
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
3276
3405
|
}
|
|
3277
|
-
if (type.flags &
|
|
3406
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
3278
3407
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3279
3408
|
}
|
|
3280
|
-
if (type.flags &
|
|
3409
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
3281
3410
|
return { kind: "primitive", primitiveKind: "number" };
|
|
3282
3411
|
}
|
|
3283
|
-
if (type.flags & (
|
|
3412
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
3284
3413
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
3285
3414
|
}
|
|
3286
|
-
if (type.flags &
|
|
3415
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
3287
3416
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
3288
3417
|
}
|
|
3289
|
-
if (type.flags &
|
|
3418
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
3290
3419
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3291
3420
|
}
|
|
3292
3421
|
return resolveTypeNode(
|
|
@@ -3306,7 +3435,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3306
3435
|
let typeName = null;
|
|
3307
3436
|
let namedDecl;
|
|
3308
3437
|
if (recovered !== null) {
|
|
3309
|
-
const recoveredAliasDecl =
|
|
3438
|
+
const recoveredAliasDecl = ts5.isTypeAliasDeclaration(recovered.namedDecl) ? recovered.namedDecl : void 0;
|
|
3310
3439
|
if (recoveredAliasDecl !== void 0) {
|
|
3311
3440
|
const aliasUnderlyingType = checker.getTypeFromTypeNode(recoveredAliasDecl.type);
|
|
3312
3441
|
const isNonGeneric = recoveredAliasDecl.typeParameters === void 0 || recoveredAliasDecl.typeParameters.length === 0;
|
|
@@ -3328,13 +3457,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3328
3457
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
3329
3458
|
);
|
|
3330
3459
|
const nonNullTypes = allTypes.filter(
|
|
3331
|
-
(memberType) => !(memberType.flags & (
|
|
3460
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3332
3461
|
);
|
|
3333
3462
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
3334
3463
|
memberType,
|
|
3335
3464
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
3336
3465
|
}));
|
|
3337
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
3466
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
3338
3467
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3339
3468
|
if (namedDecl) {
|
|
3340
3469
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -3354,7 +3483,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3354
3483
|
if (existing !== void 0 && existing.type !== RESOLVING_TYPE_PLACEHOLDER) {
|
|
3355
3484
|
return { kind: "reference", name: typeName, typeArguments: [] };
|
|
3356
3485
|
}
|
|
3357
|
-
const annotations = namedDecl ?
|
|
3486
|
+
const annotations = namedDecl ? extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) : void 0;
|
|
3358
3487
|
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
3359
3488
|
metadataPolicy,
|
|
3360
3489
|
"type",
|
|
@@ -3381,7 +3510,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3381
3510
|
const displayName = memberDisplayNames.get(String(value));
|
|
3382
3511
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
3383
3512
|
});
|
|
3384
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
3513
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
3385
3514
|
if (isBooleanUnion2) {
|
|
3386
3515
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
3387
3516
|
const result = hasNull ? {
|
|
@@ -3473,7 +3602,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
3473
3602
|
if (type.getProperties().length > 0) {
|
|
3474
3603
|
return null;
|
|
3475
3604
|
}
|
|
3476
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
3605
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
3477
3606
|
if (!indexInfo) {
|
|
3478
3607
|
return null;
|
|
3479
3608
|
}
|
|
@@ -3521,20 +3650,53 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
3521
3650
|
}
|
|
3522
3651
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
3523
3652
|
const name = declaration.name;
|
|
3524
|
-
if (
|
|
3653
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
3525
3654
|
return false;
|
|
3526
3655
|
}
|
|
3527
|
-
if (!
|
|
3656
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
3528
3657
|
return false;
|
|
3529
3658
|
}
|
|
3530
3659
|
}
|
|
3531
3660
|
return true;
|
|
3532
3661
|
}
|
|
3662
|
+
function getPassThroughTypeAliasFromSourceNode(sourceNode, checker, extensionRegistry, resolvedTypeName) {
|
|
3663
|
+
const aliasDecl = getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
3664
|
+
if (!aliasDecl) return void 0;
|
|
3665
|
+
const aliasName = aliasDecl.name.text;
|
|
3666
|
+
if (aliasName === resolvedTypeName) return void 0;
|
|
3667
|
+
if (!ts5.isTypeReferenceNode(aliasDecl.type)) return void 0;
|
|
3668
|
+
if (!hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry)) {
|
|
3669
|
+
return void 0;
|
|
3670
|
+
}
|
|
3671
|
+
return { aliasName, aliasDecl };
|
|
3672
|
+
}
|
|
3673
|
+
function hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry) {
|
|
3674
|
+
const file = aliasDecl.getSourceFile().fileName;
|
|
3675
|
+
const local = extractJSDocAnnotationNodes(aliasDecl, file, makeParseOptions(extensionRegistry));
|
|
3676
|
+
for (const annotation of local) {
|
|
3677
|
+
if (!INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) continue;
|
|
3678
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
3679
|
+
return true;
|
|
3680
|
+
}
|
|
3681
|
+
const inherited = collectInheritedTypeAnnotations(aliasDecl, local, checker, extensionRegistry);
|
|
3682
|
+
for (const annotation of inherited) {
|
|
3683
|
+
if (INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) return true;
|
|
3684
|
+
}
|
|
3685
|
+
return false;
|
|
3686
|
+
}
|
|
3533
3687
|
function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
3534
3688
|
const collectedDiagnostics = diagnostics ?? [];
|
|
3535
3689
|
const typeName = getNamedTypeName(type);
|
|
3536
3690
|
const namedTypeName = typeName ?? void 0;
|
|
3537
3691
|
const namedDecl = getNamedTypeDeclaration(type);
|
|
3692
|
+
const passThroughAlias = getPassThroughTypeAliasFromSourceNode(
|
|
3693
|
+
sourceNode,
|
|
3694
|
+
checker,
|
|
3695
|
+
extensionRegistry,
|
|
3696
|
+
namedTypeName
|
|
3697
|
+
);
|
|
3698
|
+
const effectiveTypeName = passThroughAlias?.aliasName ?? namedTypeName;
|
|
3699
|
+
const effectiveNamedDecl = passThroughAlias?.aliasDecl ?? namedDecl;
|
|
3538
3700
|
const referenceTypeArguments = extractReferenceTypeArguments(
|
|
3539
3701
|
type,
|
|
3540
3702
|
checker,
|
|
@@ -3546,13 +3708,13 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3546
3708
|
extensionRegistry,
|
|
3547
3709
|
collectedDiagnostics
|
|
3548
3710
|
);
|
|
3549
|
-
const instantiatedTypeName =
|
|
3550
|
-
|
|
3711
|
+
const instantiatedTypeName = effectiveTypeName !== void 0 && referenceTypeArguments.length > 0 ? buildInstantiatedReferenceName(
|
|
3712
|
+
effectiveTypeName,
|
|
3551
3713
|
referenceTypeArguments.map((argument) => argument.tsType),
|
|
3552
3714
|
checker
|
|
3553
3715
|
) : void 0;
|
|
3554
|
-
const registryTypeName = instantiatedTypeName ??
|
|
3555
|
-
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" &&
|
|
3716
|
+
const registryTypeName = instantiatedTypeName ?? effectiveTypeName;
|
|
3717
|
+
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" && effectiveNamedDecl?.getSourceFile().fileName !== file);
|
|
3556
3718
|
const clearNamedTypeRegistration = () => {
|
|
3557
3719
|
if (registryTypeName === void 0 || !shouldRegisterNamedType) {
|
|
3558
3720
|
return;
|
|
@@ -3573,7 +3735,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3573
3735
|
typeRegistry[registryTypeName] = {
|
|
3574
3736
|
name: registryTypeName,
|
|
3575
3737
|
type: RESOLVING_TYPE_PLACEHOLDER,
|
|
3576
|
-
provenance: provenanceForDeclaration(
|
|
3738
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
3577
3739
|
};
|
|
3578
3740
|
}
|
|
3579
3741
|
visiting.add(type);
|
|
@@ -3605,17 +3767,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3605
3767
|
clearNamedTypeRegistration();
|
|
3606
3768
|
return recordNode;
|
|
3607
3769
|
}
|
|
3608
|
-
const annotations =
|
|
3609
|
-
const metadata =
|
|
3770
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
3771
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
3610
3772
|
metadataPolicy,
|
|
3611
3773
|
"type",
|
|
3612
3774
|
registryTypeName,
|
|
3613
|
-
|
|
3775
|
+
effectiveNamedDecl,
|
|
3614
3776
|
checker,
|
|
3615
3777
|
extensionRegistry,
|
|
3616
3778
|
{
|
|
3617
3779
|
checker,
|
|
3618
|
-
declaration:
|
|
3780
|
+
declaration: effectiveNamedDecl,
|
|
3619
3781
|
subjectType: type
|
|
3620
3782
|
}
|
|
3621
3783
|
) : void 0;
|
|
@@ -3624,7 +3786,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3624
3786
|
...metadata !== void 0 && { metadata },
|
|
3625
3787
|
type: recordNode,
|
|
3626
3788
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
3627
|
-
provenance: provenanceForDeclaration(
|
|
3789
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
3628
3790
|
};
|
|
3629
3791
|
return {
|
|
3630
3792
|
kind: "reference",
|
|
@@ -3650,7 +3812,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3650
3812
|
if (!declaration) continue;
|
|
3651
3813
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
3652
3814
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
3653
|
-
const optional = !!(prop.flags &
|
|
3815
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
3654
3816
|
const propTypeNode = resolveTypeNode(
|
|
3655
3817
|
propType,
|
|
3656
3818
|
checker,
|
|
@@ -3663,7 +3825,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3663
3825
|
collectedDiagnostics
|
|
3664
3826
|
);
|
|
3665
3827
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
3666
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
3828
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
3667
3829
|
declaration,
|
|
3668
3830
|
checker,
|
|
3669
3831
|
file,
|
|
@@ -3673,7 +3835,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3673
3835
|
type,
|
|
3674
3836
|
metadataPolicy,
|
|
3675
3837
|
extensionRegistry
|
|
3676
|
-
) :
|
|
3838
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
3677
3839
|
declaration,
|
|
3678
3840
|
checker,
|
|
3679
3841
|
file,
|
|
@@ -3701,9 +3863,9 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3701
3863
|
visiting.delete(type);
|
|
3702
3864
|
const objectNode = {
|
|
3703
3865
|
kind: "object",
|
|
3704
|
-
properties:
|
|
3866
|
+
properties: effectiveNamedDecl !== void 0 && (ts5.isClassDeclaration(effectiveNamedDecl) || ts5.isInterfaceDeclaration(effectiveNamedDecl) || ts5.isTypeAliasDeclaration(effectiveNamedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
3705
3867
|
properties,
|
|
3706
|
-
|
|
3868
|
+
effectiveNamedDecl,
|
|
3707
3869
|
type,
|
|
3708
3870
|
checker,
|
|
3709
3871
|
file,
|
|
@@ -3713,17 +3875,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3713
3875
|
additionalProperties: true
|
|
3714
3876
|
};
|
|
3715
3877
|
if (registryTypeName !== void 0 && shouldRegisterNamedType) {
|
|
3716
|
-
const annotations =
|
|
3717
|
-
const metadata =
|
|
3878
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
3879
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
3718
3880
|
metadataPolicy,
|
|
3719
3881
|
"type",
|
|
3720
3882
|
registryTypeName,
|
|
3721
|
-
|
|
3883
|
+
effectiveNamedDecl,
|
|
3722
3884
|
checker,
|
|
3723
3885
|
extensionRegistry,
|
|
3724
3886
|
{
|
|
3725
3887
|
checker,
|
|
3726
|
-
declaration:
|
|
3888
|
+
declaration: effectiveNamedDecl,
|
|
3727
3889
|
subjectType: type
|
|
3728
3890
|
}
|
|
3729
3891
|
) : void 0;
|
|
@@ -3732,7 +3894,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3732
3894
|
...metadata !== void 0 && { metadata },
|
|
3733
3895
|
type: objectNode,
|
|
3734
3896
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
3735
|
-
provenance: provenanceForDeclaration(
|
|
3897
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
3736
3898
|
};
|
|
3737
3899
|
return {
|
|
3738
3900
|
kind: "reference",
|
|
@@ -3749,12 +3911,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3749
3911
|
for (const symbol of symbols) {
|
|
3750
3912
|
const declarations = symbol.declarations;
|
|
3751
3913
|
if (!declarations) continue;
|
|
3752
|
-
const classDecl = declarations.find(
|
|
3914
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
3753
3915
|
if (classDecl) {
|
|
3754
3916
|
const map = /* @__PURE__ */ new Map();
|
|
3755
3917
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
3756
3918
|
for (const member of classDecl.members) {
|
|
3757
|
-
if (
|
|
3919
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
3758
3920
|
const fieldNode = analyzeFieldToIR(
|
|
3759
3921
|
member,
|
|
3760
3922
|
checker,
|
|
@@ -3778,7 +3940,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3778
3940
|
}
|
|
3779
3941
|
return map;
|
|
3780
3942
|
}
|
|
3781
|
-
const interfaceDecl = declarations.find(
|
|
3943
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
3782
3944
|
if (interfaceDecl) {
|
|
3783
3945
|
return buildFieldNodeInfoMap(
|
|
3784
3946
|
interfaceDecl.members,
|
|
@@ -3792,7 +3954,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3792
3954
|
extensionRegistry
|
|
3793
3955
|
);
|
|
3794
3956
|
}
|
|
3795
|
-
const typeAliasDecl = declarations.find(
|
|
3957
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
3796
3958
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
3797
3959
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
3798
3960
|
return buildFieldNodeInfoMap(
|
|
@@ -3816,10 +3978,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
3816
3978
|
return void 0;
|
|
3817
3979
|
}
|
|
3818
3980
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3819
|
-
if (
|
|
3981
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
3820
3982
|
return resolvedTypeNode.elementType;
|
|
3821
3983
|
}
|
|
3822
|
-
if (
|
|
3984
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
3823
3985
|
return resolvedTypeNode.typeArguments[0];
|
|
3824
3986
|
}
|
|
3825
3987
|
return void 0;
|
|
@@ -3830,13 +3992,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
3830
3992
|
return [];
|
|
3831
3993
|
}
|
|
3832
3994
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3833
|
-
return
|
|
3995
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
3834
3996
|
}
|
|
3835
3997
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
3836
|
-
if (
|
|
3998
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3837
3999
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
3838
4000
|
}
|
|
3839
|
-
if (!
|
|
4001
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
3840
4002
|
return typeNode;
|
|
3841
4003
|
}
|
|
3842
4004
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3847,15 +4009,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
3847
4009
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
3848
4010
|
}
|
|
3849
4011
|
function isNullishTypeNode(typeNode) {
|
|
3850
|
-
if (typeNode.kind ===
|
|
4012
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
3851
4013
|
return true;
|
|
3852
4014
|
}
|
|
3853
|
-
return
|
|
4015
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
3854
4016
|
}
|
|
3855
4017
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
3856
4018
|
const map = /* @__PURE__ */ new Map();
|
|
3857
4019
|
for (const member of members) {
|
|
3858
|
-
if (
|
|
4020
|
+
if (ts5.isPropertySignature(member)) {
|
|
3859
4021
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3860
4022
|
member,
|
|
3861
4023
|
checker,
|
|
@@ -3881,7 +4043,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
3881
4043
|
}
|
|
3882
4044
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
3883
4045
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
3884
|
-
if (!
|
|
4046
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
3885
4047
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
3886
4048
|
const aliasName = typeNode.typeName.getText();
|
|
3887
4049
|
throw new Error(
|
|
@@ -3890,7 +4052,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
3890
4052
|
}
|
|
3891
4053
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
3892
4054
|
if (!aliasDecl) return [];
|
|
3893
|
-
if (
|
|
4055
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
3894
4056
|
const aliasFieldType = resolveTypeNode(
|
|
3895
4057
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
3896
4058
|
checker,
|
|
@@ -3934,14 +4096,14 @@ function getNamedTypeName(type) {
|
|
|
3934
4096
|
const symbol = type.getSymbol();
|
|
3935
4097
|
if (symbol?.declarations) {
|
|
3936
4098
|
const decl = symbol.declarations[0];
|
|
3937
|
-
if (decl && (
|
|
3938
|
-
const name =
|
|
4099
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
4100
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
3939
4101
|
if (name) return name;
|
|
3940
4102
|
}
|
|
3941
4103
|
}
|
|
3942
4104
|
const aliasSymbol = type.aliasSymbol;
|
|
3943
4105
|
if (aliasSymbol?.declarations) {
|
|
3944
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
4106
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
3945
4107
|
if (aliasDecl) {
|
|
3946
4108
|
return aliasDecl.name.text;
|
|
3947
4109
|
}
|
|
@@ -3952,24 +4114,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
3952
4114
|
const symbol = type.getSymbol();
|
|
3953
4115
|
if (symbol?.declarations) {
|
|
3954
4116
|
const decl = symbol.declarations[0];
|
|
3955
|
-
if (decl && (
|
|
4117
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
3956
4118
|
return decl;
|
|
3957
4119
|
}
|
|
3958
4120
|
}
|
|
3959
4121
|
const aliasSymbol = type.aliasSymbol;
|
|
3960
4122
|
if (aliasSymbol?.declarations) {
|
|
3961
|
-
return aliasSymbol.declarations.find(
|
|
4123
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
3962
4124
|
}
|
|
3963
4125
|
return void 0;
|
|
3964
4126
|
}
|
|
3965
4127
|
function analyzeMethod(method, checker) {
|
|
3966
|
-
if (!
|
|
4128
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
3967
4129
|
return null;
|
|
3968
4130
|
}
|
|
3969
4131
|
const name = method.name.text;
|
|
3970
4132
|
const parameters = [];
|
|
3971
4133
|
for (const param of method.parameters) {
|
|
3972
|
-
if (
|
|
4134
|
+
if (ts5.isIdentifier(param.name)) {
|
|
3973
4135
|
const paramInfo = analyzeParameter(param, checker);
|
|
3974
4136
|
parameters.push(paramInfo);
|
|
3975
4137
|
}
|
|
@@ -3980,7 +4142,7 @@ function analyzeMethod(method, checker) {
|
|
|
3980
4142
|
return { name, parameters, returnTypeNode, returnType };
|
|
3981
4143
|
}
|
|
3982
4144
|
function analyzeParameter(param, checker) {
|
|
3983
|
-
const name =
|
|
4145
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
3984
4146
|
const typeNode = param.type;
|
|
3985
4147
|
const type = checker.getTypeAtLocation(param);
|
|
3986
4148
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -3989,15 +4151,15 @@ function analyzeParameter(param, checker) {
|
|
|
3989
4151
|
}
|
|
3990
4152
|
function detectFormSpecReference(typeNode) {
|
|
3991
4153
|
if (!typeNode) return null;
|
|
3992
|
-
if (!
|
|
3993
|
-
const typeName =
|
|
4154
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
4155
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
3994
4156
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
3995
4157
|
const typeArg = typeNode.typeArguments?.[0];
|
|
3996
|
-
if (!typeArg || !
|
|
3997
|
-
if (
|
|
4158
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
4159
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
3998
4160
|
return typeArg.exprName.text;
|
|
3999
4161
|
}
|
|
4000
|
-
if (
|
|
4162
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
4001
4163
|
return typeArg.exprName.right.text;
|
|
4002
4164
|
}
|
|
4003
4165
|
return null;
|
|
@@ -4019,23 +4181,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
4019
4181
|
function createProgramContext(filePath, additionalFiles) {
|
|
4020
4182
|
const absolutePath = path.resolve(filePath);
|
|
4021
4183
|
const fileDir = path.dirname(absolutePath);
|
|
4022
|
-
const configPath =
|
|
4184
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
4023
4185
|
let compilerOptions;
|
|
4024
4186
|
let fileNames;
|
|
4025
4187
|
if (configPath) {
|
|
4026
|
-
const configFile =
|
|
4188
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
4027
4189
|
if (configFile.error) {
|
|
4028
4190
|
throw new Error(
|
|
4029
|
-
`Error reading tsconfig.json: ${
|
|
4191
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
4030
4192
|
);
|
|
4031
4193
|
}
|
|
4032
|
-
const parsed =
|
|
4194
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
4033
4195
|
configFile.config,
|
|
4034
|
-
|
|
4196
|
+
ts6.sys,
|
|
4035
4197
|
path.dirname(configPath)
|
|
4036
4198
|
);
|
|
4037
4199
|
if (parsed.errors.length > 0) {
|
|
4038
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
4200
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
4039
4201
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
4040
4202
|
}
|
|
4041
4203
|
compilerOptions = parsed.options;
|
|
@@ -4043,9 +4205,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
4043
4205
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
4044
4206
|
} else {
|
|
4045
4207
|
compilerOptions = {
|
|
4046
|
-
target:
|
|
4047
|
-
module:
|
|
4048
|
-
moduleResolution:
|
|
4208
|
+
target: ts6.ScriptTarget.ES2022,
|
|
4209
|
+
module: ts6.ModuleKind.NodeNext,
|
|
4210
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
4049
4211
|
strict: true,
|
|
4050
4212
|
skipLibCheck: true,
|
|
4051
4213
|
declaration: true
|
|
@@ -4053,7 +4215,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
4053
4215
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
4054
4216
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
4055
4217
|
}
|
|
4056
|
-
const program =
|
|
4218
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
4057
4219
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
4058
4220
|
if (!sourceFile) {
|
|
4059
4221
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -4072,19 +4234,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
4072
4234
|
result = node;
|
|
4073
4235
|
return;
|
|
4074
4236
|
}
|
|
4075
|
-
|
|
4237
|
+
ts6.forEachChild(node, visit);
|
|
4076
4238
|
}
|
|
4077
4239
|
visit(sourceFile);
|
|
4078
4240
|
return result;
|
|
4079
4241
|
}
|
|
4080
4242
|
function findClassByName(sourceFile, className) {
|
|
4081
|
-
return findNodeByName(sourceFile, className,
|
|
4243
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
4082
4244
|
}
|
|
4083
4245
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
4084
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
4246
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
4085
4247
|
}
|
|
4086
4248
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
4087
|
-
return findNodeByName(sourceFile, aliasName,
|
|
4249
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
4088
4250
|
}
|
|
4089
4251
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
4090
4252
|
if (rootType.kind === "object") {
|
|
@@ -4124,22 +4286,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
4124
4286
|
};
|
|
4125
4287
|
}
|
|
4126
4288
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
4127
|
-
if (
|
|
4289
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
4128
4290
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
4129
4291
|
}
|
|
4130
|
-
if (
|
|
4292
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
4131
4293
|
return true;
|
|
4132
4294
|
}
|
|
4133
|
-
return
|
|
4295
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
4134
4296
|
}
|
|
4135
4297
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
4136
|
-
if (
|
|
4298
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
4137
4299
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
4138
4300
|
}
|
|
4139
|
-
if (
|
|
4301
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
4140
4302
|
const propertyNames = [];
|
|
4141
4303
|
for (const member of typeNode.members) {
|
|
4142
|
-
if (!
|
|
4304
|
+
if (!ts6.isPropertySignature(member)) {
|
|
4143
4305
|
continue;
|
|
4144
4306
|
}
|
|
4145
4307
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4149,13 +4311,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
4149
4311
|
}
|
|
4150
4312
|
return propertyNames;
|
|
4151
4313
|
}
|
|
4152
|
-
if (
|
|
4314
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
4153
4315
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
4154
4316
|
}
|
|
4155
4317
|
return null;
|
|
4156
4318
|
}
|
|
4157
4319
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
4158
|
-
if (!
|
|
4320
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
4159
4321
|
return [];
|
|
4160
4322
|
}
|
|
4161
4323
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -4345,7 +4507,7 @@ function makeFileProvenance(filePath) {
|
|
|
4345
4507
|
}
|
|
4346
4508
|
|
|
4347
4509
|
// src/generators/class-schema.ts
|
|
4348
|
-
import * as
|
|
4510
|
+
import * as ts8 from "typescript";
|
|
4349
4511
|
|
|
4350
4512
|
// src/metadata/collision-guards.ts
|
|
4351
4513
|
function assertUniqueSerializedNames(entries, scope) {
|
|
@@ -4514,7 +4676,7 @@ function generateJsonSchemaFromIR(ir, options) {
|
|
|
4514
4676
|
applyConstraints(ctx.defs[schemaName], typeDef.constraints, ctx);
|
|
4515
4677
|
}
|
|
4516
4678
|
if (typeDef.annotations && typeDef.annotations.length > 0) {
|
|
4517
|
-
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx);
|
|
4679
|
+
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx, typeDef.type);
|
|
4518
4680
|
}
|
|
4519
4681
|
}
|
|
4520
4682
|
const properties = {};
|
|
@@ -4587,7 +4749,7 @@ function generateFieldSchema(field, ctx) {
|
|
|
4587
4749
|
}
|
|
4588
4750
|
}
|
|
4589
4751
|
applyResolvedMetadata(schema, field.metadata);
|
|
4590
|
-
applyAnnotations(schema, rootAnnotations, ctx);
|
|
4752
|
+
applyAnnotations(schema, rootAnnotations, ctx, field.type);
|
|
4591
4753
|
if (itemStringSchema !== void 0) {
|
|
4592
4754
|
applyAnnotations(itemStringSchema, itemAnnotations, ctx);
|
|
4593
4755
|
}
|
|
@@ -4630,32 +4792,36 @@ function applyPathTargetedConstraints(schema, pathConstraints, ctx, typeNode) {
|
|
|
4630
4792
|
return schema;
|
|
4631
4793
|
}
|
|
4632
4794
|
if (schema.$ref) {
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
properties: propertyOverrides,
|
|
4637
|
-
...rest
|
|
4795
|
+
return {
|
|
4796
|
+
...schema,
|
|
4797
|
+
properties: propertyOverrides
|
|
4638
4798
|
};
|
|
4639
|
-
return { allOf: [refPart, overridePart] };
|
|
4640
4799
|
}
|
|
4641
4800
|
if (schema.type === "object" && schema.properties) {
|
|
4642
|
-
const missingOverrides = {};
|
|
4643
4801
|
for (const [target, overrideSchema] of Object.entries(propertyOverrides)) {
|
|
4644
|
-
if (schema.properties
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4802
|
+
if (Object.hasOwn(schema.properties, target)) {
|
|
4803
|
+
const existing = schema.properties[target];
|
|
4804
|
+
if (existing) {
|
|
4805
|
+
mergeSchemaOverride(existing, overrideSchema);
|
|
4806
|
+
continue;
|
|
4807
|
+
}
|
|
4648
4808
|
}
|
|
4809
|
+
Object.defineProperty(schema.properties, target, {
|
|
4810
|
+
value: overrideSchema,
|
|
4811
|
+
writable: true,
|
|
4812
|
+
enumerable: true,
|
|
4813
|
+
configurable: true
|
|
4814
|
+
});
|
|
4649
4815
|
}
|
|
4650
|
-
|
|
4651
|
-
return schema;
|
|
4652
|
-
}
|
|
4653
|
-
return {
|
|
4654
|
-
allOf: [schema, { properties: missingOverrides }]
|
|
4655
|
-
};
|
|
4816
|
+
return schema;
|
|
4656
4817
|
}
|
|
4657
4818
|
if (schema.allOf) {
|
|
4658
|
-
|
|
4819
|
+
const overrideMember = { properties: propertyOverrides };
|
|
4820
|
+
const flattened = tryFlattenAllOfToSiblings(schema, overrideMember);
|
|
4821
|
+
if (flattened !== void 0) {
|
|
4822
|
+
return flattened;
|
|
4823
|
+
}
|
|
4824
|
+
schema.allOf = [...schema.allOf, overrideMember];
|
|
4659
4825
|
return schema;
|
|
4660
4826
|
}
|
|
4661
4827
|
return schema;
|
|
@@ -4768,7 +4934,7 @@ function generatePropertySchema(prop, ctx) {
|
|
|
4768
4934
|
const schema = generateTypeNode(prop.type, ctx);
|
|
4769
4935
|
applyConstraints(schema, prop.constraints, ctx);
|
|
4770
4936
|
applyResolvedMetadata(schema, prop.metadata);
|
|
4771
|
-
applyAnnotations(schema, prop.annotations, ctx);
|
|
4937
|
+
applyAnnotations(schema, prop.annotations, ctx, prop.type);
|
|
4772
4938
|
return schema;
|
|
4773
4939
|
}
|
|
4774
4940
|
function generateUnionType(type, ctx) {
|
|
@@ -4871,13 +5037,20 @@ function buildPropertyOverrides(pathConstraints, typeNode, ctx) {
|
|
|
4871
5037
|
grouped.push(constraint);
|
|
4872
5038
|
byTarget.set(target, grouped);
|
|
4873
5039
|
}
|
|
4874
|
-
const overrides =
|
|
5040
|
+
const overrides = /* @__PURE__ */ Object.create(null);
|
|
4875
5041
|
for (const [target, constraints] of byTarget) {
|
|
4876
|
-
|
|
5042
|
+
const resolvedName = resolveSerializedPropertyName(target, typeNode, ctx);
|
|
5043
|
+
const schema = buildPathOverrideSchema(
|
|
4877
5044
|
constraints.map(stripLeadingPathSegment),
|
|
4878
5045
|
resolveTargetTypeNode(target, typeNode, ctx),
|
|
4879
5046
|
ctx
|
|
4880
5047
|
);
|
|
5048
|
+
Object.defineProperty(overrides, resolvedName, {
|
|
5049
|
+
value: schema,
|
|
5050
|
+
writable: true,
|
|
5051
|
+
enumerable: true,
|
|
5052
|
+
configurable: true
|
|
5053
|
+
});
|
|
4881
5054
|
}
|
|
4882
5055
|
return overrides;
|
|
4883
5056
|
}
|
|
@@ -4904,6 +5077,34 @@ function buildPathOverrideSchema(constraints, typeNode, ctx) {
|
|
|
4904
5077
|
schema.properties = buildPropertyOverrides(nestedConstraints, effectiveType, ctx);
|
|
4905
5078
|
return schema;
|
|
4906
5079
|
}
|
|
5080
|
+
function tryFlattenAllOfToSiblings(schema, overrideMember) {
|
|
5081
|
+
if (schema.allOf?.length !== 1) {
|
|
5082
|
+
return void 0;
|
|
5083
|
+
}
|
|
5084
|
+
const [soleMember] = schema.allOf;
|
|
5085
|
+
if (soleMember === void 0) {
|
|
5086
|
+
return void 0;
|
|
5087
|
+
}
|
|
5088
|
+
const { allOf: _allOf, ...outerRest } = schema;
|
|
5089
|
+
const outerKeys = new Set(Object.keys(outerRest));
|
|
5090
|
+
const memberKeys = new Set(Object.keys(soleMember));
|
|
5091
|
+
const overrideKeys = new Set(Object.keys(overrideMember));
|
|
5092
|
+
for (const key of memberKeys) {
|
|
5093
|
+
if (outerKeys.has(key) || overrideKeys.has(key)) {
|
|
5094
|
+
return void 0;
|
|
5095
|
+
}
|
|
5096
|
+
}
|
|
5097
|
+
for (const key of overrideKeys) {
|
|
5098
|
+
if (outerKeys.has(key)) {
|
|
5099
|
+
return void 0;
|
|
5100
|
+
}
|
|
5101
|
+
}
|
|
5102
|
+
return {
|
|
5103
|
+
...outerRest,
|
|
5104
|
+
...soleMember,
|
|
5105
|
+
...overrideMember
|
|
5106
|
+
};
|
|
5107
|
+
}
|
|
4907
5108
|
function mergeSchemaOverride(target, override) {
|
|
4908
5109
|
const nullableValueBranch = getNullableUnionValueSchema(target);
|
|
4909
5110
|
if (nullableValueBranch !== void 0) {
|
|
@@ -4911,11 +5112,16 @@ function mergeSchemaOverride(target, override) {
|
|
|
4911
5112
|
return;
|
|
4912
5113
|
}
|
|
4913
5114
|
if (override.properties !== void 0) {
|
|
4914
|
-
const mergedProperties = target.properties ??
|
|
5115
|
+
const mergedProperties = target.properties ?? /* @__PURE__ */ Object.create(null);
|
|
4915
5116
|
for (const [name, propertyOverride] of Object.entries(override.properties)) {
|
|
4916
|
-
const existing = mergedProperties[name];
|
|
5117
|
+
const existing = Object.hasOwn(mergedProperties, name) ? mergedProperties[name] : void 0;
|
|
4917
5118
|
if (existing === void 0) {
|
|
4918
|
-
mergedProperties
|
|
5119
|
+
Object.defineProperty(mergedProperties, name, {
|
|
5120
|
+
value: propertyOverride,
|
|
5121
|
+
writable: true,
|
|
5122
|
+
enumerable: true,
|
|
5123
|
+
configurable: true
|
|
5124
|
+
});
|
|
4919
5125
|
} else {
|
|
4920
5126
|
mergeSchemaOverride(existing, propertyOverride);
|
|
4921
5127
|
}
|
|
@@ -4933,7 +5139,12 @@ function mergeSchemaOverride(target, override) {
|
|
|
4933
5139
|
if (key === "properties" || key === "items") {
|
|
4934
5140
|
continue;
|
|
4935
5141
|
}
|
|
4936
|
-
target
|
|
5142
|
+
Object.defineProperty(target, key, {
|
|
5143
|
+
value,
|
|
5144
|
+
writable: true,
|
|
5145
|
+
enumerable: true,
|
|
5146
|
+
configurable: true
|
|
5147
|
+
});
|
|
4937
5148
|
}
|
|
4938
5149
|
}
|
|
4939
5150
|
function stripLeadingPathSegment(constraint) {
|
|
@@ -5033,7 +5244,7 @@ function applyConstraints(schema, constraints, ctx) {
|
|
|
5033
5244
|
}
|
|
5034
5245
|
}
|
|
5035
5246
|
}
|
|
5036
|
-
function applyAnnotations(schema, annotations, ctx) {
|
|
5247
|
+
function applyAnnotations(schema, annotations, ctx, typeNode) {
|
|
5037
5248
|
for (const annotation of annotations) {
|
|
5038
5249
|
switch (annotation.annotationKind) {
|
|
5039
5250
|
case "displayName":
|
|
@@ -5046,7 +5257,7 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
5046
5257
|
schema[`${ctx.vendorPrefix}-remarks`] = annotation.value;
|
|
5047
5258
|
break;
|
|
5048
5259
|
case "defaultValue":
|
|
5049
|
-
schema.default = annotation.value;
|
|
5260
|
+
schema.default = coerceDefaultValue(annotation.value, typeNode, schema, ctx);
|
|
5050
5261
|
break;
|
|
5051
5262
|
case "format":
|
|
5052
5263
|
schema.format = annotation.value;
|
|
@@ -5071,6 +5282,34 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
5071
5282
|
}
|
|
5072
5283
|
}
|
|
5073
5284
|
}
|
|
5285
|
+
function coerceDefaultValue(value, typeNode, emittedSchema, ctx) {
|
|
5286
|
+
if (typeNode?.kind !== "custom") {
|
|
5287
|
+
return value;
|
|
5288
|
+
}
|
|
5289
|
+
const registration = ctx.extensionRegistry?.findType(typeNode.typeId);
|
|
5290
|
+
if (registration === void 0) {
|
|
5291
|
+
return value;
|
|
5292
|
+
}
|
|
5293
|
+
if (registration.serializeDefault !== void 0) {
|
|
5294
|
+
return registration.serializeDefault(value, typeNode.payload);
|
|
5295
|
+
}
|
|
5296
|
+
const declaredType = emittedSchema["type"];
|
|
5297
|
+
if (declaredType === "string" && typeof value !== "string") {
|
|
5298
|
+
if (typeof value === "number") {
|
|
5299
|
+
if (!Number.isFinite(value)) {
|
|
5300
|
+
return value;
|
|
5301
|
+
}
|
|
5302
|
+
return String(value);
|
|
5303
|
+
}
|
|
5304
|
+
if (typeof value === "boolean") {
|
|
5305
|
+
return String(value);
|
|
5306
|
+
}
|
|
5307
|
+
if (typeof value === "bigint") {
|
|
5308
|
+
return value.toString();
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5311
|
+
return value;
|
|
5312
|
+
}
|
|
5074
5313
|
function generateCustomType(type, ctx) {
|
|
5075
5314
|
const registration = ctx.extensionRegistry?.findType(type.typeId);
|
|
5076
5315
|
if (registration === void 0) {
|
|
@@ -5203,7 +5442,9 @@ import {
|
|
|
5203
5442
|
import {
|
|
5204
5443
|
getTagDefinition as getTagDefinition2,
|
|
5205
5444
|
normalizeFormSpecTagName as normalizeFormSpecTagName2,
|
|
5206
|
-
getSyntheticLogger as getSyntheticLogger2
|
|
5445
|
+
getSyntheticLogger as getSyntheticLogger2,
|
|
5446
|
+
_validateExtensionSetup,
|
|
5447
|
+
logSetupDiagnostics
|
|
5207
5448
|
} from "@formspec/analysis/internal";
|
|
5208
5449
|
var BUILTIN_METADATA_TAGS = /* @__PURE__ */ new Set(["apiName", "displayName"]);
|
|
5209
5450
|
function buildConstraintTagSources(extensions) {
|
|
@@ -5213,6 +5454,16 @@ function buildConstraintTagSources(extensions) {
|
|
|
5213
5454
|
constraintTags: extension.constraintTags.map((tag) => ({
|
|
5214
5455
|
tagName: normalizeFormSpecTagName2(tag.tagName)
|
|
5215
5456
|
}))
|
|
5457
|
+
} : {},
|
|
5458
|
+
// Include customTypes so _validateExtensionSetup can check tsTypeNames for
|
|
5459
|
+
// unsupported built-in overrides and invalid identifier patterns.
|
|
5460
|
+
...extension.types !== void 0 ? {
|
|
5461
|
+
customTypes: extension.types.map((type) => ({
|
|
5462
|
+
// tsTypeNames: deprecated in favour of symbol-based detection, but
|
|
5463
|
+
// still required for name-based validation in _validateExtensionSetup
|
|
5464
|
+
// until the bridge is fully retired (see §synthetic-checker-retirement §4C).
|
|
5465
|
+
tsTypeNames: type.tsTypeNames ?? [type.typeName]
|
|
5466
|
+
}))
|
|
5216
5467
|
} : {}
|
|
5217
5468
|
}));
|
|
5218
5469
|
}
|
|
@@ -5222,7 +5473,13 @@ function createExtensionRegistry(extensions) {
|
|
|
5222
5473
|
extensionCount: extensions.length,
|
|
5223
5474
|
extensionIds: extensions.map((e) => e.extensionId)
|
|
5224
5475
|
});
|
|
5225
|
-
const
|
|
5476
|
+
const extensionTagSources = buildConstraintTagSources(extensions);
|
|
5477
|
+
const setupDiagnostics = _validateExtensionSetup(extensionTagSources);
|
|
5478
|
+
logSetupDiagnostics(registryLog, {
|
|
5479
|
+
diagnosticCount: setupDiagnostics.length,
|
|
5480
|
+
codes: setupDiagnostics.map((d) => d.kind)
|
|
5481
|
+
});
|
|
5482
|
+
const reservedTagSources = extensionTagSources;
|
|
5226
5483
|
let symbolMap = /* @__PURE__ */ new Map();
|
|
5227
5484
|
const typeMap = /* @__PURE__ */ new Map();
|
|
5228
5485
|
const typeNameMap = /* @__PURE__ */ new Map();
|
|
@@ -5359,10 +5616,12 @@ function createExtensionRegistry(extensions) {
|
|
|
5359
5616
|
constraintTagCount: constraintTagMap.size,
|
|
5360
5617
|
broadeningCount: builtinBroadeningMap.size,
|
|
5361
5618
|
annotationCount: annotationMap.size,
|
|
5362
|
-
metadataSlotCount: metadataSlotMap.size
|
|
5619
|
+
metadataSlotCount: metadataSlotMap.size,
|
|
5620
|
+
setupDiagnosticCount: setupDiagnostics.length
|
|
5363
5621
|
});
|
|
5364
5622
|
return {
|
|
5365
5623
|
extensions,
|
|
5624
|
+
setupDiagnostics,
|
|
5366
5625
|
findType: (typeId) => typeMap.get(typeId),
|
|
5367
5626
|
findTypeByName: (typeName) => typeNameMap.get(typeName),
|
|
5368
5627
|
findTypeByBrand: (brand) => brandMap.get(brand),
|
|
@@ -5378,7 +5637,7 @@ function createExtensionRegistry(extensions) {
|
|
|
5378
5637
|
}
|
|
5379
5638
|
|
|
5380
5639
|
// src/extensions/symbol-registry.ts
|
|
5381
|
-
import * as
|
|
5640
|
+
import * as ts7 from "typescript";
|
|
5382
5641
|
import * as path2 from "path";
|
|
5383
5642
|
|
|
5384
5643
|
// src/ui-schema/schema.ts
|
|
@@ -5771,7 +6030,7 @@ function formatLocation(location) {
|
|
|
5771
6030
|
}
|
|
5772
6031
|
function resolveStaticOptions(options) {
|
|
5773
6032
|
const legacyRegistry = options.extensionRegistry;
|
|
5774
|
-
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
6033
|
+
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
5775
6034
|
return {
|
|
5776
6035
|
extensionRegistry: legacyRegistry ?? configRegistry,
|
|
5777
6036
|
// eslint-disable-next-line @typescript-eslint/no-deprecated -- migration bridge reads deprecated fields
|