@formspec/build 0.1.0-alpha.51 → 0.1.0-alpha.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/builtin-brands.d.ts +13 -0
- package/dist/analyzer/builtin-brands.d.ts.map +1 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/cli.cjs +206 -196
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +198 -188
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +189 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +190 -188
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +159 -158
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +160 -158
- package/dist/internals.js.map +1 -1
- package/package.json +4 -4
package/dist/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 ts7 from "typescript";
|
|
795
795
|
import * as path from "path";
|
|
796
796
|
|
|
797
797
|
// src/analyzer/class-analyzer.ts
|
|
798
|
-
import * as
|
|
798
|
+
import * as ts6 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 ts5 from "typescript";
|
|
806
806
|
|
|
807
807
|
// src/analyzer/tsdoc-parser.ts
|
|
808
|
-
import * as
|
|
808
|
+
import * as ts4 from "typescript";
|
|
809
809
|
import {
|
|
810
810
|
checkSyntheticTagApplication,
|
|
811
811
|
choosePreferredPayloadText,
|
|
@@ -813,6 +813,7 @@ import {
|
|
|
813
813
|
getTagDefinition,
|
|
814
814
|
hasTypeSemanticCapability,
|
|
815
815
|
normalizeFormSpecTagName,
|
|
816
|
+
stripNullishUnion as stripNullishUnion2,
|
|
816
817
|
parseConstraintTagValue,
|
|
817
818
|
parseDefaultValueTagValue,
|
|
818
819
|
parseTagSyntax,
|
|
@@ -945,6 +946,14 @@ function customTypeIdFromLookup(result) {
|
|
|
945
946
|
return `${result.extensionId}/${result.registration.typeName}`;
|
|
946
947
|
}
|
|
947
948
|
|
|
949
|
+
// src/analyzer/builtin-brands.ts
|
|
950
|
+
import * as ts3 from "typescript";
|
|
951
|
+
function isIntegerBrandedType(type) {
|
|
952
|
+
if (!type.isIntersection()) return false;
|
|
953
|
+
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
954
|
+
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
955
|
+
}
|
|
956
|
+
|
|
948
957
|
// src/analyzer/tsdoc-parser.ts
|
|
949
958
|
function sharedTagValueOptions(options) {
|
|
950
959
|
return {
|
|
@@ -952,7 +961,7 @@ function sharedTagValueOptions(options) {
|
|
|
952
961
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
953
962
|
};
|
|
954
963
|
}
|
|
955
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
964
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts4.TypeFormatFlags.NoTruncation | ts4.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
956
965
|
function getExtensionTypeNames(registry) {
|
|
957
966
|
if (registry === void 0) {
|
|
958
967
|
return /* @__PURE__ */ new Set();
|
|
@@ -966,23 +975,23 @@ function getExtensionTypeNames(registry) {
|
|
|
966
975
|
function collectImportedNames(sourceFile) {
|
|
967
976
|
const importedNames = /* @__PURE__ */ new Set();
|
|
968
977
|
for (const statement of sourceFile.statements) {
|
|
969
|
-
if (
|
|
978
|
+
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
970
979
|
const clause = statement.importClause;
|
|
971
980
|
if (clause.name !== void 0) {
|
|
972
981
|
importedNames.add(clause.name.text);
|
|
973
982
|
}
|
|
974
983
|
if (clause.namedBindings !== void 0) {
|
|
975
|
-
if (
|
|
984
|
+
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
976
985
|
for (const specifier of clause.namedBindings.elements) {
|
|
977
986
|
importedNames.add(specifier.name.text);
|
|
978
987
|
}
|
|
979
|
-
} else if (
|
|
988
|
+
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
980
989
|
importedNames.add(clause.namedBindings.name.text);
|
|
981
990
|
}
|
|
982
991
|
}
|
|
983
992
|
continue;
|
|
984
993
|
}
|
|
985
|
-
if (
|
|
994
|
+
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
986
995
|
importedNames.add(statement.name.text);
|
|
987
996
|
}
|
|
988
997
|
}
|
|
@@ -990,13 +999,13 @@ function collectImportedNames(sourceFile) {
|
|
|
990
999
|
}
|
|
991
1000
|
function isNonReferenceIdentifier(node) {
|
|
992
1001
|
const parent = node.parent;
|
|
993
|
-
if ((
|
|
1002
|
+
if ((ts4.isBindingElement(parent) || ts4.isClassDeclaration(parent) || ts4.isEnumDeclaration(parent) || ts4.isEnumMember(parent) || ts4.isFunctionDeclaration(parent) || ts4.isFunctionExpression(parent) || ts4.isImportClause(parent) || ts4.isImportEqualsDeclaration(parent) || ts4.isImportSpecifier(parent) || ts4.isInterfaceDeclaration(parent) || ts4.isMethodDeclaration(parent) || ts4.isMethodSignature(parent) || ts4.isModuleDeclaration(parent) || ts4.isNamespaceExport(parent) || ts4.isNamespaceImport(parent) || ts4.isParameter(parent) || ts4.isPropertyDeclaration(parent) || ts4.isPropertySignature(parent) || ts4.isSetAccessorDeclaration(parent) || ts4.isGetAccessorDeclaration(parent) || ts4.isTypeAliasDeclaration(parent) || ts4.isTypeParameterDeclaration(parent) || ts4.isVariableDeclaration(parent)) && parent.name === node) {
|
|
994
1003
|
return true;
|
|
995
1004
|
}
|
|
996
|
-
if ((
|
|
1005
|
+
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
997
1006
|
return true;
|
|
998
1007
|
}
|
|
999
|
-
if (
|
|
1008
|
+
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
1000
1009
|
return true;
|
|
1001
1010
|
}
|
|
1002
1011
|
return false;
|
|
@@ -1010,11 +1019,11 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
1010
1019
|
if (referencesImportedName) {
|
|
1011
1020
|
return;
|
|
1012
1021
|
}
|
|
1013
|
-
if (
|
|
1022
|
+
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
1014
1023
|
referencesImportedName = true;
|
|
1015
1024
|
return;
|
|
1016
1025
|
}
|
|
1017
|
-
|
|
1026
|
+
ts4.forEachChild(node, visit);
|
|
1018
1027
|
};
|
|
1019
1028
|
visit(statement);
|
|
1020
1029
|
return referencesImportedName;
|
|
@@ -1025,9 +1034,9 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
1025
1034
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
1026
1035
|
);
|
|
1027
1036
|
return sourceFile.statements.filter((statement) => {
|
|
1028
|
-
if (
|
|
1029
|
-
if (
|
|
1030
|
-
if (
|
|
1037
|
+
if (ts4.isImportDeclaration(statement)) return false;
|
|
1038
|
+
if (ts4.isImportEqualsDeclaration(statement)) return false;
|
|
1039
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
1031
1040
|
return false;
|
|
1032
1041
|
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
1033
1042
|
return false;
|
|
@@ -1125,7 +1134,7 @@ function stripHintNullishUnion(type) {
|
|
|
1125
1134
|
return type;
|
|
1126
1135
|
}
|
|
1127
1136
|
const nonNullish = type.types.filter(
|
|
1128
|
-
(member) => (member.flags & (
|
|
1137
|
+
(member) => (member.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) === 0
|
|
1129
1138
|
);
|
|
1130
1139
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
1131
1140
|
return nonNullish[0];
|
|
@@ -1141,10 +1150,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
1141
1150
|
}
|
|
1142
1151
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
1143
1152
|
const name = declaration.name;
|
|
1144
|
-
if (
|
|
1153
|
+
if (ts4.isComputedPropertyName(name) || ts4.isPrivateIdentifier(name)) {
|
|
1145
1154
|
return false;
|
|
1146
1155
|
}
|
|
1147
|
-
if (!
|
|
1156
|
+
if (!ts4.isIdentifier(name) && !ts4.isStringLiteral(name) && !ts4.isNumericLiteral(name)) {
|
|
1148
1157
|
return false;
|
|
1149
1158
|
}
|
|
1150
1159
|
}
|
|
@@ -1362,6 +1371,9 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1362
1371
|
}
|
|
1363
1372
|
const hasBroadening = (() => {
|
|
1364
1373
|
if (target === null) {
|
|
1374
|
+
if (isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
1375
|
+
return true;
|
|
1376
|
+
}
|
|
1365
1377
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
1366
1378
|
}
|
|
1367
1379
|
const registry = options?.extensionRegistry;
|
|
@@ -1514,12 +1526,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1514
1526
|
const sourceText = sourceFile.getFullText();
|
|
1515
1527
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
1516
1528
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
1517
|
-
const commentRanges =
|
|
1529
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1518
1530
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
1519
1531
|
const extensionTagNames = getExtensionTagNames(options);
|
|
1520
1532
|
if (commentRanges) {
|
|
1521
1533
|
for (const range of commentRanges) {
|
|
1522
|
-
if (range.kind !==
|
|
1534
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) {
|
|
1523
1535
|
continue;
|
|
1524
1536
|
}
|
|
1525
1537
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -1676,10 +1688,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
1676
1688
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
1677
1689
|
const sourceFile = node.getSourceFile();
|
|
1678
1690
|
const sourceText = sourceFile.getFullText();
|
|
1679
|
-
const commentRanges =
|
|
1691
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1680
1692
|
if (commentRanges) {
|
|
1681
1693
|
for (const range of commentRanges) {
|
|
1682
|
-
if (range.kind !==
|
|
1694
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
1683
1695
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
1684
1696
|
if (!commentText.startsWith("/**")) continue;
|
|
1685
1697
|
const unified = parseUnifiedComment(commentText);
|
|
@@ -1704,7 +1716,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
1704
1716
|
}
|
|
1705
1717
|
function collectRawTextFallbacks(node, file) {
|
|
1706
1718
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
1707
|
-
for (const tag of
|
|
1719
|
+
for (const tag of ts4.getJSDocTags(node)) {
|
|
1708
1720
|
const tagName = normalizeConstraintTagName(tag.tagName.text);
|
|
1709
1721
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
1710
1722
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -1759,7 +1771,7 @@ function getTagCommentText(tag) {
|
|
|
1759
1771
|
if (typeof tag.comment === "string") {
|
|
1760
1772
|
return tag.comment;
|
|
1761
1773
|
}
|
|
1762
|
-
return
|
|
1774
|
+
return ts4.getTextOfJSDocComment(tag.comment);
|
|
1763
1775
|
}
|
|
1764
1776
|
|
|
1765
1777
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -1777,18 +1789,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
1777
1789
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
1778
1790
|
if (!initializer) return null;
|
|
1779
1791
|
let value;
|
|
1780
|
-
if (
|
|
1792
|
+
if (ts5.isStringLiteral(initializer)) {
|
|
1781
1793
|
value = initializer.text;
|
|
1782
|
-
} else if (
|
|
1794
|
+
} else if (ts5.isNumericLiteral(initializer)) {
|
|
1783
1795
|
value = Number(initializer.text);
|
|
1784
|
-
} else if (initializer.kind ===
|
|
1796
|
+
} else if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
|
|
1785
1797
|
value = true;
|
|
1786
|
-
} else if (initializer.kind ===
|
|
1798
|
+
} else if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
|
|
1787
1799
|
value = false;
|
|
1788
|
-
} else if (initializer.kind ===
|
|
1800
|
+
} else if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
|
|
1789
1801
|
value = null;
|
|
1790
|
-
} else if (
|
|
1791
|
-
if (initializer.operator ===
|
|
1802
|
+
} else if (ts5.isPrefixUnaryExpression(initializer)) {
|
|
1803
|
+
if (initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
|
|
1792
1804
|
value = -Number(initializer.operand.text);
|
|
1793
1805
|
}
|
|
1794
1806
|
}
|
|
@@ -1810,38 +1822,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
1810
1822
|
|
|
1811
1823
|
// src/analyzer/class-analyzer.ts
|
|
1812
1824
|
function isObjectType(type) {
|
|
1813
|
-
return !!(type.flags &
|
|
1825
|
+
return !!(type.flags & ts6.TypeFlags.Object);
|
|
1814
1826
|
}
|
|
1815
1827
|
function isIntersectionType(type) {
|
|
1816
|
-
return !!(type.flags &
|
|
1817
|
-
}
|
|
1818
|
-
function isIntegerBrandedType(type) {
|
|
1819
|
-
if (!type.isIntersection()) {
|
|
1820
|
-
return false;
|
|
1821
|
-
}
|
|
1822
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
1823
|
-
if (!hasNumberBase) {
|
|
1824
|
-
return false;
|
|
1825
|
-
}
|
|
1826
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
1828
|
+
return !!(type.flags & ts6.TypeFlags.Intersection);
|
|
1827
1829
|
}
|
|
1828
1830
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
1829
|
-
if (
|
|
1831
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
1830
1832
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
1831
1833
|
}
|
|
1832
|
-
if (
|
|
1834
|
+
if (ts6.isTypeLiteralNode(typeNode) || ts6.isTypeReferenceNode(typeNode)) {
|
|
1833
1835
|
return true;
|
|
1834
1836
|
}
|
|
1835
|
-
return
|
|
1837
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
1836
1838
|
}
|
|
1837
1839
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
1838
1840
|
if (isIntersectionType(type)) {
|
|
1839
1841
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
1840
1842
|
}
|
|
1841
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
1843
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts6.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts6.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
1842
1844
|
}
|
|
1843
1845
|
function isTypeReference(type) {
|
|
1844
|
-
return !!(type.flags &
|
|
1846
|
+
return !!(type.flags & ts6.TypeFlags.Object) && !!(type.objectFlags & ts6.ObjectFlags.Reference);
|
|
1845
1847
|
}
|
|
1846
1848
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
1847
1849
|
kind: "object",
|
|
@@ -1906,7 +1908,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
1906
1908
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
1907
1909
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
1908
1910
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
1909
|
-
const logicalName =
|
|
1911
|
+
const logicalName = ts6.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
1910
1912
|
const docResult = extractJSDocParseResult(
|
|
1911
1913
|
declaration,
|
|
1912
1914
|
file,
|
|
@@ -1954,7 +1956,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
1954
1956
|
const instanceMethods = [];
|
|
1955
1957
|
const staticMethods = [];
|
|
1956
1958
|
for (const member of classDecl.members) {
|
|
1957
|
-
if (
|
|
1959
|
+
if (ts6.isPropertyDeclaration(member)) {
|
|
1958
1960
|
const fieldNode = analyzeFieldToIR(
|
|
1959
1961
|
member,
|
|
1960
1962
|
checker,
|
|
@@ -1970,10 +1972,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
1970
1972
|
fields.push(fieldNode);
|
|
1971
1973
|
fieldLayouts.push({});
|
|
1972
1974
|
}
|
|
1973
|
-
} else if (
|
|
1975
|
+
} else if (ts6.isMethodDeclaration(member)) {
|
|
1974
1976
|
const methodInfo = analyzeMethod(member, checker);
|
|
1975
1977
|
if (methodInfo) {
|
|
1976
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
1978
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts6.SyntaxKind.StaticKeyword);
|
|
1977
1979
|
if (isStatic) {
|
|
1978
1980
|
staticMethods.push(methodInfo);
|
|
1979
1981
|
} else {
|
|
@@ -2036,7 +2038,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
2036
2038
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
2037
2039
|
const visiting = /* @__PURE__ */ new Set();
|
|
2038
2040
|
for (const member of interfaceDecl.members) {
|
|
2039
|
-
if (
|
|
2041
|
+
if (ts6.isPropertySignature(member)) {
|
|
2040
2042
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2041
2043
|
member,
|
|
2042
2044
|
checker,
|
|
@@ -2094,7 +2096,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2094
2096
|
if (members === null) {
|
|
2095
2097
|
const sourceFile = typeAlias.getSourceFile();
|
|
2096
2098
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
2097
|
-
const kindDesc =
|
|
2099
|
+
const kindDesc = ts6.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
2098
2100
|
return {
|
|
2099
2101
|
ok: false,
|
|
2100
2102
|
kind: "not-object-like",
|
|
@@ -2129,7 +2131,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2129
2131
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
2130
2132
|
const visiting = /* @__PURE__ */ new Set();
|
|
2131
2133
|
for (const member of members) {
|
|
2132
|
-
if (
|
|
2134
|
+
if (ts6.isPropertySignature(member)) {
|
|
2133
2135
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2134
2136
|
member,
|
|
2135
2137
|
checker,
|
|
@@ -2196,13 +2198,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
2196
2198
|
function getLeadingParsedTags(node) {
|
|
2197
2199
|
const sourceFile = node.getSourceFile();
|
|
2198
2200
|
const sourceText = sourceFile.getFullText();
|
|
2199
|
-
const commentRanges =
|
|
2201
|
+
const commentRanges = ts6.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2200
2202
|
if (commentRanges === void 0) {
|
|
2201
2203
|
return [];
|
|
2202
2204
|
}
|
|
2203
2205
|
const parsedTags = [];
|
|
2204
2206
|
for (const range of commentRanges) {
|
|
2205
|
-
if (range.kind !==
|
|
2207
|
+
if (range.kind !== ts6.SyntaxKind.MultiLineCommentTrivia) {
|
|
2206
2208
|
continue;
|
|
2207
2209
|
}
|
|
2208
2210
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -2220,19 +2222,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
2220
2222
|
return null;
|
|
2221
2223
|
}
|
|
2222
2224
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
2223
|
-
(candidate) =>
|
|
2225
|
+
(candidate) => ts6.isPropertyDeclaration(candidate) || ts6.isPropertySignature(candidate)
|
|
2224
2226
|
) ?? propertySymbol.declarations?.[0];
|
|
2225
2227
|
return {
|
|
2226
2228
|
declaration,
|
|
2227
2229
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
2228
|
-
optional: !!(propertySymbol.flags &
|
|
2230
|
+
optional: !!(propertySymbol.flags & ts6.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
2229
2231
|
};
|
|
2230
2232
|
}
|
|
2231
2233
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
2232
2234
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
2233
2235
|
}
|
|
2234
2236
|
function isNullishSemanticType(type) {
|
|
2235
|
-
if (type.flags & (
|
|
2237
|
+
if (type.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined | ts6.TypeFlags.Void | ts6.TypeFlags.Unknown | ts6.TypeFlags.Any)) {
|
|
2236
2238
|
return true;
|
|
2237
2239
|
}
|
|
2238
2240
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -2242,7 +2244,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2242
2244
|
return false;
|
|
2243
2245
|
}
|
|
2244
2246
|
seen.add(type);
|
|
2245
|
-
if (type.flags &
|
|
2247
|
+
if (type.flags & ts6.TypeFlags.StringLike) {
|
|
2246
2248
|
return true;
|
|
2247
2249
|
}
|
|
2248
2250
|
if (type.isUnion()) {
|
|
@@ -2255,13 +2257,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2255
2257
|
return false;
|
|
2256
2258
|
}
|
|
2257
2259
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
2258
|
-
if (
|
|
2260
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
2259
2261
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
2260
2262
|
}
|
|
2261
|
-
if (
|
|
2263
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
2262
2264
|
return [...typeNode.members];
|
|
2263
2265
|
}
|
|
2264
|
-
if (
|
|
2266
|
+
if (ts6.isIntersectionTypeNode(typeNode)) {
|
|
2265
2267
|
const members = [];
|
|
2266
2268
|
for (const intersectionMember of typeNode.types) {
|
|
2267
2269
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -2424,7 +2426,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
2424
2426
|
}
|
|
2425
2427
|
if (propertyType.isUnion()) {
|
|
2426
2428
|
const nonNullMembers = propertyType.types.filter(
|
|
2427
|
-
(member) => !(member.flags & (
|
|
2429
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
2428
2430
|
);
|
|
2429
2431
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2430
2432
|
diagnostics.push(
|
|
@@ -2473,13 +2475,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
2473
2475
|
seen.add(type);
|
|
2474
2476
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
2475
2477
|
if (symbol !== void 0) {
|
|
2476
|
-
const aliased = symbol.flags &
|
|
2478
|
+
const aliased = symbol.flags & ts6.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
2477
2479
|
const targetSymbol = aliased ?? symbol;
|
|
2478
2480
|
const declaration = targetSymbol.declarations?.find(
|
|
2479
|
-
(candidate) =>
|
|
2481
|
+
(candidate) => ts6.isClassDeclaration(candidate) || ts6.isInterfaceDeclaration(candidate) || ts6.isTypeAliasDeclaration(candidate) || ts6.isEnumDeclaration(candidate)
|
|
2480
2482
|
);
|
|
2481
2483
|
if (declaration !== void 0) {
|
|
2482
|
-
if (
|
|
2484
|
+
if (ts6.isTypeAliasDeclaration(declaration) && ts6.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
2483
2485
|
return resolveNamedDiscriminatorDeclaration(
|
|
2484
2486
|
checker.getTypeFromTypeNode(declaration.type),
|
|
2485
2487
|
checker,
|
|
@@ -2507,7 +2509,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2507
2509
|
}
|
|
2508
2510
|
if (boundType.isUnion()) {
|
|
2509
2511
|
const nonNullMembers = boundType.types.filter(
|
|
2510
|
-
(member) => !(member.flags & (
|
|
2512
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
2511
2513
|
);
|
|
2512
2514
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2513
2515
|
diagnostics.push(
|
|
@@ -2552,7 +2554,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2552
2554
|
return null;
|
|
2553
2555
|
}
|
|
2554
2556
|
function getDeclarationName(node) {
|
|
2555
|
-
if (
|
|
2557
|
+
if (ts6.isClassDeclaration(node) || ts6.isInterfaceDeclaration(node) || ts6.isTypeAliasDeclaration(node) || ts6.isEnumDeclaration(node)) {
|
|
2556
2558
|
return node.name?.text ?? "anonymous";
|
|
2557
2559
|
}
|
|
2558
2560
|
return "anonymous";
|
|
@@ -2607,11 +2609,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
2607
2609
|
if (sourceTypeNode === void 0) {
|
|
2608
2610
|
return [];
|
|
2609
2611
|
}
|
|
2610
|
-
const unwrapParentheses = (typeNode) =>
|
|
2612
|
+
const unwrapParentheses = (typeNode) => ts6.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
2611
2613
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
2612
|
-
const referenceTypeNode =
|
|
2614
|
+
const referenceTypeNode = ts6.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
2613
2615
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
2614
|
-
return
|
|
2616
|
+
return ts6.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
2615
2617
|
})();
|
|
2616
2618
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
2617
2619
|
return [];
|
|
@@ -2666,7 +2668,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
2666
2668
|
);
|
|
2667
2669
|
}
|
|
2668
2670
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
2669
|
-
if (!
|
|
2671
|
+
if (!ts6.isIdentifier(prop.name)) {
|
|
2670
2672
|
return null;
|
|
2671
2673
|
}
|
|
2672
2674
|
const name = prop.name.text;
|
|
@@ -2793,7 +2795,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2793
2795
|
const seen = /* @__PURE__ */ new Set();
|
|
2794
2796
|
const duplicates = /* @__PURE__ */ new Set();
|
|
2795
2797
|
for (const member of members) {
|
|
2796
|
-
if (!
|
|
2798
|
+
if (!ts6.isPropertySignature(member)) {
|
|
2797
2799
|
continue;
|
|
2798
2800
|
}
|
|
2799
2801
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -2809,7 +2811,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2809
2811
|
return [...duplicates].sort();
|
|
2810
2812
|
}
|
|
2811
2813
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
2812
|
-
if (
|
|
2814
|
+
if (ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNumericLiteral(name)) {
|
|
2813
2815
|
return name.text;
|
|
2814
2816
|
}
|
|
2815
2817
|
return null;
|
|
@@ -2907,25 +2909,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
2907
2909
|
if (isIntegerBrandedType(type)) {
|
|
2908
2910
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
2909
2911
|
}
|
|
2910
|
-
if (type.flags &
|
|
2912
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
2911
2913
|
return { kind: "primitive", primitiveKind: "string" };
|
|
2912
2914
|
}
|
|
2913
|
-
if (type.flags &
|
|
2915
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
2914
2916
|
return { kind: "primitive", primitiveKind: "number" };
|
|
2915
2917
|
}
|
|
2916
|
-
if (type.flags & (
|
|
2918
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
2917
2919
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
2918
2920
|
}
|
|
2919
|
-
if (type.flags &
|
|
2921
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
2920
2922
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
2921
2923
|
}
|
|
2922
|
-
if (type.flags &
|
|
2924
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
2923
2925
|
return { kind: "primitive", primitiveKind: "null" };
|
|
2924
2926
|
}
|
|
2925
|
-
if (type.flags &
|
|
2927
|
+
if (type.flags & ts6.TypeFlags.Undefined) {
|
|
2926
2928
|
return { kind: "primitive", primitiveKind: "null" };
|
|
2927
2929
|
}
|
|
2928
|
-
if (type.flags &
|
|
2930
|
+
if (type.flags & ts6.TypeFlags.Void) {
|
|
2929
2931
|
return { kind: "primitive", primitiveKind: "null" };
|
|
2930
2932
|
}
|
|
2931
2933
|
if (type.isStringLiteral()) {
|
|
@@ -3012,10 +3014,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
3012
3014
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3013
3015
|
}
|
|
3014
3016
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
3015
|
-
if (!(type.flags & (
|
|
3017
|
+
if (!(type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
3016
3018
|
return null;
|
|
3017
3019
|
}
|
|
3018
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3020
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
3019
3021
|
if (!aliasDecl) {
|
|
3020
3022
|
return null;
|
|
3021
3023
|
}
|
|
@@ -3065,14 +3067,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
3065
3067
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
3066
3068
|
}
|
|
3067
3069
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
3068
|
-
const typeNode = sourceNode && (
|
|
3069
|
-
if (!typeNode || !
|
|
3070
|
+
const typeNode = sourceNode && (ts6.isPropertyDeclaration(sourceNode) || ts6.isPropertySignature(sourceNode) || ts6.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
3071
|
+
if (!typeNode || !ts6.isTypeReferenceNode(typeNode)) {
|
|
3070
3072
|
return void 0;
|
|
3071
3073
|
}
|
|
3072
3074
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
3073
3075
|
}
|
|
3074
3076
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
3075
|
-
if (!
|
|
3077
|
+
if (!ts6.isTypeReferenceNode(typeNode)) {
|
|
3076
3078
|
return false;
|
|
3077
3079
|
}
|
|
3078
3080
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3080,10 +3082,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
3080
3082
|
return false;
|
|
3081
3083
|
}
|
|
3082
3084
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
3083
|
-
return !!(resolved.flags & (
|
|
3085
|
+
return !!(resolved.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null));
|
|
3084
3086
|
}
|
|
3085
3087
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
3086
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3088
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration);
|
|
3087
3089
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
3088
3090
|
visitedAliases.add(nestedAliasDecl);
|
|
3089
3091
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -3101,19 +3103,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
3101
3103
|
if (isIntegerBrandedType(type)) {
|
|
3102
3104
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
3103
3105
|
}
|
|
3104
|
-
if (type.flags &
|
|
3106
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
3105
3107
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3106
3108
|
}
|
|
3107
|
-
if (type.flags &
|
|
3109
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
3108
3110
|
return { kind: "primitive", primitiveKind: "number" };
|
|
3109
3111
|
}
|
|
3110
|
-
if (type.flags & (
|
|
3112
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
3111
3113
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
3112
3114
|
}
|
|
3113
|
-
if (type.flags &
|
|
3115
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
3114
3116
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
3115
3117
|
}
|
|
3116
|
-
if (type.flags &
|
|
3118
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
3117
3119
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3118
3120
|
}
|
|
3119
3121
|
return resolveTypeNode(
|
|
@@ -3140,13 +3142,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3140
3142
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
3141
3143
|
);
|
|
3142
3144
|
const nonNullTypes = allTypes.filter(
|
|
3143
|
-
(memberType) => !(memberType.flags & (
|
|
3145
|
+
(memberType) => !(memberType.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3144
3146
|
);
|
|
3145
3147
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
3146
3148
|
memberType,
|
|
3147
3149
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
3148
3150
|
}));
|
|
3149
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
3151
|
+
const hasNull = allTypes.some((t) => t.flags & ts6.TypeFlags.Null);
|
|
3150
3152
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3151
3153
|
if (namedDecl) {
|
|
3152
3154
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -3189,7 +3191,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3189
3191
|
const displayName = memberDisplayNames.get(String(value));
|
|
3190
3192
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
3191
3193
|
});
|
|
3192
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
3194
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts6.TypeFlags.BooleanLiteral);
|
|
3193
3195
|
if (isBooleanUnion2) {
|
|
3194
3196
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
3195
3197
|
const result = hasNull ? {
|
|
@@ -3281,7 +3283,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
3281
3283
|
if (type.getProperties().length > 0) {
|
|
3282
3284
|
return null;
|
|
3283
3285
|
}
|
|
3284
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
3286
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts6.IndexKind.String);
|
|
3285
3287
|
if (!indexInfo) {
|
|
3286
3288
|
return null;
|
|
3287
3289
|
}
|
|
@@ -3329,10 +3331,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
3329
3331
|
}
|
|
3330
3332
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
3331
3333
|
const name = declaration.name;
|
|
3332
|
-
if (
|
|
3334
|
+
if (ts6.isComputedPropertyName(name) || ts6.isPrivateIdentifier(name)) {
|
|
3333
3335
|
return false;
|
|
3334
3336
|
}
|
|
3335
|
-
if (!
|
|
3337
|
+
if (!ts6.isIdentifier(name) && !ts6.isStringLiteral(name) && !ts6.isNumericLiteral(name)) {
|
|
3336
3338
|
return false;
|
|
3337
3339
|
}
|
|
3338
3340
|
}
|
|
@@ -3458,7 +3460,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3458
3460
|
if (!declaration) continue;
|
|
3459
3461
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
3460
3462
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
3461
|
-
const optional = !!(prop.flags &
|
|
3463
|
+
const optional = !!(prop.flags & ts6.SymbolFlags.Optional);
|
|
3462
3464
|
const propTypeNode = resolveTypeNode(
|
|
3463
3465
|
propType,
|
|
3464
3466
|
checker,
|
|
@@ -3471,7 +3473,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3471
3473
|
collectedDiagnostics
|
|
3472
3474
|
);
|
|
3473
3475
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
3474
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
3476
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts6.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
3475
3477
|
declaration,
|
|
3476
3478
|
checker,
|
|
3477
3479
|
file,
|
|
@@ -3481,7 +3483,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3481
3483
|
type,
|
|
3482
3484
|
metadataPolicy,
|
|
3483
3485
|
extensionRegistry
|
|
3484
|
-
) :
|
|
3486
|
+
) : ts6.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
3485
3487
|
declaration,
|
|
3486
3488
|
checker,
|
|
3487
3489
|
file,
|
|
@@ -3509,7 +3511,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3509
3511
|
visiting.delete(type);
|
|
3510
3512
|
const objectNode = {
|
|
3511
3513
|
kind: "object",
|
|
3512
|
-
properties: namedDecl !== void 0 && (
|
|
3514
|
+
properties: namedDecl !== void 0 && (ts6.isClassDeclaration(namedDecl) || ts6.isInterfaceDeclaration(namedDecl) || ts6.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
3513
3515
|
properties,
|
|
3514
3516
|
namedDecl,
|
|
3515
3517
|
type,
|
|
@@ -3557,12 +3559,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3557
3559
|
for (const symbol of symbols) {
|
|
3558
3560
|
const declarations = symbol.declarations;
|
|
3559
3561
|
if (!declarations) continue;
|
|
3560
|
-
const classDecl = declarations.find(
|
|
3562
|
+
const classDecl = declarations.find(ts6.isClassDeclaration);
|
|
3561
3563
|
if (classDecl) {
|
|
3562
3564
|
const map = /* @__PURE__ */ new Map();
|
|
3563
3565
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
3564
3566
|
for (const member of classDecl.members) {
|
|
3565
|
-
if (
|
|
3567
|
+
if (ts6.isPropertyDeclaration(member) && ts6.isIdentifier(member.name)) {
|
|
3566
3568
|
const fieldNode = analyzeFieldToIR(
|
|
3567
3569
|
member,
|
|
3568
3570
|
checker,
|
|
@@ -3586,7 +3588,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3586
3588
|
}
|
|
3587
3589
|
return map;
|
|
3588
3590
|
}
|
|
3589
|
-
const interfaceDecl = declarations.find(
|
|
3591
|
+
const interfaceDecl = declarations.find(ts6.isInterfaceDeclaration);
|
|
3590
3592
|
if (interfaceDecl) {
|
|
3591
3593
|
return buildFieldNodeInfoMap(
|
|
3592
3594
|
interfaceDecl.members,
|
|
@@ -3600,7 +3602,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3600
3602
|
extensionRegistry
|
|
3601
3603
|
);
|
|
3602
3604
|
}
|
|
3603
|
-
const typeAliasDecl = declarations.find(
|
|
3605
|
+
const typeAliasDecl = declarations.find(ts6.isTypeAliasDeclaration);
|
|
3604
3606
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
3605
3607
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
3606
3608
|
return buildFieldNodeInfoMap(
|
|
@@ -3624,10 +3626,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
3624
3626
|
return void 0;
|
|
3625
3627
|
}
|
|
3626
3628
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3627
|
-
if (
|
|
3629
|
+
if (ts6.isArrayTypeNode(resolvedTypeNode)) {
|
|
3628
3630
|
return resolvedTypeNode.elementType;
|
|
3629
3631
|
}
|
|
3630
|
-
if (
|
|
3632
|
+
if (ts6.isTypeReferenceNode(resolvedTypeNode) && ts6.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
3631
3633
|
return resolvedTypeNode.typeArguments[0];
|
|
3632
3634
|
}
|
|
3633
3635
|
return void 0;
|
|
@@ -3638,13 +3640,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
3638
3640
|
return [];
|
|
3639
3641
|
}
|
|
3640
3642
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3641
|
-
return
|
|
3643
|
+
return ts6.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
3642
3644
|
}
|
|
3643
3645
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
3644
|
-
if (
|
|
3646
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3645
3647
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
3646
3648
|
}
|
|
3647
|
-
if (!
|
|
3649
|
+
if (!ts6.isTypeReferenceNode(typeNode) || !ts6.isIdentifier(typeNode.typeName)) {
|
|
3648
3650
|
return typeNode;
|
|
3649
3651
|
}
|
|
3650
3652
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3655,15 +3657,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
3655
3657
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
3656
3658
|
}
|
|
3657
3659
|
function isNullishTypeNode(typeNode) {
|
|
3658
|
-
if (typeNode.kind ===
|
|
3660
|
+
if (typeNode.kind === ts6.SyntaxKind.NullKeyword || typeNode.kind === ts6.SyntaxKind.UndefinedKeyword) {
|
|
3659
3661
|
return true;
|
|
3660
3662
|
}
|
|
3661
|
-
return
|
|
3663
|
+
return ts6.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts6.SyntaxKind.NullKeyword || typeNode.literal.kind === ts6.SyntaxKind.UndefinedKeyword);
|
|
3662
3664
|
}
|
|
3663
3665
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
3664
3666
|
const map = /* @__PURE__ */ new Map();
|
|
3665
3667
|
for (const member of members) {
|
|
3666
|
-
if (
|
|
3668
|
+
if (ts6.isPropertySignature(member)) {
|
|
3667
3669
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3668
3670
|
member,
|
|
3669
3671
|
checker,
|
|
@@ -3689,7 +3691,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
3689
3691
|
}
|
|
3690
3692
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
3691
3693
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
3692
|
-
if (!
|
|
3694
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return [];
|
|
3693
3695
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
3694
3696
|
const aliasName = typeNode.typeName.getText();
|
|
3695
3697
|
throw new Error(
|
|
@@ -3698,7 +3700,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
3698
3700
|
}
|
|
3699
3701
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
3700
3702
|
if (!aliasDecl) return [];
|
|
3701
|
-
if (
|
|
3703
|
+
if (ts6.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
3702
3704
|
const aliasFieldType = resolveTypeNode(
|
|
3703
3705
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
3704
3706
|
checker,
|
|
@@ -3742,14 +3744,14 @@ function getNamedTypeName(type) {
|
|
|
3742
3744
|
const symbol = type.getSymbol();
|
|
3743
3745
|
if (symbol?.declarations) {
|
|
3744
3746
|
const decl = symbol.declarations[0];
|
|
3745
|
-
if (decl && (
|
|
3746
|
-
const name =
|
|
3747
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
3748
|
+
const name = ts6.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
3747
3749
|
if (name) return name;
|
|
3748
3750
|
}
|
|
3749
3751
|
}
|
|
3750
3752
|
const aliasSymbol = type.aliasSymbol;
|
|
3751
3753
|
if (aliasSymbol?.declarations) {
|
|
3752
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
3754
|
+
const aliasDecl = aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
3753
3755
|
if (aliasDecl) {
|
|
3754
3756
|
return aliasDecl.name.text;
|
|
3755
3757
|
}
|
|
@@ -3760,24 +3762,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
3760
3762
|
const symbol = type.getSymbol();
|
|
3761
3763
|
if (symbol?.declarations) {
|
|
3762
3764
|
const decl = symbol.declarations[0];
|
|
3763
|
-
if (decl && (
|
|
3765
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
3764
3766
|
return decl;
|
|
3765
3767
|
}
|
|
3766
3768
|
}
|
|
3767
3769
|
const aliasSymbol = type.aliasSymbol;
|
|
3768
3770
|
if (aliasSymbol?.declarations) {
|
|
3769
|
-
return aliasSymbol.declarations.find(
|
|
3771
|
+
return aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
3770
3772
|
}
|
|
3771
3773
|
return void 0;
|
|
3772
3774
|
}
|
|
3773
3775
|
function analyzeMethod(method, checker) {
|
|
3774
|
-
if (!
|
|
3776
|
+
if (!ts6.isIdentifier(method.name)) {
|
|
3775
3777
|
return null;
|
|
3776
3778
|
}
|
|
3777
3779
|
const name = method.name.text;
|
|
3778
3780
|
const parameters = [];
|
|
3779
3781
|
for (const param of method.parameters) {
|
|
3780
|
-
if (
|
|
3782
|
+
if (ts6.isIdentifier(param.name)) {
|
|
3781
3783
|
const paramInfo = analyzeParameter(param, checker);
|
|
3782
3784
|
parameters.push(paramInfo);
|
|
3783
3785
|
}
|
|
@@ -3788,7 +3790,7 @@ function analyzeMethod(method, checker) {
|
|
|
3788
3790
|
return { name, parameters, returnTypeNode, returnType };
|
|
3789
3791
|
}
|
|
3790
3792
|
function analyzeParameter(param, checker) {
|
|
3791
|
-
const name =
|
|
3793
|
+
const name = ts6.isIdentifier(param.name) ? param.name.text : "param";
|
|
3792
3794
|
const typeNode = param.type;
|
|
3793
3795
|
const type = checker.getTypeAtLocation(param);
|
|
3794
3796
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -3797,15 +3799,15 @@ function analyzeParameter(param, checker) {
|
|
|
3797
3799
|
}
|
|
3798
3800
|
function detectFormSpecReference(typeNode) {
|
|
3799
3801
|
if (!typeNode) return null;
|
|
3800
|
-
if (!
|
|
3801
|
-
const typeName =
|
|
3802
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return null;
|
|
3803
|
+
const typeName = ts6.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts6.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
3802
3804
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
3803
3805
|
const typeArg = typeNode.typeArguments?.[0];
|
|
3804
|
-
if (!typeArg || !
|
|
3805
|
-
if (
|
|
3806
|
+
if (!typeArg || !ts6.isTypeQueryNode(typeArg)) return null;
|
|
3807
|
+
if (ts6.isIdentifier(typeArg.exprName)) {
|
|
3806
3808
|
return typeArg.exprName.text;
|
|
3807
3809
|
}
|
|
3808
|
-
if (
|
|
3810
|
+
if (ts6.isQualifiedName(typeArg.exprName)) {
|
|
3809
3811
|
return typeArg.exprName.right.text;
|
|
3810
3812
|
}
|
|
3811
3813
|
return null;
|
|
@@ -3827,23 +3829,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
3827
3829
|
function createProgramContext(filePath, additionalFiles) {
|
|
3828
3830
|
const absolutePath = path.resolve(filePath);
|
|
3829
3831
|
const fileDir = path.dirname(absolutePath);
|
|
3830
|
-
const configPath =
|
|
3832
|
+
const configPath = ts7.findConfigFile(fileDir, ts7.sys.fileExists.bind(ts7.sys), "tsconfig.json");
|
|
3831
3833
|
let compilerOptions;
|
|
3832
3834
|
let fileNames;
|
|
3833
3835
|
if (configPath) {
|
|
3834
|
-
const configFile =
|
|
3836
|
+
const configFile = ts7.readConfigFile(configPath, ts7.sys.readFile.bind(ts7.sys));
|
|
3835
3837
|
if (configFile.error) {
|
|
3836
3838
|
throw new Error(
|
|
3837
|
-
`Error reading tsconfig.json: ${
|
|
3839
|
+
`Error reading tsconfig.json: ${ts7.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
3838
3840
|
);
|
|
3839
3841
|
}
|
|
3840
|
-
const parsed =
|
|
3842
|
+
const parsed = ts7.parseJsonConfigFileContent(
|
|
3841
3843
|
configFile.config,
|
|
3842
|
-
|
|
3844
|
+
ts7.sys,
|
|
3843
3845
|
path.dirname(configPath)
|
|
3844
3846
|
);
|
|
3845
3847
|
if (parsed.errors.length > 0) {
|
|
3846
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
3848
|
+
const errorMessages = parsed.errors.map((e) => ts7.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
3847
3849
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
3848
3850
|
}
|
|
3849
3851
|
compilerOptions = parsed.options;
|
|
@@ -3851,9 +3853,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
3851
3853
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
3852
3854
|
} else {
|
|
3853
3855
|
compilerOptions = {
|
|
3854
|
-
target:
|
|
3855
|
-
module:
|
|
3856
|
-
moduleResolution:
|
|
3856
|
+
target: ts7.ScriptTarget.ES2022,
|
|
3857
|
+
module: ts7.ModuleKind.NodeNext,
|
|
3858
|
+
moduleResolution: ts7.ModuleResolutionKind.NodeNext,
|
|
3857
3859
|
strict: true,
|
|
3858
3860
|
skipLibCheck: true,
|
|
3859
3861
|
declaration: true
|
|
@@ -3861,7 +3863,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
3861
3863
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
3862
3864
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
3863
3865
|
}
|
|
3864
|
-
const program =
|
|
3866
|
+
const program = ts7.createProgram(fileNames, compilerOptions);
|
|
3865
3867
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
3866
3868
|
if (!sourceFile) {
|
|
3867
3869
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -3880,19 +3882,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
3880
3882
|
result = node;
|
|
3881
3883
|
return;
|
|
3882
3884
|
}
|
|
3883
|
-
|
|
3885
|
+
ts7.forEachChild(node, visit);
|
|
3884
3886
|
}
|
|
3885
3887
|
visit(sourceFile);
|
|
3886
3888
|
return result;
|
|
3887
3889
|
}
|
|
3888
3890
|
function findClassByName(sourceFile, className) {
|
|
3889
|
-
return findNodeByName(sourceFile, className,
|
|
3891
|
+
return findNodeByName(sourceFile, className, ts7.isClassDeclaration, (n) => n.name?.text);
|
|
3890
3892
|
}
|
|
3891
3893
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
3892
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
3894
|
+
return findNodeByName(sourceFile, interfaceName, ts7.isInterfaceDeclaration, (n) => n.name.text);
|
|
3893
3895
|
}
|
|
3894
3896
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
3895
|
-
return findNodeByName(sourceFile, aliasName,
|
|
3897
|
+
return findNodeByName(sourceFile, aliasName, ts7.isTypeAliasDeclaration, (n) => n.name.text);
|
|
3896
3898
|
}
|
|
3897
3899
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
3898
3900
|
if (rootType.kind === "object") {
|
|
@@ -3932,22 +3934,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
3932
3934
|
};
|
|
3933
3935
|
}
|
|
3934
3936
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
3935
|
-
if (
|
|
3937
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
3936
3938
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
3937
3939
|
}
|
|
3938
|
-
if (
|
|
3940
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
3939
3941
|
return true;
|
|
3940
3942
|
}
|
|
3941
|
-
return
|
|
3943
|
+
return ts7.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
3942
3944
|
}
|
|
3943
3945
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
3944
|
-
if (
|
|
3946
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
3945
3947
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
3946
3948
|
}
|
|
3947
|
-
if (
|
|
3949
|
+
if (ts7.isTypeLiteralNode(typeNode)) {
|
|
3948
3950
|
const propertyNames = [];
|
|
3949
3951
|
for (const member of typeNode.members) {
|
|
3950
|
-
if (!
|
|
3952
|
+
if (!ts7.isPropertySignature(member)) {
|
|
3951
3953
|
continue;
|
|
3952
3954
|
}
|
|
3953
3955
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -3957,13 +3959,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
3957
3959
|
}
|
|
3958
3960
|
return propertyNames;
|
|
3959
3961
|
}
|
|
3960
|
-
if (
|
|
3962
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
3961
3963
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
3962
3964
|
}
|
|
3963
3965
|
return null;
|
|
3964
3966
|
}
|
|
3965
3967
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
3966
|
-
if (!
|
|
3968
|
+
if (!ts7.isIntersectionTypeNode(typeNode)) {
|
|
3967
3969
|
return [];
|
|
3968
3970
|
}
|
|
3969
3971
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -4153,7 +4155,7 @@ function makeFileProvenance(filePath) {
|
|
|
4153
4155
|
}
|
|
4154
4156
|
|
|
4155
4157
|
// src/generators/class-schema.ts
|
|
4156
|
-
import * as
|
|
4158
|
+
import * as ts9 from "typescript";
|
|
4157
4159
|
|
|
4158
4160
|
// src/metadata/collision-guards.ts
|
|
4159
4161
|
function assertUniqueSerializedNames(entries, scope) {
|
|
@@ -5153,7 +5155,7 @@ function createExtensionRegistry(extensions) {
|
|
|
5153
5155
|
}
|
|
5154
5156
|
|
|
5155
5157
|
// src/extensions/symbol-registry.ts
|
|
5156
|
-
import * as
|
|
5158
|
+
import * as ts8 from "typescript";
|
|
5157
5159
|
import * as path2 from "path";
|
|
5158
5160
|
|
|
5159
5161
|
// src/ui-schema/schema.ts
|