@formspec/build 0.1.0-alpha.49 → 0.1.0-alpha.50
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/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/cli.cjs +381 -374
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +339 -334
- package/dist/cli.js.map +1 -1
- package/dist/extensions/resolve-custom-type.d.ts +37 -0
- package/dist/extensions/resolve-custom-type.d.ts.map +1 -0
- package/dist/extensions/symbol-registry.d.ts.map +1 -1
- package/dist/extensions/ts-type-utils.d.ts +40 -0
- package/dist/extensions/ts-type-utils.d.ts.map +1 -0
- package/dist/index.cjs +359 -365
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +328 -334
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +332 -333
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +297 -298
- package/dist/internals.js.map +1 -1
- package/package.json +2 -2
package/dist/internals.cjs
CHANGED
|
@@ -847,28 +847,147 @@ 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_internal3 = 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_internal2 = require("@formspec/analysis/internal");
|
|
863
863
|
var import_internals3 = require("@formspec/core/internals");
|
|
864
864
|
var import_internals4 = require("@formspec/core/internals");
|
|
865
|
+
|
|
866
|
+
// src/extensions/resolve-custom-type.ts
|
|
867
|
+
var ts2 = __toESM(require("typescript"), 1);
|
|
868
|
+
var import_internal = require("@formspec/analysis/internal");
|
|
869
|
+
|
|
870
|
+
// src/extensions/ts-type-utils.ts
|
|
871
|
+
var ts = __toESM(require("typescript"), 1);
|
|
872
|
+
function collectBrandIdentifiers(type) {
|
|
873
|
+
if (!type.isIntersection()) {
|
|
874
|
+
return [];
|
|
875
|
+
}
|
|
876
|
+
const brands = [];
|
|
877
|
+
for (const prop of type.getProperties()) {
|
|
878
|
+
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
879
|
+
if (decl === void 0) continue;
|
|
880
|
+
if (!ts.isPropertySignature(decl) && !ts.isPropertyDeclaration(decl)) continue;
|
|
881
|
+
if (!ts.isComputedPropertyName(decl.name)) continue;
|
|
882
|
+
if (!ts.isIdentifier(decl.name.expression)) continue;
|
|
883
|
+
brands.push(decl.name.expression.text);
|
|
884
|
+
}
|
|
885
|
+
return brands;
|
|
886
|
+
}
|
|
887
|
+
function resolveCanonicalSymbol(type, checker) {
|
|
888
|
+
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
889
|
+
if (raw === void 0) return void 0;
|
|
890
|
+
return raw.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
891
|
+
}
|
|
892
|
+
function extractTypeNodeFromSource(sourceNode) {
|
|
893
|
+
if (ts.isPropertyDeclaration(sourceNode) || ts.isPropertySignature(sourceNode) || ts.isParameter(sourceNode) || ts.isTypeAliasDeclaration(sourceNode)) {
|
|
894
|
+
return sourceNode.type;
|
|
895
|
+
}
|
|
896
|
+
if (ts.isTypeNode(sourceNode)) {
|
|
897
|
+
return sourceNode;
|
|
898
|
+
}
|
|
899
|
+
return void 0;
|
|
900
|
+
}
|
|
901
|
+
function resolveAliasedSymbol(symbol, checker) {
|
|
902
|
+
if (symbol === void 0) return void 0;
|
|
903
|
+
return symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
904
|
+
}
|
|
905
|
+
function getTypeAliasDeclarationFromTypeReference(typeNode, checker) {
|
|
906
|
+
const symbol = checker.getSymbolAtLocation(typeNode.typeName);
|
|
907
|
+
return resolveAliasedSymbol(symbol, checker)?.declarations?.find(ts.isTypeAliasDeclaration);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// src/extensions/resolve-custom-type.ts
|
|
911
|
+
function getTypeNodeRegistrationName(typeNode) {
|
|
912
|
+
if (ts2.isTypeReferenceNode(typeNode)) {
|
|
913
|
+
return ts2.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : typeNode.typeName.right.text;
|
|
914
|
+
}
|
|
915
|
+
if (ts2.isParenthesizedTypeNode(typeNode)) {
|
|
916
|
+
return getTypeNodeRegistrationName(typeNode.type);
|
|
917
|
+
}
|
|
918
|
+
if (typeNode.kind === ts2.SyntaxKind.BigIntKeyword || typeNode.kind === ts2.SyntaxKind.StringKeyword || typeNode.kind === ts2.SyntaxKind.NumberKeyword || typeNode.kind === ts2.SyntaxKind.BooleanKeyword) {
|
|
919
|
+
return typeNode.getText();
|
|
920
|
+
}
|
|
921
|
+
return null;
|
|
922
|
+
}
|
|
923
|
+
function resolveByNameFromTypeNode(typeNode, registry, checker) {
|
|
924
|
+
if (ts2.isParenthesizedTypeNode(typeNode)) {
|
|
925
|
+
return resolveByNameFromTypeNode(typeNode.type, registry, checker);
|
|
926
|
+
}
|
|
927
|
+
const typeName = getTypeNodeRegistrationName(typeNode);
|
|
928
|
+
if (typeName !== null) {
|
|
929
|
+
const byName = registry.findTypeByName(typeName);
|
|
930
|
+
if (byName !== void 0) {
|
|
931
|
+
return byName;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (ts2.isTypeReferenceNode(typeNode) && ts2.isIdentifier(typeNode.typeName)) {
|
|
935
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
936
|
+
if (aliasDecl !== void 0) {
|
|
937
|
+
return resolveByNameFromTypeNode(aliasDecl.type, registry, checker);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
942
|
+
function resolveCustomTypeFromTsType(type, checker, registry, sourceNode) {
|
|
943
|
+
if (registry === void 0) {
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
const stripped = (0, import_internal.stripNullishUnion)(type);
|
|
947
|
+
if (sourceNode !== void 0) {
|
|
948
|
+
const typeNode = extractTypeNodeFromSource(sourceNode);
|
|
949
|
+
if (typeNode !== void 0) {
|
|
950
|
+
const byName = resolveByNameFromTypeNode(typeNode, registry, checker);
|
|
951
|
+
if (byName !== null) {
|
|
952
|
+
return byName;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
} else {
|
|
956
|
+
const typeName = (stripped.aliasSymbol ?? stripped.getSymbol())?.getName();
|
|
957
|
+
if (typeName !== void 0) {
|
|
958
|
+
const byName = registry.findTypeByName(typeName);
|
|
959
|
+
if (byName !== void 0) {
|
|
960
|
+
return byName;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
const canonical = resolveCanonicalSymbol(stripped, checker);
|
|
965
|
+
if (canonical !== void 0) {
|
|
966
|
+
const bySymbol = registry.findTypeBySymbol(canonical);
|
|
967
|
+
if (bySymbol !== void 0) {
|
|
968
|
+
return bySymbol;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
for (const brand of collectBrandIdentifiers(stripped)) {
|
|
972
|
+
const byBrand = registry.findTypeByBrand(brand);
|
|
973
|
+
if (byBrand !== void 0) {
|
|
974
|
+
return byBrand;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
return null;
|
|
978
|
+
}
|
|
979
|
+
function customTypeIdFromLookup(result) {
|
|
980
|
+
return `${result.extensionId}/${result.registration.typeName}`;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// src/analyzer/tsdoc-parser.ts
|
|
865
984
|
function sharedTagValueOptions(options) {
|
|
866
985
|
return {
|
|
867
986
|
...options?.extensionRegistry !== void 0 ? { registry: options.extensionRegistry } : {},
|
|
868
987
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
869
988
|
};
|
|
870
989
|
}
|
|
871
|
-
var SYNTHETIC_TYPE_FORMAT_FLAGS =
|
|
990
|
+
var SYNTHETIC_TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
872
991
|
function getExtensionTypeNames(registry) {
|
|
873
992
|
if (registry === void 0) {
|
|
874
993
|
return /* @__PURE__ */ new Set();
|
|
@@ -882,23 +1001,23 @@ function getExtensionTypeNames(registry) {
|
|
|
882
1001
|
function collectImportedNames(sourceFile) {
|
|
883
1002
|
const importedNames = /* @__PURE__ */ new Set();
|
|
884
1003
|
for (const statement of sourceFile.statements) {
|
|
885
|
-
if (
|
|
1004
|
+
if (ts3.isImportDeclaration(statement) && statement.importClause !== void 0) {
|
|
886
1005
|
const clause = statement.importClause;
|
|
887
1006
|
if (clause.name !== void 0) {
|
|
888
1007
|
importedNames.add(clause.name.text);
|
|
889
1008
|
}
|
|
890
1009
|
if (clause.namedBindings !== void 0) {
|
|
891
|
-
if (
|
|
1010
|
+
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
892
1011
|
for (const specifier of clause.namedBindings.elements) {
|
|
893
1012
|
importedNames.add(specifier.name.text);
|
|
894
1013
|
}
|
|
895
|
-
} else if (
|
|
1014
|
+
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
896
1015
|
importedNames.add(clause.namedBindings.name.text);
|
|
897
1016
|
}
|
|
898
1017
|
}
|
|
899
1018
|
continue;
|
|
900
1019
|
}
|
|
901
|
-
if (
|
|
1020
|
+
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
902
1021
|
importedNames.add(statement.name.text);
|
|
903
1022
|
}
|
|
904
1023
|
}
|
|
@@ -906,13 +1025,13 @@ function collectImportedNames(sourceFile) {
|
|
|
906
1025
|
}
|
|
907
1026
|
function isNonReferenceIdentifier(node) {
|
|
908
1027
|
const parent = node.parent;
|
|
909
|
-
if ((
|
|
1028
|
+
if ((ts3.isBindingElement(parent) || ts3.isClassDeclaration(parent) || ts3.isEnumDeclaration(parent) || ts3.isEnumMember(parent) || ts3.isFunctionDeclaration(parent) || ts3.isFunctionExpression(parent) || ts3.isImportClause(parent) || ts3.isImportEqualsDeclaration(parent) || ts3.isImportSpecifier(parent) || ts3.isInterfaceDeclaration(parent) || ts3.isMethodDeclaration(parent) || ts3.isMethodSignature(parent) || ts3.isModuleDeclaration(parent) || ts3.isNamespaceExport(parent) || ts3.isNamespaceImport(parent) || ts3.isParameter(parent) || ts3.isPropertyDeclaration(parent) || ts3.isPropertySignature(parent) || ts3.isSetAccessorDeclaration(parent) || ts3.isGetAccessorDeclaration(parent) || ts3.isTypeAliasDeclaration(parent) || ts3.isTypeParameterDeclaration(parent) || ts3.isVariableDeclaration(parent)) && parent.name === node) {
|
|
910
1029
|
return true;
|
|
911
1030
|
}
|
|
912
|
-
if ((
|
|
1031
|
+
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
913
1032
|
return true;
|
|
914
1033
|
}
|
|
915
|
-
if (
|
|
1034
|
+
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
916
1035
|
return true;
|
|
917
1036
|
}
|
|
918
1037
|
return false;
|
|
@@ -926,11 +1045,11 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
926
1045
|
if (referencesImportedName) {
|
|
927
1046
|
return;
|
|
928
1047
|
}
|
|
929
|
-
if (
|
|
1048
|
+
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
930
1049
|
referencesImportedName = true;
|
|
931
1050
|
return;
|
|
932
1051
|
}
|
|
933
|
-
|
|
1052
|
+
ts3.forEachChild(node, visit);
|
|
934
1053
|
};
|
|
935
1054
|
visit(statement);
|
|
936
1055
|
return referencesImportedName;
|
|
@@ -941,9 +1060,9 @@ function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
|
941
1060
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
942
1061
|
);
|
|
943
1062
|
return sourceFile.statements.filter((statement) => {
|
|
944
|
-
if (
|
|
945
|
-
if (
|
|
946
|
-
if (
|
|
1063
|
+
if (ts3.isImportDeclaration(statement)) return false;
|
|
1064
|
+
if (ts3.isImportEqualsDeclaration(statement)) return false;
|
|
1065
|
+
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
947
1066
|
return false;
|
|
948
1067
|
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
949
1068
|
return false;
|
|
@@ -975,7 +1094,7 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
975
1094
|
pushUniqueCompilerDiagnostics(diagnostics, compilerDiagnostics);
|
|
976
1095
|
return;
|
|
977
1096
|
}
|
|
978
|
-
const constraintNode = (0,
|
|
1097
|
+
const constraintNode = (0, import_internal2.parseConstraintTagValue)(
|
|
979
1098
|
tagName,
|
|
980
1099
|
text,
|
|
981
1100
|
provenance,
|
|
@@ -1025,12 +1144,12 @@ function supportsConstraintCapability(type, checker, capability) {
|
|
|
1025
1144
|
if (capability === void 0) {
|
|
1026
1145
|
return true;
|
|
1027
1146
|
}
|
|
1028
|
-
if ((0,
|
|
1147
|
+
if ((0, import_internal2.hasTypeSemanticCapability)(type, checker, capability)) {
|
|
1029
1148
|
return true;
|
|
1030
1149
|
}
|
|
1031
1150
|
if (capability === "string-like") {
|
|
1032
1151
|
const itemType = getArrayElementType(type, checker);
|
|
1033
|
-
return itemType !== null && (0,
|
|
1152
|
+
return itemType !== null && (0, import_internal2.hasTypeSemanticCapability)(itemType, checker, capability);
|
|
1034
1153
|
}
|
|
1035
1154
|
return false;
|
|
1036
1155
|
}
|
|
@@ -1041,7 +1160,7 @@ function stripHintNullishUnion(type) {
|
|
|
1041
1160
|
return type;
|
|
1042
1161
|
}
|
|
1043
1162
|
const nonNullish = type.types.filter(
|
|
1044
|
-
(member) => (member.flags & (
|
|
1163
|
+
(member) => (member.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) === 0
|
|
1045
1164
|
);
|
|
1046
1165
|
if (nonNullish.length === 1 && nonNullish[0] !== void 0) {
|
|
1047
1166
|
return nonNullish[0];
|
|
@@ -1057,10 +1176,10 @@ function isUserEmittableHintProperty(property, declaration) {
|
|
|
1057
1176
|
}
|
|
1058
1177
|
if ("name" in declaration && declaration.name !== void 0) {
|
|
1059
1178
|
const name = declaration.name;
|
|
1060
|
-
if (
|
|
1179
|
+
if (ts3.isComputedPropertyName(name) || ts3.isPrivateIdentifier(name)) {
|
|
1061
1180
|
return false;
|
|
1062
1181
|
}
|
|
1063
|
-
if (!
|
|
1182
|
+
if (!ts3.isIdentifier(name) && !ts3.isStringLiteral(name) && !ts3.isNumericLiteral(name)) {
|
|
1064
1183
|
return false;
|
|
1065
1184
|
}
|
|
1066
1185
|
}
|
|
@@ -1076,7 +1195,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
1076
1195
|
if (isCallableType(stripped)) {
|
|
1077
1196
|
return;
|
|
1078
1197
|
}
|
|
1079
|
-
if (!(0,
|
|
1198
|
+
if (!(0, import_internal2.hasTypeSemanticCapability)(stripped, checker, "object-like")) {
|
|
1080
1199
|
return;
|
|
1081
1200
|
}
|
|
1082
1201
|
for (const property of stripped.getProperties()) {
|
|
@@ -1094,7 +1213,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
1094
1213
|
continue;
|
|
1095
1214
|
}
|
|
1096
1215
|
const strippedPropertyType = stripHintNullishUnion(propertyType);
|
|
1097
|
-
if (!isCallableType(strippedPropertyType) && (0,
|
|
1216
|
+
if (!isCallableType(strippedPropertyType) && (0, import_internal2.hasTypeSemanticCapability)(strippedPropertyType, checker, "object-like")) {
|
|
1098
1217
|
visit(strippedPropertyType, path3, depth + 1);
|
|
1099
1218
|
}
|
|
1100
1219
|
}
|
|
@@ -1103,7 +1222,7 @@ function collectObjectSubfieldCandidates(type, checker, capability) {
|
|
|
1103
1222
|
return out;
|
|
1104
1223
|
}
|
|
1105
1224
|
function buildPathTargetHint(subjectType, checker, capability, tagName, argumentText) {
|
|
1106
|
-
if (!(0,
|
|
1225
|
+
if (!(0, import_internal2.hasTypeSemanticCapability)(subjectType, checker, "object-like")) {
|
|
1107
1226
|
return null;
|
|
1108
1227
|
}
|
|
1109
1228
|
const candidates = collectObjectSubfieldCandidates(subjectType, checker, capability);
|
|
@@ -1214,11 +1333,11 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1214
1333
|
if (checker === void 0 || subjectType === void 0) {
|
|
1215
1334
|
return [];
|
|
1216
1335
|
}
|
|
1217
|
-
const placement = (0,
|
|
1336
|
+
const placement = (0, import_internal2.resolveDeclarationPlacement)(node);
|
|
1218
1337
|
if (placement === null) {
|
|
1219
1338
|
return [];
|
|
1220
1339
|
}
|
|
1221
|
-
const definition = (0,
|
|
1340
|
+
const definition = (0, import_internal2.getTagDefinition)(tagName, options?.extensionRegistry?.extensions);
|
|
1222
1341
|
if (definition === null) {
|
|
1223
1342
|
return [];
|
|
1224
1343
|
}
|
|
@@ -1232,7 +1351,8 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1232
1351
|
];
|
|
1233
1352
|
}
|
|
1234
1353
|
const target = parsedTag?.target ?? null;
|
|
1235
|
-
|
|
1354
|
+
let evaluatedType = subjectType;
|
|
1355
|
+
let targetLabel = node.getText(sourceFile);
|
|
1236
1356
|
if (target !== null) {
|
|
1237
1357
|
if (target.kind !== "path") {
|
|
1238
1358
|
return [
|
|
@@ -1252,7 +1372,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1252
1372
|
)
|
|
1253
1373
|
];
|
|
1254
1374
|
}
|
|
1255
|
-
const resolution = (0,
|
|
1375
|
+
const resolution = (0, import_internal2.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
1256
1376
|
if (resolution.kind === "missing-property") {
|
|
1257
1377
|
return [
|
|
1258
1378
|
makeDiagnostic(
|
|
@@ -1272,29 +1392,30 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1272
1392
|
)
|
|
1273
1393
|
];
|
|
1274
1394
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
`Target "${target.rawText}": constraint "${tagName}" is only valid on ${capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`,
|
|
1282
|
-
provenance
|
|
1283
|
-
)
|
|
1284
|
-
];
|
|
1395
|
+
evaluatedType = resolution.type;
|
|
1396
|
+
targetLabel = target.rawText;
|
|
1397
|
+
}
|
|
1398
|
+
const hasBroadening = (() => {
|
|
1399
|
+
if (target === null) {
|
|
1400
|
+
return hasBuiltinConstraintBroadening(tagName, options);
|
|
1285
1401
|
}
|
|
1286
|
-
|
|
1402
|
+
const registry = options?.extensionRegistry;
|
|
1403
|
+
if (registry === void 0) return false;
|
|
1404
|
+
const resolved = resolveCustomTypeFromTsType(evaluatedType, checker, registry);
|
|
1405
|
+
return resolved !== null && registry.findBuiltinConstraintBroadening(customTypeIdFromLookup(resolved), tagName) !== void 0;
|
|
1406
|
+
})();
|
|
1407
|
+
if (!hasBroadening) {
|
|
1287
1408
|
const requiredCapability = definition.capabilities[0];
|
|
1288
|
-
if (requiredCapability !== void 0 && !supportsConstraintCapability(
|
|
1289
|
-
const actualType = checker.typeToString(
|
|
1290
|
-
const baseMessage = `Target "${
|
|
1291
|
-
const hint = buildPathTargetHint(
|
|
1409
|
+
if (requiredCapability !== void 0 && !supportsConstraintCapability(evaluatedType, checker, requiredCapability)) {
|
|
1410
|
+
const actualType = checker.typeToString(evaluatedType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
1411
|
+
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`;
|
|
1412
|
+
const hint = target === null ? buildPathTargetHint(
|
|
1292
1413
|
subjectType,
|
|
1293
1414
|
checker,
|
|
1294
1415
|
requiredCapability,
|
|
1295
1416
|
tagName,
|
|
1296
1417
|
parsedTag?.argumentText
|
|
1297
|
-
);
|
|
1418
|
+
) : null;
|
|
1298
1419
|
return [
|
|
1299
1420
|
makeDiagnostic(
|
|
1300
1421
|
"TYPE_MISMATCH",
|
|
@@ -1317,7 +1438,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1317
1438
|
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
1318
1439
|
const hostType = options?.hostType ?? subjectType;
|
|
1319
1440
|
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
1320
|
-
const result = (0,
|
|
1441
|
+
const result = (0, import_internal2.checkSyntheticTagApplication)({
|
|
1321
1442
|
tagName,
|
|
1322
1443
|
placement,
|
|
1323
1444
|
hostType: hostTypeText,
|
|
@@ -1368,10 +1489,10 @@ var parseResultCache = /* @__PURE__ */ new Map();
|
|
|
1368
1489
|
function getExtensionTagNames(options) {
|
|
1369
1490
|
return [
|
|
1370
1491
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
1371
|
-
(extension) => (extension.constraintTags ?? []).map((tag) => (0,
|
|
1492
|
+
(extension) => (extension.constraintTags ?? []).map((tag) => (0, import_internal2.normalizeFormSpecTagName)(tag.tagName))
|
|
1372
1493
|
) ?? [],
|
|
1373
1494
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
1374
|
-
(extension) => (extension.metadataSlots ?? []).map((slot) => (0,
|
|
1495
|
+
(extension) => (extension.metadataSlots ?? []).map((slot) => (0, import_internal2.normalizeFormSpecTagName)(slot.tagName))
|
|
1375
1496
|
) ?? []
|
|
1376
1497
|
].sort();
|
|
1377
1498
|
}
|
|
@@ -1383,9 +1504,9 @@ function getExtensionRegistryCacheKey(registry) {
|
|
|
1383
1504
|
(extension) => JSON.stringify({
|
|
1384
1505
|
extensionId: extension.extensionId,
|
|
1385
1506
|
typeNames: extension.types?.map((type) => type.typeName) ?? [],
|
|
1386
|
-
constraintTags: extension.constraintTags?.map((tag) => (0,
|
|
1507
|
+
constraintTags: extension.constraintTags?.map((tag) => (0, import_internal2.normalizeFormSpecTagName)(tag.tagName)) ?? [],
|
|
1387
1508
|
metadataSlots: extension.metadataSlots?.map((slot) => ({
|
|
1388
|
-
tagName: (0,
|
|
1509
|
+
tagName: (0, import_internal2.normalizeFormSpecTagName)(slot.tagName),
|
|
1389
1510
|
declarationKinds: [...slot.declarationKinds].sort(),
|
|
1390
1511
|
allowBare: slot.allowBare !== false,
|
|
1391
1512
|
qualifiers: (slot.qualifiers ?? []).map((qualifier) => ({
|
|
@@ -1428,12 +1549,12 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1428
1549
|
const sourceText = sourceFile.getFullText();
|
|
1429
1550
|
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
1430
1551
|
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
1431
|
-
const commentRanges =
|
|
1552
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1432
1553
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
1433
1554
|
const extensionTagNames = getExtensionTagNames(options);
|
|
1434
1555
|
if (commentRanges) {
|
|
1435
1556
|
for (const range of commentRanges) {
|
|
1436
|
-
if (range.kind !==
|
|
1557
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) {
|
|
1437
1558
|
continue;
|
|
1438
1559
|
}
|
|
1439
1560
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
@@ -1441,7 +1562,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1441
1562
|
continue;
|
|
1442
1563
|
}
|
|
1443
1564
|
const extensions = options?.extensionRegistry?.extensions;
|
|
1444
|
-
const unified = (0,
|
|
1565
|
+
const unified = (0, import_internal2.parseUnifiedComment)(commentText, {
|
|
1445
1566
|
offset: range.pos,
|
|
1446
1567
|
extensionTagNames,
|
|
1447
1568
|
...extensions !== void 0 ? { extensions } : {}
|
|
@@ -1476,13 +1597,13 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1476
1597
|
}
|
|
1477
1598
|
continue;
|
|
1478
1599
|
}
|
|
1479
|
-
if (
|
|
1600
|
+
if (import_internal2.TAGS_REQUIRING_RAW_TEXT.has(tagName)) {
|
|
1480
1601
|
const fallback = rawTextFallbacks.get(tagName)?.shift();
|
|
1481
|
-
const text2 = (0,
|
|
1602
|
+
const text2 = (0, import_internal2.choosePreferredPayloadText)(tag.resolvedPayloadText, fallback?.text ?? "");
|
|
1482
1603
|
if (text2 === "") continue;
|
|
1483
1604
|
const provenance2 = provenanceForParsedTag(tag, sourceFile, file);
|
|
1484
1605
|
if (tagName === "defaultValue") {
|
|
1485
|
-
annotations.push((0,
|
|
1606
|
+
annotations.push((0, import_internal2.parseDefaultValueTagValue)(text2, provenance2));
|
|
1486
1607
|
continue;
|
|
1487
1608
|
}
|
|
1488
1609
|
processConstraintTag(
|
|
@@ -1564,7 +1685,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1564
1685
|
if (text === "") continue;
|
|
1565
1686
|
const provenance = fallback.provenance;
|
|
1566
1687
|
if (tagName === "defaultValue") {
|
|
1567
|
-
annotations.push((0,
|
|
1688
|
+
annotations.push((0, import_internal2.parseDefaultValueTagValue)(text, provenance));
|
|
1568
1689
|
continue;
|
|
1569
1690
|
}
|
|
1570
1691
|
processConstraintTag(
|
|
@@ -1590,13 +1711,13 @@ function extractDisplayNameMetadata(node) {
|
|
|
1590
1711
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
1591
1712
|
const sourceFile = node.getSourceFile();
|
|
1592
1713
|
const sourceText = sourceFile.getFullText();
|
|
1593
|
-
const commentRanges =
|
|
1714
|
+
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1594
1715
|
if (commentRanges) {
|
|
1595
1716
|
for (const range of commentRanges) {
|
|
1596
|
-
if (range.kind !==
|
|
1717
|
+
if (range.kind !== ts3.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
1597
1718
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
1598
1719
|
if (!commentText.startsWith("/**")) continue;
|
|
1599
|
-
const unified = (0,
|
|
1720
|
+
const unified = (0, import_internal2.parseUnifiedComment)(commentText);
|
|
1600
1721
|
for (const tag of unified.tags) {
|
|
1601
1722
|
if (tag.normalizedTagName !== "displayName") {
|
|
1602
1723
|
continue;
|
|
@@ -1618,9 +1739,9 @@ function extractDisplayNameMetadata(node) {
|
|
|
1618
1739
|
}
|
|
1619
1740
|
function collectRawTextFallbacks(node, file) {
|
|
1620
1741
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
1621
|
-
for (const tag of
|
|
1742
|
+
for (const tag of ts3.getJSDocTags(node)) {
|
|
1622
1743
|
const tagName = (0, import_internals3.normalizeConstraintTagName)(tag.tagName.text);
|
|
1623
|
-
if (!
|
|
1744
|
+
if (!import_internal2.TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
1624
1745
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
1625
1746
|
if (commentText === "") continue;
|
|
1626
1747
|
const entries = fallbacks.get(tagName) ?? [];
|
|
@@ -1633,7 +1754,7 @@ function collectRawTextFallbacks(node, file) {
|
|
|
1633
1754
|
return fallbacks;
|
|
1634
1755
|
}
|
|
1635
1756
|
function isMemberTargetDisplayName(text) {
|
|
1636
|
-
return (0,
|
|
1757
|
+
return (0, import_internal2.parseTagSyntax)("displayName", text).target !== null;
|
|
1637
1758
|
}
|
|
1638
1759
|
function provenanceForComment(range, sourceFile, file, tagName) {
|
|
1639
1760
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);
|
|
@@ -1673,7 +1794,7 @@ function getTagCommentText(tag) {
|
|
|
1673
1794
|
if (typeof tag.comment === "string") {
|
|
1674
1795
|
return tag.comment;
|
|
1675
1796
|
}
|
|
1676
|
-
return
|
|
1797
|
+
return ts3.getTextOfJSDocComment(tag.comment);
|
|
1677
1798
|
}
|
|
1678
1799
|
|
|
1679
1800
|
// src/analyzer/jsdoc-constraints.ts
|
|
@@ -1691,18 +1812,18 @@ function extractJSDocAnnotationNodes(node, file = "", options) {
|
|
|
1691
1812
|
function extractDefaultValueAnnotation(initializer, file = "") {
|
|
1692
1813
|
if (!initializer) return null;
|
|
1693
1814
|
let value;
|
|
1694
|
-
if (
|
|
1815
|
+
if (ts4.isStringLiteral(initializer)) {
|
|
1695
1816
|
value = initializer.text;
|
|
1696
|
-
} else if (
|
|
1817
|
+
} else if (ts4.isNumericLiteral(initializer)) {
|
|
1697
1818
|
value = Number(initializer.text);
|
|
1698
|
-
} else if (initializer.kind ===
|
|
1819
|
+
} else if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
|
|
1699
1820
|
value = true;
|
|
1700
|
-
} else if (initializer.kind ===
|
|
1821
|
+
} else if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
|
|
1701
1822
|
value = false;
|
|
1702
|
-
} else if (initializer.kind ===
|
|
1823
|
+
} else if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
|
|
1703
1824
|
value = null;
|
|
1704
|
-
} else if (
|
|
1705
|
-
if (initializer.operator ===
|
|
1825
|
+
} else if (ts4.isPrefixUnaryExpression(initializer)) {
|
|
1826
|
+
if (initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
|
|
1706
1827
|
value = -Number(initializer.operand.text);
|
|
1707
1828
|
}
|
|
1708
1829
|
}
|
|
@@ -1724,93 +1845,38 @@ function extractDefaultValueAnnotation(initializer, file = "") {
|
|
|
1724
1845
|
|
|
1725
1846
|
// src/analyzer/class-analyzer.ts
|
|
1726
1847
|
function isObjectType(type) {
|
|
1727
|
-
return !!(type.flags &
|
|
1848
|
+
return !!(type.flags & ts5.TypeFlags.Object);
|
|
1728
1849
|
}
|
|
1729
1850
|
function isIntersectionType(type) {
|
|
1730
|
-
return !!(type.flags &
|
|
1731
|
-
}
|
|
1732
|
-
function collectBrandIdentifiers(type) {
|
|
1733
|
-
if (!type.isIntersection()) {
|
|
1734
|
-
return [];
|
|
1735
|
-
}
|
|
1736
|
-
const brands = [];
|
|
1737
|
-
for (const prop of type.getProperties()) {
|
|
1738
|
-
const decl = prop.valueDeclaration ?? prop.declarations?.[0];
|
|
1739
|
-
if (decl === void 0) continue;
|
|
1740
|
-
if (!ts3.isPropertySignature(decl) && !ts3.isPropertyDeclaration(decl)) continue;
|
|
1741
|
-
if (!ts3.isComputedPropertyName(decl.name)) continue;
|
|
1742
|
-
if (!ts3.isIdentifier(decl.name.expression)) continue;
|
|
1743
|
-
brands.push(decl.name.expression.text);
|
|
1744
|
-
}
|
|
1745
|
-
return brands;
|
|
1746
|
-
}
|
|
1747
|
-
function resolveCanonicalSymbol(type, checker) {
|
|
1748
|
-
const raw = type.aliasSymbol ?? type.getSymbol();
|
|
1749
|
-
if (raw === void 0) return void 0;
|
|
1750
|
-
return raw.flags & ts3.SymbolFlags.Alias ? checker.getAliasedSymbol(raw) : raw;
|
|
1751
|
-
}
|
|
1752
|
-
function resolveSymbolBasedCustomType(type, extensionRegistry, checker) {
|
|
1753
|
-
if (extensionRegistry === void 0) {
|
|
1754
|
-
return null;
|
|
1755
|
-
}
|
|
1756
|
-
const canonical = resolveCanonicalSymbol(type, checker);
|
|
1757
|
-
if (canonical === void 0) {
|
|
1758
|
-
return null;
|
|
1759
|
-
}
|
|
1760
|
-
const registration = extensionRegistry.findTypeBySymbol(canonical);
|
|
1761
|
-
if (registration === void 0) {
|
|
1762
|
-
return null;
|
|
1763
|
-
}
|
|
1764
|
-
return {
|
|
1765
|
-
kind: "custom",
|
|
1766
|
-
typeId: `${registration.extensionId}/${registration.registration.typeName}`,
|
|
1767
|
-
payload: null
|
|
1768
|
-
};
|
|
1851
|
+
return !!(type.flags & ts5.TypeFlags.Intersection);
|
|
1769
1852
|
}
|
|
1770
1853
|
function isIntegerBrandedType(type) {
|
|
1771
1854
|
if (!type.isIntersection()) {
|
|
1772
1855
|
return false;
|
|
1773
1856
|
}
|
|
1774
|
-
const hasNumberBase = type.types.some((member) => !!(member.flags &
|
|
1857
|
+
const hasNumberBase = type.types.some((member) => !!(member.flags & ts5.TypeFlags.Number));
|
|
1775
1858
|
if (!hasNumberBase) {
|
|
1776
1859
|
return false;
|
|
1777
1860
|
}
|
|
1778
1861
|
return collectBrandIdentifiers(type).includes("__integerBrand");
|
|
1779
1862
|
}
|
|
1780
|
-
function resolveBrandedCustomType(type, extensionRegistry) {
|
|
1781
|
-
if (extensionRegistry === void 0) {
|
|
1782
|
-
return null;
|
|
1783
|
-
}
|
|
1784
|
-
for (const brand of collectBrandIdentifiers(type)) {
|
|
1785
|
-
const registration = extensionRegistry.findTypeByBrand(brand);
|
|
1786
|
-
if (registration === void 0) {
|
|
1787
|
-
continue;
|
|
1788
|
-
}
|
|
1789
|
-
return {
|
|
1790
|
-
kind: "custom",
|
|
1791
|
-
typeId: `${registration.extensionId}/${registration.registration.typeName}`,
|
|
1792
|
-
payload: null
|
|
1793
|
-
};
|
|
1794
|
-
}
|
|
1795
|
-
return null;
|
|
1796
|
-
}
|
|
1797
1863
|
function isResolvableObjectLikeAliasTypeNode(typeNode) {
|
|
1798
|
-
if (
|
|
1864
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
1799
1865
|
return isResolvableObjectLikeAliasTypeNode(typeNode.type);
|
|
1800
1866
|
}
|
|
1801
|
-
if (
|
|
1867
|
+
if (ts5.isTypeLiteralNode(typeNode) || ts5.isTypeReferenceNode(typeNode)) {
|
|
1802
1868
|
return true;
|
|
1803
1869
|
}
|
|
1804
|
-
return
|
|
1870
|
+
return ts5.isIntersectionTypeNode(typeNode) && typeNode.types.length > 0 && typeNode.types.every((member) => isResolvableObjectLikeAliasTypeNode(member));
|
|
1805
1871
|
}
|
|
1806
1872
|
function isSemanticallyPlainObjectLikeType(type, checker) {
|
|
1807
1873
|
if (isIntersectionType(type)) {
|
|
1808
1874
|
return type.types.length > 0 && type.types.every((member) => isSemanticallyPlainObjectLikeType(member, checker));
|
|
1809
1875
|
}
|
|
1810
|
-
return isObjectType(type) && checker.getSignaturesOfType(type,
|
|
1876
|
+
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);
|
|
1811
1877
|
}
|
|
1812
1878
|
function isTypeReference(type) {
|
|
1813
|
-
return !!(type.flags &
|
|
1879
|
+
return !!(type.flags & ts5.TypeFlags.Object) && !!(type.objectFlags & ts5.ObjectFlags.Reference);
|
|
1814
1880
|
}
|
|
1815
1881
|
var RESOLVING_TYPE_PLACEHOLDER = {
|
|
1816
1882
|
kind: "object",
|
|
@@ -1837,7 +1903,7 @@ function createAnalyzerMetadataPolicy(input, discriminator) {
|
|
|
1837
1903
|
};
|
|
1838
1904
|
}
|
|
1839
1905
|
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
1840
|
-
const analysis = (0,
|
|
1906
|
+
const analysis = (0, import_internal3.analyzeMetadataForNodeWithChecker)({
|
|
1841
1907
|
checker,
|
|
1842
1908
|
node,
|
|
1843
1909
|
logicalName,
|
|
@@ -1875,7 +1941,7 @@ function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node,
|
|
|
1875
1941
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
1876
1942
|
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
1877
1943
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
1878
|
-
const logicalName =
|
|
1944
|
+
const logicalName = ts5.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
1879
1945
|
const docResult = extractJSDocParseResult(
|
|
1880
1946
|
declaration,
|
|
1881
1947
|
file,
|
|
@@ -1923,7 +1989,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
1923
1989
|
const instanceMethods = [];
|
|
1924
1990
|
const staticMethods = [];
|
|
1925
1991
|
for (const member of classDecl.members) {
|
|
1926
|
-
if (
|
|
1992
|
+
if (ts5.isPropertyDeclaration(member)) {
|
|
1927
1993
|
const fieldNode = analyzeFieldToIR(
|
|
1928
1994
|
member,
|
|
1929
1995
|
checker,
|
|
@@ -1939,10 +2005,10 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
1939
2005
|
fields.push(fieldNode);
|
|
1940
2006
|
fieldLayouts.push({});
|
|
1941
2007
|
}
|
|
1942
|
-
} else if (
|
|
2008
|
+
} else if (ts5.isMethodDeclaration(member)) {
|
|
1943
2009
|
const methodInfo = analyzeMethod(member, checker);
|
|
1944
2010
|
if (methodInfo) {
|
|
1945
|
-
const isStatic = member.modifiers?.some((m) => m.kind ===
|
|
2011
|
+
const isStatic = member.modifiers?.some((m) => m.kind === ts5.SyntaxKind.StaticKeyword);
|
|
1946
2012
|
if (isStatic) {
|
|
1947
2013
|
staticMethods.push(methodInfo);
|
|
1948
2014
|
} else {
|
|
@@ -2005,7 +2071,7 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
2005
2071
|
diagnostics.push(...interfaceDoc.diagnostics);
|
|
2006
2072
|
const visiting = /* @__PURE__ */ new Set();
|
|
2007
2073
|
for (const member of interfaceDecl.members) {
|
|
2008
|
-
if (
|
|
2074
|
+
if (ts5.isPropertySignature(member)) {
|
|
2009
2075
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2010
2076
|
member,
|
|
2011
2077
|
checker,
|
|
@@ -2063,7 +2129,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2063
2129
|
if (members === null) {
|
|
2064
2130
|
const sourceFile = typeAlias.getSourceFile();
|
|
2065
2131
|
const { line } = sourceFile.getLineAndCharacterOfPosition(typeAlias.getStart());
|
|
2066
|
-
const kindDesc =
|
|
2132
|
+
const kindDesc = ts5.SyntaxKind[typeAlias.type.kind] ?? "unknown";
|
|
2067
2133
|
return {
|
|
2068
2134
|
ok: false,
|
|
2069
2135
|
kind: "not-object-like",
|
|
@@ -2098,7 +2164,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
2098
2164
|
diagnostics.push(...typeAliasDoc.diagnostics);
|
|
2099
2165
|
const visiting = /* @__PURE__ */ new Set();
|
|
2100
2166
|
for (const member of members) {
|
|
2101
|
-
if (
|
|
2167
|
+
if (ts5.isPropertySignature(member)) {
|
|
2102
2168
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
2103
2169
|
member,
|
|
2104
2170
|
checker,
|
|
@@ -2165,20 +2231,20 @@ function makeAnalysisDiagnostic(code, message, primaryLocation, relatedLocations
|
|
|
2165
2231
|
function getLeadingParsedTags(node) {
|
|
2166
2232
|
const sourceFile = node.getSourceFile();
|
|
2167
2233
|
const sourceText = sourceFile.getFullText();
|
|
2168
|
-
const commentRanges =
|
|
2234
|
+
const commentRanges = ts5.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2169
2235
|
if (commentRanges === void 0) {
|
|
2170
2236
|
return [];
|
|
2171
2237
|
}
|
|
2172
2238
|
const parsedTags = [];
|
|
2173
2239
|
for (const range of commentRanges) {
|
|
2174
|
-
if (range.kind !==
|
|
2240
|
+
if (range.kind !== ts5.SyntaxKind.MultiLineCommentTrivia) {
|
|
2175
2241
|
continue;
|
|
2176
2242
|
}
|
|
2177
2243
|
const commentText = sourceText.slice(range.pos, range.end);
|
|
2178
2244
|
if (!commentText.startsWith("/**")) {
|
|
2179
2245
|
continue;
|
|
2180
2246
|
}
|
|
2181
|
-
parsedTags.push(...(0,
|
|
2247
|
+
parsedTags.push(...(0, import_internal3.parseCommentBlock)(commentText, { offset: range.pos }).tags);
|
|
2182
2248
|
}
|
|
2183
2249
|
return parsedTags;
|
|
2184
2250
|
}
|
|
@@ -2189,19 +2255,19 @@ function resolveDiscriminatorProperty(node, checker, fieldName) {
|
|
|
2189
2255
|
return null;
|
|
2190
2256
|
}
|
|
2191
2257
|
const declaration = propertySymbol.valueDeclaration ?? propertySymbol.declarations?.find(
|
|
2192
|
-
(candidate) =>
|
|
2258
|
+
(candidate) => ts5.isPropertyDeclaration(candidate) || ts5.isPropertySignature(candidate)
|
|
2193
2259
|
) ?? propertySymbol.declarations?.[0];
|
|
2194
2260
|
return {
|
|
2195
2261
|
declaration,
|
|
2196
2262
|
type: checker.getTypeOfSymbolAtLocation(propertySymbol, declaration ?? node),
|
|
2197
|
-
optional: !!(propertySymbol.flags &
|
|
2263
|
+
optional: !!(propertySymbol.flags & ts5.SymbolFlags.Optional) || declaration !== void 0 && "questionToken" in declaration && declaration.questionToken !== void 0
|
|
2198
2264
|
};
|
|
2199
2265
|
}
|
|
2200
2266
|
function isLocalTypeParameterName(node, typeParameterName) {
|
|
2201
2267
|
return node.typeParameters?.some((typeParameter) => typeParameter.name.text === typeParameterName) ?? false;
|
|
2202
2268
|
}
|
|
2203
2269
|
function isNullishSemanticType(type) {
|
|
2204
|
-
if (type.flags & (
|
|
2270
|
+
if (type.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined | ts5.TypeFlags.Void | ts5.TypeFlags.Unknown | ts5.TypeFlags.Any)) {
|
|
2205
2271
|
return true;
|
|
2206
2272
|
}
|
|
2207
2273
|
return type.isUnion() && type.types.some((member) => isNullishSemanticType(member));
|
|
@@ -2211,7 +2277,7 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2211
2277
|
return false;
|
|
2212
2278
|
}
|
|
2213
2279
|
seen.add(type);
|
|
2214
|
-
if (type.flags &
|
|
2280
|
+
if (type.flags & ts5.TypeFlags.StringLike) {
|
|
2215
2281
|
return true;
|
|
2216
2282
|
}
|
|
2217
2283
|
if (type.isUnion()) {
|
|
@@ -2224,13 +2290,13 @@ function isStringLikeSemanticType(type, checker, seen = /* @__PURE__ */ new Set(
|
|
|
2224
2290
|
return false;
|
|
2225
2291
|
}
|
|
2226
2292
|
function getObjectLikeTypeAliasMembers(typeNode) {
|
|
2227
|
-
if (
|
|
2293
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
2228
2294
|
return getObjectLikeTypeAliasMembers(typeNode.type);
|
|
2229
2295
|
}
|
|
2230
|
-
if (
|
|
2296
|
+
if (ts5.isTypeLiteralNode(typeNode)) {
|
|
2231
2297
|
return [...typeNode.members];
|
|
2232
2298
|
}
|
|
2233
|
-
if (
|
|
2299
|
+
if (ts5.isIntersectionTypeNode(typeNode)) {
|
|
2234
2300
|
const members = [];
|
|
2235
2301
|
for (const intersectionMember of typeNode.types) {
|
|
2236
2302
|
const resolvedMembers = getObjectLikeTypeAliasMembers(intersectionMember);
|
|
@@ -2393,7 +2459,7 @@ function resolveLiteralDiscriminatorPropertyValue(boundType, propertyName, check
|
|
|
2393
2459
|
}
|
|
2394
2460
|
if (propertyType.isUnion()) {
|
|
2395
2461
|
const nonNullMembers = propertyType.types.filter(
|
|
2396
|
-
(member) => !(member.flags & (
|
|
2462
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
2397
2463
|
);
|
|
2398
2464
|
if (nonNullMembers.length > 0 && nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2399
2465
|
diagnostics.push(
|
|
@@ -2442,13 +2508,13 @@ function resolveNamedDiscriminatorDeclaration(type, checker, seen = /* @__PURE__
|
|
|
2442
2508
|
seen.add(type);
|
|
2443
2509
|
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
2444
2510
|
if (symbol !== void 0) {
|
|
2445
|
-
const aliased = symbol.flags &
|
|
2511
|
+
const aliased = symbol.flags & ts5.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : void 0;
|
|
2446
2512
|
const targetSymbol = aliased ?? symbol;
|
|
2447
2513
|
const declaration = targetSymbol.declarations?.find(
|
|
2448
|
-
(candidate) =>
|
|
2514
|
+
(candidate) => ts5.isClassDeclaration(candidate) || ts5.isInterfaceDeclaration(candidate) || ts5.isTypeAliasDeclaration(candidate) || ts5.isEnumDeclaration(candidate)
|
|
2449
2515
|
);
|
|
2450
2516
|
if (declaration !== void 0) {
|
|
2451
|
-
if (
|
|
2517
|
+
if (ts5.isTypeAliasDeclaration(declaration) && ts5.isTypeReferenceNode(declaration.type) && checker.getTypeFromTypeNode(declaration.type) !== type) {
|
|
2452
2518
|
return resolveNamedDiscriminatorDeclaration(
|
|
2453
2519
|
checker.getTypeFromTypeNode(declaration.type),
|
|
2454
2520
|
checker,
|
|
@@ -2476,7 +2542,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2476
2542
|
}
|
|
2477
2543
|
if (boundType.isUnion()) {
|
|
2478
2544
|
const nonNullMembers = boundType.types.filter(
|
|
2479
|
-
(member) => !(member.flags & (
|
|
2545
|
+
(member) => !(member.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
2480
2546
|
);
|
|
2481
2547
|
if (nonNullMembers.every((member) => member.isStringLiteral())) {
|
|
2482
2548
|
diagnostics.push(
|
|
@@ -2521,7 +2587,7 @@ function resolveDiscriminatorValue(boundType, fieldName, checker, provenance, di
|
|
|
2521
2587
|
return null;
|
|
2522
2588
|
}
|
|
2523
2589
|
function getDeclarationName(node) {
|
|
2524
|
-
if (
|
|
2590
|
+
if (ts5.isClassDeclaration(node) || ts5.isInterfaceDeclaration(node) || ts5.isTypeAliasDeclaration(node) || ts5.isEnumDeclaration(node)) {
|
|
2525
2591
|
return node.name?.text ?? "anonymous";
|
|
2526
2592
|
}
|
|
2527
2593
|
return "anonymous";
|
|
@@ -2576,11 +2642,11 @@ function extractReferenceTypeArguments(type, checker, file, typeRegistry, visiti
|
|
|
2576
2642
|
if (sourceTypeNode === void 0) {
|
|
2577
2643
|
return [];
|
|
2578
2644
|
}
|
|
2579
|
-
const unwrapParentheses = (typeNode) =>
|
|
2645
|
+
const unwrapParentheses = (typeNode) => ts5.isParenthesizedTypeNode(typeNode) ? unwrapParentheses(typeNode.type) : typeNode;
|
|
2580
2646
|
const directTypeNode = unwrapParentheses(sourceTypeNode);
|
|
2581
|
-
const referenceTypeNode =
|
|
2647
|
+
const referenceTypeNode = ts5.isTypeReferenceNode(directTypeNode) ? directTypeNode : (() => {
|
|
2582
2648
|
const resolvedTypeNode = resolveAliasedTypeNode(directTypeNode, checker);
|
|
2583
|
-
return
|
|
2649
|
+
return ts5.isTypeReferenceNode(resolvedTypeNode) ? resolvedTypeNode : null;
|
|
2584
2650
|
})();
|
|
2585
2651
|
if (referenceTypeNode?.typeArguments === void 0) {
|
|
2586
2652
|
return [];
|
|
@@ -2635,7 +2701,7 @@ function applyDiscriminatorToObjectProperties(properties, node, subjectType, che
|
|
|
2635
2701
|
);
|
|
2636
2702
|
}
|
|
2637
2703
|
function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnostics, hostType, metadataPolicy, extensionRegistry) {
|
|
2638
|
-
if (!
|
|
2704
|
+
if (!ts5.isIdentifier(prop.name)) {
|
|
2639
2705
|
return null;
|
|
2640
2706
|
}
|
|
2641
2707
|
const name = prop.name.text;
|
|
@@ -2762,7 +2828,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2762
2828
|
const seen = /* @__PURE__ */ new Set();
|
|
2763
2829
|
const duplicates = /* @__PURE__ */ new Set();
|
|
2764
2830
|
for (const member of members) {
|
|
2765
|
-
if (!
|
|
2831
|
+
if (!ts5.isPropertySignature(member)) {
|
|
2766
2832
|
continue;
|
|
2767
2833
|
}
|
|
2768
2834
|
const name = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -2778,7 +2844,7 @@ function findDuplicateObjectLikeTypeAliasPropertyNames(members) {
|
|
|
2778
2844
|
return [...duplicates].sort();
|
|
2779
2845
|
}
|
|
2780
2846
|
function getAnalyzableObjectLikePropertyName(name) {
|
|
2781
|
-
if (
|
|
2847
|
+
if (ts5.isIdentifier(name) || ts5.isStringLiteral(name) || ts5.isNumericLiteral(name)) {
|
|
2782
2848
|
return name.text;
|
|
2783
2849
|
}
|
|
2784
2850
|
return null;
|
|
@@ -2845,74 +2911,20 @@ function parseEnumMemberDisplayName(value) {
|
|
|
2845
2911
|
if (label === "") return null;
|
|
2846
2912
|
return { value: match[1], label };
|
|
2847
2913
|
}
|
|
2848
|
-
function
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
return resolveRegisteredCustomTypeFromTypeNode(typeNode, extensionRegistry, checker);
|
|
2857
|
-
}
|
|
2858
|
-
function resolveRegisteredCustomTypeFromTypeNode(typeNode, extensionRegistry, checker) {
|
|
2859
|
-
if (ts3.isParenthesizedTypeNode(typeNode)) {
|
|
2860
|
-
return resolveRegisteredCustomTypeFromTypeNode(typeNode.type, extensionRegistry, checker);
|
|
2861
|
-
}
|
|
2862
|
-
const typeName = getTypeNodeRegistrationName(typeNode);
|
|
2863
|
-
if (typeName === null) {
|
|
2864
|
-
return null;
|
|
2865
|
-
}
|
|
2866
|
-
const registration = extensionRegistry.findTypeByName(typeName);
|
|
2867
|
-
if (registration !== void 0) {
|
|
2914
|
+
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
2915
|
+
const customTypeLookup = resolveCustomTypeFromTsType(
|
|
2916
|
+
type,
|
|
2917
|
+
checker,
|
|
2918
|
+
extensionRegistry,
|
|
2919
|
+
sourceNode
|
|
2920
|
+
);
|
|
2921
|
+
if (customTypeLookup !== null) {
|
|
2868
2922
|
return {
|
|
2869
2923
|
kind: "custom",
|
|
2870
|
-
typeId:
|
|
2924
|
+
typeId: customTypeIdFromLookup(customTypeLookup),
|
|
2871
2925
|
payload: null
|
|
2872
2926
|
};
|
|
2873
2927
|
}
|
|
2874
|
-
if (ts3.isTypeReferenceNode(typeNode) && ts3.isIdentifier(typeNode.typeName)) {
|
|
2875
|
-
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
2876
|
-
if (aliasDecl !== void 0) {
|
|
2877
|
-
return resolveRegisteredCustomTypeFromTypeNode(aliasDecl.type, extensionRegistry, checker);
|
|
2878
|
-
}
|
|
2879
|
-
}
|
|
2880
|
-
return null;
|
|
2881
|
-
}
|
|
2882
|
-
function extractTypeNodeFromSource(sourceNode) {
|
|
2883
|
-
if (ts3.isPropertyDeclaration(sourceNode) || ts3.isPropertySignature(sourceNode) || ts3.isParameter(sourceNode) || ts3.isTypeAliasDeclaration(sourceNode)) {
|
|
2884
|
-
return sourceNode.type;
|
|
2885
|
-
}
|
|
2886
|
-
if (ts3.isTypeNode(sourceNode)) {
|
|
2887
|
-
return sourceNode;
|
|
2888
|
-
}
|
|
2889
|
-
return void 0;
|
|
2890
|
-
}
|
|
2891
|
-
function getTypeNodeRegistrationName(typeNode) {
|
|
2892
|
-
if (ts3.isTypeReferenceNode(typeNode)) {
|
|
2893
|
-
return ts3.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : typeNode.typeName.right.text;
|
|
2894
|
-
}
|
|
2895
|
-
if (ts3.isParenthesizedTypeNode(typeNode)) {
|
|
2896
|
-
return getTypeNodeRegistrationName(typeNode.type);
|
|
2897
|
-
}
|
|
2898
|
-
if (typeNode.kind === ts3.SyntaxKind.BigIntKeyword || typeNode.kind === ts3.SyntaxKind.StringKeyword || typeNode.kind === ts3.SyntaxKind.NumberKeyword || typeNode.kind === ts3.SyntaxKind.BooleanKeyword) {
|
|
2899
|
-
return typeNode.getText();
|
|
2900
|
-
}
|
|
2901
|
-
return null;
|
|
2902
|
-
}
|
|
2903
|
-
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
2904
|
-
const customType = resolveRegisteredCustomType(sourceNode, extensionRegistry, checker);
|
|
2905
|
-
if (customType) {
|
|
2906
|
-
return customType;
|
|
2907
|
-
}
|
|
2908
|
-
const symbolCustomType = resolveSymbolBasedCustomType(type, extensionRegistry, checker);
|
|
2909
|
-
if (symbolCustomType) {
|
|
2910
|
-
return symbolCustomType;
|
|
2911
|
-
}
|
|
2912
|
-
const brandedCustomType = resolveBrandedCustomType(type, extensionRegistry);
|
|
2913
|
-
if (brandedCustomType) {
|
|
2914
|
-
return brandedCustomType;
|
|
2915
|
-
}
|
|
2916
2928
|
const primitiveAlias = tryResolveNamedPrimitiveAlias(
|
|
2917
2929
|
type,
|
|
2918
2930
|
checker,
|
|
@@ -2930,25 +2942,25 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
2930
2942
|
if (isIntegerBrandedType(type)) {
|
|
2931
2943
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
2932
2944
|
}
|
|
2933
|
-
if (type.flags &
|
|
2945
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
2934
2946
|
return { kind: "primitive", primitiveKind: "string" };
|
|
2935
2947
|
}
|
|
2936
|
-
if (type.flags &
|
|
2948
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
2937
2949
|
return { kind: "primitive", primitiveKind: "number" };
|
|
2938
2950
|
}
|
|
2939
|
-
if (type.flags & (
|
|
2951
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
2940
2952
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
2941
2953
|
}
|
|
2942
|
-
if (type.flags &
|
|
2954
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
2943
2955
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
2944
2956
|
}
|
|
2945
|
-
if (type.flags &
|
|
2957
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
2946
2958
|
return { kind: "primitive", primitiveKind: "null" };
|
|
2947
2959
|
}
|
|
2948
|
-
if (type.flags &
|
|
2960
|
+
if (type.flags & ts5.TypeFlags.Undefined) {
|
|
2949
2961
|
return { kind: "primitive", primitiveKind: "null" };
|
|
2950
2962
|
}
|
|
2951
|
-
if (type.flags &
|
|
2963
|
+
if (type.flags & ts5.TypeFlags.Void) {
|
|
2952
2964
|
return { kind: "primitive", primitiveKind: "null" };
|
|
2953
2965
|
}
|
|
2954
2966
|
if (type.isStringLiteral()) {
|
|
@@ -3035,10 +3047,10 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
3035
3047
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3036
3048
|
}
|
|
3037
3049
|
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
3038
|
-
if (!(type.flags & (
|
|
3050
|
+
if (!(type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
|
|
3039
3051
|
return null;
|
|
3040
3052
|
}
|
|
3041
|
-
const aliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3053
|
+
const aliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
|
|
3042
3054
|
if (!aliasDecl) {
|
|
3043
3055
|
return null;
|
|
3044
3056
|
}
|
|
@@ -3088,14 +3100,14 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
3088
3100
|
return { kind: "reference", name: aliasName, typeArguments: [] };
|
|
3089
3101
|
}
|
|
3090
3102
|
function getReferencedTypeAliasDeclaration(sourceNode, checker) {
|
|
3091
|
-
const typeNode = sourceNode && (
|
|
3092
|
-
if (!typeNode || !
|
|
3103
|
+
const typeNode = sourceNode && (ts5.isPropertyDeclaration(sourceNode) || ts5.isPropertySignature(sourceNode) || ts5.isParameter(sourceNode)) ? sourceNode.type : void 0;
|
|
3104
|
+
if (!typeNode || !ts5.isTypeReferenceNode(typeNode)) {
|
|
3093
3105
|
return void 0;
|
|
3094
3106
|
}
|
|
3095
3107
|
return getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
3096
3108
|
}
|
|
3097
3109
|
function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
3098
|
-
if (!
|
|
3110
|
+
if (!ts5.isTypeReferenceNode(typeNode)) {
|
|
3099
3111
|
return false;
|
|
3100
3112
|
}
|
|
3101
3113
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3103,10 +3115,10 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
3103
3115
|
return false;
|
|
3104
3116
|
}
|
|
3105
3117
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
3106
|
-
return !!(resolved.flags & (
|
|
3118
|
+
return !!(resolved.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral | ts5.TypeFlags.Boolean | ts5.TypeFlags.Null));
|
|
3107
3119
|
}
|
|
3108
3120
|
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics, visitedAliases = /* @__PURE__ */ new Set()) {
|
|
3109
|
-
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(
|
|
3121
|
+
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts5.isTypeAliasDeclaration);
|
|
3110
3122
|
if (nestedAliasDecl !== void 0 && !visitedAliases.has(nestedAliasDecl)) {
|
|
3111
3123
|
visitedAliases.add(nestedAliasDecl);
|
|
3112
3124
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -3124,19 +3136,19 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
3124
3136
|
if (isIntegerBrandedType(type)) {
|
|
3125
3137
|
return { kind: "primitive", primitiveKind: "integer" };
|
|
3126
3138
|
}
|
|
3127
|
-
if (type.flags &
|
|
3139
|
+
if (type.flags & ts5.TypeFlags.String) {
|
|
3128
3140
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3129
3141
|
}
|
|
3130
|
-
if (type.flags &
|
|
3142
|
+
if (type.flags & ts5.TypeFlags.Number) {
|
|
3131
3143
|
return { kind: "primitive", primitiveKind: "number" };
|
|
3132
3144
|
}
|
|
3133
|
-
if (type.flags & (
|
|
3145
|
+
if (type.flags & (ts5.TypeFlags.BigInt | ts5.TypeFlags.BigIntLiteral)) {
|
|
3134
3146
|
return { kind: "primitive", primitiveKind: "bigint" };
|
|
3135
3147
|
}
|
|
3136
|
-
if (type.flags &
|
|
3148
|
+
if (type.flags & ts5.TypeFlags.Boolean) {
|
|
3137
3149
|
return { kind: "primitive", primitiveKind: "boolean" };
|
|
3138
3150
|
}
|
|
3139
|
-
if (type.flags &
|
|
3151
|
+
if (type.flags & ts5.TypeFlags.Null) {
|
|
3140
3152
|
return { kind: "primitive", primitiveKind: "null" };
|
|
3141
3153
|
}
|
|
3142
3154
|
return resolveTypeNode(
|
|
@@ -3163,13 +3175,13 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3163
3175
|
(memberTypeNode) => !isNullishTypeNode(resolveAliasedTypeNode(memberTypeNode, checker))
|
|
3164
3176
|
);
|
|
3165
3177
|
const nonNullTypes = allTypes.filter(
|
|
3166
|
-
(memberType) => !(memberType.flags & (
|
|
3178
|
+
(memberType) => !(memberType.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined))
|
|
3167
3179
|
);
|
|
3168
3180
|
const nonNullMembers = nonNullTypes.map((memberType, index) => ({
|
|
3169
3181
|
memberType,
|
|
3170
3182
|
sourceNode: nonNullSourceNodes.length === nonNullTypes.length ? nonNullSourceNodes[index] : void 0
|
|
3171
3183
|
}));
|
|
3172
|
-
const hasNull = allTypes.some((t) => t.flags &
|
|
3184
|
+
const hasNull = allTypes.some((t) => t.flags & ts5.TypeFlags.Null);
|
|
3173
3185
|
const memberDisplayNames = /* @__PURE__ */ new Map();
|
|
3174
3186
|
if (namedDecl) {
|
|
3175
3187
|
for (const [value, label] of extractDisplayNameMetadata(namedDecl).memberDisplayNames) {
|
|
@@ -3212,7 +3224,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
3212
3224
|
const displayName = memberDisplayNames.get(String(value));
|
|
3213
3225
|
return displayName !== void 0 ? { value, displayName } : { value };
|
|
3214
3226
|
});
|
|
3215
|
-
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags &
|
|
3227
|
+
const isBooleanUnion2 = nonNullTypes.length === 2 && nonNullTypes.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
|
|
3216
3228
|
if (isBooleanUnion2) {
|
|
3217
3229
|
const boolNode = { kind: "primitive", primitiveKind: "boolean" };
|
|
3218
3230
|
const result = hasNull ? {
|
|
@@ -3304,7 +3316,7 @@ function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metad
|
|
|
3304
3316
|
if (type.getProperties().length > 0) {
|
|
3305
3317
|
return null;
|
|
3306
3318
|
}
|
|
3307
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
3319
|
+
const indexInfo = checker.getIndexInfoOfType(type, ts5.IndexKind.String);
|
|
3308
3320
|
if (!indexInfo) {
|
|
3309
3321
|
return null;
|
|
3310
3322
|
}
|
|
@@ -3352,10 +3364,10 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
3352
3364
|
}
|
|
3353
3365
|
if (declaration !== void 0 && "name" in declaration && declaration.name !== void 0) {
|
|
3354
3366
|
const name = declaration.name;
|
|
3355
|
-
if (
|
|
3367
|
+
if (ts5.isComputedPropertyName(name) || ts5.isPrivateIdentifier(name)) {
|
|
3356
3368
|
return false;
|
|
3357
3369
|
}
|
|
3358
|
-
if (!
|
|
3370
|
+
if (!ts5.isIdentifier(name) && !ts5.isStringLiteral(name) && !ts5.isNumericLiteral(name)) {
|
|
3359
3371
|
return false;
|
|
3360
3372
|
}
|
|
3361
3373
|
}
|
|
@@ -3481,7 +3493,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3481
3493
|
if (!declaration) continue;
|
|
3482
3494
|
if (!shouldEmitResolvedObjectProperty(prop, declaration)) continue;
|
|
3483
3495
|
const propType = checker.getTypeOfSymbolAtLocation(prop, declaration);
|
|
3484
|
-
const optional = !!(prop.flags &
|
|
3496
|
+
const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
|
|
3485
3497
|
const propTypeNode = resolveTypeNode(
|
|
3486
3498
|
propType,
|
|
3487
3499
|
checker,
|
|
@@ -3494,7 +3506,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3494
3506
|
collectedDiagnostics
|
|
3495
3507
|
);
|
|
3496
3508
|
const fieldNodeInfo = fieldInfoMap?.get(prop.name);
|
|
3497
|
-
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ?
|
|
3509
|
+
const inlineFieldNodeInfo = fieldNodeInfo === void 0 ? ts5.isPropertySignature(declaration) ? analyzeInterfacePropertyToIR(
|
|
3498
3510
|
declaration,
|
|
3499
3511
|
checker,
|
|
3500
3512
|
file,
|
|
@@ -3504,7 +3516,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3504
3516
|
type,
|
|
3505
3517
|
metadataPolicy,
|
|
3506
3518
|
extensionRegistry
|
|
3507
|
-
) :
|
|
3519
|
+
) : ts5.isPropertyDeclaration(declaration) ? analyzeFieldToIR(
|
|
3508
3520
|
declaration,
|
|
3509
3521
|
checker,
|
|
3510
3522
|
file,
|
|
@@ -3532,7 +3544,7 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
3532
3544
|
visiting.delete(type);
|
|
3533
3545
|
const objectNode = {
|
|
3534
3546
|
kind: "object",
|
|
3535
|
-
properties: namedDecl !== void 0 && (
|
|
3547
|
+
properties: namedDecl !== void 0 && (ts5.isClassDeclaration(namedDecl) || ts5.isInterfaceDeclaration(namedDecl) || ts5.isTypeAliasDeclaration(namedDecl)) ? applyDiscriminatorToObjectProperties(
|
|
3536
3548
|
properties,
|
|
3537
3549
|
namedDecl,
|
|
3538
3550
|
type,
|
|
@@ -3580,12 +3592,12 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3580
3592
|
for (const symbol of symbols) {
|
|
3581
3593
|
const declarations = symbol.declarations;
|
|
3582
3594
|
if (!declarations) continue;
|
|
3583
|
-
const classDecl = declarations.find(
|
|
3595
|
+
const classDecl = declarations.find(ts5.isClassDeclaration);
|
|
3584
3596
|
if (classDecl) {
|
|
3585
3597
|
const map = /* @__PURE__ */ new Map();
|
|
3586
3598
|
const hostType = checker.getTypeAtLocation(classDecl);
|
|
3587
3599
|
for (const member of classDecl.members) {
|
|
3588
|
-
if (
|
|
3600
|
+
if (ts5.isPropertyDeclaration(member) && ts5.isIdentifier(member.name)) {
|
|
3589
3601
|
const fieldNode = analyzeFieldToIR(
|
|
3590
3602
|
member,
|
|
3591
3603
|
checker,
|
|
@@ -3609,7 +3621,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3609
3621
|
}
|
|
3610
3622
|
return map;
|
|
3611
3623
|
}
|
|
3612
|
-
const interfaceDecl = declarations.find(
|
|
3624
|
+
const interfaceDecl = declarations.find(ts5.isInterfaceDeclaration);
|
|
3613
3625
|
if (interfaceDecl) {
|
|
3614
3626
|
return buildFieldNodeInfoMap(
|
|
3615
3627
|
interfaceDecl.members,
|
|
@@ -3623,7 +3635,7 @@ function getNamedTypeFieldNodeInfoMap(type, checker, file, typeRegistry, visitin
|
|
|
3623
3635
|
extensionRegistry
|
|
3624
3636
|
);
|
|
3625
3637
|
}
|
|
3626
|
-
const typeAliasDecl = declarations.find(
|
|
3638
|
+
const typeAliasDecl = declarations.find(ts5.isTypeAliasDeclaration);
|
|
3627
3639
|
const typeAliasMembers = typeAliasDecl === void 0 ? null : getObjectLikeTypeAliasMembers(typeAliasDecl.type);
|
|
3628
3640
|
if (typeAliasDecl && typeAliasMembers !== null) {
|
|
3629
3641
|
return buildFieldNodeInfoMap(
|
|
@@ -3647,10 +3659,10 @@ function extractArrayElementTypeNode(sourceNode, checker) {
|
|
|
3647
3659
|
return void 0;
|
|
3648
3660
|
}
|
|
3649
3661
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3650
|
-
if (
|
|
3662
|
+
if (ts5.isArrayTypeNode(resolvedTypeNode)) {
|
|
3651
3663
|
return resolvedTypeNode.elementType;
|
|
3652
3664
|
}
|
|
3653
|
-
if (
|
|
3665
|
+
if (ts5.isTypeReferenceNode(resolvedTypeNode) && ts5.isIdentifier(resolvedTypeNode.typeName) && resolvedTypeNode.typeName.text === "Array" && resolvedTypeNode.typeArguments?.[0]) {
|
|
3654
3666
|
return resolvedTypeNode.typeArguments[0];
|
|
3655
3667
|
}
|
|
3656
3668
|
return void 0;
|
|
@@ -3661,13 +3673,13 @@ function extractUnionMemberTypeNodes(sourceNode, checker) {
|
|
|
3661
3673
|
return [];
|
|
3662
3674
|
}
|
|
3663
3675
|
const resolvedTypeNode = resolveAliasedTypeNode(typeNode, checker);
|
|
3664
|
-
return
|
|
3676
|
+
return ts5.isUnionTypeNode(resolvedTypeNode) ? [...resolvedTypeNode.types] : [];
|
|
3665
3677
|
}
|
|
3666
3678
|
function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new Set()) {
|
|
3667
|
-
if (
|
|
3679
|
+
if (ts5.isParenthesizedTypeNode(typeNode)) {
|
|
3668
3680
|
return resolveAliasedTypeNode(typeNode.type, checker, visited);
|
|
3669
3681
|
}
|
|
3670
|
-
if (!
|
|
3682
|
+
if (!ts5.isTypeReferenceNode(typeNode) || !ts5.isIdentifier(typeNode.typeName)) {
|
|
3671
3683
|
return typeNode;
|
|
3672
3684
|
}
|
|
3673
3685
|
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
@@ -3678,15 +3690,15 @@ function resolveAliasedTypeNode(typeNode, checker, visited = /* @__PURE__ */ new
|
|
|
3678
3690
|
return resolveAliasedTypeNode(aliasDecl.type, checker, visited);
|
|
3679
3691
|
}
|
|
3680
3692
|
function isNullishTypeNode(typeNode) {
|
|
3681
|
-
if (typeNode.kind ===
|
|
3693
|
+
if (typeNode.kind === ts5.SyntaxKind.NullKeyword || typeNode.kind === ts5.SyntaxKind.UndefinedKeyword) {
|
|
3682
3694
|
return true;
|
|
3683
3695
|
}
|
|
3684
|
-
return
|
|
3696
|
+
return ts5.isLiteralTypeNode(typeNode) && (typeNode.literal.kind === ts5.SyntaxKind.NullKeyword || typeNode.literal.kind === ts5.SyntaxKind.UndefinedKeyword);
|
|
3685
3697
|
}
|
|
3686
3698
|
function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, metadataPolicy, hostType, diagnostics, extensionRegistry) {
|
|
3687
3699
|
const map = /* @__PURE__ */ new Map();
|
|
3688
3700
|
for (const member of members) {
|
|
3689
|
-
if (
|
|
3701
|
+
if (ts5.isPropertySignature(member)) {
|
|
3690
3702
|
const fieldNode = analyzeInterfacePropertyToIR(
|
|
3691
3703
|
member,
|
|
3692
3704
|
checker,
|
|
@@ -3712,17 +3724,16 @@ function buildFieldNodeInfoMap(members, checker, file, typeRegistry, visiting, m
|
|
|
3712
3724
|
}
|
|
3713
3725
|
var MAX_ALIAS_CHAIN_DEPTH = 8;
|
|
3714
3726
|
function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegistry, depth = 0) {
|
|
3715
|
-
if (!
|
|
3727
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return [];
|
|
3716
3728
|
if (depth >= MAX_ALIAS_CHAIN_DEPTH) {
|
|
3717
3729
|
const aliasName = typeNode.typeName.getText();
|
|
3718
3730
|
throw new Error(
|
|
3719
3731
|
`Type alias chain exceeds maximum depth of ${String(MAX_ALIAS_CHAIN_DEPTH)} at alias "${aliasName}" in ${file}. Simplify the alias chain or check for circular references.`
|
|
3720
3732
|
);
|
|
3721
3733
|
}
|
|
3722
|
-
const
|
|
3723
|
-
const aliasDecl = getAliasedTypeAliasDeclaration(symbol, checker);
|
|
3734
|
+
const aliasDecl = getTypeAliasDeclarationFromTypeReference(typeNode, checker);
|
|
3724
3735
|
if (!aliasDecl) return [];
|
|
3725
|
-
if (
|
|
3736
|
+
if (ts5.isTypeLiteralNode(aliasDecl.type)) return [];
|
|
3726
3737
|
const aliasFieldType = resolveTypeNode(
|
|
3727
3738
|
checker.getTypeAtLocation(aliasDecl.type),
|
|
3728
3739
|
checker,
|
|
@@ -3743,18 +3754,6 @@ function extractTypeAliasConstraintNodes(typeNode, checker, file, extensionRegis
|
|
|
3743
3754
|
);
|
|
3744
3755
|
return constraints;
|
|
3745
3756
|
}
|
|
3746
|
-
function getAliasedSymbol(symbol, checker) {
|
|
3747
|
-
if (symbol === void 0) {
|
|
3748
|
-
return void 0;
|
|
3749
|
-
}
|
|
3750
|
-
return symbol.flags & ts3.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
3751
|
-
}
|
|
3752
|
-
function getAliasedTypeAliasDeclaration(symbol, checker) {
|
|
3753
|
-
return getAliasedSymbol(symbol, checker)?.declarations?.find(ts3.isTypeAliasDeclaration);
|
|
3754
|
-
}
|
|
3755
|
-
function getTypeAliasDeclarationFromTypeReference(typeNode, checker) {
|
|
3756
|
-
return getAliasedTypeAliasDeclaration(checker.getSymbolAtLocation(typeNode.typeName), checker);
|
|
3757
|
-
}
|
|
3758
3757
|
function provenanceForNode(node, file) {
|
|
3759
3758
|
const sourceFile = node.getSourceFile();
|
|
3760
3759
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
@@ -3778,14 +3777,14 @@ function getNamedTypeName(type) {
|
|
|
3778
3777
|
const symbol = type.getSymbol();
|
|
3779
3778
|
if (symbol?.declarations) {
|
|
3780
3779
|
const decl = symbol.declarations[0];
|
|
3781
|
-
if (decl && (
|
|
3782
|
-
const name =
|
|
3780
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
3781
|
+
const name = ts5.isClassDeclaration(decl) ? decl.name?.text : decl.name.text;
|
|
3783
3782
|
if (name) return name;
|
|
3784
3783
|
}
|
|
3785
3784
|
}
|
|
3786
3785
|
const aliasSymbol = type.aliasSymbol;
|
|
3787
3786
|
if (aliasSymbol?.declarations) {
|
|
3788
|
-
const aliasDecl = aliasSymbol.declarations.find(
|
|
3787
|
+
const aliasDecl = aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
3789
3788
|
if (aliasDecl) {
|
|
3790
3789
|
return aliasDecl.name.text;
|
|
3791
3790
|
}
|
|
@@ -3796,24 +3795,24 @@ function getNamedTypeDeclaration(type) {
|
|
|
3796
3795
|
const symbol = type.getSymbol();
|
|
3797
3796
|
if (symbol?.declarations) {
|
|
3798
3797
|
const decl = symbol.declarations[0];
|
|
3799
|
-
if (decl && (
|
|
3798
|
+
if (decl && (ts5.isClassDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isTypeAliasDeclaration(decl))) {
|
|
3800
3799
|
return decl;
|
|
3801
3800
|
}
|
|
3802
3801
|
}
|
|
3803
3802
|
const aliasSymbol = type.aliasSymbol;
|
|
3804
3803
|
if (aliasSymbol?.declarations) {
|
|
3805
|
-
return aliasSymbol.declarations.find(
|
|
3804
|
+
return aliasSymbol.declarations.find(ts5.isTypeAliasDeclaration);
|
|
3806
3805
|
}
|
|
3807
3806
|
return void 0;
|
|
3808
3807
|
}
|
|
3809
3808
|
function analyzeMethod(method, checker) {
|
|
3810
|
-
if (!
|
|
3809
|
+
if (!ts5.isIdentifier(method.name)) {
|
|
3811
3810
|
return null;
|
|
3812
3811
|
}
|
|
3813
3812
|
const name = method.name.text;
|
|
3814
3813
|
const parameters = [];
|
|
3815
3814
|
for (const param of method.parameters) {
|
|
3816
|
-
if (
|
|
3815
|
+
if (ts5.isIdentifier(param.name)) {
|
|
3817
3816
|
const paramInfo = analyzeParameter(param, checker);
|
|
3818
3817
|
parameters.push(paramInfo);
|
|
3819
3818
|
}
|
|
@@ -3824,7 +3823,7 @@ function analyzeMethod(method, checker) {
|
|
|
3824
3823
|
return { name, parameters, returnTypeNode, returnType };
|
|
3825
3824
|
}
|
|
3826
3825
|
function analyzeParameter(param, checker) {
|
|
3827
|
-
const name =
|
|
3826
|
+
const name = ts5.isIdentifier(param.name) ? param.name.text : "param";
|
|
3828
3827
|
const typeNode = param.type;
|
|
3829
3828
|
const type = checker.getTypeAtLocation(param);
|
|
3830
3829
|
const formSpecExportName = detectFormSpecReference(typeNode);
|
|
@@ -3833,15 +3832,15 @@ function analyzeParameter(param, checker) {
|
|
|
3833
3832
|
}
|
|
3834
3833
|
function detectFormSpecReference(typeNode) {
|
|
3835
3834
|
if (!typeNode) return null;
|
|
3836
|
-
if (!
|
|
3837
|
-
const typeName =
|
|
3835
|
+
if (!ts5.isTypeReferenceNode(typeNode)) return null;
|
|
3836
|
+
const typeName = ts5.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : ts5.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right.text : null;
|
|
3838
3837
|
if (typeName !== "InferSchema" && typeName !== "InferFormSchema") return null;
|
|
3839
3838
|
const typeArg = typeNode.typeArguments?.[0];
|
|
3840
|
-
if (!typeArg || !
|
|
3841
|
-
if (
|
|
3839
|
+
if (!typeArg || !ts5.isTypeQueryNode(typeArg)) return null;
|
|
3840
|
+
if (ts5.isIdentifier(typeArg.exprName)) {
|
|
3842
3841
|
return typeArg.exprName.text;
|
|
3843
3842
|
}
|
|
3844
|
-
if (
|
|
3843
|
+
if (ts5.isQualifiedName(typeArg.exprName)) {
|
|
3845
3844
|
return typeArg.exprName.right.text;
|
|
3846
3845
|
}
|
|
3847
3846
|
return null;
|
|
@@ -3863,23 +3862,23 @@ function createProgramContextFromProgram(program, filePath) {
|
|
|
3863
3862
|
function createProgramContext(filePath, additionalFiles) {
|
|
3864
3863
|
const absolutePath = path.resolve(filePath);
|
|
3865
3864
|
const fileDir = path.dirname(absolutePath);
|
|
3866
|
-
const configPath =
|
|
3865
|
+
const configPath = ts6.findConfigFile(fileDir, ts6.sys.fileExists.bind(ts6.sys), "tsconfig.json");
|
|
3867
3866
|
let compilerOptions;
|
|
3868
3867
|
let fileNames;
|
|
3869
3868
|
if (configPath) {
|
|
3870
|
-
const configFile =
|
|
3869
|
+
const configFile = ts6.readConfigFile(configPath, ts6.sys.readFile.bind(ts6.sys));
|
|
3871
3870
|
if (configFile.error) {
|
|
3872
3871
|
throw new Error(
|
|
3873
|
-
`Error reading tsconfig.json: ${
|
|
3872
|
+
`Error reading tsconfig.json: ${ts6.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`
|
|
3874
3873
|
);
|
|
3875
3874
|
}
|
|
3876
|
-
const parsed =
|
|
3875
|
+
const parsed = ts6.parseJsonConfigFileContent(
|
|
3877
3876
|
configFile.config,
|
|
3878
|
-
|
|
3877
|
+
ts6.sys,
|
|
3879
3878
|
path.dirname(configPath)
|
|
3880
3879
|
);
|
|
3881
3880
|
if (parsed.errors.length > 0) {
|
|
3882
|
-
const errorMessages = parsed.errors.map((e) =>
|
|
3881
|
+
const errorMessages = parsed.errors.map((e) => ts6.flattenDiagnosticMessageText(e.messageText, "\n")).join("\n");
|
|
3883
3882
|
throw new Error(`Error parsing tsconfig.json: ${errorMessages}`);
|
|
3884
3883
|
}
|
|
3885
3884
|
compilerOptions = parsed.options;
|
|
@@ -3887,9 +3886,9 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
3887
3886
|
fileNames = [.../* @__PURE__ */ new Set([...parsed.fileNames, absolutePath, ...normalizedAdditional])];
|
|
3888
3887
|
} else {
|
|
3889
3888
|
compilerOptions = {
|
|
3890
|
-
target:
|
|
3891
|
-
module:
|
|
3892
|
-
moduleResolution:
|
|
3889
|
+
target: ts6.ScriptTarget.ES2022,
|
|
3890
|
+
module: ts6.ModuleKind.NodeNext,
|
|
3891
|
+
moduleResolution: ts6.ModuleResolutionKind.NodeNext,
|
|
3893
3892
|
strict: true,
|
|
3894
3893
|
skipLibCheck: true,
|
|
3895
3894
|
declaration: true
|
|
@@ -3897,7 +3896,7 @@ function createProgramContext(filePath, additionalFiles) {
|
|
|
3897
3896
|
const normalizedAdditional = (additionalFiles ?? []).map((f) => path.resolve(f));
|
|
3898
3897
|
fileNames = [.../* @__PURE__ */ new Set([absolutePath, ...normalizedAdditional])];
|
|
3899
3898
|
}
|
|
3900
|
-
const program =
|
|
3899
|
+
const program = ts6.createProgram(fileNames, compilerOptions);
|
|
3901
3900
|
const sourceFile = program.getSourceFile(absolutePath);
|
|
3902
3901
|
if (!sourceFile) {
|
|
3903
3902
|
throw new Error(`Could not find source file: ${absolutePath}`);
|
|
@@ -3916,19 +3915,19 @@ function findNodeByName(sourceFile, name, predicate, getName) {
|
|
|
3916
3915
|
result = node;
|
|
3917
3916
|
return;
|
|
3918
3917
|
}
|
|
3919
|
-
|
|
3918
|
+
ts6.forEachChild(node, visit);
|
|
3920
3919
|
}
|
|
3921
3920
|
visit(sourceFile);
|
|
3922
3921
|
return result;
|
|
3923
3922
|
}
|
|
3924
3923
|
function findClassByName(sourceFile, className) {
|
|
3925
|
-
return findNodeByName(sourceFile, className,
|
|
3924
|
+
return findNodeByName(sourceFile, className, ts6.isClassDeclaration, (n) => n.name?.text);
|
|
3926
3925
|
}
|
|
3927
3926
|
function findInterfaceByName(sourceFile, interfaceName) {
|
|
3928
|
-
return findNodeByName(sourceFile, interfaceName,
|
|
3927
|
+
return findNodeByName(sourceFile, interfaceName, ts6.isInterfaceDeclaration, (n) => n.name.text);
|
|
3929
3928
|
}
|
|
3930
3929
|
function findTypeAliasByName(sourceFile, aliasName) {
|
|
3931
|
-
return findNodeByName(sourceFile, aliasName,
|
|
3930
|
+
return findNodeByName(sourceFile, aliasName, ts6.isTypeAliasDeclaration, (n) => n.name.text);
|
|
3932
3931
|
}
|
|
3933
3932
|
function getResolvedObjectRootType(rootType, typeRegistry) {
|
|
3934
3933
|
if (rootType.kind === "object") {
|
|
@@ -3968,22 +3967,22 @@ function createResolvedObjectAliasAnalysis(name, rootType, typeRegistry, rootInf
|
|
|
3968
3967
|
};
|
|
3969
3968
|
}
|
|
3970
3969
|
function containsTypeReferenceInObjectLikeAlias(typeNode) {
|
|
3971
|
-
if (
|
|
3970
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3972
3971
|
return containsTypeReferenceInObjectLikeAlias(typeNode.type);
|
|
3973
3972
|
}
|
|
3974
|
-
if (
|
|
3973
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
3975
3974
|
return true;
|
|
3976
3975
|
}
|
|
3977
|
-
return
|
|
3976
|
+
return ts6.isIntersectionTypeNode(typeNode) && typeNode.types.some((member) => containsTypeReferenceInObjectLikeAlias(member));
|
|
3978
3977
|
}
|
|
3979
3978
|
function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
3980
|
-
if (
|
|
3979
|
+
if (ts6.isParenthesizedTypeNode(typeNode)) {
|
|
3981
3980
|
return collectFallbackAliasMemberPropertyNames(typeNode.type, checker);
|
|
3982
3981
|
}
|
|
3983
|
-
if (
|
|
3982
|
+
if (ts6.isTypeLiteralNode(typeNode)) {
|
|
3984
3983
|
const propertyNames = [];
|
|
3985
3984
|
for (const member of typeNode.members) {
|
|
3986
|
-
if (!
|
|
3985
|
+
if (!ts6.isPropertySignature(member)) {
|
|
3987
3986
|
continue;
|
|
3988
3987
|
}
|
|
3989
3988
|
const propertyName = getAnalyzableObjectLikePropertyName(member.name);
|
|
@@ -3993,13 +3992,13 @@ function collectFallbackAliasMemberPropertyNames(typeNode, checker) {
|
|
|
3993
3992
|
}
|
|
3994
3993
|
return propertyNames;
|
|
3995
3994
|
}
|
|
3996
|
-
if (
|
|
3995
|
+
if (ts6.isTypeReferenceNode(typeNode)) {
|
|
3997
3996
|
return checker.getTypeFromTypeNode(typeNode).getProperties().map((property) => property.getName());
|
|
3998
3997
|
}
|
|
3999
3998
|
return null;
|
|
4000
3999
|
}
|
|
4001
4000
|
function findFallbackAliasDuplicatePropertyNames(typeNode, checker) {
|
|
4002
|
-
if (!
|
|
4001
|
+
if (!ts6.isIntersectionTypeNode(typeNode)) {
|
|
4003
4002
|
return [];
|
|
4004
4003
|
}
|
|
4005
4004
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -4189,7 +4188,7 @@ function makeFileProvenance(filePath) {
|
|
|
4189
4188
|
}
|
|
4190
4189
|
|
|
4191
4190
|
// src/generators/class-schema.ts
|
|
4192
|
-
var
|
|
4191
|
+
var ts8 = __toESM(require("typescript"), 1);
|
|
4193
4192
|
|
|
4194
4193
|
// src/metadata/collision-guards.ts
|
|
4195
4194
|
function assertUniqueSerializedNames(entries, scope) {
|
|
@@ -5022,14 +5021,14 @@ function assignVendorPrefixedExtensionKeywords(schema, extensionSchema, vendorPr
|
|
|
5022
5021
|
|
|
5023
5022
|
// src/extensions/registry.ts
|
|
5024
5023
|
var import_internals5 = require("@formspec/core/internals");
|
|
5025
|
-
var
|
|
5024
|
+
var import_internal4 = require("@formspec/analysis/internal");
|
|
5026
5025
|
var BUILTIN_METADATA_TAGS = /* @__PURE__ */ new Set(["apiName", "displayName"]);
|
|
5027
5026
|
function buildConstraintTagSources(extensions) {
|
|
5028
5027
|
return extensions.map((extension) => ({
|
|
5029
5028
|
extensionId: extension.extensionId,
|
|
5030
5029
|
...extension.constraintTags !== void 0 ? {
|
|
5031
5030
|
constraintTags: extension.constraintTags.map((tag) => ({
|
|
5032
|
-
tagName: (0,
|
|
5031
|
+
tagName: (0, import_internal4.normalizeFormSpecTagName)(tag.tagName)
|
|
5033
5032
|
}))
|
|
5034
5033
|
} : {}
|
|
5035
5034
|
}));
|
|
@@ -5102,7 +5101,7 @@ function createExtensionRegistry(extensions) {
|
|
|
5102
5101
|
}
|
|
5103
5102
|
if (ext.constraintTags !== void 0) {
|
|
5104
5103
|
for (const tag of ext.constraintTags) {
|
|
5105
|
-
const canonicalTagName = (0,
|
|
5104
|
+
const canonicalTagName = (0, import_internal4.normalizeFormSpecTagName)(tag.tagName);
|
|
5106
5105
|
if (constraintTagMap.has(canonicalTagName)) {
|
|
5107
5106
|
throw new Error(`Duplicate custom constraint tag: "@${canonicalTagName}"`);
|
|
5108
5107
|
}
|
|
@@ -5127,7 +5126,7 @@ function createExtensionRegistry(extensions) {
|
|
|
5127
5126
|
throw new Error(`Duplicate metadata slot ID: "${slot.slotId}"`);
|
|
5128
5127
|
}
|
|
5129
5128
|
metadataSlotMap.set(slot.slotId, true);
|
|
5130
|
-
const canonicalTagName = (0,
|
|
5129
|
+
const canonicalTagName = (0, import_internal4.normalizeFormSpecTagName)(slot.tagName);
|
|
5131
5130
|
if (slot.allowBare === false && (slot.qualifiers?.length ?? 0) === 0) {
|
|
5132
5131
|
throw new Error(
|
|
5133
5132
|
`Metadata tag "@${canonicalTagName}" must allow bare usage or declare at least one qualifier.`
|
|
@@ -5154,7 +5153,7 @@ function createExtensionRegistry(extensions) {
|
|
|
5154
5153
|
`Metadata tag "@${canonicalTagName}" conflicts with existing FormSpec tag "@${(0, import_internals5.normalizeConstraintTagName)(canonicalTagName)}".`
|
|
5155
5154
|
);
|
|
5156
5155
|
}
|
|
5157
|
-
const existingTag = (0,
|
|
5156
|
+
const existingTag = (0, import_internal4.getTagDefinition)(canonicalTagName, reservedTagSources);
|
|
5158
5157
|
if (existingTag !== null) {
|
|
5159
5158
|
throw BUILTIN_METADATA_TAGS.has(existingTag.canonicalName) ? new Error(
|
|
5160
5159
|
`Metadata tag "@${canonicalTagName}" conflicts with built-in metadata tags.`
|
|
@@ -5176,14 +5175,14 @@ function createExtensionRegistry(extensions) {
|
|
|
5176
5175
|
symbolMap = map;
|
|
5177
5176
|
},
|
|
5178
5177
|
findConstraint: (constraintId) => constraintMap.get(constraintId),
|
|
5179
|
-
findConstraintTag: (tagName) => constraintTagMap.get((0,
|
|
5178
|
+
findConstraintTag: (tagName) => constraintTagMap.get((0, import_internal4.normalizeFormSpecTagName)(tagName)),
|
|
5180
5179
|
findBuiltinConstraintBroadening: (typeId, tagName) => builtinBroadeningMap.get(`${typeId}:${tagName}`),
|
|
5181
5180
|
findAnnotation: (annotationId) => annotationMap.get(annotationId)
|
|
5182
5181
|
};
|
|
5183
5182
|
}
|
|
5184
5183
|
|
|
5185
5184
|
// src/extensions/symbol-registry.ts
|
|
5186
|
-
var
|
|
5185
|
+
var ts7 = __toESM(require("typescript"), 1);
|
|
5187
5186
|
var path2 = __toESM(require("path"), 1);
|
|
5188
5187
|
|
|
5189
5188
|
// src/ui-schema/schema.ts
|
|
@@ -5444,9 +5443,9 @@ function collectFieldNameMap(elements) {
|
|
|
5444
5443
|
}
|
|
5445
5444
|
|
|
5446
5445
|
// src/validate/constraint-validator.ts
|
|
5447
|
-
var
|
|
5446
|
+
var import_internal5 = require("@formspec/analysis/internal");
|
|
5448
5447
|
function validateFieldNode(ctx, field) {
|
|
5449
|
-
const analysis = (0,
|
|
5448
|
+
const analysis = (0, import_internal5.analyzeConstraintTargets)(
|
|
5450
5449
|
field.name,
|
|
5451
5450
|
field.type,
|
|
5452
5451
|
field.constraints,
|
|
@@ -5464,7 +5463,7 @@ function validateFieldNode(ctx, field) {
|
|
|
5464
5463
|
}
|
|
5465
5464
|
function validateObjectProperty(ctx, parentName, property) {
|
|
5466
5465
|
const qualifiedName = `${parentName}.${property.name}`;
|
|
5467
|
-
const analysis = (0,
|
|
5466
|
+
const analysis = (0, import_internal5.analyzeConstraintTargets)(
|
|
5468
5467
|
qualifiedName,
|
|
5469
5468
|
property.type,
|
|
5470
5469
|
property.constraints,
|