@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.cjs
CHANGED
|
@@ -847,18 +847,18 @@ function wrapInConditional(field, layout, provenance) {
|
|
|
847
847
|
}
|
|
848
848
|
|
|
849
849
|
// src/analyzer/program.ts
|
|
850
|
-
var
|
|
850
|
+
var ts7 = __toESM(require("typescript"), 1);
|
|
851
851
|
var path = __toESM(require("path"), 1);
|
|
852
852
|
|
|
853
853
|
// src/analyzer/class-analyzer.ts
|
|
854
|
-
var
|
|
854
|
+
var ts6 = __toESM(require("typescript"), 1);
|
|
855
855
|
var import_internal3 = require("@formspec/analysis/internal");
|
|
856
856
|
|
|
857
857
|
// src/analyzer/jsdoc-constraints.ts
|
|
858
|
-
var
|
|
858
|
+
var ts5 = __toESM(require("typescript"), 1);
|
|
859
859
|
|
|
860
860
|
// src/analyzer/tsdoc-parser.ts
|
|
861
|
-
var
|
|
861
|
+
var ts4 = __toESM(require("typescript"), 1);
|
|
862
862
|
var import_internal2 = require("@formspec/analysis/internal");
|
|
863
863
|
var import_internals3 = require("@formspec/core/internals");
|
|
864
864
|
var import_internals4 = require("@formspec/core/internals");
|
|
@@ -980,6 +980,14 @@ function customTypeIdFromLookup(result) {
|
|
|
980
980
|
return `${result.extensionId}/${result.registration.typeName}`;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
// src/analyzer/builtin-brands.ts
|
|
984
|
+
var ts3 = __toESM(require("typescript"), 1);
|
|
985
|
+
function isIntegerBrandedType(type) {
|
|
986
|
+
if (!type.isIntersection()) return false;
|
|
987
|
+
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
988
|
+
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
989
|
+
}
|
|
990
|
+
|
|
983
991
|
// src/analyzer/tsdoc-parser.ts
|
|
984
992
|
function sharedTagValueOptions(options) {
|
|
985
993
|
return {
|
|
@@ -987,7 +995,7 @@ function sharedTagValueOptions(options) {
|
|
|
987
995
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
988
996
|
};
|
|
989
997
|
}
|
|
990
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
998
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts4.TypeFormatFlags.NoTruncation | ts4.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
991
999
|
function getExtensionTypeNames(registry) {
|
|
992
1000
|
if (registry === void 0) {
|
|
993
1001
|
return /* @__PURE__ */ new Set();
|
|
@@ -1001,23 +1009,23 @@ function getExtensionTypeNames(registry) {
|
|
|
1001
1009
|
function collectImportedNames(sourceFile) {
|
|
1002
1010
|
const importedNames = /* @__PURE__ */ new Set();
|
|
1003
1011
|
for (const statement of sourceFile.statements) {
|
|
1004
|
-
if (
|
|
1012
|
+
if (ts4.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
1005
1013
|
const clause = statement.importClause;
|
|
1006
1014
|
if (clause.name !== void 0) {
|
|
1007
1015
|
importedNames.add(clause.name.text);
|
|
1008
1016
|
}
|
|
1009
1017
|
if (clause.namedBindings !== void 0) {
|
|
1010
|
-
if (
|
|
1018
|
+
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
1011
1019
|
for (const specifier of clause.namedBindings.elements) {
|
|
1012
1020
|
importedNames.add(specifier.name.text);
|
|
1013
1021
|
}
|
|
1014
|
-
} else if (
|
|
1022
|
+
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
1015
1023
|
importedNames.add(clause.namedBindings.name.text);
|
|
1016
1024
|
}
|
|
1017
1025
|
}
|
|
1018
1026
|
continue;
|
|
1019
1027
|
}
|
|
1020
|
-
if (
|
|
1028
|
+
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
1021
1029
|
importedNames.add(statement.name.text);
|
|
1022
1030
|
}
|
|
1023
1031
|
}
|
|
@@ -1025,13 +1033,13 @@ function collectImportedNames(sourceFile) {
|
|
|
1025
1033
|
}
|
|
1026
1034
|
function isNonReferenceIdentifier(node) {
|
|
1027
1035
|
const parent = node.parent;
|
|
1028
|
-
if ((
|
|
1036
|
+
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) {
|
|
1029
1037
|
return true;
|
|
1030
1038
|
}
|
|
1031
|
-
if ((
|
|
1039
|
+
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
1032
1040
|
return true;
|
|
1033
1041
|
}
|
|
1034
|
-
if (
|
|
1042
|
+
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
1035
1043
|
return true;
|
|
1036
1044
|
}
|
|
1037
1045
|
return false;
|
|
@@ -1045,11 +1053,11 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
1045
1053
|
if (referencesImportedName) {
|
|
1046
1054
|
return;
|
|
1047
1055
|
}
|
|
1048
|
-
if (
|
|
1056
|
+
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
1049
1057
|
referencesImportedName = true;
|
|
1050
1058
|
return;
|
|
1051
1059
|
}
|
|
1052
|
-
|
|
1060
|
+
ts4.forEachChild(node, visit);
|
|
1053
1061
|
};
|
|
1054
1062
|
visit(statement);
|
|
1055
1063
|
return referencesImportedName;
|
|
@@ -1060,9 +1068,9 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
1060
1068
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
1061
1069
|
);
|
|
1062
1070
|
return sourceFile.statements.filter((statement) => {
|
|
1063
|
-
if (
|
|
1064
|
-
if (
|
|
1065
|
-
if (
|
|
1071
|
+
if (ts4.isImportDeclaration(statement)) return false;
|
|
1072
|
+
if (ts4.isImportEqualsDeclaration(statement)) return false;
|
|
1073
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
1066
1074
|
return false;
|
|
1067
1075
|
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
1068
1076
|
return false;
|
|
@@ -1160,7 +1168,7 @@ function stripHintNullishUnion(type) {
|
|
|
1160
1168
|
return type;
|
|
1161
1169
|
}
|
|
1162
1170
|
const nonNullish = type.types.filter(
|
|
1163
|
-
(member) => (member.flags & (
|
|
1171
|
+
(member) => (member.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) === 0
|
|
1164
1172
|
);
|
|
1165
1173
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
1166
1174
|
return nonNullish[0];
|
|
@@ -1176,10 +1184,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
1176
1184
|
}
|
|
1177
1185
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
1178
1186
|
const name = declaration.name;
|
|
1179
|
-
if (
|
|
1187
|
+
if (ts4.isComputedPropertyName(name) || ts4.isPrivateIdentifier(name)) {
|
|
1180
1188
|
return false;
|
|
1181
1189
|
}
|
|
1182
|
-
if (!
|
|
1190
|
+
if (!ts4.isIdentifier(name) && !ts4.isStringLiteral(name) && !ts4.isNumericLiteral(name)) {
|
|
1183
1191
|
return false;
|
|
1184
1192
|
}
|
|
1185
1193
|
}
|
|
@@ -1397,6 +1405,9 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1397
1405
|
}
|
|
1398
1406
|
const hasBroadening = (() => {
|
|
1399
1407
|
if (target === null) {
|
|
1408
|
+
if (isIntegerBrandedType((0, import_internal2.stripNullishUnion)(subjectType)) && definition.capabilities.includes("numeric-comparable")) {
|
|
1409
|
+
return true;
|
|
1410
|
+
}
|
|
1400
1411
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
1401
1412
|
}
|
|
1402
1413
|
const registry = options?.extensionRegistry;
|
|
@@ -1549,12 +1560,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1549
1560
|
const sourceText = sourceFile.getFullText();
|
|
1550
1561
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
1551
1562
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
1552
|
-
const commentRanges =
|
|
1563
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1553
1564
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
1554
1565
|
const extensionTagNames = getExtensionTagNames(options);
|
|
1555
1566
|
if (commentRanges) {
|
|
1556
1567
|
for (const range of commentRanges) {
|
|
1557
|
-
if (range.kind !==
|
|
1568
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) {
|
|
1558
1569
|
continue;
|
|
1559
1570
|
}
|
|
1560
1571
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -1711,10 +1722,10 @@ function extractDisplayNameMetadata(node) {
|
|
|
1711
1722
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
1712
1723
|
const sourceFile = node.getSourceFile();
|
|
1713
1724
|
const sourceText = sourceFile.getFullText();
|
|
1714
|
-
const commentRanges =
|
|
1725
|
+
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1715
1726
|
if (commentRanges) {
|
|
1716
1727
|
for (const range of commentRanges) {
|
|
1717
|
-
if (range.kind !==
|
|
1728
|
+
if (range.kind !== ts4.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
1718
1729
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
1719
1730
|
if (!commentText.startsWith("/**")) continue;
|
|
1720
1731
|
const unified = (0, import_internal2.parseUnifiedComment)(commentText);
|
|
@@ -1739,7 +1750,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
1739
1750
|
}
|
|
1740
1751
|
function collectRawTextFallbacks(node, file) {
|
|
1741
1752
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
1742
|
-
for (const tag of
|
|
1753
|
+
for (const tag of ts4.getJSDocTags(node)) {
|
|
1743
1754
|
const tagName = (0, import_internals3.normalizeConstraintTagName)(tag.tagName.text);
|
|
1744
1755
|
if (!import_internal2.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
1745
1756
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
@@ -1794,7 +1805,7 @@ function getTagCommentText(tag) {
|
|
|
1794
1805
|
if (typeof tag.comment === "string") {
|
|
1795
1806
|
return tag.comment;
|
|
1796
1807
|
}
|
|
1797
|
-
return
|
|
1808
|
+
return ts4.getTextOfJSDocComment(tag.comment);
|
|
1798
1809
|
}
|
|
1799
1810
|
|
|
1800
1811
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -1812,18 +1823,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
1812
1823
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
1813
1824
|
if (!initializer) return null;
|
|
1814
1825
|
let value;
|
|
1815
|
-
if (
|
|
1826
|
+
if (ts5.isStringLiteral(initializer)) {
|
|
1816
1827
|
value = initializer.text;
|
|
1817
|
-
} else if (
|
|
1828
|
+
} else if (ts5.isNumericLiteral(initializer)) {
|
|
1818
1829
|
value = Number(initializer.text);
|
|
1819
|
-
} else if (initializer.kind ===
|
|
1830
|
+
} else if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
|
|
1820
1831
|
value = true;
|
|
1821
|
-
} else if (initializer.kind ===
|
|
1832
|
+
} else if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
|
|
1822
1833
|
value = false;
|
|
1823
|
-
} else if (initializer.kind ===
|
|
1834
|
+
} else if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
|
|
1824
1835
|
value = null;
|
|
1825
|
-
} else if (
|
|
1826
|
-
if (initializer.operator ===
|
|
1836
|
+
} else if (ts5.isPrefixUnaryExpression(initializer)) {
|
|
1837
|
+
if (initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
|
|
1827
1838
|
value = -Number(initializer.operand.text);
|
|
1828
1839
|
}
|
|
1829
1840
|
}
|
|
@@ -1845,38 +1856,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
1845
1856
|
|
|
1846
1857
|
// src/analyzer/class-analyzer.ts
|
|
1847
1858
|
function isObjectType(type) {
|
|
1848
|
-
return !!(type.flags &
|
|
1859
|
+
return !!(type.flags & ts6.TypeFlags.Object);
|
|
1849
1860
|
}
|
|
1850
1861
|
function isIntersectionType(type) {
|
|
1851
|
-
return !!(type.flags &
|
|
1852
|
-
}
|
|
1853
|
-
function isIntegerBrandedType(type) {
|
|
1854
|
-
if (!type.isIntersection()) {
|
|
1855
|
-
return false;
|
|
1856
|
-
}
|
|
1857
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
1858
|
-
if (!hasNumberBase) {
|
|
1859
|
-
return false;
|
|
1860
|
-
}
|
|
1861
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
1862
|
+
return !!(type.flags & ts6.TypeFlags.Intersection);
|
|
1862
1863
|
}
|
|
1863
1864
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
1864
|
-
if (
|
|
1865
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
1865
1866
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
1866
1867
|
}
|
|
1867
|
-
if (
|
|
1868
|
+
if (ts6.isTypeLiteralNode(typeNode) || ts6.isTypeReferenceNode(typeNode)) {
|
|
1868
1869
|
return true;
|
|
1869
1870
|
}
|
|
1870
|
-
return
|
|
1871
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
1871
1872
|
}
|
|
1872
1873
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
1873
1874
|
if (isIntersectionType(type)) {
|
|
1874
1875
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
1875
1876
|
}
|
|
1876
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
1877
|
+
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);
|
|
1877
1878
|
}
|
|
1878
1879
|
function isTypeReference(type) {
|
|
1879
|
-
return !!(type.flags &
|
|
1880
|
+
return !!(type.flags & ts6.TypeFlags.Object) && !!(type.objectFlags & ts6.ObjectFlags.Reference);
|
|
1880
1881
|
}
|
|
1881
1882
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
1882
1883
|
kind: "object",
|
|
@@ -1941,7 +1942,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
1941
1942
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
1942
1943
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
1943
1944
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
1944
|
-
const logicalName =
|
|
1945
|
+
const logicalName = ts6.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
1945
1946
|
const docResult = extractJSDocParseResult(
|
|
1946
1947
|
declaration,
|
|
1947
1948
|
file,
|
|
@@ -1989,7 +1990,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
1989
1990
|
const instanceMethods = [];
|
|
1990
1991
|
const staticMethods = [];
|
|
1991
1992
|
for (const member of classDecl.members) {
|
|
1992
|
-
if (
|
|
1993
|
+
if (ts6.isPropertyDeclaration(member)) {
|
|
1993
1994
|
const fieldNode = analyzeFieldToIR(
|
|
1994
1995
|
member,
|
|
1995
1996
|
checker,
|
|
@@ -2005,10 +2006,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
2005
2006
|
fields.push(fieldNode);
|
|
2006
2007
|
fieldLayouts.push({});
|
|
2007
2008
|
}
|
|
2008
|
-
} else if (
|
|
2009
|
+
} else if (ts6.isMethodDeclaration(member)) {
|
|
2009
2010
|
const methodInfo = analyzeMethod(member, checker);
|
|
2010
2011
|
if (methodInfo) {
|
|
2011
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
2012
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts6.SyntaxKind.StaticKeyword);
|
|
2012
2013
|
if (isStatic) {
|
|
2013
2014
|
staticMethods.push(methodInfo);
|
|
2014
2015
|
} else {
|
|
@@ -2071,7 +2072,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
2071
2072
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
2072
2073
|
const visiting = /* @__PURE__ */ new Set();
|
|
2073
2074
|
for (const member of interfaceDecl.members) {
|
|
2074
|
-
if (
|
|
2075
|
+
if (ts6.isPropertySignature(member)) {
|
|
2075
2076
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2076
2077
|
member,
|
|
2077
2078
|
checker,
|
|
@@ -2129,7 +2130,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2129
2130
|
if (members === null) {
|
|
2130
2131
|
const sourceFile = typeAlias.getSourceFile();
|
|
2131
2132
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
2132
|
-
const kindDesc =
|
|
2133
|
+
const kindDesc = ts6.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
2133
2134
|
return {
|
|
2134
2135
|
ok: false,
|
|
2135
2136
|
kind: "not-object-like",
|
|
@@ -2164,7 +2165,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2164
2165
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
2165
2166
|
const visiting = /* @__PURE__ */ new Set();
|
|
2166
2167
|
for (const member of members) {
|
|
2167
|
-
if (
|
|
2168
|
+
if (ts6.isPropertySignature(member)) {
|
|
2168
2169
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2169
2170
|
member,
|
|
2170
2171
|
checker,
|
|
@@ -2231,13 +2232,13 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
2231
2232
|
function getLeadingParsedTags(node) {
|
|
2232
2233
|
const sourceFile = node.getSourceFile();
|
|
2233
2234
|
const sourceText = sourceFile.getFullText();
|
|
2234
|
-
const commentRanges =
|
|
2235
|
+
const commentRanges = ts6.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2235
2236
|
if (commentRanges === void 0) {
|
|
2236
2237
|
return [];
|
|
2237
2238
|
}
|
|
2238
2239
|
const parsedTags = [];
|
|
2239
2240
|
for (const range of commentRanges) {
|
|
2240
|
-
if (range.kind !==
|
|
2241
|
+
if (range.kind !== ts6.SyntaxKind.MultiLineCommentTrivia) {
|
|
2241
2242
|
continue;
|
|
2242
2243
|
}
|
|
2243
2244
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
@@ -2255,19 +2256,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
2255
2256
|
return null;
|
|
2256
2257
|
}
|
|
2257
2258
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
2258
|
-
(candidate) =>
|
|
2259
|
+
(candidate) => ts6.isPropertyDeclaration(candidate) || ts6.isPropertySignature(candidate)
|
|
2259
2260
|
) ?? propertySymbol.declarations?.[0];
|
|
2260
2261
|
return {
|
|
2261
2262
|
declaration,
|
|
2262
2263
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
2263
|
-
optional: !!(propertySymbol.flags &
|
|
2264
|
+
optional: !!(propertySymbol.flags & ts6.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
2264
2265
|
};
|
|
2265
2266
|
}
|
|
2266
2267
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
2267
2268
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
2268
2269
|
}
|
|
2269
2270
|
function isNullishSemanticType(type) {
|
|
2270
|
-
if (type.flags & (
|
|
2271
|
+
if (type.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined | ts6.TypeFlags.Void | ts6.TypeFlags.Unknown | ts6.TypeFlags.Any)) {
|
|
2271
2272
|
return true;
|
|
2272
2273
|
}
|
|
2273
2274
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -2277,7 +2278,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2277
2278
|
return false;
|
|
2278
2279
|
}
|
|
2279
2280
|
seen.add(type);
|
|
2280
|
-
if (type.flags &
|
|
2281
|
+
if (type.flags & ts6.TypeFlags.StringLike) {
|
|
2281
2282
|
return true;
|
|
2282
2283
|
}
|
|
2283
2284
|
if (type.isUnion()) {
|
|
@@ -2290,13 +2291,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2290
2291
|
return false;
|
|
2291
2292
|
}
|
|
2292
2293
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
2293
|
-
if (
|
|
2294
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
2294
2295
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
2295
2296
|
}
|
|
2296
|
-
if (
|
|
2297
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
2297
2298
|
return [...typeNode.members];
|
|
2298
2299
|
}
|
|
2299
|
-
if (
|
|
2300
|
+
if (ts6.isIntersectionTypeNode(typeNode)) {
|
|
2300
2301
|
const members = [];
|
|
2301
2302
|
for (const intersectionMember of typeNode.types) {
|
|
2302
2303
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -2459,7 +2460,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
2459
2460
|
}
|
|
2460
2461
|
if (propertyType.isUnion()) {
|
|
2461
2462
|
const nonNullMembers = propertyType.types.filter(
|
|
2462
|
-
(member) => !(member.flags & (
|
|
2463
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
2463
2464
|
);
|
|
2464
2465
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2465
2466
|
diagnostics.push(
|
|
@@ -2508,13 +2509,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
2508
2509
|
seen.add(type);
|
|
2509
2510
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
2510
2511
|
if (symbol !== void 0) {
|
|
2511
|
-
const aliased = symbol.flags &
|
|
2512
|
+
const aliased = symbol.flags & ts6.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
2512
2513
|
const targetSymbol = aliased ?? symbol;
|
|
2513
2514
|
const declaration = targetSymbol.declarations?.find(
|
|
2514
|
-
(candidate) =>
|
|
2515
|
+
(candidate) => ts6.isClassDeclaration(candidate) || ts6.isInterfaceDeclaration(candidate) || ts6.isTypeAliasDeclaration(candidate) || ts6.isEnumDeclaration(candidate)
|
|
2515
2516
|
);
|
|
2516
2517
|
if (declaration !== void 0) {
|
|
2517
|
-
if (
|
|
2518
|
+
if (ts6.isTypeAliasDeclaration(declaration) && ts6.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
2518
2519
|
return resolveNamedDiscriminatorDeclaration(
|
|
2519
2520
|
checker.getTypeFromTypeNode(declaration.type),
|
|
2520
2521
|
checker,
|
|
@@ -2542,7 +2543,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2542
2543
|
}
|
|
2543
2544
|
if (boundType.isUnion()) {
|
|
2544
2545
|
const nonNullMembers = boundType.types.filter(
|
|
2545
|
-
(member) => !(member.flags & (
|
|
2546
|
+
(member) => !(member.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
2546
2547
|
);
|
|
2547
2548
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2548
2549
|
diagnostics.push(
|
|
@@ -2587,7 +2588,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2587
2588
|
return null;
|
|
2588
2589
|
}
|
|
2589
2590
|
function getDeclarationName(node) {
|
|
2590
|
-
if (
|
|
2591
|
+
if (ts6.isClassDeclaration(node) || ts6.isInterfaceDeclaration(node) || ts6.isTypeAliasDeclaration(node) || ts6.isEnumDeclaration(node)) {
|
|
2591
2592
|
return node.name?.text ?? "anonymous";
|
|
2592
2593
|
}
|
|
2593
2594
|
return "anonymous";
|
|
@@ -2642,11 +2643,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
2642
2643
|
if (sourceTypeNode === void 0) {
|
|
2643
2644
|
return [];
|
|
2644
2645
|
}
|
|
2645
|
-
const unwrapParentheses = (typeNode) =>
|
|
2646
|
+
const unwrapParentheses = (typeNode) => ts6.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
2646
2647
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
2647
|
-
const referenceTypeNode =
|
|
2648
|
+
const referenceTypeNode = ts6.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
2648
2649
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
2649
|
-
return
|
|
2650
|
+
return ts6.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
2650
2651
|
})();
|
|
2651
2652
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
2652
2653
|
return [];
|
|
@@ -2701,7 +2702,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
2701
2702
|
);
|
|
2702
2703
|
}
|
|
2703
2704
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
2704
|
-
if (!
|
|
2705
|
+
if (!ts6.isIdentifier(prop.name)) {
|
|
2705
2706
|
return null;
|
|
2706
2707
|
}
|
|
2707
2708
|
const name = prop.name.text;
|
|
@@ -2828,7 +2829,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2828
2829
|
const seen = /* @__PURE__ */ new Set();
|
|
2829
2830
|
const duplicates = /* @__PURE__ */ new Set();
|
|
2830
2831
|
for (const member of members) {
|
|
2831
|
-
if (!
|
|
2832
|
+
if (!ts6.isPropertySignature(member)) {
|
|
2832
2833
|
continue;
|
|
2833
2834
|
}
|
|
2834
2835
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -2844,7 +2845,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2844
2845
|
return [...duplicates].sort();
|
|
2845
2846
|
}
|
|
2846
2847
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
2847
|
-
if (
|
|
2848
|
+
if (ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNumericLiteral(name)) {
|
|
2848
2849
|
return name.text;
|
|
2849
2850
|
}
|
|
2850
2851
|
return null;
|
|
@@ -2942,25 +2943,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
2942
2943
|
if (isIntegerBrandedType(type)) {
|
|
2943
2944
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
2944
2945
|
}
|
|
2945
|
-
if (type.flags &
|
|
2946
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
2946
2947
|
return { kind: "primitive", primitiveKind: "string" };
|
|
2947
2948
|
}
|
|
2948
|
-
if (type.flags &
|
|
2949
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
2949
2950
|
return { kind: "primitive", primitiveKind: "number" };
|
|
2950
2951
|
}
|
|
2951
|
-
if (type.flags & (
|
|
2952
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
2952
2953
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
2953
2954
|
}
|
|
2954
|
-
if (type.flags &
|
|
2955
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
2955
2956
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
2956
2957
|
}
|
|
2957
|
-
if (type.flags &
|
|
2958
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
2958
2959
|
return { kind: "primitive", primitiveKind: "null" };
|
|
2959
2960
|
}
|
|
2960
|
-
if (type.flags &
|
|
2961
|
+
if (type.flags & ts6.TypeFlags.Undefined) {
|
|
2961
2962
|
return { kind: "primitive", primitiveKind: "null" };
|
|
2962
2963
|
}
|
|
2963
|
-
if (type.flags &
|
|
2964
|
+
if (type.flags & ts6.TypeFlags.Void) {
|
|
2964
2965
|
return { kind: "primitive", primitiveKind: "null" };
|
|
2965
2966
|
}
|
|
2966
2967
|
if (type.isStringLiteral()) {
|
|
@@ -3047,10 +3048,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
3047
3048
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3048
3049
|
}
|
|
3049
3050
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
3050
|
-
if (!(type.flags & (
|
|
3051
|
+
if (!(type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
3051
3052
|
return null;
|
|
3052
3053
|
}
|
|
3053
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3054
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
3054
3055
|
if (!aliasDecl) {
|
|
3055
3056
|
return null;
|
|
3056
3057
|
}
|
|
@@ -3100,14 +3101,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
3100
3101
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
3101
3102
|
}
|
|
3102
3103
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
3103
|
-
const typeNode = sourceNode && (
|
|
3104
|
-
if (!typeNode || !
|
|
3104
|
+
const typeNode = sourceNode && (ts6.isPropertyDeclaration(sourceNode) || ts6.isPropertySignature(sourceNode) || ts6.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
3105
|
+
if (!typeNode || !ts6.isTypeReferenceNode(typeNode)) {
|
|
3105
3106
|
return void 0;
|
|
3106
3107
|
}
|
|
3107
3108
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
3108
3109
|
}
|
|
3109
3110
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
3110
|
-
if (!
|
|
3111
|
+
if (!ts6.isTypeReferenceNode(typeNode)) {
|
|
3111
3112
|
return false;
|
|
3112
3113
|
}
|
|
3113
3114
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3115,10 +3116,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
3115
3116
|
return false;
|
|
3116
3117
|
}
|
|
3117
3118
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
3118
|
-
return !!(resolved.flags & (
|
|
3119
|
+
return !!(resolved.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral | ts6.TypeFlags.Boolean | ts6.TypeFlags.Null));
|
|
3119
3120
|
}
|
|
3120
3121
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
3121
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3122
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts6.isTypeAliasDeclaration);
|
|
3122
3123
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
3123
3124
|
visitedAliases.add(nestedAliasDecl);
|
|
3124
3125
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -3136,19 +3137,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
3136
3137
|
if (isIntegerBrandedType(type)) {
|
|
3137
3138
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
3138
3139
|
}
|
|
3139
|
-
if (type.flags &
|
|
3140
|
+
if (type.flags & ts6.TypeFlags.String) {
|
|
3140
3141
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3141
3142
|
}
|
|
3142
|
-
if (type.flags &
|
|
3143
|
+
if (type.flags & ts6.TypeFlags.Number) {
|
|
3143
3144
|
return { kind: "primitive", primitiveKind: "number" };
|
|
3144
3145
|
}
|
|
3145
|
-
if (type.flags & (
|
|
3146
|
+
if (type.flags & (ts6.TypeFlags.BigInt | ts6.TypeFlags.BigIntLiteral)) {
|
|
3146
3147
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
3147
3148
|
}
|
|
3148
|
-
if (type.flags &
|
|
3149
|
+
if (type.flags & ts6.TypeFlags.Boolean) {
|
|
3149
3150
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
3150
3151
|
}
|
|
3151
|
-
if (type.flags &
|
|
3152
|
+
if (type.flags & ts6.TypeFlags.Null) {
|
|
3152
3153
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3153
3154
|
}
|
|
3154
3155
|
return resolveTypeNode(
|
|
@@ -3175,13 +3176,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3175
3176
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
3176
3177
|
);
|
|
3177
3178
|
const nonNullTypes = allTypes.filter(
|
|
3178
|
-
(memberType) => !(memberType.flags & (
|
|
3179
|
+
(memberType) => !(memberType.flags & (ts6.TypeFlags.Null | ts6.TypeFlags.Undefined))
|
|
3179
3180
|
);
|
|
3180
3181
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
3181
3182
|
memberType,
|
|
3182
3183
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
3183
3184
|
}));
|
|
3184
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
3185
|
+
const hasNull = allTypes.some((t) => t.flags & ts6.TypeFlags.Null);
|
|
3185
3186
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3186
3187
|
if (namedDecl) {
|
|
3187
3188
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -3224,7 +3225,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3224
3225
|
const displayName = memberDisplayNames.get(String(value));
|
|
3225
3226
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
3226
3227
|
});
|
|
3227
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
3228
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts6.TypeFlags.BooleanLiteral);
|
|
3228
3229
|
if (isBooleanUnion2) {
|
|
3229
3230
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
3230
3231
|
const result = hasNull ? {
|
|
@@ -3316,7 +3317,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
3316
3317
|
if (type.getProperties().length > 0) {
|
|
3317
3318
|
return null;
|
|
3318
3319
|
}
|
|
3319
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
3320
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts6.IndexKind.String);
|
|
3320
3321
|
if (!indexInfo) {
|
|
3321
3322
|
return null;
|
|
3322
3323
|
}
|
|
@@ -3364,10 +3365,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
3364
3365
|
}
|
|
3365
3366
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
3366
3367
|
const name = declaration.name;
|
|
3367
|
-
if (
|
|
3368
|
+
if (ts6.isComputedPropertyName(name) || ts6.isPrivateIdentifier(name)) {
|
|
3368
3369
|
return false;
|
|
3369
3370
|
}
|
|
3370
|
-
if (!
|
|
3371
|
+
if (!ts6.isIdentifier(name) && !ts6.isStringLiteral(name) && !ts6.isNumericLiteral(name)) {
|
|
3371
3372
|
return false;
|
|
3372
3373
|
}
|
|
3373
3374
|
}
|
|
@@ -3493,7 +3494,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3493
3494
|
if (!declaration) continue;
|
|
3494
3495
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
3495
3496
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
3496
|
-
const optional = !!(prop.flags &
|
|
3497
|
+
const optional = !!(prop.flags & ts6.SymbolFlags.Optional);
|
|
3497
3498
|
const propTypeNode = resolveTypeNode(
|
|
3498
3499
|
propType,
|
|
3499
3500
|
checker,
|
|
@@ -3506,7 +3507,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3506
3507
|
collectedDiagnostics
|
|
3507
3508
|
);
|
|
3508
3509
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
3509
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
3510
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts6.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
3510
3511
|
declaration,
|
|
3511
3512
|
checker,
|
|
3512
3513
|
file,
|
|
@@ -3516,7 +3517,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3516
3517
|
type,
|
|
3517
3518
|
metadataPolicy,
|
|
3518
3519
|
extensionRegistry
|
|
3519
|
-
) :
|
|
3520
|
+
) : ts6.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
3520
3521
|
declaration,
|
|
3521
3522
|
checker,
|
|
3522
3523
|
file,
|
|
@@ -3544,7 +3545,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3544
3545
|
visiting.delete(type);
|
|
3545
3546
|
const objectNode = {
|
|
3546
3547
|
kind: "object",
|
|
3547
|
-
properties: namedDecl !== void 0 && (
|
|
3548
|
+
properties: namedDecl !== void 0 && (ts6.isClassDeclaration(namedDecl) || ts6.isInterfaceDeclaration(namedDecl) || ts6.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
3548
3549
|
properties,
|
|
3549
3550
|
namedDecl,
|
|
3550
3551
|
type,
|
|
@@ -3592,12 +3593,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3592
3593
|
for (const symbol of symbols) {
|
|
3593
3594
|
const declarations = symbol.declarations;
|
|
3594
3595
|
if (!declarations) continue;
|
|
3595
|
-
const classDecl = declarations.find(
|
|
3596
|
+
const classDecl = declarations.find(ts6.isClassDeclaration);
|
|
3596
3597
|
if (classDecl) {
|
|
3597
3598
|
const map = /* @__PURE__ */ new Map();
|
|
3598
3599
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
3599
3600
|
for (const member of classDecl.members) {
|
|
3600
|
-
if (
|
|
3601
|
+
if (ts6.isPropertyDeclaration(member) && ts6.isIdentifier(member.name)) {
|
|
3601
3602
|
const fieldNode = analyzeFieldToIR(
|
|
3602
3603
|
member,
|
|
3603
3604
|
checker,
|
|
@@ -3621,7 +3622,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3621
3622
|
}
|
|
3622
3623
|
return map;
|
|
3623
3624
|
}
|
|
3624
|
-
const interfaceDecl = declarations.find(
|
|
3625
|
+
const interfaceDecl = declarations.find(ts6.isInterfaceDeclaration);
|
|
3625
3626
|
if (interfaceDecl) {
|
|
3626
3627
|
return buildFieldNodeInfoMap(
|
|
3627
3628
|
interfaceDecl.members,
|
|
@@ -3635,7 +3636,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3635
3636
|
extensionRegistry
|
|
3636
3637
|
);
|
|
3637
3638
|
}
|
|
3638
|
-
const typeAliasDecl = declarations.find(
|
|
3639
|
+
const typeAliasDecl = declarations.find(ts6.isTypeAliasDeclaration);
|
|
3639
3640
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
3640
3641
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
3641
3642
|
return buildFieldNodeInfoMap(
|
|
@@ -3659,10 +3660,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
3659
3660
|
return void 0;
|
|
3660
3661
|
}
|
|
3661
3662
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3662
|
-
if (
|
|
3663
|
+
if (ts6.isArrayTypeNode(resolvedTypeNode)) {
|
|
3663
3664
|
return resolvedTypeNode.elementType;
|
|
3664
3665
|
}
|
|
3665
|
-
if (
|
|
3666
|
+
if (ts6.isTypeReferenceNode(resolvedTypeNode) && ts6.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
3666
3667
|
return resolvedTypeNode.typeArguments[0];
|
|
3667
3668
|
}
|
|
3668
3669
|
return void 0;
|
|
@@ -3673,13 +3674,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
3673
3674
|
return [];
|
|
3674
3675
|
}
|
|
3675
3676
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3676
|
-
return
|
|
3677
|
+
return ts6.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
3677
3678
|
}
|
|
3678
3679
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
3679
|
-
if (
|
|
3680
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3680
3681
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
3681
3682
|
}
|
|
3682
|
-
if (!
|
|
3683
|
+
if (!ts6.isTypeReferenceNode(typeNode) || !ts6.isIdentifier(typeNode.typeName)) {
|
|
3683
3684
|
return typeNode;
|
|
3684
3685
|
}
|
|
3685
3686
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3690,15 +3691,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
3690
3691
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
3691
3692
|
}
|
|
3692
3693
|
function isNullishTypeNode(typeNode) {
|
|
3693
|
-
if (typeNode.kind ===
|
|
3694
|
+
if (typeNode.kind === ts6.SyntaxKind.NullKeyword || typeNode.kind === ts6.SyntaxKind.UndefinedKeyword) {
|
|
3694
3695
|
return true;
|
|
3695
3696
|
}
|
|
3696
|
-
return
|
|
3697
|
+
return ts6.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts6.SyntaxKind.NullKeyword || typeNode.literal.kind === ts6.SyntaxKind.UndefinedKeyword);
|
|
3697
3698
|
}
|
|
3698
3699
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
3699
3700
|
const map = /* @__PURE__ */ new Map();
|
|
3700
3701
|
for (const member of members) {
|
|
3701
|
-
if (
|
|
3702
|
+
if (ts6.isPropertySignature(member)) {
|
|
3702
3703
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3703
3704
|
member,
|
|
3704
3705
|
checker,
|
|
@@ -3724,7 +3725,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
3724
3725
|
}
|
|
3725
3726
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
3726
3727
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
3727
|
-
if (!
|
|
3728
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return [];
|
|
3728
3729
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
3729
3730
|
const aliasName = typeNode.typeName.getText();
|
|
3730
3731
|
throw new Error(
|
|
@@ -3733,7 +3734,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
3733
3734
|
}
|
|
3734
3735
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
3735
3736
|
if (!aliasDecl) return [];
|
|
3736
|
-
if (
|
|
3737
|
+
if (ts6.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
3737
3738
|
const aliasFieldType = resolveTypeNode(
|
|
3738
3739
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
3739
3740
|
checker,
|
|
@@ -3777,14 +3778,14 @@ function getNamedTypeName(type) {
|
|
|
3777
3778
|
const symbol = type.getSymbol();
|
|
3778
3779
|
if (symbol?.declarations) {
|
|
3779
3780
|
const decl = symbol.declarations[0];
|
|
3780
|
-
if (decl && (
|
|
3781
|
-
const name =
|
|
3781
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
3782
|
+
const name = ts6.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
3782
3783
|
if (name) return name;
|
|
3783
3784
|
}
|
|
3784
3785
|
}
|
|
3785
3786
|
const aliasSymbol = type.aliasSymbol;
|
|
3786
3787
|
if (aliasSymbol?.declarations) {
|
|
3787
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
3788
|
+
const aliasDecl = aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
3788
3789
|
if (aliasDecl) {
|
|
3789
3790
|
return aliasDecl.name.text;
|
|
3790
3791
|
}
|
|
@@ -3795,24 +3796,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
3795
3796
|
const symbol = type.getSymbol();
|
|
3796
3797
|
if (symbol?.declarations) {
|
|
3797
3798
|
const decl = symbol.declarations[0];
|
|
3798
|
-
if (decl && (
|
|
3799
|
+
if (decl && (ts6.isClassDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isTypeAliasDeclaration(decl))) {
|
|
3799
3800
|
return decl;
|
|
3800
3801
|
}
|
|
3801
3802
|
}
|
|
3802
3803
|
const aliasSymbol = type.aliasSymbol;
|
|
3803
3804
|
if (aliasSymbol?.declarations) {
|
|
3804
|
-
return aliasSymbol.declarations.find(
|
|
3805
|
+
return aliasSymbol.declarations.find(ts6.isTypeAliasDeclaration);
|
|
3805
3806
|
}
|
|
3806
3807
|
return void 0;
|
|
3807
3808
|
}
|
|
3808
3809
|
function analyzeMethod(method, checker) {
|
|
3809
|
-
if (!
|
|
3810
|
+
if (!ts6.isIdentifier(method.name)) {
|
|
3810
3811
|
return null;
|
|
3811
3812
|
}
|
|
3812
3813
|
const name = method.name.text;
|
|
3813
3814
|
const parameters = [];
|
|
3814
3815
|
for (const param of method.parameters) {
|
|
3815
|
-
if (
|
|
3816
|
+
if (ts6.isIdentifier(param.name)) {
|
|
3816
3817
|
const paramInfo = analyzeParameter(param, checker);
|
|
3817
3818
|
parameters.push(paramInfo);
|
|
3818
3819
|
}
|
|
@@ -3823,7 +3824,7 @@ function analyzeMethod(method, checker) {
|
|
|
3823
3824
|
return { name, parameters, returnTypeNode, returnType };
|
|
3824
3825
|
}
|
|
3825
3826
|
function analyzeParameter(param, checker) {
|
|
3826
|
-
const name =
|
|
3827
|
+
const name = ts6.isIdentifier(param.name) ? param.name.text : "param";
|
|
3827
3828
|
const typeNode = param.type;
|
|
3828
3829
|
const type = checker.getTypeAtLocation(param);
|
|
3829
3830
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -3832,15 +3833,15 @@ function analyzeParameter(param, checker) {
|
|
|
3832
3833
|
}
|
|
3833
3834
|
function detectFormSpecReference(typeNode) {
|
|
3834
3835
|
if (!typeNode) return null;
|
|
3835
|
-
if (!
|
|
3836
|
-
const typeName =
|
|
3836
|
+
if (!ts6.isTypeReferenceNode(typeNode)) return null;
|
|
3837
|
+
const typeName = ts6.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts6.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
3837
3838
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
3838
3839
|
const typeArg = typeNode.typeArguments?.[0];
|
|
3839
|
-
if (!typeArg || !
|
|
3840
|
-
if (
|
|
3840
|
+
if (!typeArg || !ts6.isTypeQueryNode(typeArg)) return null;
|
|
3841
|
+
if (ts6.isIdentifier(typeArg.exprName)) {
|
|
3841
3842
|
return typeArg.exprName.text;
|
|
3842
3843
|
}
|
|
3843
|
-
if (
|
|
3844
|
+
if (ts6.isQualifiedName(typeArg.exprName)) {
|
|
3844
3845
|
return typeArg.exprName.right.text;
|
|
3845
3846
|
}
|
|
3846
3847
|
return null;
|
|
@@ -3862,23 +3863,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
3862
3863
|
function createProgramContext(filePath, additionalFiles) {
|
|
3863
3864
|
const absolutePath = path.resolve(filePath);
|
|
3864
3865
|
const fileDir = path.dirname(absolutePath);
|
|
3865
|
-
const configPath =
|
|
3866
|
+
const configPath = ts7.findConfigFile(fileDir, ts7.sys.fileExists.bind(ts7.sys), "tsconfig.json");
|
|
3866
3867
|
let compilerOptions;
|
|
3867
3868
|
let fileNames;
|
|
3868
3869
|
if (configPath) {
|
|
3869
|
-
const configFile =
|
|
3870
|
+
const configFile = ts7.readConfigFile(configPath, ts7.sys.readFile.bind(ts7.sys));
|
|
3870
3871
|
if (configFile.error) {
|
|
3871
3872
|
throw new Error(
|
|
3872
|
-
`Error reading tsconfig.json: ${
|
|
3873
|
+
`Error reading tsconfig.json: ${ts7.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
3873
3874
|
);
|
|
3874
3875
|
}
|
|
3875
|
-
const parsed =
|
|
3876
|
+
const parsed = ts7.parseJsonConfigFileContent(
|
|
3876
3877
|
configFile.config,
|
|
3877
|
-
|
|
3878
|
+
ts7.sys,
|
|
3878
3879
|
path.dirname(configPath)
|
|
3879
3880
|
);
|
|
3880
3881
|
if (parsed.errors.length > 0) {
|
|
3881
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
3882
|
+
const errorMessages = parsed.errors.map((e) => ts7.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
3882
3883
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
3883
3884
|
}
|
|
3884
3885
|
compilerOptions = parsed.options;
|
|
@@ -3886,9 +3887,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
3886
3887
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
3887
3888
|
} else {
|
|
3888
3889
|
compilerOptions = {
|
|
3889
|
-
target:
|
|
3890
|
-
module:
|
|
3891
|
-
moduleResolution:
|
|
3890
|
+
target: ts7.ScriptTarget.ES2022,
|
|
3891
|
+
module: ts7.ModuleKind.NodeNext,
|
|
3892
|
+
moduleResolution: ts7.ModuleResolutionKind.NodeNext,
|
|
3892
3893
|
strict: true,
|
|
3893
3894
|
skipLibCheck: true,
|
|
3894
3895
|
declaration: true
|
|
@@ -3896,7 +3897,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
3896
3897
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
3897
3898
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
3898
3899
|
}
|
|
3899
|
-
const program =
|
|
3900
|
+
const program = ts7.createProgram(fileNames, compilerOptions);
|
|
3900
3901
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
3901
3902
|
if (!sourceFile) {
|
|
3902
3903
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -3915,19 +3916,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
3915
3916
|
result = node;
|
|
3916
3917
|
return;
|
|
3917
3918
|
}
|
|
3918
|
-
|
|
3919
|
+
ts7.forEachChild(node, visit);
|
|
3919
3920
|
}
|
|
3920
3921
|
visit(sourceFile);
|
|
3921
3922
|
return result;
|
|
3922
3923
|
}
|
|
3923
3924
|
function findClassByName(sourceFile, className) {
|
|
3924
|
-
return findNodeByName(sourceFile, className,
|
|
3925
|
+
return findNodeByName(sourceFile, className, ts7.isClassDeclaration, (n) => n.name?.text);
|
|
3925
3926
|
}
|
|
3926
3927
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
3927
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
3928
|
+
return findNodeByName(sourceFile, interfaceName, ts7.isInterfaceDeclaration, (n) => n.name.text);
|
|
3928
3929
|
}
|
|
3929
3930
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
3930
|
-
return findNodeByName(sourceFile, aliasName,
|
|
3931
|
+
return findNodeByName(sourceFile, aliasName, ts7.isTypeAliasDeclaration, (n) => n.name.text);
|
|
3931
3932
|
}
|
|
3932
3933
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
3933
3934
|
if (rootType.kind === "object") {
|
|
@@ -3967,22 +3968,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
3967
3968
|
};
|
|
3968
3969
|
}
|
|
3969
3970
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
3970
|
-
if (
|
|
3971
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
3971
3972
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
3972
3973
|
}
|
|
3973
|
-
if (
|
|
3974
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
3974
3975
|
return true;
|
|
3975
3976
|
}
|
|
3976
|
-
return
|
|
3977
|
+
return ts7.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
3977
3978
|
}
|
|
3978
3979
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
3979
|
-
if (
|
|
3980
|
+
if (ts7.isParenthesizedTypeNode(typeNode)) {
|
|
3980
3981
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
3981
3982
|
}
|
|
3982
|
-
if (
|
|
3983
|
+
if (ts7.isTypeLiteralNode(typeNode)) {
|
|
3983
3984
|
const propertyNames = [];
|
|
3984
3985
|
for (const member of typeNode.members) {
|
|
3985
|
-
if (!
|
|
3986
|
+
if (!ts7.isPropertySignature(member)) {
|
|
3986
3987
|
continue;
|
|
3987
3988
|
}
|
|
3988
3989
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -3992,13 +3993,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
3992
3993
|
}
|
|
3993
3994
|
return propertyNames;
|
|
3994
3995
|
}
|
|
3995
|
-
if (
|
|
3996
|
+
if (ts7.isTypeReferenceNode(typeNode)) {
|
|
3996
3997
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
3997
3998
|
}
|
|
3998
3999
|
return null;
|
|
3999
4000
|
}
|
|
4000
4001
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
4001
|
-
if (!
|
|
4002
|
+
if (!ts7.isIntersectionTypeNode(typeNode)) {
|
|
4002
4003
|
return [];
|
|
4003
4004
|
}
|
|
4004
4005
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -4188,7 +4189,7 @@ function makeFileProvenance(filePath) {
|
|
|
4188
4189
|
}
|
|
4189
4190
|
|
|
4190
4191
|
// src/generators/class-schema.ts
|
|
4191
|
-
var
|
|
4192
|
+
var ts9 = __toESM(require("typescript"), 1);
|
|
4192
4193
|
|
|
4193
4194
|
// src/metadata/collision-guards.ts
|
|
4194
4195
|
function assertUniqueSerializedNames(entries, scope) {
|
|
@@ -5182,7 +5183,7 @@ function createExtensionRegistry(extensions) {
|
|
|
5182
5183
|
}
|
|
5183
5184
|
|
|
5184
5185
|
// src/extensions/symbol-registry.ts
|
|
5185
|
-
var
|
|
5186
|
+
var ts8 = __toESM(require("typescript"), 1);
|
|
5186
5187
|
var path2 = __toESM(require("path"), 1);
|
|
5187
5188
|
|
|
5188
5189
|
// src/ui-schema/schema.ts
|