@formspec/build 0.1.0-alpha.58 → 0.1.0-alpha.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/builtin-brands.d.ts +10 -7
- package/dist/analyzer/builtin-brands.d.ts.map +1 -1
- package/dist/analyzer/class-analyzer.d.ts +30 -1
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/jsdoc-constraints.d.ts +0 -6
- package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts +2 -5
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +127 -32
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +130 -33
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +432 -12
- package/dist/build-beta.d.ts +400 -12
- package/dist/build-internal.d.ts +463 -12
- package/dist/build.d.ts +400 -12
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +2 -1
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -1
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts +2 -1
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -1
- package/dist/cli.cjs +610 -629
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +573 -586
- package/dist/cli.js.map +1 -1
- package/dist/extensions/registry.d.ts +19 -1
- package/dist/extensions/registry.d.ts.map +1 -1
- package/dist/extensions/resolve-custom-type.d.ts.map +1 -1
- package/dist/extensions/ts-type-utils.d.ts +0 -11
- package/dist/extensions/ts-type-utils.d.ts.map +1 -1
- package/dist/generators/class-schema.d.ts.map +1 -1
- package/dist/generators/method-schema.d.ts +3 -2
- package/dist/generators/method-schema.d.ts.map +1 -1
- package/dist/index.cjs +600 -618
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +571 -583
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +573 -591
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +540 -552
- package/dist/internals.js.map +1 -1
- package/dist/metadata/index.d.ts +1 -4
- package/dist/metadata/index.d.ts.map +1 -1
- package/dist/metadata/policy.d.ts +2 -6
- package/dist/metadata/policy.d.ts.map +1 -1
- package/dist/metadata/resolve.d.ts +3 -2
- package/dist/metadata/resolve.d.ts.map +1 -1
- package/dist/ui-schema/schema.d.ts +11 -28
- package/dist/ui-schema/schema.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/internals.cjs
CHANGED
|
@@ -847,19 +847,19 @@ function wrapInConditional(field, layout, provenance) {
|
|
|
847
847
|
}
|
|
848
848
|
|
|
849
849
|
// src/analyzer/program.ts
|
|
850
|
-
var
|
|
850
|
+
var ts6 = __toESM(require("typescript"), 1);
|
|
851
851
|
var path = __toESM(require("path"), 1);
|
|
852
852
|
|
|
853
853
|
// src/analyzer/class-analyzer.ts
|
|
854
|
-
var
|
|
855
|
-
var
|
|
854
|
+
var ts5 = __toESM(require("typescript"), 1);
|
|
855
|
+
var import_internal5 = require("@formspec/analysis/internal");
|
|
856
856
|
|
|
857
857
|
// src/analyzer/jsdoc-constraints.ts
|
|
858
|
-
var
|
|
858
|
+
var ts4 = __toESM(require("typescript"), 1);
|
|
859
859
|
|
|
860
860
|
// src/analyzer/tsdoc-parser.ts
|
|
861
|
-
var
|
|
862
|
-
var
|
|
861
|
+
var ts3 = __toESM(require("typescript"), 1);
|
|
862
|
+
var import_internal3 = require("@formspec/analysis/internal");
|
|
863
863
|
var import_internals3 = require("@formspec/core/internals");
|
|
864
864
|
var import_internals4 = require("@formspec/core/internals");
|
|
865
865
|
var import_core = require("@formspec/core");
|
|
@@ -870,21 +870,6 @@ var import_internal = require("@formspec/analysis/internal");
|
|
|
870
870
|
|
|
871
871
|
// src/extensions/ts-type-utils.ts
|
|
872
872
|
var ts = __toESM(require("typescript"), 1);
|
|
873
|
-
function collectBrandIdentifiers(type) {
|
|
874
|
-
if (!type.isIntersection()) {
|
|
875
|
-
return [];
|
|
876
|
-
}
|
|
877
|
-
const brands = [];
|
|
878
|
-
for (const prop of type.getProperties()) {
|
|
879
|
-
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
880
|
-
if (decl === void 0) continue;
|
|
881
|
-
if (!ts.isPropertySignature(decl) && !ts.isPropertyDeclaration(decl)) continue;
|
|
882
|
-
if (!ts.isComputedPropertyName(decl.name)) continue;
|
|
883
|
-
if (!ts.isIdentifier(decl.name.expression)) continue;
|
|
884
|
-
brands.push(decl.name.expression.text);
|
|
885
|
-
}
|
|
886
|
-
return brands;
|
|
887
|
-
}
|
|
888
873
|
function resolveCanonicalSymbol(type, checker) {
|
|
889
874
|
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
890
875
|
if (raw === void 0) return void 0;
|
|
@@ -969,7 +954,7 @@ function resolveCustomTypeFromTsType(type, checker, registry, sourceNode) {
|
|
|
969
954
|
return bySymbol;
|
|
970
955
|
}
|
|
971
956
|
}
|
|
972
|
-
for (const brand of
|
|
957
|
+
for (const brand of (0, import_internal._collectBrandIdentifiers)(stripped)) {
|
|
973
958
|
const byBrand = registry.findTypeByBrand(brand);
|
|
974
959
|
if (byBrand !== void 0) {
|
|
975
960
|
return byBrand;
|
|
@@ -982,161 +967,39 @@ function customTypeIdFromLookup(result) {
|
|
|
982
967
|
}
|
|
983
968
|
|
|
984
969
|
// src/analyzer/builtin-brands.ts
|
|
985
|
-
var
|
|
986
|
-
function isIntegerBrandedType(type) {
|
|
987
|
-
if (!type.isIntersection()) return false;
|
|
988
|
-
if (!type.types.some((member) => !!(member.flags & ts3.TypeFlags.Number))) return false;
|
|
989
|
-
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
990
|
-
}
|
|
970
|
+
var import_internal2 = require("@formspec/analysis/internal");
|
|
991
971
|
|
|
992
972
|
// src/analyzer/tsdoc-parser.ts
|
|
993
|
-
var
|
|
994
|
-
function sharedTagValueOptions(options) {
|
|
973
|
+
var import_internal4 = require("@formspec/analysis/internal");
|
|
974
|
+
function sharedTagValueOptions(options, pathResolvedCustomTypeId) {
|
|
995
975
|
return {
|
|
996
976
|
...options?.extensionRegistry !== void 0 ? { registry: options.extensionRegistry } : {},
|
|
997
|
-
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
977
|
+
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {},
|
|
978
|
+
...pathResolvedCustomTypeId !== void 0 ? { pathResolvedCustomTypeId } : {}
|
|
998
979
|
};
|
|
999
980
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
}
|
|
1005
|
-
return new Set(
|
|
1006
|
-
registry.extensions.flatMap(
|
|
1007
|
-
(ext) => (ext.types ?? []).flatMap((t) => t.tsTypeNames ?? [t.typeName])
|
|
1008
|
-
)
|
|
1009
|
-
);
|
|
981
|
+
function customTypeIdForResolvedType(resolvedType, checker, registry) {
|
|
982
|
+
if (registry === void 0) return void 0;
|
|
983
|
+
const lookup = resolveCustomTypeFromTsType(resolvedType, checker, registry);
|
|
984
|
+
return lookup === null ? void 0 : customTypeIdFromLookup(lookup);
|
|
1010
985
|
}
|
|
1011
|
-
function
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
if (clause.name !== void 0) {
|
|
1017
|
-
importedNames.add(clause.name.text);
|
|
1018
|
-
}
|
|
1019
|
-
if (clause.namedBindings !== void 0) {
|
|
1020
|
-
if (ts4.isNamedImports(clause.namedBindings)) {
|
|
1021
|
-
for (const specifier of clause.namedBindings.elements) {
|
|
1022
|
-
importedNames.add(specifier.name.text);
|
|
1023
|
-
}
|
|
1024
|
-
} else if (ts4.isNamespaceImport(clause.namedBindings)) {
|
|
1025
|
-
importedNames.add(clause.namedBindings.name.text);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
continue;
|
|
1029
|
-
}
|
|
1030
|
-
if (ts4.isImportEqualsDeclaration(statement)) {
|
|
1031
|
-
importedNames.add(statement.name.text);
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
return importedNames;
|
|
1035
|
-
}
|
|
1036
|
-
function isNonReferenceIdentifier(node) {
|
|
1037
|
-
const parent = node.parent;
|
|
1038
|
-
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) {
|
|
1039
|
-
return true;
|
|
1040
|
-
}
|
|
1041
|
-
if ((ts4.isPropertyAssignment(parent) || ts4.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
1042
|
-
return true;
|
|
1043
|
-
}
|
|
1044
|
-
if (ts4.isQualifiedName(parent) && parent.right === node) {
|
|
1045
|
-
return true;
|
|
1046
|
-
}
|
|
1047
|
-
return false;
|
|
1048
|
-
}
|
|
1049
|
-
function astReferencesImportedName(root, importedNames) {
|
|
1050
|
-
if (importedNames.size === 0) {
|
|
1051
|
-
return false;
|
|
1052
|
-
}
|
|
1053
|
-
let found = false;
|
|
1054
|
-
const visit = (node) => {
|
|
1055
|
-
if (found) return;
|
|
1056
|
-
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
1057
|
-
found = true;
|
|
1058
|
-
return;
|
|
1059
|
-
}
|
|
1060
|
-
ts4.forEachChild(node, visit);
|
|
1061
|
-
};
|
|
1062
|
-
visit(root);
|
|
1063
|
-
return found;
|
|
1064
|
-
}
|
|
1065
|
-
function getObjectMembers(statement) {
|
|
1066
|
-
if (ts4.isInterfaceDeclaration(statement)) {
|
|
1067
|
-
return statement.members;
|
|
1068
|
-
}
|
|
1069
|
-
if (ts4.isTypeLiteralNode(statement.type)) {
|
|
1070
|
-
return statement.type.members;
|
|
1071
|
-
}
|
|
1072
|
-
return void 0;
|
|
1073
|
-
}
|
|
1074
|
-
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
1075
|
-
const members = getObjectMembers(statement);
|
|
1076
|
-
if (members === void 0) {
|
|
1077
|
-
return null;
|
|
1078
|
-
}
|
|
1079
|
-
const replacements = [];
|
|
1080
|
-
for (const member of members) {
|
|
1081
|
-
if (!ts4.isPropertySignature(member)) {
|
|
1082
|
-
if (astReferencesImportedName(member, importedNames)) {
|
|
1083
|
-
return null;
|
|
1084
|
-
}
|
|
1085
|
-
continue;
|
|
1086
|
-
}
|
|
1087
|
-
const typeAnnotation = member.type;
|
|
1088
|
-
if (typeAnnotation === void 0) continue;
|
|
1089
|
-
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
1090
|
-
replacements.push({
|
|
1091
|
-
start: typeAnnotation.getStart(sourceFile),
|
|
1092
|
-
end: typeAnnotation.getEnd()
|
|
1093
|
-
});
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
if (replacements.length === 0) {
|
|
1097
|
-
return statement.getText(sourceFile);
|
|
1098
|
-
}
|
|
1099
|
-
const stmtStart = statement.getStart(sourceFile);
|
|
1100
|
-
let result = statement.getText(sourceFile);
|
|
1101
|
-
for (const { start, end } of [...replacements].reverse()) {
|
|
1102
|
-
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
986
|
+
function resolvePathTargetCustomTypeId(parsedTag, subjectType, checker, registry) {
|
|
987
|
+
if (parsedTag === null) return void 0;
|
|
988
|
+
const target = parsedTag.target;
|
|
989
|
+
if (target?.kind !== "path" || !target.valid || target.path === null) {
|
|
990
|
+
return void 0;
|
|
1103
991
|
}
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
1107
|
-
const importedNames = collectImportedNames(sourceFile);
|
|
1108
|
-
const importedNamesToSkip = new Set(
|
|
1109
|
-
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
1110
|
-
);
|
|
1111
|
-
const result = [];
|
|
1112
|
-
for (const statement of sourceFile.statements) {
|
|
1113
|
-
if (ts4.isImportDeclaration(statement)) continue;
|
|
1114
|
-
if (ts4.isImportEqualsDeclaration(statement)) continue;
|
|
1115
|
-
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
1116
|
-
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
1117
|
-
result.push(statement.getText(sourceFile));
|
|
1118
|
-
continue;
|
|
1119
|
-
}
|
|
1120
|
-
if (ts4.isInterfaceDeclaration(statement) || ts4.isTypeAliasDeclaration(statement)) {
|
|
1121
|
-
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
1122
|
-
if (rewritten !== null) {
|
|
1123
|
-
result.push(rewritten);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
992
|
+
if (subjectType === void 0 || checker === void 0) {
|
|
993
|
+
return void 0;
|
|
1126
994
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
for (const diagnostic of additions) {
|
|
1131
|
-
if ((diagnostic.code === "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" || diagnostic.code === "SYNTHETIC_SETUP_FAILURE") && target.some(
|
|
1132
|
-
(existing) => existing.code === diagnostic.code && existing.message === diagnostic.message
|
|
1133
|
-
)) {
|
|
1134
|
-
continue;
|
|
1135
|
-
}
|
|
1136
|
-
target.push(diagnostic);
|
|
995
|
+
const resolution = (0, import_internal3.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
996
|
+
if (resolution.kind !== "resolved") {
|
|
997
|
+
return void 0;
|
|
1137
998
|
}
|
|
999
|
+
return customTypeIdForResolvedType(resolution.type, checker, registry);
|
|
1138
1000
|
}
|
|
1139
|
-
|
|
1001
|
+
var TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
1002
|
+
function processConstraintTag(tagName, text, parsedTag, provenance, node, sourceFile, options, constraints, diagnostics) {
|
|
1140
1003
|
const compilerDiagnostics = buildCompilerBackedConstraintDiagnostics(
|
|
1141
1004
|
node,
|
|
1142
1005
|
sourceFile,
|
|
@@ -1144,74 +1007,30 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
1144
1007
|
parsedTag,
|
|
1145
1008
|
text,
|
|
1146
1009
|
provenance,
|
|
1147
|
-
supportingDeclarations,
|
|
1148
1010
|
options
|
|
1149
1011
|
);
|
|
1150
1012
|
if (compilerDiagnostics.length > 0) {
|
|
1151
|
-
|
|
1013
|
+
diagnostics.push(...compilerDiagnostics);
|
|
1152
1014
|
return;
|
|
1153
1015
|
}
|
|
1154
|
-
const
|
|
1016
|
+
const pathResolvedCustomTypeId = resolvePathTargetCustomTypeId(
|
|
1017
|
+
parsedTag,
|
|
1018
|
+
options?.subjectType,
|
|
1019
|
+
options?.checker,
|
|
1020
|
+
options?.extensionRegistry
|
|
1021
|
+
);
|
|
1022
|
+
const constraintNode = (0, import_internal3.parseConstraintTagValue)(
|
|
1155
1023
|
tagName,
|
|
1156
1024
|
text,
|
|
1157
1025
|
provenance,
|
|
1158
|
-
sharedTagValueOptions(options)
|
|
1026
|
+
sharedTagValueOptions(options, pathResolvedCustomTypeId)
|
|
1159
1027
|
);
|
|
1160
1028
|
if (constraintNode) {
|
|
1161
1029
|
constraints.push(constraintNode);
|
|
1162
1030
|
}
|
|
1163
1031
|
}
|
|
1164
|
-
function renderSyntheticArgumentExpression(valueKind, argumentText) {
|
|
1165
|
-
const trimmed = argumentText.trim();
|
|
1166
|
-
if (trimmed === "") {
|
|
1167
|
-
return null;
|
|
1168
|
-
}
|
|
1169
|
-
switch (valueKind) {
|
|
1170
|
-
case "number":
|
|
1171
|
-
case "integer":
|
|
1172
|
-
case "signedInteger":
|
|
1173
|
-
if (trimmed === "Infinity" || trimmed === "-Infinity" || trimmed === "NaN") {
|
|
1174
|
-
return trimmed;
|
|
1175
|
-
}
|
|
1176
|
-
return Number.isFinite(Number(trimmed)) ? trimmed : JSON.stringify(trimmed);
|
|
1177
|
-
case "string":
|
|
1178
|
-
return JSON.stringify(argumentText);
|
|
1179
|
-
case "json":
|
|
1180
|
-
try {
|
|
1181
|
-
JSON.parse(trimmed);
|
|
1182
|
-
return `(${trimmed})`;
|
|
1183
|
-
} catch {
|
|
1184
|
-
return JSON.stringify(trimmed);
|
|
1185
|
-
}
|
|
1186
|
-
case "boolean":
|
|
1187
|
-
return trimmed === "true" || trimmed === "false" ? trimmed : JSON.stringify(trimmed);
|
|
1188
|
-
case "condition":
|
|
1189
|
-
return "undefined as unknown as FormSpecCondition";
|
|
1190
|
-
case null:
|
|
1191
|
-
return null;
|
|
1192
|
-
default: {
|
|
1193
|
-
return String(valueKind);
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
function getArrayElementType(type, checker) {
|
|
1198
|
-
if (!checker.isArrayType(type)) {
|
|
1199
|
-
return null;
|
|
1200
|
-
}
|
|
1201
|
-
return checker.getTypeArguments(type)[0] ?? null;
|
|
1202
|
-
}
|
|
1203
1032
|
function supportsConstraintCapability(type, checker, capability) {
|
|
1204
|
-
|
|
1205
|
-
return true;
|
|
1206
|
-
}
|
|
1207
|
-
if ((0, import_internal2.hasTypeSemanticCapability)(type, checker, capability)) {
|
|
1208
|
-
return true;
|
|
1209
|
-
}
|
|
1210
|
-
if (capability === "string-like") {
|
|
1211
|
-
const itemType = getArrayElementType(type, checker);
|
|
1212
|
-
return itemType !== null && (0, import_internal2.hasTypeSemanticCapability)(itemType, checker, capability);
|
|
1213
|
-
}
|
|
1214
|
-
return false;
|
|
1033
|
+
return (0, import_internal3._supportsConstraintCapability)(capability, type, checker);
|
|
1215
1034
|
}
|
|
1216
1035
|
var MAX_HINT_CANDIDATES = 5;
|
|
1217
1036
|
var MAX_HINT_DEPTH = 3;
|
|
@@ -1220,7 +1039,7 @@ function stripHintNullishUnion(type) {
|
|
|
1220
1039
|
return type;
|
|
1221
1040
|
}
|
|
1222
1041
|
const nonNullish = type.types.filter(
|
|
1223
|
-
(member) => (member.flags & (
|
|
1042
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
1224
1043
|
);
|
|
1225
1044
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
1226
1045
|
return nonNullish[0];
|
|
@@ -1236,10 +1055,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
1236
1055
|
}
|
|
1237
1056
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
1238
1057
|
const name = declaration.name;
|
|
1239
|
-
if (
|
|
1058
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
1240
1059
|
return false;
|
|
1241
1060
|
}
|
|
1242
|
-
if (!
|
|
1061
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
1243
1062
|
return false;
|
|
1244
1063
|
}
|
|
1245
1064
|
}
|
|
@@ -1255,7 +1074,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
1255
1074
|
if (isCallableType(stripped)) {
|
|
1256
1075
|
return;
|
|
1257
1076
|
}
|
|
1258
|
-
if (!(0,
|
|
1077
|
+
if (!(0, import_internal3.hasTypeSemanticCapability)(stripped, checker, "object-like")) {
|
|
1259
1078
|
return;
|
|
1260
1079
|
}
|
|
1261
1080
|
for (const property of stripped.getProperties()) {
|
|
@@ -1273,7 +1092,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
1273
1092
|
continue;
|
|
1274
1093
|
}
|
|
1275
1094
|
const strippedPropertyType = stripHintNullishUnion(propertyType);
|
|
1276
|
-
if (!isCallableType(strippedPropertyType) && (0,
|
|
1095
|
+
if (!isCallableType(strippedPropertyType) && (0, import_internal3.hasTypeSemanticCapability)(strippedPropertyType, checker, "object-like")) {
|
|
1277
1096
|
visit(strippedPropertyType, path3, depth + 1);
|
|
1278
1097
|
}
|
|
1279
1098
|
}
|
|
@@ -1282,7 +1101,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
1282
1101
|
return out;
|
|
1283
1102
|
}
|
|
1284
1103
|
function buildPathTargetHint(subjectType, checker, capability, tagName, argumentText) {
|
|
1285
|
-
if (!(0,
|
|
1104
|
+
if (!(0, import_internal3.hasTypeSemanticCapability)(subjectType, checker, "object-like")) {
|
|
1286
1105
|
return null;
|
|
1287
1106
|
}
|
|
1288
1107
|
const candidates = collectObjectSubfieldCandidates(subjectType, checker, capability);
|
|
@@ -1338,53 +1157,11 @@ function placementLabel(placement) {
|
|
|
1338
1157
|
}
|
|
1339
1158
|
}
|
|
1340
1159
|
}
|
|
1341
|
-
function capabilityLabel(capability) {
|
|
1342
|
-
switch (capability) {
|
|
1343
|
-
case "numeric-comparable":
|
|
1344
|
-
return "number";
|
|
1345
|
-
case "string-like":
|
|
1346
|
-
return "string";
|
|
1347
|
-
case "array-like":
|
|
1348
|
-
return "array";
|
|
1349
|
-
case "enum-member-addressable":
|
|
1350
|
-
return "enum";
|
|
1351
|
-
case "json-like":
|
|
1352
|
-
return "JSON-compatible";
|
|
1353
|
-
case "object-like":
|
|
1354
|
-
return "object";
|
|
1355
|
-
case "condition-like":
|
|
1356
|
-
return "conditional";
|
|
1357
|
-
case void 0:
|
|
1358
|
-
return "compatible";
|
|
1359
|
-
default:
|
|
1360
|
-
return capability;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
function getBroadenedCustomTypeId(fieldType) {
|
|
1364
|
-
if (fieldType?.kind === "custom") {
|
|
1365
|
-
return fieldType.typeId;
|
|
1366
|
-
}
|
|
1367
|
-
if (fieldType?.kind !== "union") {
|
|
1368
|
-
return void 0;
|
|
1369
|
-
}
|
|
1370
|
-
const customMembers = fieldType.members.filter(
|
|
1371
|
-
(member) => member.kind === "custom"
|
|
1372
|
-
);
|
|
1373
|
-
if (customMembers.length !== 1) {
|
|
1374
|
-
return void 0;
|
|
1375
|
-
}
|
|
1376
|
-
const nonCustomMembers = fieldType.members.filter((member) => member.kind !== "custom");
|
|
1377
|
-
const allOtherMembersAreNull = nonCustomMembers.every(
|
|
1378
|
-
(member) => member.kind === "primitive" && member.primitiveKind === "null"
|
|
1379
|
-
);
|
|
1380
|
-
const customMember = customMembers[0];
|
|
1381
|
-
return allOtherMembersAreNull && customMember !== void 0 ? customMember.typeId : void 0;
|
|
1382
|
-
}
|
|
1383
1160
|
function hasBuiltinConstraintBroadening(tagName, options) {
|
|
1384
|
-
const broadenedTypeId = getBroadenedCustomTypeId(options?.fieldType);
|
|
1161
|
+
const broadenedTypeId = (0, import_internal3.getBroadenedCustomTypeId)(options?.fieldType);
|
|
1385
1162
|
return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
|
|
1386
1163
|
}
|
|
1387
|
-
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance,
|
|
1164
|
+
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance, options) {
|
|
1388
1165
|
if (!(0, import_internals3.isBuiltinConstraintName)(tagName)) {
|
|
1389
1166
|
return [];
|
|
1390
1167
|
}
|
|
@@ -1393,27 +1170,25 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1393
1170
|
if (checker === void 0 || subjectType === void 0) {
|
|
1394
1171
|
return [];
|
|
1395
1172
|
}
|
|
1396
|
-
const placement = (0,
|
|
1173
|
+
const placement = (0, import_internal3.resolveDeclarationPlacement)(node);
|
|
1397
1174
|
if (placement === null) {
|
|
1398
1175
|
return [];
|
|
1399
1176
|
}
|
|
1400
|
-
const definition = (0,
|
|
1177
|
+
const definition = (0, import_internal3.getTagDefinition)(tagName, options?.extensionRegistry?.extensions);
|
|
1401
1178
|
if (definition === null) {
|
|
1402
1179
|
return [];
|
|
1403
1180
|
}
|
|
1404
1181
|
const nonNullPlacement = placement;
|
|
1405
|
-
const log = (0,
|
|
1406
|
-
const broadeningLog = (0,
|
|
1407
|
-
const
|
|
1408
|
-
const typedParserLog = (0, import_internal3.getTypedParserLogger)();
|
|
1182
|
+
const log = (0, import_internal4.getBuildLogger)();
|
|
1183
|
+
const broadeningLog = (0, import_internal4.getBroadeningLogger)();
|
|
1184
|
+
const typedParserLog = (0, import_internal4.getTypedParserLogger)();
|
|
1409
1185
|
const logsEnabled = log !== import_core.noopLogger || broadeningLog !== import_core.noopLogger;
|
|
1410
|
-
const syntheticTraceEnabled = syntheticLog !== import_core.noopLogger;
|
|
1411
1186
|
const typedParserTraceEnabled = typedParserLog !== import_core.noopLogger;
|
|
1412
|
-
const logStart = logsEnabled ? (0,
|
|
1413
|
-
const subjectTypeKind = logsEnabled ? (0,
|
|
1414
|
-
function emit(outcome,
|
|
1187
|
+
const logStart = logsEnabled ? (0, import_internal4.nowMicros)() : 0;
|
|
1188
|
+
const subjectTypeKind = logsEnabled ? (0, import_internal4.describeTypeKind)(subjectType, checker) : "";
|
|
1189
|
+
function emit(outcome, result) {
|
|
1415
1190
|
if (!logsEnabled) {
|
|
1416
|
-
return
|
|
1191
|
+
return result;
|
|
1417
1192
|
}
|
|
1418
1193
|
const entry = {
|
|
1419
1194
|
consumer: "build",
|
|
@@ -1421,13 +1196,13 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1421
1196
|
placement: nonNullPlacement,
|
|
1422
1197
|
subjectTypeKind,
|
|
1423
1198
|
roleOutcome: outcome,
|
|
1424
|
-
elapsedMicros: (0,
|
|
1199
|
+
elapsedMicros: (0, import_internal4.elapsedMicros)(logStart)
|
|
1425
1200
|
};
|
|
1426
|
-
(0,
|
|
1201
|
+
(0, import_internal4.logTagApplication)(log, entry);
|
|
1427
1202
|
if (outcome === "bypass" || outcome === "D1" || outcome === "D2") {
|
|
1428
|
-
(0,
|
|
1203
|
+
(0, import_internal4.logTagApplication)(broadeningLog, entry);
|
|
1429
1204
|
}
|
|
1430
|
-
return
|
|
1205
|
+
return result;
|
|
1431
1206
|
}
|
|
1432
1207
|
if (!definition.placements.includes(placement)) {
|
|
1433
1208
|
return emit("A-reject", [
|
|
@@ -1460,7 +1235,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1460
1235
|
)
|
|
1461
1236
|
]);
|
|
1462
1237
|
}
|
|
1463
|
-
const resolution = (0,
|
|
1238
|
+
const resolution = (0, import_internal3.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
1464
1239
|
if (resolution.kind === "missing-property") {
|
|
1465
1240
|
return emit("B-reject", [
|
|
1466
1241
|
makeDiagnostic(
|
|
@@ -1471,7 +1246,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1471
1246
|
]);
|
|
1472
1247
|
}
|
|
1473
1248
|
if (resolution.kind === "unresolvable") {
|
|
1474
|
-
const actualType = checker.typeToString(resolution.type, node,
|
|
1249
|
+
const actualType = checker.typeToString(resolution.type, node, TYPE_FORMAT_FLAGS);
|
|
1475
1250
|
return emit("B-reject", [
|
|
1476
1251
|
makeDiagnostic(
|
|
1477
1252
|
"TYPE_MISMATCH",
|
|
@@ -1485,21 +1260,21 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1485
1260
|
}
|
|
1486
1261
|
const hasBroadening = (() => {
|
|
1487
1262
|
if (target === null) {
|
|
1488
|
-
if (
|
|
1263
|
+
if ((0, import_internal2._isIntegerBrandedType)((0, import_internal3.stripNullishUnion)(subjectType)) && definition.capabilities[0] === "numeric-comparable") {
|
|
1489
1264
|
return true;
|
|
1490
1265
|
}
|
|
1491
1266
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
1492
1267
|
}
|
|
1493
1268
|
const registry = options?.extensionRegistry;
|
|
1494
1269
|
if (registry === void 0) return false;
|
|
1495
|
-
const
|
|
1496
|
-
return
|
|
1270
|
+
const typeId = customTypeIdForResolvedType(evaluatedType, checker, registry);
|
|
1271
|
+
return typeId !== void 0 && registry.findBuiltinConstraintBroadening(typeId, tagName) !== void 0;
|
|
1497
1272
|
})();
|
|
1498
1273
|
if (!hasBroadening) {
|
|
1499
1274
|
const requiredCapability = definition.capabilities[0];
|
|
1500
1275
|
if (requiredCapability !== void 0 && !supportsConstraintCapability(evaluatedType, checker, requiredCapability)) {
|
|
1501
|
-
const actualType = checker.typeToString(evaluatedType, node,
|
|
1502
|
-
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${
|
|
1276
|
+
const actualType = checker.typeToString(evaluatedType, node, TYPE_FORMAT_FLAGS);
|
|
1277
|
+
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${(0, import_internal3._capabilityLabel)(requiredCapability)} targets, but field type is "${actualType}"`;
|
|
1503
1278
|
const hint = target === null ? buildPathTargetHint(
|
|
1504
1279
|
subjectType,
|
|
1505
1280
|
checker,
|
|
@@ -1516,11 +1291,11 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1516
1291
|
]);
|
|
1517
1292
|
}
|
|
1518
1293
|
}
|
|
1519
|
-
const effectiveArgumentText = parsedTag !== null ? (0, import_internal2.parseTagSyntax)(tagName, rawText).argumentText : rawText;
|
|
1520
1294
|
if (hasBroadening) {
|
|
1521
1295
|
return emit("bypass", []);
|
|
1522
1296
|
}
|
|
1523
|
-
const
|
|
1297
|
+
const effectiveArgumentText = (0, import_internal4.extractEffectiveArgumentText)(tagName, rawText, parsedTag);
|
|
1298
|
+
const typedParseResult = (0, import_internal4.parseTagArgument)(tagName, effectiveArgumentText, "build");
|
|
1524
1299
|
if (!typedParseResult.ok) {
|
|
1525
1300
|
if (typedParserTraceEnabled) {
|
|
1526
1301
|
typedParserLog.trace("typed-parser C-reject", {
|
|
@@ -1532,23 +1307,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1532
1307
|
diagnosticCode: typedParseResult.diagnostic.code
|
|
1533
1308
|
});
|
|
1534
1309
|
}
|
|
1535
|
-
|
|
1536
|
-
switch (typedParseResult.diagnostic.code) {
|
|
1537
|
-
case "MISSING_TAG_ARGUMENT":
|
|
1538
|
-
mappedCode = "MISSING_TAG_ARGUMENT";
|
|
1539
|
-
break;
|
|
1540
|
-
case "INVALID_TAG_ARGUMENT":
|
|
1541
|
-
mappedCode = "INVALID_TAG_ARGUMENT";
|
|
1542
|
-
break;
|
|
1543
|
-
case "UNKNOWN_TAG":
|
|
1544
|
-
throw new Error(
|
|
1545
|
-
`Unexpected UNKNOWN_TAG from parseTagArgument("${tagName}") \u2014 tag was resolved via getTagDefinition.`
|
|
1546
|
-
);
|
|
1547
|
-
default: {
|
|
1548
|
-
const _exhaustive = typedParseResult.diagnostic.code;
|
|
1549
|
-
throw new Error(`Unknown diagnostic code: ${String(_exhaustive)}`);
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1310
|
+
const mappedCode = (0, import_internal4.mapTypedParserDiagnosticCode)(typedParseResult.diagnostic.code, tagName);
|
|
1552
1311
|
return emit("C-reject", [
|
|
1553
1312
|
makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
|
|
1554
1313
|
]);
|
|
@@ -1563,77 +1322,16 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1563
1322
|
valueKind: typedParseResult.value.kind
|
|
1564
1323
|
});
|
|
1565
1324
|
}
|
|
1566
|
-
|
|
1567
|
-
definition.valueKind,
|
|
1568
|
-
effectiveArgumentText
|
|
1569
|
-
);
|
|
1570
|
-
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
1571
|
-
const hostType = options?.hostType ?? subjectType;
|
|
1572
|
-
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
1573
|
-
if (syntheticTraceEnabled) {
|
|
1574
|
-
syntheticLog.trace("invoking synthetic checker", {
|
|
1575
|
-
consumer: "build",
|
|
1576
|
-
tag: tagName,
|
|
1577
|
-
placement,
|
|
1578
|
-
subjectTypeKind,
|
|
1579
|
-
subjectTypeText
|
|
1580
|
-
});
|
|
1581
|
-
}
|
|
1582
|
-
const result = (0, import_internal2.checkSyntheticTagApplication)({
|
|
1583
|
-
tagName,
|
|
1584
|
-
placement,
|
|
1585
|
-
hostType: hostTypeText,
|
|
1586
|
-
subjectType: subjectTypeText,
|
|
1587
|
-
...target?.kind === "path" ? { target: { kind: "path", text: target.rawText } } : {},
|
|
1588
|
-
...argumentExpression !== null ? { argumentExpression } : {},
|
|
1589
|
-
supportingDeclarations,
|
|
1590
|
-
...options?.extensionRegistry !== void 0 ? {
|
|
1591
|
-
extensions: options.extensionRegistry.extensions.map((extension) => ({
|
|
1592
|
-
extensionId: extension.extensionId,
|
|
1593
|
-
...extension.constraintTags !== void 0 ? {
|
|
1594
|
-
constraintTags: extension.constraintTags.map((tag) => ({ tagName: tag.tagName }))
|
|
1595
|
-
} : {},
|
|
1596
|
-
...extension.metadataSlots !== void 0 ? {
|
|
1597
|
-
metadataSlots: extension.metadataSlots
|
|
1598
|
-
} : {},
|
|
1599
|
-
...extension.types !== void 0 ? {
|
|
1600
|
-
customTypes: extension.types.map((t) => ({
|
|
1601
|
-
tsTypeNames: t.tsTypeNames ?? [t.typeName]
|
|
1602
|
-
}))
|
|
1603
|
-
} : {}
|
|
1604
|
-
}))
|
|
1605
|
-
} : {}
|
|
1606
|
-
});
|
|
1607
|
-
if (result.diagnostics.length === 0) {
|
|
1608
|
-
return emit("C-pass", []);
|
|
1609
|
-
}
|
|
1610
|
-
const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
|
|
1611
|
-
if (setupDiagnostic !== void 0) {
|
|
1612
|
-
return emit("C-reject", [
|
|
1613
|
-
makeDiagnostic(
|
|
1614
|
-
setupDiagnostic.kind === "unsupported-custom-type-override" ? "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" : "SYNTHETIC_SETUP_FAILURE",
|
|
1615
|
-
setupDiagnostic.message,
|
|
1616
|
-
provenance
|
|
1617
|
-
)
|
|
1618
|
-
]);
|
|
1619
|
-
}
|
|
1620
|
-
const expectedLabel = definition.valueKind === null ? "compatible argument" : capabilityLabel(definition.valueKind);
|
|
1621
|
-
return emit("C-reject", [
|
|
1622
|
-
makeDiagnostic(
|
|
1623
|
-
"TYPE_MISMATCH",
|
|
1624
|
-
`Tag "@${tagName}" received an invalid argument for ${expectedLabel}.`,
|
|
1625
|
-
provenance
|
|
1626
|
-
)
|
|
1627
|
-
]);
|
|
1325
|
+
return emit("C-pass", []);
|
|
1628
1326
|
}
|
|
1629
1327
|
var parseResultCache = /* @__PURE__ */ new Map();
|
|
1630
1328
|
function getExtensionTagNames(options) {
|
|
1631
1329
|
return [
|
|
1632
1330
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
1633
|
-
(extension) => (extension.constraintTags ?? []).map((tag) => (0,
|
|
1331
|
+
(extension) => (extension.constraintTags ?? []).map((tag) => (0, import_internal3.normalizeFormSpecTagName)(tag.tagName))
|
|
1634
1332
|
) ?? [],
|
|
1635
1333
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
1636
|
-
(extension) => (extension.metadataSlots ?? []).map((slot) => (0,
|
|
1334
|
+
(extension) => (extension.metadataSlots ?? []).map((slot) => (0, import_internal3.normalizeFormSpecTagName)(slot.tagName))
|
|
1637
1335
|
) ?? []
|
|
1638
1336
|
].sort();
|
|
1639
1337
|
}
|
|
@@ -1645,9 +1343,9 @@ function getExtensionRegistryCacheKey(registry) {
|
|
|
1645
1343
|
(extension) => JSON.stringify({
|
|
1646
1344
|
extensionId: extension.extensionId,
|
|
1647
1345
|
typeNames: extension.types?.map((type) => type.typeName) ?? [],
|
|
1648
|
-
constraintTags: extension.constraintTags?.map((tag) => (0,
|
|
1346
|
+
constraintTags: extension.constraintTags?.map((tag) => (0, import_internal3.normalizeFormSpecTagName)(tag.tagName)) ?? [],
|
|
1649
1347
|
metadataSlots: extension.metadataSlots?.map((slot) => ({
|
|
1650
|
-
tagName: (0,
|
|
1348
|
+
tagName: (0, import_internal3.normalizeFormSpecTagName)(slot.tagName),
|
|
1651
1349
|
declarationKinds: [...slot.declarationKinds].sort(),
|
|
1652
1350
|
allowBare: slot.allowBare !== false,
|
|
1653
1351
|
qualifiers: (slot.qualifiers ?? []).map((qualifier) => ({
|
|
@@ -1668,8 +1366,8 @@ function getParseCacheKey(node, file, options) {
|
|
|
1668
1366
|
start: node.getFullStart(),
|
|
1669
1367
|
end: node.getEnd(),
|
|
1670
1368
|
fieldType: options?.fieldType ?? null,
|
|
1671
|
-
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node,
|
|
1672
|
-
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node,
|
|
1369
|
+
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node, TYPE_FORMAT_FLAGS) : null,
|
|
1370
|
+
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node, TYPE_FORMAT_FLAGS) : null,
|
|
1673
1371
|
extensions: getExtensionRegistryCacheKey(options?.extensionRegistry)
|
|
1674
1372
|
});
|
|
1675
1373
|
}
|
|
@@ -1679,6 +1377,16 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1679
1377
|
if (cached !== void 0) {
|
|
1680
1378
|
return cached;
|
|
1681
1379
|
}
|
|
1380
|
+
const setupDiags = options?.extensionRegistry?.setupDiagnostics;
|
|
1381
|
+
if (setupDiags !== void 0 && setupDiags.length > 0) {
|
|
1382
|
+
const result2 = {
|
|
1383
|
+
constraints: [],
|
|
1384
|
+
annotations: [],
|
|
1385
|
+
diagnostics: (0, import_internal4._emitSetupDiagnostics)(setupDiags, file)
|
|
1386
|
+
};
|
|
1387
|
+
parseResultCache.set(cacheKey, result2);
|
|
1388
|
+
return result2;
|
|
1389
|
+
}
|
|
1682
1390
|
const constraints = [];
|
|
1683
1391
|
const annotations = [];
|
|
1684
1392
|
const diagnostics = [];
|
|
@@ -1688,14 +1396,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1688
1396
|
let placeholderProvenance;
|
|
1689
1397
|
const sourceFile = node.getSourceFile();
|
|
1690
1398
|
const sourceText = sourceFile.getFullText();
|
|
1691
|
-
const
|
|
1692
|
-
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
1693
|
-
const commentRanges = ts4.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1399
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1694
1400
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
1695
1401
|
const extensionTagNames = getExtensionTagNames(options);
|
|
1696
1402
|
if (commentRanges) {
|
|
1697
1403
|
for (const range of commentRanges) {
|
|
1698
|
-
if (range.kind !==
|
|
1404
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
1699
1405
|
continue;
|
|
1700
1406
|
}
|
|
1701
1407
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -1703,7 +1409,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1703
1409
|
continue;
|
|
1704
1410
|
}
|
|
1705
1411
|
const extensions = options?.extensionRegistry?.extensions;
|
|
1706
|
-
const unified = (0,
|
|
1412
|
+
const unified = (0, import_internal3.parseUnifiedComment)(commentText, {
|
|
1707
1413
|
offset: range.pos,
|
|
1708
1414
|
extensionTagNames,
|
|
1709
1415
|
...extensions !== void 0 ? { extensions } : {}
|
|
@@ -1738,13 +1444,13 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1738
1444
|
}
|
|
1739
1445
|
continue;
|
|
1740
1446
|
}
|
|
1741
|
-
if (
|
|
1447
|
+
if (import_internal3.TAGS_REQUIRING_RAW_TEXT.has(tagName)) {
|
|
1742
1448
|
const fallback = rawTextFallbacks.get(tagName)?.shift();
|
|
1743
|
-
const text2 = (0,
|
|
1449
|
+
const text2 = (0, import_internal3.choosePreferredPayloadText)(tag.resolvedPayloadText, fallback?.text ?? "");
|
|
1744
1450
|
if (text2 === "") continue;
|
|
1745
1451
|
const provenance2 = provenanceForParsedTag(tag, sourceFile, file);
|
|
1746
1452
|
if (tagName === "defaultValue") {
|
|
1747
|
-
annotations.push((0,
|
|
1453
|
+
annotations.push((0, import_internal3.parseDefaultValueTagValue)(text2, provenance2));
|
|
1748
1454
|
continue;
|
|
1749
1455
|
}
|
|
1750
1456
|
processConstraintTag(
|
|
@@ -1754,7 +1460,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1754
1460
|
provenance2,
|
|
1755
1461
|
node,
|
|
1756
1462
|
sourceFile,
|
|
1757
|
-
supportingDeclarations,
|
|
1758
1463
|
options,
|
|
1759
1464
|
constraints,
|
|
1760
1465
|
diagnostics
|
|
@@ -1772,7 +1477,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1772
1477
|
provenance,
|
|
1773
1478
|
node,
|
|
1774
1479
|
sourceFile,
|
|
1775
|
-
supportingDeclarations,
|
|
1776
1480
|
options,
|
|
1777
1481
|
constraints,
|
|
1778
1482
|
diagnostics
|
|
@@ -1826,7 +1530,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1826
1530
|
if (text === "") continue;
|
|
1827
1531
|
const provenance = fallback.provenance;
|
|
1828
1532
|
if (tagName === "defaultValue") {
|
|
1829
|
-
annotations.push((0,
|
|
1533
|
+
annotations.push((0, import_internal3.parseDefaultValueTagValue)(text, provenance));
|
|
1830
1534
|
continue;
|
|
1831
1535
|
}
|
|
1832
1536
|
processConstraintTag(
|
|
@@ -1836,7 +1540,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1836
1540
|
provenance,
|
|
1837
1541
|
node,
|
|
1838
1542
|
sourceFile,
|
|
1839
|
-
supportingDeclarations,
|
|
1840
1543
|
options,
|
|
1841
1544
|
constraints,
|
|
1842
1545
|
diagnostics
|
|
@@ -1852,13 +1555,13 @@ function extractDisplayNameMetadata(node) {
|
|
|
1852
1555
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
1853
1556
|
const sourceFile = node.getSourceFile();
|
|
1854
1557
|
const sourceText = sourceFile.getFullText();
|
|
1855
|
-
const commentRanges =
|
|
1558
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1856
1559
|
if (commentRanges) {
|
|
1857
1560
|
for (const range of commentRanges) {
|
|
1858
|
-
if (range.kind !==
|
|
1561
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
1859
1562
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
1860
1563
|
if (!commentText.startsWith("/**")) continue;
|
|
1861
|
-
const unified = (0,
|
|
1564
|
+
const unified = (0, import_internal3.parseUnifiedComment)(commentText);
|
|
1862
1565
|
for (const tag of unified.tags) {
|
|
1863
1566
|
if (tag.normalizedTagName !== "displayName") {
|
|
1864
1567
|
continue;
|
|
@@ -1880,9 +1583,9 @@ function extractDisplayNameMetadata(node) {
|
|
|
1880
1583
|
}
|
|
1881
1584
|
function collectRawTextFallbacks(node, file) {
|
|
1882
1585
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
1883
|
-
for (const tag of
|
|
1586
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
1884
1587
|
const tagName = (0, import_internals3.normalizeConstraintTagName)(tag.tagName.text);
|
|
1885
|
-
if (!
|
|
1588
|
+
if (!import_internal3.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
1886
1589
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
1887
1590
|
if (commentText === "") continue;
|
|
1888
1591
|
const entries = fallbacks.get(tagName) ?? [];
|
|
@@ -1895,7 +1598,7 @@ function collectRawTextFallbacks(node, file) {
|
|
|
1895
1598
|
return fallbacks;
|
|
1896
1599
|
}
|
|
1897
1600
|
function isMemberTargetDisplayName(text) {
|
|
1898
|
-
return (0,
|
|
1601
|
+
return (0, import_internal3.parseTagSyntax)("displayName", text).target !== null;
|
|
1899
1602
|
}
|
|
1900
1603
|
function provenanceForComment(range, sourceFile, file, tagName) {
|
|
1901
1604
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);
|
|
@@ -1935,7 +1638,7 @@ function getTagCommentText(tag) {
|
|
|
1935
1638
|
if (typeof tag.comment === "string") {
|
|
1936
1639
|
return tag.comment;
|
|
1937
1640
|
}
|
|
1938
|
-
return
|
|
1641
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
1939
1642
|
}
|
|
1940
1643
|
|
|
1941
1644
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -1953,18 +1656,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
1953
1656
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
1954
1657
|
if (!initializer) return null;
|
|
1955
1658
|
let value;
|
|
1956
|
-
if (
|
|
1659
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
1957
1660
|
value = initializer.text;
|
|
1958
|
-
} else if (
|
|
1661
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
1959
1662
|
value = Number(initializer.text);
|
|
1960
|
-
} else if (initializer.kind ===
|
|
1663
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
1961
1664
|
value = true;
|
|
1962
|
-
} else if (initializer.kind ===
|
|
1665
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
1963
1666
|
value = false;
|
|
1964
|
-
} else if (initializer.kind ===
|
|
1667
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
1965
1668
|
value = null;
|
|
1966
|
-
} else if (
|
|
1967
|
-
if (initializer.operator ===
|
|
1669
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
1670
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
1968
1671
|
value = -Number(initializer.operand.text);
|
|
1969
1672
|
}
|
|
1970
1673
|
}
|
|
@@ -1986,28 +1689,28 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
1986
1689
|
|
|
1987
1690
|
// src/analyzer/class-analyzer.ts
|
|
1988
1691
|
function isObjectType(type) {
|
|
1989
|
-
return !!(type.flags &
|
|
1692
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
1990
1693
|
}
|
|
1991
1694
|
function isIntersectionType(type) {
|
|
1992
|
-
return !!(type.flags &
|
|
1695
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
1993
1696
|
}
|
|
1994
1697
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
1995
|
-
if (
|
|
1698
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
1996
1699
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
1997
1700
|
}
|
|
1998
|
-
if (
|
|
1701
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
1999
1702
|
return true;
|
|
2000
1703
|
}
|
|
2001
|
-
return
|
|
1704
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
2002
1705
|
}
|
|
2003
1706
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
2004
1707
|
if (isIntersectionType(type)) {
|
|
2005
1708
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
2006
1709
|
}
|
|
2007
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
1710
|
+
return isObjectType(type) && checker.getSignaturesOfType(type, ts5.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, ts5.SignatureKind.Construct).length === 0 && !checker.isArrayType(type) && !checker.isTupleType(type);
|
|
2008
1711
|
}
|
|
2009
1712
|
function isTypeReference(type) {
|
|
2010
|
-
return !!(type.flags &
|
|
1713
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
2011
1714
|
}
|
|
2012
1715
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
2013
1716
|
kind: "object",
|
|
@@ -2033,8 +1736,23 @@ function createAnalyzerMetadataPolicy(input, discriminator) {
|
|
|
2033
1736
|
discriminator
|
|
2034
1737
|
};
|
|
2035
1738
|
}
|
|
1739
|
+
var DEDUPLICATABLE_DIAGNOSTIC_CODES = /* @__PURE__ */ new Set([
|
|
1740
|
+
"SYNTHETIC_SETUP_FAILURE",
|
|
1741
|
+
"UNSUPPORTED_CUSTOM_TYPE_OVERRIDE"
|
|
1742
|
+
]);
|
|
1743
|
+
function deduplicateDiagnostics(diagnostics) {
|
|
1744
|
+
if (diagnostics.length <= 1) return diagnostics;
|
|
1745
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1746
|
+
return diagnostics.filter((d) => {
|
|
1747
|
+
if (!DEDUPLICATABLE_DIAGNOSTIC_CODES.has(d.code)) return true;
|
|
1748
|
+
const key = `${d.code}\0${d.message}`;
|
|
1749
|
+
if (seen.has(key)) return false;
|
|
1750
|
+
seen.add(key);
|
|
1751
|
+
return true;
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
2036
1754
|
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
2037
|
-
const analysis = (0,
|
|
1755
|
+
const analysis = (0, import_internal5.analyzeMetadataForNodeWithChecker)({
|
|
2038
1756
|
checker,
|
|
2039
1757
|
node,
|
|
2040
1758
|
logicalName,
|
|
@@ -2069,10 +1787,121 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
2069
1787
|
}
|
|
2070
1788
|
return resolvedMetadata;
|
|
2071
1789
|
}
|
|
1790
|
+
var INHERITABLE_TYPE_ANNOTATION_KINDS = /* @__PURE__ */ new Set(["format"]);
|
|
1791
|
+
function getInheritableAnnotationStringValue(annotation) {
|
|
1792
|
+
if (annotation.annotationKind === "format") return annotation.value;
|
|
1793
|
+
return void 0;
|
|
1794
|
+
}
|
|
1795
|
+
function isOverridingInheritableAnnotation(annotation) {
|
|
1796
|
+
const value = getInheritableAnnotationStringValue(annotation);
|
|
1797
|
+
if (value === void 0) return true;
|
|
1798
|
+
return value.trim().length > 0;
|
|
1799
|
+
}
|
|
1800
|
+
function collectInheritedTypeAnnotations(derivedDecl, existingAnnotations, checker, extensionRegistry) {
|
|
1801
|
+
const existingKinds = new Set(
|
|
1802
|
+
existingAnnotations.filter(isOverridingInheritableAnnotation).map((a) => a.annotationKind)
|
|
1803
|
+
);
|
|
1804
|
+
const needed = /* @__PURE__ */ new Set();
|
|
1805
|
+
for (const kind of INHERITABLE_TYPE_ANNOTATION_KINDS) {
|
|
1806
|
+
if (!existingKinds.has(kind)) needed.add(kind);
|
|
1807
|
+
}
|
|
1808
|
+
if (needed.size === 0) return [];
|
|
1809
|
+
const inherited = [];
|
|
1810
|
+
const seen = /* @__PURE__ */ new Set([derivedDecl]);
|
|
1811
|
+
const queue = [];
|
|
1812
|
+
const resolveSymbolTarget = (sym) => {
|
|
1813
|
+
if ((sym.flags & ts5.SymbolFlags.Alias) === 0) return sym;
|
|
1814
|
+
try {
|
|
1815
|
+
return checker.getAliasedSymbol(sym);
|
|
1816
|
+
} catch {
|
|
1817
|
+
return sym;
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
const isObjectShapedTypeAlias = (alias) => {
|
|
1821
|
+
const type = checker.getTypeFromTypeNode(alias.type);
|
|
1822
|
+
if ((type.flags & ts5.TypeFlags.Object) !== 0) return true;
|
|
1823
|
+
if (type.isIntersection()) return true;
|
|
1824
|
+
return false;
|
|
1825
|
+
};
|
|
1826
|
+
const enqueueCandidate = (baseDecl, fromTypeAliasRhs) => {
|
|
1827
|
+
if (seen.has(baseDecl)) return;
|
|
1828
|
+
if (ts5.isClassDeclaration(baseDecl) || ts5.isInterfaceDeclaration(baseDecl)) {
|
|
1829
|
+
seen.add(baseDecl);
|
|
1830
|
+
queue.push(baseDecl);
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1833
|
+
if (ts5.isTypeAliasDeclaration(baseDecl)) {
|
|
1834
|
+
if (!fromTypeAliasRhs && !isObjectShapedTypeAlias(baseDecl)) return;
|
|
1835
|
+
seen.add(baseDecl);
|
|
1836
|
+
queue.push(baseDecl);
|
|
1837
|
+
}
|
|
1838
|
+
};
|
|
1839
|
+
const enqueueBasesOf = (decl) => {
|
|
1840
|
+
if (ts5.isTypeAliasDeclaration(decl)) {
|
|
1841
|
+
const rhs = decl.type;
|
|
1842
|
+
if (!ts5.isTypeReferenceNode(rhs)) return;
|
|
1843
|
+
const sym = checker.getSymbolAtLocation(rhs.typeName);
|
|
1844
|
+
if (!sym) return;
|
|
1845
|
+
const target = resolveSymbolTarget(sym);
|
|
1846
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
1847
|
+
enqueueCandidate(
|
|
1848
|
+
baseDecl,
|
|
1849
|
+
/*fromTypeAliasRhs*/
|
|
1850
|
+
true
|
|
1851
|
+
);
|
|
1852
|
+
}
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
const heritageClauses = decl.heritageClauses;
|
|
1856
|
+
if (!heritageClauses) return;
|
|
1857
|
+
for (const clause of heritageClauses) {
|
|
1858
|
+
if (clause.token !== ts5.SyntaxKind.ExtendsKeyword) continue;
|
|
1859
|
+
for (const typeExpr of clause.types) {
|
|
1860
|
+
const sym = checker.getSymbolAtLocation(typeExpr.expression);
|
|
1861
|
+
if (!sym) continue;
|
|
1862
|
+
const target = resolveSymbolTarget(sym);
|
|
1863
|
+
for (const baseDecl of target.declarations ?? []) {
|
|
1864
|
+
enqueueCandidate(
|
|
1865
|
+
baseDecl,
|
|
1866
|
+
/*fromTypeAliasRhs*/
|
|
1867
|
+
false
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
enqueueBasesOf(derivedDecl);
|
|
1874
|
+
for (let queueIndex = 0; queueIndex < queue.length && needed.size > 0; queueIndex++) {
|
|
1875
|
+
const baseDecl = queue[queueIndex];
|
|
1876
|
+
if (baseDecl === void 0) continue;
|
|
1877
|
+
const baseFile = baseDecl.getSourceFile().fileName;
|
|
1878
|
+
const baseAnnotations = extractJSDocAnnotationNodes(
|
|
1879
|
+
baseDecl,
|
|
1880
|
+
baseFile,
|
|
1881
|
+
makeParseOptions(extensionRegistry)
|
|
1882
|
+
);
|
|
1883
|
+
for (const annotation of baseAnnotations) {
|
|
1884
|
+
if (!needed.has(annotation.annotationKind)) continue;
|
|
1885
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
1886
|
+
inherited.push(annotation);
|
|
1887
|
+
needed.delete(annotation.annotationKind);
|
|
1888
|
+
}
|
|
1889
|
+
if (needed.size > 0) {
|
|
1890
|
+
enqueueBasesOf(baseDecl);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
return inherited;
|
|
1894
|
+
}
|
|
1895
|
+
function extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) {
|
|
1896
|
+
const local = extractJSDocAnnotationNodes(namedDecl, file, makeParseOptions(extensionRegistry));
|
|
1897
|
+
const inherited = collectInheritedTypeAnnotations(namedDecl, local, checker, extensionRegistry);
|
|
1898
|
+
if (inherited.length === 0) return [...local];
|
|
1899
|
+
return [...local, ...inherited];
|
|
1900
|
+
}
|
|
2072
1901
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
2073
1902
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
2074
1903
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
2075
|
-
const logicalName =
|
|
1904
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
2076
1905
|
const docResult = extractJSDocParseResult(
|
|
2077
1906
|
declaration,
|
|
2078
1907
|
file,
|
|
@@ -2114,13 +1943,19 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
2114
1943
|
file,
|
|
2115
1944
|
makeParseOptions(extensionRegistry, void 0, checker, classType, classType)
|
|
2116
1945
|
);
|
|
2117
|
-
const
|
|
1946
|
+
const inheritedClassAnnotations = collectInheritedTypeAnnotations(
|
|
1947
|
+
classDecl,
|
|
1948
|
+
classDoc.annotations,
|
|
1949
|
+
checker,
|
|
1950
|
+
extensionRegistry
|
|
1951
|
+
);
|
|
1952
|
+
const annotations = [...classDoc.annotations, ...inheritedClassAnnotations];
|
|
2118
1953
|
diagnostics.push(...classDoc.diagnostics);
|
|
2119
1954
|
const visiting = /* @__PURE__ */ new Set();
|
|
2120
1955
|
const instanceMethods = [];
|
|
2121
1956
|
const staticMethods = [];
|
|
2122
1957
|
for (const member of classDecl.members) {
|
|
2123
|
-
if (
|
|
1958
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
2124
1959
|
const fieldNode = analyzeFieldToIR(
|
|
2125
1960
|
member,
|
|
2126
1961
|
checker,
|
|
@@ -2136,10 +1971,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
2136
1971
|
fields.push(fieldNode);
|
|
2137
1972
|
fieldLayouts.push({});
|
|
2138
1973
|
}
|
|
2139
|
-
} else if (
|
|
1974
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
2140
1975
|
const methodInfo = analyzeMethod(member, checker);
|
|
2141
1976
|
if (methodInfo) {
|
|
2142
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
1977
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
2143
1978
|
if (isStatic) {
|
|
2144
1979
|
staticMethods.push(methodInfo);
|
|
2145
1980
|
} else {
|
|
@@ -2171,6 +2006,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
2171
2006
|
hostType: classType
|
|
2172
2007
|
}
|
|
2173
2008
|
);
|
|
2009
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
2174
2010
|
return {
|
|
2175
2011
|
name,
|
|
2176
2012
|
...metadata !== void 0 && { metadata },
|
|
@@ -2178,7 +2014,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
2178
2014
|
fieldLayouts,
|
|
2179
2015
|
typeRegistry,
|
|
2180
2016
|
...annotations.length > 0 && { annotations },
|
|
2181
|
-
...
|
|
2017
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
2182
2018
|
instanceMethods,
|
|
2183
2019
|
staticMethods
|
|
2184
2020
|
};
|
|
@@ -2198,11 +2034,20 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
2198
2034
|
file,
|
|
2199
2035
|
makeParseOptions(extensionRegistry, void 0, checker, interfaceType, interfaceType)
|
|
2200
2036
|
);
|
|
2201
|
-
const
|
|
2037
|
+
const inheritedInterfaceAnnotations = collectInheritedTypeAnnotations(
|
|
2038
|
+
interfaceDecl,
|
|
2039
|
+
interfaceDoc.annotations,
|
|
2040
|
+
checker,
|
|
2041
|
+
extensionRegistry
|
|
2042
|
+
);
|
|
2043
|
+
const annotations = [
|
|
2044
|
+
...interfaceDoc.annotations,
|
|
2045
|
+
...inheritedInterfaceAnnotations
|
|
2046
|
+
];
|
|
2202
2047
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
2203
2048
|
const visiting = /* @__PURE__ */ new Set();
|
|
2204
2049
|
for (const member of interfaceDecl.members) {
|
|
2205
|
-
if (
|
|
2050
|
+
if (ts5.isPropertySignature(member)) {
|
|
2206
2051
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2207
2052
|
member,
|
|
2208
2053
|
checker,
|
|
@@ -2243,6 +2088,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
2243
2088
|
hostType: interfaceType
|
|
2244
2089
|
}
|
|
2245
2090
|
);
|
|
2091
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
2246
2092
|
return {
|
|
2247
2093
|
name,
|
|
2248
2094
|
...metadata !== void 0 && { metadata },
|
|
@@ -2250,7 +2096,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
2250
2096
|
fieldLayouts,
|
|
2251
2097
|
typeRegistry,
|
|
2252
2098
|
...annotations.length > 0 && { annotations },
|
|
2253
|
-
...
|
|
2099
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
2254
2100
|
instanceMethods: [],
|
|
2255
2101
|
staticMethods: []
|
|
2256
2102
|
};
|
|
@@ -2260,7 +2106,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2260
2106
|
if (members === null) {
|
|
2261
2107
|
const sourceFile = typeAlias.getSourceFile();
|
|
2262
2108
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
2263
|
-
const kindDesc =
|
|
2109
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
2264
2110
|
return {
|
|
2265
2111
|
ok: false,
|
|
2266
2112
|
kind: "not-object-like",
|
|
@@ -2295,7 +2141,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2295
2141
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
2296
2142
|
const visiting = /* @__PURE__ */ new Set();
|
|
2297
2143
|
for (const member of members) {
|
|
2298
|
-
if (
|
|
2144
|
+
if (ts5.isPropertySignature(member)) {
|
|
2299
2145
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2300
2146
|
member,
|
|
2301
2147
|
checker,
|
|
@@ -2335,6 +2181,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2335
2181
|
hostType: aliasType
|
|
2336
2182
|
}
|
|
2337
2183
|
);
|
|
2184
|
+
const deduplicatedDiagnostics = deduplicateDiagnostics(diagnostics);
|
|
2338
2185
|
return {
|
|
2339
2186
|
ok: true,
|
|
2340
2187
|
analysis: {
|
|
@@ -2344,7 +2191,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2344
2191
|
fieldLayouts: specializedFields.map(() => ({})),
|
|
2345
2192
|
typeRegistry,
|
|
2346
2193
|
...annotations.length > 0 && { annotations },
|
|
2347
|
-
...
|
|
2194
|
+
...deduplicatedDiagnostics.length > 0 && { diagnostics: deduplicatedDiagnostics },
|
|
2348
2195
|
instanceMethods: [],
|
|
2349
2196
|
staticMethods: []
|
|
2350
2197
|
}
|
|
@@ -2362,20 +2209,20 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
2362
2209
|
function getLeadingParsedTags(node) {
|
|
2363
2210
|
const sourceFile = node.getSourceFile();
|
|
2364
2211
|
const sourceText = sourceFile.getFullText();
|
|
2365
|
-
const commentRanges =
|
|
2212
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2366
2213
|
if (commentRanges === void 0) {
|
|
2367
2214
|
return [];
|
|
2368
2215
|
}
|
|
2369
2216
|
const parsedTags = [];
|
|
2370
2217
|
for (const range of commentRanges) {
|
|
2371
|
-
if (range.kind !==
|
|
2218
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
2372
2219
|
continue;
|
|
2373
2220
|
}
|
|
2374
2221
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
2375
2222
|
if (!commentText.startsWith("/**")) {
|
|
2376
2223
|
continue;
|
|
2377
2224
|
}
|
|
2378
|
-
parsedTags.push(...(0,
|
|
2225
|
+
parsedTags.push(...(0, import_internal5.parseCommentBlock)(commentText, { offset: range.pos }).tags);
|
|
2379
2226
|
}
|
|
2380
2227
|
return parsedTags;
|
|
2381
2228
|
}
|
|
@@ -2386,19 +2233,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
2386
2233
|
return null;
|
|
2387
2234
|
}
|
|
2388
2235
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
2389
|
-
(candidate) =>
|
|
2236
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
2390
2237
|
) ?? propertySymbol.declarations?.[0];
|
|
2391
2238
|
return {
|
|
2392
2239
|
declaration,
|
|
2393
2240
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
2394
|
-
optional: !!(propertySymbol.flags &
|
|
2241
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
2395
2242
|
};
|
|
2396
2243
|
}
|
|
2397
2244
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
2398
2245
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
2399
2246
|
}
|
|
2400
2247
|
function isNullishSemanticType(type) {
|
|
2401
|
-
if (type.flags & (
|
|
2248
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
2402
2249
|
return true;
|
|
2403
2250
|
}
|
|
2404
2251
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -2408,7 +2255,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2408
2255
|
return false;
|
|
2409
2256
|
}
|
|
2410
2257
|
seen.add(type);
|
|
2411
|
-
if (type.flags &
|
|
2258
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
2412
2259
|
return true;
|
|
2413
2260
|
}
|
|
2414
2261
|
if (type.isUnion()) {
|
|
@@ -2421,13 +2268,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2421
2268
|
return false;
|
|
2422
2269
|
}
|
|
2423
2270
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
2424
|
-
if (
|
|
2271
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
2425
2272
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
2426
2273
|
}
|
|
2427
|
-
if (
|
|
2274
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
2428
2275
|
return [...typeNode.members];
|
|
2429
2276
|
}
|
|
2430
|
-
if (
|
|
2277
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
2431
2278
|
const members = [];
|
|
2432
2279
|
for (const intersectionMember of typeNode.types) {
|
|
2433
2280
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -2590,7 +2437,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
2590
2437
|
}
|
|
2591
2438
|
if (propertyType.isUnion()) {
|
|
2592
2439
|
const nonNullMembers = propertyType.types.filter(
|
|
2593
|
-
(member) => !(member.flags & (
|
|
2440
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
2594
2441
|
);
|
|
2595
2442
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2596
2443
|
diagnostics.push(
|
|
@@ -2639,13 +2486,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
2639
2486
|
seen.add(type);
|
|
2640
2487
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
2641
2488
|
if (symbol !== void 0) {
|
|
2642
|
-
const aliased = symbol.flags &
|
|
2489
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
2643
2490
|
const targetSymbol = aliased ?? symbol;
|
|
2644
2491
|
const declaration = targetSymbol.declarations?.find(
|
|
2645
|
-
(candidate) =>
|
|
2492
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
2646
2493
|
);
|
|
2647
2494
|
if (declaration !== void 0) {
|
|
2648
|
-
if (
|
|
2495
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
2649
2496
|
return resolveNamedDiscriminatorDeclaration(
|
|
2650
2497
|
checker.getTypeFromTypeNode(declaration.type),
|
|
2651
2498
|
checker,
|
|
@@ -2673,7 +2520,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2673
2520
|
}
|
|
2674
2521
|
if (boundType.isUnion()) {
|
|
2675
2522
|
const nonNullMembers = boundType.types.filter(
|
|
2676
|
-
(member) => !(member.flags & (
|
|
2523
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
2677
2524
|
);
|
|
2678
2525
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2679
2526
|
diagnostics.push(
|
|
@@ -2718,7 +2565,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2718
2565
|
return null;
|
|
2719
2566
|
}
|
|
2720
2567
|
function getDeclarationName(node) {
|
|
2721
|
-
if (
|
|
2568
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
2722
2569
|
return node.name?.text ?? "anonymous";
|
|
2723
2570
|
}
|
|
2724
2571
|
return "anonymous";
|
|
@@ -2773,11 +2620,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
2773
2620
|
if (sourceTypeNode === void 0) {
|
|
2774
2621
|
return [];
|
|
2775
2622
|
}
|
|
2776
|
-
const unwrapParentheses = (typeNode) =>
|
|
2623
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
2777
2624
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
2778
|
-
const referenceTypeNode =
|
|
2625
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
2779
2626
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
2780
|
-
return
|
|
2627
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
2781
2628
|
})();
|
|
2782
2629
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
2783
2630
|
return [];
|
|
@@ -2785,7 +2632,7 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
2785
2632
|
return referenceTypeNode.typeArguments.map((argumentNode) => {
|
|
2786
2633
|
const argumentType = checker.getTypeFromTypeNode(argumentNode);
|
|
2787
2634
|
const baseSymbol = argumentType.aliasSymbol ?? argumentType.getSymbol();
|
|
2788
|
-
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags &
|
|
2635
|
+
const argumentSymbol = baseSymbol !== void 0 && baseSymbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(baseSymbol) : baseSymbol;
|
|
2789
2636
|
const argumentDecl = argumentSymbol?.declarations?.[0];
|
|
2790
2637
|
if (argumentDecl !== void 0 && argumentDecl.getSourceFile().fileName !== file) {
|
|
2791
2638
|
const argumentName = argumentSymbol?.getName() ?? baseSymbol?.getName();
|
|
@@ -2848,7 +2695,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
2848
2695
|
);
|
|
2849
2696
|
}
|
|
2850
2697
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
2851
|
-
if (!
|
|
2698
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
2852
2699
|
return null;
|
|
2853
2700
|
}
|
|
2854
2701
|
const name = prop.name.text;
|
|
@@ -2975,7 +2822,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2975
2822
|
const seen = /* @__PURE__ */ new Set();
|
|
2976
2823
|
const duplicates = /* @__PURE__ */ new Set();
|
|
2977
2824
|
for (const member of members) {
|
|
2978
|
-
if (!
|
|
2825
|
+
if (!ts5.isPropertySignature(member)) {
|
|
2979
2826
|
continue;
|
|
2980
2827
|
}
|
|
2981
2828
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -2991,7 +2838,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2991
2838
|
return [...duplicates].sort();
|
|
2992
2839
|
}
|
|
2993
2840
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
2994
|
-
if (
|
|
2841
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
2995
2842
|
return name.text;
|
|
2996
2843
|
}
|
|
2997
2844
|
return null;
|
|
@@ -3086,28 +2933,28 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
3086
2933
|
if (primitiveAlias) {
|
|
3087
2934
|
return primitiveAlias;
|
|
3088
2935
|
}
|
|
3089
|
-
if (
|
|
2936
|
+
if ((0, import_internal2._isIntegerBrandedType)(type)) {
|
|
3090
2937
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
3091
2938
|
}
|
|
3092
|
-
if (type.flags &
|
|
2939
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
3093
2940
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3094
2941
|
}
|
|
3095
|
-
if (type.flags &
|
|
2942
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
3096
2943
|
return { kind: "primitive", primitiveKind: "number" };
|
|
3097
2944
|
}
|
|
3098
|
-
if (type.flags & (
|
|
2945
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
3099
2946
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
3100
2947
|
}
|
|
3101
|
-
if (type.flags &
|
|
2948
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
3102
2949
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
3103
2950
|
}
|
|
3104
|
-
if (type.flags &
|
|
2951
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
3105
2952
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3106
2953
|
}
|
|
3107
|
-
if (type.flags &
|
|
2954
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
3108
2955
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3109
2956
|
}
|
|
3110
|
-
if (type.flags &
|
|
2957
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
3111
2958
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3112
2959
|
}
|
|
3113
2960
|
if (type.isStringLiteral()) {
|
|
@@ -3194,10 +3041,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
3194
3041
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3195
3042
|
}
|
|
3196
3043
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
3197
|
-
if (!(type.flags & (
|
|
3044
|
+
if (!(type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null)) && !(0, import_internal2._isIntegerBrandedType)(type)) {
|
|
3198
3045
|
return null;
|
|
3199
3046
|
}
|
|
3200
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3047
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
3201
3048
|
if (!aliasDecl) {
|
|
3202
3049
|
return null;
|
|
3203
3050
|
}
|
|
@@ -3208,11 +3055,18 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
3208
3055
|
...extractJSDocConstraintNodes(aliasDecl, file, makeParseOptions(extensionRegistry)),
|
|
3209
3056
|
...extractTypeAliasConstraintNodes(aliasDecl.type, checker, file, extensionRegistry)
|
|
3210
3057
|
];
|
|
3211
|
-
const
|
|
3058
|
+
const localAnnotations = extractJSDocAnnotationNodes(
|
|
3212
3059
|
aliasDecl,
|
|
3213
3060
|
file,
|
|
3214
3061
|
makeParseOptions(extensionRegistry)
|
|
3215
3062
|
);
|
|
3063
|
+
const inheritedAnnotations = collectInheritedTypeAnnotations(
|
|
3064
|
+
aliasDecl,
|
|
3065
|
+
localAnnotations,
|
|
3066
|
+
checker,
|
|
3067
|
+
extensionRegistry
|
|
3068
|
+
);
|
|
3069
|
+
const annotations = [...localAnnotations, ...inheritedAnnotations];
|
|
3216
3070
|
const metadata = resolveNodeMetadata(
|
|
3217
3071
|
metadataPolicy,
|
|
3218
3072
|
"type",
|
|
@@ -3247,8 +3101,8 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
3247
3101
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
3248
3102
|
}
|
|
3249
3103
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
3250
|
-
const typeNode = sourceNode && (
|
|
3251
|
-
if (!typeNode || !
|
|
3104
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
3105
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
3252
3106
|
return void 0;
|
|
3253
3107
|
}
|
|
3254
3108
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3269,7 +3123,7 @@ function resolveNamedTypeWithSourceRecovery(type, sourceNode, checker) {
|
|
|
3269
3123
|
return { typeName: refAliasDecl.name.text, namedDecl: refAliasDecl };
|
|
3270
3124
|
}
|
|
3271
3125
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
3272
|
-
if (!
|
|
3126
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
3273
3127
|
return false;
|
|
3274
3128
|
}
|
|
3275
3129
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3277,10 +3131,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
3277
3131
|
return false;
|
|
3278
3132
|
}
|
|
3279
3133
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
3280
|
-
return !!(resolved.flags & (
|
|
3134
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
3281
3135
|
}
|
|
3282
3136
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
3283
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3137
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
3284
3138
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
3285
3139
|
visitedAliases.add(nestedAliasDecl);
|
|
3286
3140
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -3295,22 +3149,22 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
3295
3149
|
visitedAliases
|
|
3296
3150
|
);
|
|
3297
3151
|
}
|
|
3298
|
-
if (
|
|
3152
|
+
if ((0, import_internal2._isIntegerBrandedType)(type)) {
|
|
3299
3153
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
3300
3154
|
}
|
|
3301
|
-
if (type.flags &
|
|
3155
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
3302
3156
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3303
3157
|
}
|
|
3304
|
-
if (type.flags &
|
|
3158
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
3305
3159
|
return { kind: "primitive", primitiveKind: "number" };
|
|
3306
3160
|
}
|
|
3307
|
-
if (type.flags & (
|
|
3161
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
3308
3162
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
3309
3163
|
}
|
|
3310
|
-
if (type.flags &
|
|
3164
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
3311
3165
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
3312
3166
|
}
|
|
3313
|
-
if (type.flags &
|
|
3167
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
3314
3168
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3315
3169
|
}
|
|
3316
3170
|
return resolveTypeNode(
|
|
@@ -3330,7 +3184,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3330
3184
|
let typeName = null;
|
|
3331
3185
|
let namedDecl;
|
|
3332
3186
|
if (recovered !== null) {
|
|
3333
|
-
const recoveredAliasDecl =
|
|
3187
|
+
const recoveredAliasDecl = ts5.isTypeAliasDeclaration(recovered.namedDecl) ? recovered.namedDecl : void 0;
|
|
3334
3188
|
if (recoveredAliasDecl !== void 0) {
|
|
3335
3189
|
const aliasUnderlyingType = checker.getTypeFromTypeNode(recoveredAliasDecl.type);
|
|
3336
3190
|
const isNonGeneric = recoveredAliasDecl.typeParameters === void 0 || recoveredAliasDecl.typeParameters.length === 0;
|
|
@@ -3352,13 +3206,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3352
3206
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
3353
3207
|
);
|
|
3354
3208
|
const nonNullTypes = allTypes.filter(
|
|
3355
|
-
(memberType) => !(memberType.flags & (
|
|
3209
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3356
3210
|
);
|
|
3357
3211
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
3358
3212
|
memberType,
|
|
3359
3213
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
3360
3214
|
}));
|
|
3361
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
3215
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
3362
3216
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3363
3217
|
if (namedDecl) {
|
|
3364
3218
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -3378,7 +3232,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3378
3232
|
if (existing !== void 0 && existing.type !== RESOLVING_TYPE_PLACEHOLDER) {
|
|
3379
3233
|
return { kind: "reference", name: typeName, typeArguments: [] };
|
|
3380
3234
|
}
|
|
3381
|
-
const annotations = namedDecl ?
|
|
3235
|
+
const annotations = namedDecl ? extractNamedTypeAnnotations(namedDecl, checker, file, extensionRegistry) : void 0;
|
|
3382
3236
|
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
3383
3237
|
metadataPolicy,
|
|
3384
3238
|
"type",
|
|
@@ -3405,7 +3259,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3405
3259
|
const displayName = memberDisplayNames.get(String(value));
|
|
3406
3260
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
3407
3261
|
});
|
|
3408
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
3262
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
3409
3263
|
if (isBooleanUnion2) {
|
|
3410
3264
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
3411
3265
|
const result = hasNull ? {
|
|
@@ -3497,7 +3351,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
3497
3351
|
if (type.getProperties().length > 0) {
|
|
3498
3352
|
return null;
|
|
3499
3353
|
}
|
|
3500
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
3354
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
3501
3355
|
if (!indexInfo) {
|
|
3502
3356
|
return null;
|
|
3503
3357
|
}
|
|
@@ -3545,20 +3399,53 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
3545
3399
|
}
|
|
3546
3400
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
3547
3401
|
const name = declaration.name;
|
|
3548
|
-
if (
|
|
3402
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
3549
3403
|
return false;
|
|
3550
3404
|
}
|
|
3551
|
-
if (!
|
|
3405
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
3552
3406
|
return false;
|
|
3553
3407
|
}
|
|
3554
3408
|
}
|
|
3555
3409
|
return true;
|
|
3556
3410
|
}
|
|
3411
|
+
function getPassThroughTypeAliasFromSourceNode(sourceNode, checker, extensionRegistry, resolvedTypeName) {
|
|
3412
|
+
const aliasDecl = getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
3413
|
+
if (!aliasDecl) return void 0;
|
|
3414
|
+
const aliasName = aliasDecl.name.text;
|
|
3415
|
+
if (aliasName === resolvedTypeName) return void 0;
|
|
3416
|
+
if (!ts5.isTypeReferenceNode(aliasDecl.type)) return void 0;
|
|
3417
|
+
if (!hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry)) {
|
|
3418
|
+
return void 0;
|
|
3419
|
+
}
|
|
3420
|
+
return { aliasName, aliasDecl };
|
|
3421
|
+
}
|
|
3422
|
+
function hasInheritableTypeAnnotation(aliasDecl, checker, extensionRegistry) {
|
|
3423
|
+
const file = aliasDecl.getSourceFile().fileName;
|
|
3424
|
+
const local = extractJSDocAnnotationNodes(aliasDecl, file, makeParseOptions(extensionRegistry));
|
|
3425
|
+
for (const annotation of local) {
|
|
3426
|
+
if (!INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) continue;
|
|
3427
|
+
if (!isOverridingInheritableAnnotation(annotation)) continue;
|
|
3428
|
+
return true;
|
|
3429
|
+
}
|
|
3430
|
+
const inherited = collectInheritedTypeAnnotations(aliasDecl, local, checker, extensionRegistry);
|
|
3431
|
+
for (const annotation of inherited) {
|
|
3432
|
+
if (INHERITABLE_TYPE_ANNOTATION_KINDS.has(annotation.annotationKind)) return true;
|
|
3433
|
+
}
|
|
3434
|
+
return false;
|
|
3435
|
+
}
|
|
3557
3436
|
function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
3558
3437
|
const collectedDiagnostics = diagnostics ?? [];
|
|
3559
3438
|
const typeName = getNamedTypeName(type);
|
|
3560
3439
|
const namedTypeName = typeName ?? void 0;
|
|
3561
3440
|
const namedDecl = getNamedTypeDeclaration(type);
|
|
3441
|
+
const passThroughAlias = getPassThroughTypeAliasFromSourceNode(
|
|
3442
|
+
sourceNode,
|
|
3443
|
+
checker,
|
|
3444
|
+
extensionRegistry,
|
|
3445
|
+
namedTypeName
|
|
3446
|
+
);
|
|
3447
|
+
const effectiveTypeName = passThroughAlias?.aliasName ?? namedTypeName;
|
|
3448
|
+
const effectiveNamedDecl = passThroughAlias?.aliasDecl ?? namedDecl;
|
|
3562
3449
|
const referenceTypeArguments = extractReferenceTypeArguments(
|
|
3563
3450
|
type,
|
|
3564
3451
|
checker,
|
|
@@ -3570,13 +3457,13 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3570
3457
|
extensionRegistry,
|
|
3571
3458
|
collectedDiagnostics
|
|
3572
3459
|
);
|
|
3573
|
-
const instantiatedTypeName =
|
|
3574
|
-
|
|
3460
|
+
const instantiatedTypeName = effectiveTypeName !== void 0 && referenceTypeArguments.length > 0 ? buildInstantiatedReferenceName(
|
|
3461
|
+
effectiveTypeName,
|
|
3575
3462
|
referenceTypeArguments.map((argument) => argument.tsType),
|
|
3576
3463
|
checker
|
|
3577
3464
|
) : void 0;
|
|
3578
|
-
const registryTypeName = instantiatedTypeName ??
|
|
3579
|
-
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" &&
|
|
3465
|
+
const registryTypeName = instantiatedTypeName ?? effectiveTypeName;
|
|
3466
|
+
const shouldRegisterNamedType = registryTypeName !== void 0 && !(registryTypeName === "Record" && effectiveNamedDecl?.getSourceFile().fileName !== file);
|
|
3580
3467
|
const clearNamedTypeRegistration = () => {
|
|
3581
3468
|
if (registryTypeName === void 0 || !shouldRegisterNamedType) {
|
|
3582
3469
|
return;
|
|
@@ -3597,7 +3484,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3597
3484
|
typeRegistry[registryTypeName] = {
|
|
3598
3485
|
name: registryTypeName,
|
|
3599
3486
|
type: RESOLVING_TYPE_PLACEHOLDER,
|
|
3600
|
-
provenance: provenanceForDeclaration(
|
|
3487
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
3601
3488
|
};
|
|
3602
3489
|
}
|
|
3603
3490
|
visiting.add(type);
|
|
@@ -3629,17 +3516,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3629
3516
|
clearNamedTypeRegistration();
|
|
3630
3517
|
return recordNode;
|
|
3631
3518
|
}
|
|
3632
|
-
const annotations =
|
|
3633
|
-
const metadata =
|
|
3519
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
3520
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
3634
3521
|
metadataPolicy,
|
|
3635
3522
|
"type",
|
|
3636
3523
|
registryTypeName,
|
|
3637
|
-
|
|
3524
|
+
effectiveNamedDecl,
|
|
3638
3525
|
checker,
|
|
3639
3526
|
extensionRegistry,
|
|
3640
3527
|
{
|
|
3641
3528
|
checker,
|
|
3642
|
-
declaration:
|
|
3529
|
+
declaration: effectiveNamedDecl,
|
|
3643
3530
|
subjectType: type
|
|
3644
3531
|
}
|
|
3645
3532
|
) : void 0;
|
|
@@ -3648,7 +3535,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3648
3535
|
...metadata !== void 0 && { metadata },
|
|
3649
3536
|
type: recordNode,
|
|
3650
3537
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
3651
|
-
provenance: provenanceForDeclaration(
|
|
3538
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
3652
3539
|
};
|
|
3653
3540
|
return {
|
|
3654
3541
|
kind: "reference",
|
|
@@ -3674,7 +3561,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3674
3561
|
if (!declaration) continue;
|
|
3675
3562
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
3676
3563
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
3677
|
-
const optional = !!(prop.flags &
|
|
3564
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
3678
3565
|
const propTypeNode = resolveTypeNode(
|
|
3679
3566
|
propType,
|
|
3680
3567
|
checker,
|
|
@@ -3687,7 +3574,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3687
3574
|
collectedDiagnostics
|
|
3688
3575
|
);
|
|
3689
3576
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
3690
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
3577
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
3691
3578
|
declaration,
|
|
3692
3579
|
checker,
|
|
3693
3580
|
file,
|
|
@@ -3697,7 +3584,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3697
3584
|
type,
|
|
3698
3585
|
metadataPolicy,
|
|
3699
3586
|
extensionRegistry
|
|
3700
|
-
) :
|
|
3587
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
3701
3588
|
declaration,
|
|
3702
3589
|
checker,
|
|
3703
3590
|
file,
|
|
@@ -3725,9 +3612,9 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3725
3612
|
visiting.delete(type);
|
|
3726
3613
|
const objectNode = {
|
|
3727
3614
|
kind: "object",
|
|
3728
|
-
properties:
|
|
3615
|
+
properties: effectiveNamedDecl !== void 0 && (ts5.isClassDeclaration(effectiveNamedDecl) || ts5.isInterfaceDeclaration(effectiveNamedDecl) || ts5.isTypeAliasDeclaration(effectiveNamedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
3729
3616
|
properties,
|
|
3730
|
-
|
|
3617
|
+
effectiveNamedDecl,
|
|
3731
3618
|
type,
|
|
3732
3619
|
checker,
|
|
3733
3620
|
file,
|
|
@@ -3737,17 +3624,17 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3737
3624
|
additionalProperties: true
|
|
3738
3625
|
};
|
|
3739
3626
|
if (registryTypeName !== void 0 && shouldRegisterNamedType) {
|
|
3740
|
-
const annotations =
|
|
3741
|
-
const metadata =
|
|
3627
|
+
const annotations = effectiveNamedDecl ? extractNamedTypeAnnotations(effectiveNamedDecl, checker, file, extensionRegistry) : void 0;
|
|
3628
|
+
const metadata = effectiveNamedDecl !== void 0 ? resolveNodeMetadata(
|
|
3742
3629
|
metadataPolicy,
|
|
3743
3630
|
"type",
|
|
3744
3631
|
registryTypeName,
|
|
3745
|
-
|
|
3632
|
+
effectiveNamedDecl,
|
|
3746
3633
|
checker,
|
|
3747
3634
|
extensionRegistry,
|
|
3748
3635
|
{
|
|
3749
3636
|
checker,
|
|
3750
|
-
declaration:
|
|
3637
|
+
declaration: effectiveNamedDecl,
|
|
3751
3638
|
subjectType: type
|
|
3752
3639
|
}
|
|
3753
3640
|
) : void 0;
|
|
@@ -3756,7 +3643,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3756
3643
|
...metadata !== void 0 && { metadata },
|
|
3757
3644
|
type: objectNode,
|
|
3758
3645
|
...annotations !== void 0 && annotations.length > 0 && { annotations },
|
|
3759
|
-
provenance: provenanceForDeclaration(
|
|
3646
|
+
provenance: provenanceForDeclaration(effectiveNamedDecl, file)
|
|
3760
3647
|
};
|
|
3761
3648
|
return {
|
|
3762
3649
|
kind: "reference",
|
|
@@ -3773,12 +3660,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3773
3660
|
for (const symbol of symbols) {
|
|
3774
3661
|
const declarations = symbol.declarations;
|
|
3775
3662
|
if (!declarations) continue;
|
|
3776
|
-
const classDecl = declarations.find(
|
|
3663
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
3777
3664
|
if (classDecl) {
|
|
3778
3665
|
const map = /* @__PURE__ */ new Map();
|
|
3779
3666
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
3780
3667
|
for (const member of classDecl.members) {
|
|
3781
|
-
if (
|
|
3668
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
3782
3669
|
const fieldNode = analyzeFieldToIR(
|
|
3783
3670
|
member,
|
|
3784
3671
|
checker,
|
|
@@ -3802,7 +3689,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3802
3689
|
}
|
|
3803
3690
|
return map;
|
|
3804
3691
|
}
|
|
3805
|
-
const interfaceDecl = declarations.find(
|
|
3692
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
3806
3693
|
if (interfaceDecl) {
|
|
3807
3694
|
return buildFieldNodeInfoMap(
|
|
3808
3695
|
interfaceDecl.members,
|
|
@@ -3816,7 +3703,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3816
3703
|
extensionRegistry
|
|
3817
3704
|
);
|
|
3818
3705
|
}
|
|
3819
|
-
const typeAliasDecl = declarations.find(
|
|
3706
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
3820
3707
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
3821
3708
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
3822
3709
|
return buildFieldNodeInfoMap(
|
|
@@ -3840,10 +3727,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
3840
3727
|
return void 0;
|
|
3841
3728
|
}
|
|
3842
3729
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3843
|
-
if (
|
|
3730
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
3844
3731
|
return resolvedTypeNode.elementType;
|
|
3845
3732
|
}
|
|
3846
|
-
if (
|
|
3733
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
3847
3734
|
return resolvedTypeNode.typeArguments[0];
|
|
3848
3735
|
}
|
|
3849
3736
|
return void 0;
|
|
@@ -3854,13 +3741,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
3854
3741
|
return [];
|
|
3855
3742
|
}
|
|
3856
3743
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3857
|
-
return
|
|
3744
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
3858
3745
|
}
|
|
3859
3746
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
3860
|
-
if (
|
|
3747
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3861
3748
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
3862
3749
|
}
|
|
3863
|
-
if (!
|
|
3750
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
3864
3751
|
return typeNode;
|
|
3865
3752
|
}
|
|
3866
3753
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3871,15 +3758,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
3871
3758
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
3872
3759
|
}
|
|
3873
3760
|
function isNullishTypeNode(typeNode) {
|
|
3874
|
-
if (typeNode.kind ===
|
|
3761
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
3875
3762
|
return true;
|
|
3876
3763
|
}
|
|
3877
|
-
return
|
|
3764
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
3878
3765
|
}
|
|
3879
3766
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
3880
3767
|
const map = /* @__PURE__ */ new Map();
|
|
3881
3768
|
for (const member of members) {
|
|
3882
|
-
if (
|
|
3769
|
+
if (ts5.isPropertySignature(member)) {
|
|
3883
3770
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3884
3771
|
member,
|
|
3885
3772
|
checker,
|
|
@@ -3905,7 +3792,7 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
3905
3792
|
}
|
|
3906
3793
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
3907
3794
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
3908
|
-
if (!
|
|
3795
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
3909
3796
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
3910
3797
|
const aliasName = typeNode.typeName.getText();
|
|
3911
3798
|
throw new Error(
|
|
@@ -3914,7 +3801,7 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
3914
3801
|
}
|
|
3915
3802
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
3916
3803
|
if (!aliasDecl) return [];
|
|
3917
|
-
if (
|
|
3804
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
3918
3805
|
const aliasFieldType = resolveTypeNode(
|
|
3919
3806
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
3920
3807
|
checker,
|
|
@@ -3958,14 +3845,14 @@ function getNamedTypeName(type) {
|
|
|
3958
3845
|
const symbol = type.getSymbol();
|
|
3959
3846
|
if (symbol?.declarations) {
|
|
3960
3847
|
const decl = symbol.declarations[0];
|
|
3961
|
-
if (decl && (
|
|
3962
|
-
const name =
|
|
3848
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
3849
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
3963
3850
|
if (name) return name;
|
|
3964
3851
|
}
|
|
3965
3852
|
}
|
|
3966
3853
|
const aliasSymbol = type.aliasSymbol;
|
|
3967
3854
|
if (aliasSymbol?.declarations) {
|
|
3968
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
3855
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
3969
3856
|
if (aliasDecl) {
|
|
3970
3857
|
return aliasDecl.name.text;
|
|
3971
3858
|
}
|
|
@@ -3976,24 +3863,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
3976
3863
|
const symbol = type.getSymbol();
|
|
3977
3864
|
if (symbol?.declarations) {
|
|
3978
3865
|
const decl = symbol.declarations[0];
|
|
3979
|
-
if (decl && (
|
|
3866
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
3980
3867
|
return decl;
|
|
3981
3868
|
}
|
|
3982
3869
|
}
|
|
3983
3870
|
const aliasSymbol = type.aliasSymbol;
|
|
3984
3871
|
if (aliasSymbol?.declarations) {
|
|
3985
|
-
return aliasSymbol.declarations.find(
|
|
3872
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
3986
3873
|
}
|
|
3987
3874
|
return void 0;
|
|
3988
3875
|
}
|
|
3989
3876
|
function analyzeMethod(method, checker) {
|
|
3990
|
-
if (!
|
|
3877
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
3991
3878
|
return null;
|
|
3992
3879
|
}
|
|
3993
3880
|
const name = method.name.text;
|
|
3994
3881
|
const parameters = [];
|
|
3995
3882
|
for (const param of method.parameters) {
|
|
3996
|
-
if (
|
|
3883
|
+
if (ts5.isIdentifier(param.name)) {
|
|
3997
3884
|
const paramInfo = analyzeParameter(param, checker);
|
|
3998
3885
|
parameters.push(paramInfo);
|
|
3999
3886
|
}
|
|
@@ -4004,7 +3891,7 @@ function analyzeMethod(method, checker) {
|
|
|
4004
3891
|
return { name, parameters, returnTypeNode, returnType };
|
|
4005
3892
|
}
|
|
4006
3893
|
function analyzeParameter(param, checker) {
|
|
4007
|
-
const name =
|
|
3894
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
4008
3895
|
const typeNode = param.type;
|
|
4009
3896
|
const type = checker.getTypeAtLocation(param);
|
|
4010
3897
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -4013,15 +3900,15 @@ function analyzeParameter(param, checker) {
|
|
|
4013
3900
|
}
|
|
4014
3901
|
function detectFormSpecReference(typeNode) {
|
|
4015
3902
|
if (!typeNode) return null;
|
|
4016
|
-
if (!
|
|
4017
|
-
const typeName =
|
|
3903
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
3904
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
4018
3905
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
4019
3906
|
const typeArg = typeNode.typeArguments?.[0];
|
|
4020
|
-
if (!typeArg || !
|
|
4021
|
-
if (
|
|
3907
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
3908
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
4022
3909
|
return typeArg.exprName.text;
|
|
4023
3910
|
}
|
|
4024
|
-
if (
|
|
3911
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
4025
3912
|
return typeArg.exprName.right.text;
|
|
4026
3913
|
}
|
|
4027
3914
|
return null;
|
|
@@ -4043,23 +3930,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
4043
3930
|
function createProgramContext(filePath, additionalFiles) {
|
|
4044
3931
|
const absolutePath = path.resolve(filePath);
|
|
4045
3932
|
const fileDir = path.dirname(absolutePath);
|
|
4046
|
-
const configPath =
|
|
3933
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
4047
3934
|
let compilerOptions;
|
|
4048
3935
|
let fileNames;
|
|
4049
3936
|
if (configPath) {
|
|
4050
|
-
const configFile =
|
|
3937
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
4051
3938
|
if (configFile.error) {
|
|
4052
3939
|
throw new Error(
|
|
4053
|
-
`Error reading tsconfig.json: ${
|
|
3940
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
4054
3941
|
);
|
|
4055
3942
|
}
|
|
4056
|
-
const parsed =
|
|
3943
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
4057
3944
|
configFile.config,
|
|
4058
|
-
|
|
3945
|
+
ts6.sys,
|
|
4059
3946
|
path.dirname(configPath)
|
|
4060
3947
|
);
|
|
4061
3948
|
if (parsed.errors.length > 0) {
|
|
4062
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
3949
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
4063
3950
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
4064
3951
|
}
|
|
4065
3952
|
compilerOptions = parsed.options;
|
|
@@ -4067,9 +3954,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
4067
3954
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
4068
3955
|
} else {
|
|
4069
3956
|
compilerOptions = {
|
|
4070
|
-
target:
|
|
4071
|
-
module:
|
|
4072
|
-
moduleResolution:
|
|
3957
|
+
target: ts6.ScriptTarget.ES2022,
|
|
3958
|
+
module: ts6.ModuleKind.NodeNext,
|
|
3959
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
4073
3960
|
strict: true,
|
|
4074
3961
|
skipLibCheck: true,
|
|
4075
3962
|
declaration: true
|
|
@@ -4077,7 +3964,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
4077
3964
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
4078
3965
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
4079
3966
|
}
|
|
4080
|
-
const program =
|
|
3967
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
4081
3968
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
4082
3969
|
if (!sourceFile) {
|
|
4083
3970
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -4096,19 +3983,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
4096
3983
|
result = node;
|
|
4097
3984
|
return;
|
|
4098
3985
|
}
|
|
4099
|
-
|
|
3986
|
+
ts6.forEachChild(node, visit);
|
|
4100
3987
|
}
|
|
4101
3988
|
visit(sourceFile);
|
|
4102
3989
|
return result;
|
|
4103
3990
|
}
|
|
4104
3991
|
function findClassByName(sourceFile, className) {
|
|
4105
|
-
return findNodeByName(sourceFile, className,
|
|
3992
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
4106
3993
|
}
|
|
4107
3994
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
4108
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
3995
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
4109
3996
|
}
|
|
4110
3997
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
4111
|
-
return findNodeByName(sourceFile, aliasName,
|
|
3998
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
4112
3999
|
}
|
|
4113
4000
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
4114
4001
|
if (rootType.kind === "object") {
|
|
@@ -4148,22 +4035,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
4148
4035
|
};
|
|
4149
4036
|
}
|
|
4150
4037
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
4151
|
-
if (
|
|
4038
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
4152
4039
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
4153
4040
|
}
|
|
4154
|
-
if (
|
|
4041
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
4155
4042
|
return true;
|
|
4156
4043
|
}
|
|
4157
|
-
return
|
|
4044
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
4158
4045
|
}
|
|
4159
4046
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
4160
|
-
if (
|
|
4047
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
4161
4048
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
4162
4049
|
}
|
|
4163
|
-
if (
|
|
4050
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
4164
4051
|
const propertyNames = [];
|
|
4165
4052
|
for (const member of typeNode.members) {
|
|
4166
|
-
if (!
|
|
4053
|
+
if (!ts6.isPropertySignature(member)) {
|
|
4167
4054
|
continue;
|
|
4168
4055
|
}
|
|
4169
4056
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -4173,13 +4060,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
4173
4060
|
}
|
|
4174
4061
|
return propertyNames;
|
|
4175
4062
|
}
|
|
4176
|
-
if (
|
|
4063
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
4177
4064
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
4178
4065
|
}
|
|
4179
4066
|
return null;
|
|
4180
4067
|
}
|
|
4181
4068
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
4182
|
-
if (!
|
|
4069
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
4183
4070
|
return [];
|
|
4184
4071
|
}
|
|
4185
4072
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -4369,7 +4256,7 @@ function makeFileProvenance(filePath) {
|
|
|
4369
4256
|
}
|
|
4370
4257
|
|
|
4371
4258
|
// src/generators/class-schema.ts
|
|
4372
|
-
var
|
|
4259
|
+
var ts8 = __toESM(require("typescript"), 1);
|
|
4373
4260
|
|
|
4374
4261
|
// src/metadata/collision-guards.ts
|
|
4375
4262
|
function assertUniqueSerializedNames(entries, scope) {
|
|
@@ -4538,7 +4425,7 @@ function generateJsonSchemaFromIR(ir, options) {
|
|
|
4538
4425
|
applyConstraints(ctx.defs[schemaName], typeDef.constraints, ctx);
|
|
4539
4426
|
}
|
|
4540
4427
|
if (typeDef.annotations && typeDef.annotations.length > 0) {
|
|
4541
|
-
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx);
|
|
4428
|
+
applyAnnotations(ctx.defs[schemaName], typeDef.annotations, ctx, typeDef.type);
|
|
4542
4429
|
}
|
|
4543
4430
|
}
|
|
4544
4431
|
const properties = {};
|
|
@@ -4611,7 +4498,7 @@ function generateFieldSchema(field, ctx) {
|
|
|
4611
4498
|
}
|
|
4612
4499
|
}
|
|
4613
4500
|
applyResolvedMetadata(schema, field.metadata);
|
|
4614
|
-
applyAnnotations(schema, rootAnnotations, ctx);
|
|
4501
|
+
applyAnnotations(schema, rootAnnotations, ctx, field.type);
|
|
4615
4502
|
if (itemStringSchema !== void 0) {
|
|
4616
4503
|
applyAnnotations(itemStringSchema, itemAnnotations, ctx);
|
|
4617
4504
|
}
|
|
@@ -4654,32 +4541,36 @@ function applyPathTargetedConstraints(schema, pathConstraints, ctx, typeNode) {
|
|
|
4654
4541
|
return schema;
|
|
4655
4542
|
}
|
|
4656
4543
|
if (schema.$ref) {
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
properties: propertyOverrides,
|
|
4661
|
-
...rest
|
|
4544
|
+
return {
|
|
4545
|
+
...schema,
|
|
4546
|
+
properties: propertyOverrides
|
|
4662
4547
|
};
|
|
4663
|
-
return { allOf: [refPart, overridePart] };
|
|
4664
4548
|
}
|
|
4665
4549
|
if (schema.type === "object" && schema.properties) {
|
|
4666
|
-
const missingOverrides = {};
|
|
4667
4550
|
for (const [target, overrideSchema] of Object.entries(propertyOverrides)) {
|
|
4668
|
-
if (schema.properties
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4551
|
+
if (Object.hasOwn(schema.properties, target)) {
|
|
4552
|
+
const existing = schema.properties[target];
|
|
4553
|
+
if (existing) {
|
|
4554
|
+
mergeSchemaOverride(existing, overrideSchema);
|
|
4555
|
+
continue;
|
|
4556
|
+
}
|
|
4672
4557
|
}
|
|
4558
|
+
Object.defineProperty(schema.properties, target, {
|
|
4559
|
+
value: overrideSchema,
|
|
4560
|
+
writable: true,
|
|
4561
|
+
enumerable: true,
|
|
4562
|
+
configurable: true
|
|
4563
|
+
});
|
|
4673
4564
|
}
|
|
4674
|
-
|
|
4675
|
-
return schema;
|
|
4676
|
-
}
|
|
4677
|
-
return {
|
|
4678
|
-
allOf: [schema, { properties: missingOverrides }]
|
|
4679
|
-
};
|
|
4565
|
+
return schema;
|
|
4680
4566
|
}
|
|
4681
4567
|
if (schema.allOf) {
|
|
4682
|
-
|
|
4568
|
+
const overrideMember = { properties: propertyOverrides };
|
|
4569
|
+
const flattened = tryFlattenAllOfToSiblings(schema, overrideMember);
|
|
4570
|
+
if (flattened !== void 0) {
|
|
4571
|
+
return flattened;
|
|
4572
|
+
}
|
|
4573
|
+
schema.allOf = [...schema.allOf, overrideMember];
|
|
4683
4574
|
return schema;
|
|
4684
4575
|
}
|
|
4685
4576
|
return schema;
|
|
@@ -4792,7 +4683,7 @@ function generatePropertySchema(prop, ctx) {
|
|
|
4792
4683
|
const schema = generateTypeNode(prop.type, ctx);
|
|
4793
4684
|
applyConstraints(schema, prop.constraints, ctx);
|
|
4794
4685
|
applyResolvedMetadata(schema, prop.metadata);
|
|
4795
|
-
applyAnnotations(schema, prop.annotations, ctx);
|
|
4686
|
+
applyAnnotations(schema, prop.annotations, ctx, prop.type);
|
|
4796
4687
|
return schema;
|
|
4797
4688
|
}
|
|
4798
4689
|
function generateUnionType(type, ctx) {
|
|
@@ -4895,13 +4786,20 @@ function buildPropertyOverrides(pathConstraints, typeNode, ctx) {
|
|
|
4895
4786
|
grouped.push(constraint);
|
|
4896
4787
|
byTarget.set(target, grouped);
|
|
4897
4788
|
}
|
|
4898
|
-
const overrides =
|
|
4789
|
+
const overrides = /* @__PURE__ */ Object.create(null);
|
|
4899
4790
|
for (const [target, constraints] of byTarget) {
|
|
4900
|
-
|
|
4791
|
+
const resolvedName = resolveSerializedPropertyName(target, typeNode, ctx);
|
|
4792
|
+
const schema = buildPathOverrideSchema(
|
|
4901
4793
|
constraints.map(stripLeadingPathSegment),
|
|
4902
4794
|
resolveTargetTypeNode(target, typeNode, ctx),
|
|
4903
4795
|
ctx
|
|
4904
4796
|
);
|
|
4797
|
+
Object.defineProperty(overrides, resolvedName, {
|
|
4798
|
+
value: schema,
|
|
4799
|
+
writable: true,
|
|
4800
|
+
enumerable: true,
|
|
4801
|
+
configurable: true
|
|
4802
|
+
});
|
|
4905
4803
|
}
|
|
4906
4804
|
return overrides;
|
|
4907
4805
|
}
|
|
@@ -4928,6 +4826,34 @@ function buildPathOverrideSchema(constraints, typeNode, ctx) {
|
|
|
4928
4826
|
schema.properties = buildPropertyOverrides(nestedConstraints, effectiveType, ctx);
|
|
4929
4827
|
return schema;
|
|
4930
4828
|
}
|
|
4829
|
+
function tryFlattenAllOfToSiblings(schema, overrideMember) {
|
|
4830
|
+
if (schema.allOf?.length !== 1) {
|
|
4831
|
+
return void 0;
|
|
4832
|
+
}
|
|
4833
|
+
const [soleMember] = schema.allOf;
|
|
4834
|
+
if (soleMember === void 0) {
|
|
4835
|
+
return void 0;
|
|
4836
|
+
}
|
|
4837
|
+
const { allOf: _allOf, ...outerRest } = schema;
|
|
4838
|
+
const outerKeys = new Set(Object.keys(outerRest));
|
|
4839
|
+
const memberKeys = new Set(Object.keys(soleMember));
|
|
4840
|
+
const overrideKeys = new Set(Object.keys(overrideMember));
|
|
4841
|
+
for (const key of memberKeys) {
|
|
4842
|
+
if (outerKeys.has(key) || overrideKeys.has(key)) {
|
|
4843
|
+
return void 0;
|
|
4844
|
+
}
|
|
4845
|
+
}
|
|
4846
|
+
for (const key of overrideKeys) {
|
|
4847
|
+
if (outerKeys.has(key)) {
|
|
4848
|
+
return void 0;
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
return {
|
|
4852
|
+
...outerRest,
|
|
4853
|
+
...soleMember,
|
|
4854
|
+
...overrideMember
|
|
4855
|
+
};
|
|
4856
|
+
}
|
|
4931
4857
|
function mergeSchemaOverride(target, override) {
|
|
4932
4858
|
const nullableValueBranch = getNullableUnionValueSchema(target);
|
|
4933
4859
|
if (nullableValueBranch !== void 0) {
|
|
@@ -4935,11 +4861,16 @@ function mergeSchemaOverride(target, override) {
|
|
|
4935
4861
|
return;
|
|
4936
4862
|
}
|
|
4937
4863
|
if (override.properties !== void 0) {
|
|
4938
|
-
const mergedProperties = target.properties ??
|
|
4864
|
+
const mergedProperties = target.properties ?? /* @__PURE__ */ Object.create(null);
|
|
4939
4865
|
for (const [name, propertyOverride] of Object.entries(override.properties)) {
|
|
4940
|
-
const existing = mergedProperties[name];
|
|
4866
|
+
const existing = Object.hasOwn(mergedProperties, name) ? mergedProperties[name] : void 0;
|
|
4941
4867
|
if (existing === void 0) {
|
|
4942
|
-
mergedProperties
|
|
4868
|
+
Object.defineProperty(mergedProperties, name, {
|
|
4869
|
+
value: propertyOverride,
|
|
4870
|
+
writable: true,
|
|
4871
|
+
enumerable: true,
|
|
4872
|
+
configurable: true
|
|
4873
|
+
});
|
|
4943
4874
|
} else {
|
|
4944
4875
|
mergeSchemaOverride(existing, propertyOverride);
|
|
4945
4876
|
}
|
|
@@ -4957,7 +4888,12 @@ function mergeSchemaOverride(target, override) {
|
|
|
4957
4888
|
if (key === "properties" || key === "items") {
|
|
4958
4889
|
continue;
|
|
4959
4890
|
}
|
|
4960
|
-
target
|
|
4891
|
+
Object.defineProperty(target, key, {
|
|
4892
|
+
value,
|
|
4893
|
+
writable: true,
|
|
4894
|
+
enumerable: true,
|
|
4895
|
+
configurable: true
|
|
4896
|
+
});
|
|
4961
4897
|
}
|
|
4962
4898
|
}
|
|
4963
4899
|
function stripLeadingPathSegment(constraint) {
|
|
@@ -5057,7 +4993,7 @@ function applyConstraints(schema, constraints, ctx) {
|
|
|
5057
4993
|
}
|
|
5058
4994
|
}
|
|
5059
4995
|
}
|
|
5060
|
-
function applyAnnotations(schema, annotations, ctx) {
|
|
4996
|
+
function applyAnnotations(schema, annotations, ctx, typeNode) {
|
|
5061
4997
|
for (const annotation of annotations) {
|
|
5062
4998
|
switch (annotation.annotationKind) {
|
|
5063
4999
|
case "displayName":
|
|
@@ -5070,7 +5006,7 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
5070
5006
|
schema[`${ctx.vendorPrefix}-remarks`] = annotation.value;
|
|
5071
5007
|
break;
|
|
5072
5008
|
case "defaultValue":
|
|
5073
|
-
schema.default = annotation.value;
|
|
5009
|
+
schema.default = coerceDefaultValue(annotation.value, typeNode, schema, ctx);
|
|
5074
5010
|
break;
|
|
5075
5011
|
case "format":
|
|
5076
5012
|
schema.format = annotation.value;
|
|
@@ -5095,6 +5031,34 @@ function applyAnnotations(schema, annotations, ctx) {
|
|
|
5095
5031
|
}
|
|
5096
5032
|
}
|
|
5097
5033
|
}
|
|
5034
|
+
function coerceDefaultValue(value, typeNode, emittedSchema, ctx) {
|
|
5035
|
+
if (typeNode?.kind !== "custom") {
|
|
5036
|
+
return value;
|
|
5037
|
+
}
|
|
5038
|
+
const registration = ctx.extensionRegistry?.findType(typeNode.typeId);
|
|
5039
|
+
if (registration === void 0) {
|
|
5040
|
+
return value;
|
|
5041
|
+
}
|
|
5042
|
+
if (registration.serializeDefault !== void 0) {
|
|
5043
|
+
return registration.serializeDefault(value, typeNode.payload);
|
|
5044
|
+
}
|
|
5045
|
+
const declaredType = emittedSchema["type"];
|
|
5046
|
+
if (declaredType === "string" && typeof value !== "string") {
|
|
5047
|
+
if (typeof value === "number") {
|
|
5048
|
+
if (!Number.isFinite(value)) {
|
|
5049
|
+
return value;
|
|
5050
|
+
}
|
|
5051
|
+
return String(value);
|
|
5052
|
+
}
|
|
5053
|
+
if (typeof value === "boolean") {
|
|
5054
|
+
return String(value);
|
|
5055
|
+
}
|
|
5056
|
+
if (typeof value === "bigint") {
|
|
5057
|
+
return value.toString();
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
return value;
|
|
5061
|
+
}
|
|
5098
5062
|
function generateCustomType(type, ctx) {
|
|
5099
5063
|
const registration = ctx.extensionRegistry?.findType(type.typeId);
|
|
5100
5064
|
if (registration === void 0) {
|
|
@@ -5221,25 +5185,41 @@ function assignVendorPrefixedExtensionKeywords(schema, extensionSchema, vendorPr
|
|
|
5221
5185
|
|
|
5222
5186
|
// src/extensions/registry.ts
|
|
5223
5187
|
var import_internals5 = require("@formspec/core/internals");
|
|
5224
|
-
var
|
|
5188
|
+
var import_internal6 = require("@formspec/analysis/internal");
|
|
5225
5189
|
var BUILTIN_METADATA_TAGS = /* @__PURE__ */ new Set(["apiName", "displayName"]);
|
|
5226
5190
|
function buildConstraintTagSources(extensions) {
|
|
5227
5191
|
return extensions.map((extension) => ({
|
|
5228
5192
|
extensionId: extension.extensionId,
|
|
5229
5193
|
...extension.constraintTags !== void 0 ? {
|
|
5230
5194
|
constraintTags: extension.constraintTags.map((tag) => ({
|
|
5231
|
-
tagName: (0,
|
|
5195
|
+
tagName: (0, import_internal6.normalizeFormSpecTagName)(tag.tagName)
|
|
5196
|
+
}))
|
|
5197
|
+
} : {},
|
|
5198
|
+
// Include customTypes so _validateExtensionSetup can check tsTypeNames for
|
|
5199
|
+
// unsupported built-in overrides and invalid identifier patterns.
|
|
5200
|
+
...extension.types !== void 0 ? {
|
|
5201
|
+
customTypes: extension.types.map((type) => ({
|
|
5202
|
+
// tsTypeNames: deprecated in favour of symbol-based detection, but
|
|
5203
|
+
// still required for name-based validation in _validateExtensionSetup
|
|
5204
|
+
// until the bridge is fully retired (see §synthetic-checker-retirement §4C).
|
|
5205
|
+
tsTypeNames: type.tsTypeNames ?? [type.typeName]
|
|
5232
5206
|
}))
|
|
5233
5207
|
} : {}
|
|
5234
5208
|
}));
|
|
5235
5209
|
}
|
|
5236
5210
|
function createExtensionRegistry(extensions) {
|
|
5237
|
-
const registryLog = (0,
|
|
5211
|
+
const registryLog = (0, import_internal6.getRegistryLogger)();
|
|
5238
5212
|
registryLog.debug("createExtensionRegistry: constructing", {
|
|
5239
5213
|
extensionCount: extensions.length,
|
|
5240
5214
|
extensionIds: extensions.map((e) => e.extensionId)
|
|
5241
5215
|
});
|
|
5242
|
-
const
|
|
5216
|
+
const extensionTagSources = buildConstraintTagSources(extensions);
|
|
5217
|
+
const setupDiagnostics = (0, import_internal6._validateExtensionSetup)(extensionTagSources);
|
|
5218
|
+
(0, import_internal6.logSetupDiagnostics)(registryLog, {
|
|
5219
|
+
diagnosticCount: setupDiagnostics.length,
|
|
5220
|
+
codes: setupDiagnostics.map((d) => d.kind)
|
|
5221
|
+
});
|
|
5222
|
+
const reservedTagSources = extensionTagSources;
|
|
5243
5223
|
let symbolMap = /* @__PURE__ */ new Map();
|
|
5244
5224
|
const typeMap = /* @__PURE__ */ new Map();
|
|
5245
5225
|
const typeNameMap = /* @__PURE__ */ new Map();
|
|
@@ -5306,7 +5286,7 @@ function createExtensionRegistry(extensions) {
|
|
|
5306
5286
|
}
|
|
5307
5287
|
if (ext.constraintTags !== void 0) {
|
|
5308
5288
|
for (const tag of ext.constraintTags) {
|
|
5309
|
-
const canonicalTagName = (0,
|
|
5289
|
+
const canonicalTagName = (0, import_internal6.normalizeFormSpecTagName)(tag.tagName);
|
|
5310
5290
|
if (constraintTagMap.has(canonicalTagName)) {
|
|
5311
5291
|
throw new Error(`Duplicate custom constraint tag: "@${canonicalTagName}"`);
|
|
5312
5292
|
}
|
|
@@ -5331,7 +5311,7 @@ function createExtensionRegistry(extensions) {
|
|
|
5331
5311
|
throw new Error(`Duplicate metadata slot ID: "${slot.slotId}"`);
|
|
5332
5312
|
}
|
|
5333
5313
|
metadataSlotMap.set(slot.slotId, true);
|
|
5334
|
-
const canonicalTagName = (0,
|
|
5314
|
+
const canonicalTagName = (0, import_internal6.normalizeFormSpecTagName)(slot.tagName);
|
|
5335
5315
|
if (slot.allowBare === false && (slot.qualifiers?.length ?? 0) === 0) {
|
|
5336
5316
|
throw new Error(
|
|
5337
5317
|
`Metadata tag "@${canonicalTagName}" must allow bare usage or declare at least one qualifier.`
|
|
@@ -5358,7 +5338,7 @@ function createExtensionRegistry(extensions) {
|
|
|
5358
5338
|
`Metadata tag "@${canonicalTagName}" conflicts with existing FormSpec tag "@${(0, import_internals5.normalizeConstraintTagName)(canonicalTagName)}".`
|
|
5359
5339
|
);
|
|
5360
5340
|
}
|
|
5361
|
-
const existingTag = (0,
|
|
5341
|
+
const existingTag = (0, import_internal6.getTagDefinition)(canonicalTagName, reservedTagSources);
|
|
5362
5342
|
if (existingTag !== null) {
|
|
5363
5343
|
throw BUILTIN_METADATA_TAGS.has(existingTag.canonicalName) ? new Error(
|
|
5364
5344
|
`Metadata tag "@${canonicalTagName}" conflicts with built-in metadata tags.`
|
|
@@ -5376,10 +5356,12 @@ function createExtensionRegistry(extensions) {
|
|
|
5376
5356
|
constraintTagCount: constraintTagMap.size,
|
|
5377
5357
|
broadeningCount: builtinBroadeningMap.size,
|
|
5378
5358
|
annotationCount: annotationMap.size,
|
|
5379
|
-
metadataSlotCount: metadataSlotMap.size
|
|
5359
|
+
metadataSlotCount: metadataSlotMap.size,
|
|
5360
|
+
setupDiagnosticCount: setupDiagnostics.length
|
|
5380
5361
|
});
|
|
5381
5362
|
return {
|
|
5382
5363
|
extensions,
|
|
5364
|
+
setupDiagnostics,
|
|
5383
5365
|
findType: (typeId) => typeMap.get(typeId),
|
|
5384
5366
|
findTypeByName: (typeName) => typeNameMap.get(typeName),
|
|
5385
5367
|
findTypeByBrand: (brand) => brandMap.get(brand),
|
|
@@ -5388,14 +5370,14 @@ function createExtensionRegistry(extensions) {
|
|
|
5388
5370
|
symbolMap = map;
|
|
5389
5371
|
},
|
|
5390
5372
|
findConstraint: (constraintId) => constraintMap.get(constraintId),
|
|
5391
|
-
findConstraintTag: (tagName) => constraintTagMap.get((0,
|
|
5373
|
+
findConstraintTag: (tagName) => constraintTagMap.get((0, import_internal6.normalizeFormSpecTagName)(tagName)),
|
|
5392
5374
|
findBuiltinConstraintBroadening: (typeId, tagName) => builtinBroadeningMap.get(`${typeId}:${tagName}`),
|
|
5393
5375
|
findAnnotation: (annotationId) => annotationMap.get(annotationId)
|
|
5394
5376
|
};
|
|
5395
5377
|
}
|
|
5396
5378
|
|
|
5397
5379
|
// src/extensions/symbol-registry.ts
|
|
5398
|
-
var
|
|
5380
|
+
var ts7 = __toESM(require("typescript"), 1);
|
|
5399
5381
|
var path2 = __toESM(require("path"), 1);
|
|
5400
5382
|
|
|
5401
5383
|
// src/ui-schema/schema.ts
|
|
@@ -5656,9 +5638,9 @@ function collectFieldNameMap(elements) {
|
|
|
5656
5638
|
}
|
|
5657
5639
|
|
|
5658
5640
|
// src/validate/constraint-validator.ts
|
|
5659
|
-
var
|
|
5641
|
+
var import_internal7 = require("@formspec/analysis/internal");
|
|
5660
5642
|
function validateFieldNode(ctx, field) {
|
|
5661
|
-
const analysis = (0,
|
|
5643
|
+
const analysis = (0, import_internal7.analyzeConstraintTargets)(
|
|
5662
5644
|
field.name,
|
|
5663
5645
|
field.type,
|
|
5664
5646
|
field.constraints,
|
|
@@ -5676,7 +5658,7 @@ function validateFieldNode(ctx, field) {
|
|
|
5676
5658
|
}
|
|
5677
5659
|
function validateObjectProperty(ctx, parentName, property) {
|
|
5678
5660
|
const qualifiedName = `${parentName}.${property.name}`;
|
|
5679
|
-
const analysis = (0,
|
|
5661
|
+
const analysis = (0, import_internal7.analyzeConstraintTargets)(
|
|
5680
5662
|
qualifiedName,
|
|
5681
5663
|
property.type,
|
|
5682
5664
|
property.constraints,
|
|
@@ -5788,7 +5770,7 @@ function formatLocation(location) {
|
|
|
5788
5770
|
}
|
|
5789
5771
|
function resolveStaticOptions(options) {
|
|
5790
5772
|
const legacyRegistry = options.extensionRegistry;
|
|
5791
|
-
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
5773
|
+
const configRegistry = legacyRegistry === void 0 && options.config?.extensions !== void 0 && options.config.extensions.length > 0 ? createExtensionRegistry(options.config.extensions) : void 0;
|
|
5792
5774
|
return {
|
|
5793
5775
|
extensionRegistry: legacyRegistry ?? configRegistry,
|
|
5794
5776
|
// eslint-disable-next-line @typescript-eslint/no-deprecated -- migration bridge reads deprecated fields
|