@formspec/build 0.1.0-alpha.59 → 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/class-analyzer.d.ts +1 -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 +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +2 -2
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +2 -1
- package/dist/build-beta.d.ts +2 -1
- package/dist/build-internal.d.ts +18 -15
- package/dist/build.d.ts +2 -1
- 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 +45 -316
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +48 -319
- package/dist/cli.js.map +1 -1
- package/dist/extensions/registry.d.ts +2 -2
- package/dist/extensions/registry.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 +44 -315
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -318
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +44 -315
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +47 -318
- 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 +6 -6
package/dist/internals.js
CHANGED
|
@@ -807,9 +807,11 @@ import * as ts4 from "typescript";
|
|
|
807
807
|
// src/analyzer/tsdoc-parser.ts
|
|
808
808
|
import * as ts3 from "typescript";
|
|
809
809
|
import {
|
|
810
|
-
|
|
810
|
+
_capabilityLabel,
|
|
811
|
+
_supportsConstraintCapability,
|
|
811
812
|
choosePreferredPayloadText,
|
|
812
813
|
extractPathTarget as extractSharedPathTarget,
|
|
814
|
+
getBroadenedCustomTypeId,
|
|
813
815
|
getTagDefinition,
|
|
814
816
|
hasTypeSemanticCapability,
|
|
815
817
|
normalizeFormSpecTagName,
|
|
@@ -938,10 +940,8 @@ import { _isIntegerBrandedType } from "@formspec/analysis/internal";
|
|
|
938
940
|
// src/analyzer/tsdoc-parser.ts
|
|
939
941
|
import {
|
|
940
942
|
_emitSetupDiagnostics,
|
|
941
|
-
_mapSetupDiagnosticCode,
|
|
942
943
|
getBuildLogger,
|
|
943
944
|
getBroadeningLogger,
|
|
944
|
-
getSyntheticLogger,
|
|
945
945
|
getTypedParserLogger,
|
|
946
946
|
extractEffectiveArgumentText,
|
|
947
947
|
mapTypedParserDiagnosticCode,
|
|
@@ -951,152 +951,35 @@ import {
|
|
|
951
951
|
nowMicros,
|
|
952
952
|
logTagApplication
|
|
953
953
|
} from "@formspec/analysis/internal";
|
|
954
|
-
function sharedTagValueOptions(options) {
|
|
954
|
+
function sharedTagValueOptions(options, pathResolvedCustomTypeId) {
|
|
955
955
|
return {
|
|
956
956
|
...options?.extensionRegistry !== void 0 ? { registry: options.extensionRegistry } : {},
|
|
957
|
-
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
957
|
+
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {},
|
|
958
|
+
...pathResolvedCustomTypeId !== void 0 ? { pathResolvedCustomTypeId } : {}
|
|
958
959
|
};
|
|
959
960
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
}
|
|
965
|
-
return new Set(
|
|
966
|
-
registry.extensions.flatMap(
|
|
967
|
-
(ext) => (ext.types ?? []).flatMap((t) => t.tsTypeNames ?? [t.typeName])
|
|
968
|
-
)
|
|
969
|
-
);
|
|
961
|
+
function customTypeIdForResolvedType(resolvedType, checker, registry) {
|
|
962
|
+
if (registry === void 0) return void 0;
|
|
963
|
+
const lookup = resolveCustomTypeFromTsType(resolvedType, checker, registry);
|
|
964
|
+
return lookup === null ? void 0 : customTypeIdFromLookup(lookup);
|
|
970
965
|
}
|
|
971
|
-
function
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
if (clause.name !== void 0) {
|
|
977
|
-
importedNames.add(clause.name.text);
|
|
978
|
-
}
|
|
979
|
-
if (clause.namedBindings !== void 0) {
|
|
980
|
-
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
981
|
-
for (const specifier of clause.namedBindings.elements) {
|
|
982
|
-
importedNames.add(specifier.name.text);
|
|
983
|
-
}
|
|
984
|
-
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
985
|
-
importedNames.add(clause.namedBindings.name.text);
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
continue;
|
|
989
|
-
}
|
|
990
|
-
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
991
|
-
importedNames.add(statement.name.text);
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
return importedNames;
|
|
995
|
-
}
|
|
996
|
-
function isNonReferenceIdentifier(node) {
|
|
997
|
-
const parent = node.parent;
|
|
998
|
-
if ((ts3.isBindingElement(parent) || ts3.isClassDeclaration(parent) || ts3.isEnumDeclaration(parent) || ts3.isEnumMember(parent) || ts3.isFunctionDeclaration(parent) || ts3.isFunctionExpression(parent) || ts3.isImportClause(parent) || ts3.isImportEqualsDeclaration(parent) || ts3.isImportSpecifier(parent) || ts3.isInterfaceDeclaration(parent) || ts3.isMethodDeclaration(parent) || ts3.isMethodSignature(parent) || ts3.isModuleDeclaration(parent) || ts3.isNamespaceExport(parent) || ts3.isNamespaceImport(parent) || ts3.isParameter(parent) || ts3.isPropertyDeclaration(parent) || ts3.isPropertySignature(parent) || ts3.isSetAccessorDeclaration(parent) || ts3.isGetAccessorDeclaration(parent) || ts3.isTypeAliasDeclaration(parent) || ts3.isTypeParameterDeclaration(parent) || ts3.isVariableDeclaration(parent)) && parent.name === node) {
|
|
999
|
-
return true;
|
|
1000
|
-
}
|
|
1001
|
-
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
1002
|
-
return true;
|
|
1003
|
-
}
|
|
1004
|
-
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
1005
|
-
return true;
|
|
1006
|
-
}
|
|
1007
|
-
return false;
|
|
1008
|
-
}
|
|
1009
|
-
function astReferencesImportedName(root, importedNames) {
|
|
1010
|
-
if (importedNames.size === 0) {
|
|
1011
|
-
return false;
|
|
1012
|
-
}
|
|
1013
|
-
let found = false;
|
|
1014
|
-
const visit = (node) => {
|
|
1015
|
-
if (found) return;
|
|
1016
|
-
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
1017
|
-
found = true;
|
|
1018
|
-
return;
|
|
1019
|
-
}
|
|
1020
|
-
ts3.forEachChild(node, visit);
|
|
1021
|
-
};
|
|
1022
|
-
visit(root);
|
|
1023
|
-
return found;
|
|
1024
|
-
}
|
|
1025
|
-
function getObjectMembers(statement) {
|
|
1026
|
-
if (ts3.isInterfaceDeclaration(statement)) {
|
|
1027
|
-
return statement.members;
|
|
1028
|
-
}
|
|
1029
|
-
if (ts3.isTypeLiteralNode(statement.type)) {
|
|
1030
|
-
return statement.type.members;
|
|
1031
|
-
}
|
|
1032
|
-
return void 0;
|
|
1033
|
-
}
|
|
1034
|
-
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
1035
|
-
const members = getObjectMembers(statement);
|
|
1036
|
-
if (members === void 0) {
|
|
1037
|
-
return null;
|
|
1038
|
-
}
|
|
1039
|
-
const replacements = [];
|
|
1040
|
-
for (const member of members) {
|
|
1041
|
-
if (!ts3.isPropertySignature(member)) {
|
|
1042
|
-
if (astReferencesImportedName(member, importedNames)) {
|
|
1043
|
-
return null;
|
|
1044
|
-
}
|
|
1045
|
-
continue;
|
|
1046
|
-
}
|
|
1047
|
-
const typeAnnotation = member.type;
|
|
1048
|
-
if (typeAnnotation === void 0) continue;
|
|
1049
|
-
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
1050
|
-
replacements.push({
|
|
1051
|
-
start: typeAnnotation.getStart(sourceFile),
|
|
1052
|
-
end: typeAnnotation.getEnd()
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
if (replacements.length === 0) {
|
|
1057
|
-
return statement.getText(sourceFile);
|
|
1058
|
-
}
|
|
1059
|
-
const stmtStart = statement.getStart(sourceFile);
|
|
1060
|
-
let result = statement.getText(sourceFile);
|
|
1061
|
-
for (const { start, end } of [...replacements].reverse()) {
|
|
1062
|
-
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
966
|
+
function resolvePathTargetCustomTypeId(parsedTag, subjectType, checker, registry) {
|
|
967
|
+
if (parsedTag === null) return void 0;
|
|
968
|
+
const target = parsedTag.target;
|
|
969
|
+
if (target?.kind !== "path" || !target.valid || target.path === null) {
|
|
970
|
+
return void 0;
|
|
1063
971
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
1067
|
-
const importedNames = collectImportedNames(sourceFile);
|
|
1068
|
-
const importedNamesToSkip = new Set(
|
|
1069
|
-
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
1070
|
-
);
|
|
1071
|
-
const result = [];
|
|
1072
|
-
for (const statement of sourceFile.statements) {
|
|
1073
|
-
if (ts3.isImportDeclaration(statement)) continue;
|
|
1074
|
-
if (ts3.isImportEqualsDeclaration(statement)) continue;
|
|
1075
|
-
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
1076
|
-
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
1077
|
-
result.push(statement.getText(sourceFile));
|
|
1078
|
-
continue;
|
|
1079
|
-
}
|
|
1080
|
-
if (ts3.isInterfaceDeclaration(statement) || ts3.isTypeAliasDeclaration(statement)) {
|
|
1081
|
-
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
1082
|
-
if (rewritten !== null) {
|
|
1083
|
-
result.push(rewritten);
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
972
|
+
if (subjectType === void 0 || checker === void 0) {
|
|
973
|
+
return void 0;
|
|
1086
974
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
for (const diagnostic of additions) {
|
|
1091
|
-
if ((diagnostic.code === "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" || diagnostic.code === "SYNTHETIC_SETUP_FAILURE") && target.some(
|
|
1092
|
-
(existing) => existing.code === diagnostic.code && existing.message === diagnostic.message
|
|
1093
|
-
)) {
|
|
1094
|
-
continue;
|
|
1095
|
-
}
|
|
1096
|
-
target.push(diagnostic);
|
|
975
|
+
const resolution = resolvePathTargetType(subjectType, checker, target.path.segments);
|
|
976
|
+
if (resolution.kind !== "resolved") {
|
|
977
|
+
return void 0;
|
|
1097
978
|
}
|
|
979
|
+
return customTypeIdForResolvedType(resolution.type, checker, registry);
|
|
1098
980
|
}
|
|
1099
|
-
|
|
981
|
+
var TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
982
|
+
function processConstraintTag(tagName, text, parsedTag, provenance, node, sourceFile, options, constraints, diagnostics) {
|
|
1100
983
|
const compilerDiagnostics = buildCompilerBackedConstraintDiagnostics(
|
|
1101
984
|
node,
|
|
1102
985
|
sourceFile,
|
|
@@ -1104,74 +987,30 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
1104
987
|
parsedTag,
|
|
1105
988
|
text,
|
|
1106
989
|
provenance,
|
|
1107
|
-
supportingDeclarations,
|
|
1108
990
|
options
|
|
1109
991
|
);
|
|
1110
992
|
if (compilerDiagnostics.length > 0) {
|
|
1111
|
-
|
|
993
|
+
diagnostics.push(...compilerDiagnostics);
|
|
1112
994
|
return;
|
|
1113
995
|
}
|
|
996
|
+
const pathResolvedCustomTypeId = resolvePathTargetCustomTypeId(
|
|
997
|
+
parsedTag,
|
|
998
|
+
options?.subjectType,
|
|
999
|
+
options?.checker,
|
|
1000
|
+
options?.extensionRegistry
|
|
1001
|
+
);
|
|
1114
1002
|
const constraintNode = parseConstraintTagValue(
|
|
1115
1003
|
tagName,
|
|
1116
1004
|
text,
|
|
1117
1005
|
provenance,
|
|
1118
|
-
sharedTagValueOptions(options)
|
|
1006
|
+
sharedTagValueOptions(options, pathResolvedCustomTypeId)
|
|
1119
1007
|
);
|
|
1120
1008
|
if (constraintNode) {
|
|
1121
1009
|
constraints.push(constraintNode);
|
|
1122
1010
|
}
|
|
1123
1011
|
}
|
|
1124
|
-
function renderSyntheticArgumentExpression(valueKind, argumentText) {
|
|
1125
|
-
const trimmed = argumentText.trim();
|
|
1126
|
-
if (trimmed === "") {
|
|
1127
|
-
return null;
|
|
1128
|
-
}
|
|
1129
|
-
switch (valueKind) {
|
|
1130
|
-
case "number":
|
|
1131
|
-
case "integer":
|
|
1132
|
-
case "signedInteger":
|
|
1133
|
-
if (trimmed === "Infinity" || trimmed === "-Infinity" || trimmed === "NaN") {
|
|
1134
|
-
return trimmed;
|
|
1135
|
-
}
|
|
1136
|
-
return Number.isFinite(Number(trimmed)) ? trimmed : JSON.stringify(trimmed);
|
|
1137
|
-
case "string":
|
|
1138
|
-
return JSON.stringify(argumentText);
|
|
1139
|
-
case "json":
|
|
1140
|
-
try {
|
|
1141
|
-
JSON.parse(trimmed);
|
|
1142
|
-
return `(${trimmed})`;
|
|
1143
|
-
} catch {
|
|
1144
|
-
return JSON.stringify(trimmed);
|
|
1145
|
-
}
|
|
1146
|
-
case "boolean":
|
|
1147
|
-
return trimmed === "true" || trimmed === "false" ? trimmed : JSON.stringify(trimmed);
|
|
1148
|
-
case "condition":
|
|
1149
|
-
return "undefined as unknown as FormSpecCondition";
|
|
1150
|
-
case null:
|
|
1151
|
-
return null;
|
|
1152
|
-
default: {
|
|
1153
|
-
return String(valueKind);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
function getArrayElementType(type, checker) {
|
|
1158
|
-
if (!checker.isArrayType(type)) {
|
|
1159
|
-
return null;
|
|
1160
|
-
}
|
|
1161
|
-
return checker.getTypeArguments(type)[0] ?? null;
|
|
1162
|
-
}
|
|
1163
1012
|
function supportsConstraintCapability(type, checker, capability) {
|
|
1164
|
-
|
|
1165
|
-
return true;
|
|
1166
|
-
}
|
|
1167
|
-
if (hasTypeSemanticCapability(type, checker, capability)) {
|
|
1168
|
-
return true;
|
|
1169
|
-
}
|
|
1170
|
-
if (capability === "string-like") {
|
|
1171
|
-
const itemType = getArrayElementType(type, checker);
|
|
1172
|
-
return itemType !== null && hasTypeSemanticCapability(itemType, checker, capability);
|
|
1173
|
-
}
|
|
1174
|
-
return false;
|
|
1013
|
+
return _supportsConstraintCapability(capability, type, checker);
|
|
1175
1014
|
}
|
|
1176
1015
|
var MAX_HINT_CANDIDATES = 5;
|
|
1177
1016
|
var MAX_HINT_DEPTH = 3;
|
|
@@ -1298,53 +1137,11 @@ function placementLabel(placement) {
|
|
|
1298
1137
|
}
|
|
1299
1138
|
}
|
|
1300
1139
|
}
|
|
1301
|
-
function capabilityLabel(capability) {
|
|
1302
|
-
switch (capability) {
|
|
1303
|
-
case "numeric-comparable":
|
|
1304
|
-
return "number";
|
|
1305
|
-
case "string-like":
|
|
1306
|
-
return "string";
|
|
1307
|
-
case "array-like":
|
|
1308
|
-
return "array";
|
|
1309
|
-
case "enum-member-addressable":
|
|
1310
|
-
return "enum";
|
|
1311
|
-
case "json-like":
|
|
1312
|
-
return "JSON-compatible";
|
|
1313
|
-
case "object-like":
|
|
1314
|
-
return "object";
|
|
1315
|
-
case "condition-like":
|
|
1316
|
-
return "conditional";
|
|
1317
|
-
case void 0:
|
|
1318
|
-
return "compatible";
|
|
1319
|
-
default:
|
|
1320
|
-
return capability;
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
function getBroadenedCustomTypeId(fieldType) {
|
|
1324
|
-
if (fieldType?.kind === "custom") {
|
|
1325
|
-
return fieldType.typeId;
|
|
1326
|
-
}
|
|
1327
|
-
if (fieldType?.kind !== "union") {
|
|
1328
|
-
return void 0;
|
|
1329
|
-
}
|
|
1330
|
-
const customMembers = fieldType.members.filter(
|
|
1331
|
-
(member) => member.kind === "custom"
|
|
1332
|
-
);
|
|
1333
|
-
if (customMembers.length !== 1) {
|
|
1334
|
-
return void 0;
|
|
1335
|
-
}
|
|
1336
|
-
const nonCustomMembers = fieldType.members.filter((member) => member.kind !== "custom");
|
|
1337
|
-
const allOtherMembersAreNull = nonCustomMembers.every(
|
|
1338
|
-
(member) => member.kind === "primitive" && member.primitiveKind === "null"
|
|
1339
|
-
);
|
|
1340
|
-
const customMember = customMembers[0];
|
|
1341
|
-
return allOtherMembersAreNull && customMember !== void 0 ? customMember.typeId : void 0;
|
|
1342
|
-
}
|
|
1343
1140
|
function hasBuiltinConstraintBroadening(tagName, options) {
|
|
1344
1141
|
const broadenedTypeId = getBroadenedCustomTypeId(options?.fieldType);
|
|
1345
1142
|
return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
|
|
1346
1143
|
}
|
|
1347
|
-
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance,
|
|
1144
|
+
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance, options) {
|
|
1348
1145
|
if (!isBuiltinConstraintName(tagName)) {
|
|
1349
1146
|
return [];
|
|
1350
1147
|
}
|
|
@@ -1364,16 +1161,14 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1364
1161
|
const nonNullPlacement = placement;
|
|
1365
1162
|
const log = getBuildLogger();
|
|
1366
1163
|
const broadeningLog = getBroadeningLogger();
|
|
1367
|
-
const syntheticLog = getSyntheticLogger();
|
|
1368
1164
|
const typedParserLog = getTypedParserLogger();
|
|
1369
1165
|
const logsEnabled = log !== noopLogger || broadeningLog !== noopLogger;
|
|
1370
|
-
const syntheticTraceEnabled = syntheticLog !== noopLogger;
|
|
1371
1166
|
const typedParserTraceEnabled = typedParserLog !== noopLogger;
|
|
1372
1167
|
const logStart = logsEnabled ? nowMicros() : 0;
|
|
1373
1168
|
const subjectTypeKind = logsEnabled ? describeTypeKind(subjectType, checker) : "";
|
|
1374
|
-
function emit(outcome,
|
|
1169
|
+
function emit(outcome, result) {
|
|
1375
1170
|
if (!logsEnabled) {
|
|
1376
|
-
return
|
|
1171
|
+
return result;
|
|
1377
1172
|
}
|
|
1378
1173
|
const entry = {
|
|
1379
1174
|
consumer: "build",
|
|
@@ -1387,7 +1182,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1387
1182
|
if (outcome === "bypass" || outcome === "D1" || outcome === "D2") {
|
|
1388
1183
|
logTagApplication(broadeningLog, entry);
|
|
1389
1184
|
}
|
|
1390
|
-
return
|
|
1185
|
+
return result;
|
|
1391
1186
|
}
|
|
1392
1187
|
if (!definition.placements.includes(placement)) {
|
|
1393
1188
|
return emit("A-reject", [
|
|
@@ -1431,7 +1226,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1431
1226
|
]);
|
|
1432
1227
|
}
|
|
1433
1228
|
if (resolution.kind === "unresolvable") {
|
|
1434
|
-
const actualType = checker.typeToString(resolution.type, node,
|
|
1229
|
+
const actualType = checker.typeToString(resolution.type, node, TYPE_FORMAT_FLAGS);
|
|
1435
1230
|
return emit("B-reject", [
|
|
1436
1231
|
makeDiagnostic(
|
|
1437
1232
|
"TYPE_MISMATCH",
|
|
@@ -1445,21 +1240,21 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1445
1240
|
}
|
|
1446
1241
|
const hasBroadening = (() => {
|
|
1447
1242
|
if (target === null) {
|
|
1448
|
-
if (_isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities
|
|
1243
|
+
if (_isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities[0] === "numeric-comparable") {
|
|
1449
1244
|
return true;
|
|
1450
1245
|
}
|
|
1451
1246
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
1452
1247
|
}
|
|
1453
1248
|
const registry = options?.extensionRegistry;
|
|
1454
1249
|
if (registry === void 0) return false;
|
|
1455
|
-
const
|
|
1456
|
-
return
|
|
1250
|
+
const typeId = customTypeIdForResolvedType(evaluatedType, checker, registry);
|
|
1251
|
+
return typeId !== void 0 && registry.findBuiltinConstraintBroadening(typeId, tagName) !== void 0;
|
|
1457
1252
|
})();
|
|
1458
1253
|
if (!hasBroadening) {
|
|
1459
1254
|
const requiredCapability = definition.capabilities[0];
|
|
1460
1255
|
if (requiredCapability !== void 0 && !supportsConstraintCapability(evaluatedType, checker, requiredCapability)) {
|
|
1461
|
-
const actualType = checker.typeToString(evaluatedType, node,
|
|
1462
|
-
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${
|
|
1256
|
+
const actualType = checker.typeToString(evaluatedType, node, TYPE_FORMAT_FLAGS);
|
|
1257
|
+
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${_capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`;
|
|
1463
1258
|
const hint = target === null ? buildPathTargetHint(
|
|
1464
1259
|
subjectType,
|
|
1465
1260
|
checker,
|
|
@@ -1507,68 +1302,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
1507
1302
|
valueKind: typedParseResult.value.kind
|
|
1508
1303
|
});
|
|
1509
1304
|
}
|
|
1510
|
-
|
|
1511
|
-
definition.valueKind,
|
|
1512
|
-
effectiveArgumentText
|
|
1513
|
-
);
|
|
1514
|
-
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
1515
|
-
const hostType = options?.hostType ?? subjectType;
|
|
1516
|
-
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
1517
|
-
if (syntheticTraceEnabled) {
|
|
1518
|
-
syntheticLog.trace("invoking synthetic checker", {
|
|
1519
|
-
consumer: "build",
|
|
1520
|
-
tag: tagName,
|
|
1521
|
-
placement,
|
|
1522
|
-
subjectTypeKind,
|
|
1523
|
-
subjectTypeText
|
|
1524
|
-
});
|
|
1525
|
-
}
|
|
1526
|
-
const result = checkSyntheticTagApplication({
|
|
1527
|
-
tagName,
|
|
1528
|
-
placement,
|
|
1529
|
-
hostType: hostTypeText,
|
|
1530
|
-
subjectType: subjectTypeText,
|
|
1531
|
-
...target?.kind === "path" ? { target: { kind: "path", text: target.rawText } } : {},
|
|
1532
|
-
...argumentExpression !== null ? { argumentExpression } : {},
|
|
1533
|
-
supportingDeclarations,
|
|
1534
|
-
...options?.extensionRegistry !== void 0 ? {
|
|
1535
|
-
extensions: options.extensionRegistry.extensions.map((extension) => ({
|
|
1536
|
-
extensionId: extension.extensionId,
|
|
1537
|
-
...extension.constraintTags !== void 0 ? {
|
|
1538
|
-
constraintTags: extension.constraintTags.map((tag) => ({ tagName: tag.tagName }))
|
|
1539
|
-
} : {},
|
|
1540
|
-
...extension.metadataSlots !== void 0 ? {
|
|
1541
|
-
metadataSlots: extension.metadataSlots
|
|
1542
|
-
} : {},
|
|
1543
|
-
...extension.types !== void 0 ? {
|
|
1544
|
-
customTypes: extension.types.map((t) => ({
|
|
1545
|
-
tsTypeNames: t.tsTypeNames ?? [t.typeName]
|
|
1546
|
-
}))
|
|
1547
|
-
} : {}
|
|
1548
|
-
}))
|
|
1549
|
-
} : {}
|
|
1550
|
-
});
|
|
1551
|
-
if (result.diagnostics.length === 0) {
|
|
1552
|
-
return emit("D-pass", []);
|
|
1553
|
-
}
|
|
1554
|
-
const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
|
|
1555
|
-
if (setupDiagnostic !== void 0) {
|
|
1556
|
-
return emit("C-reject", [
|
|
1557
|
-
makeDiagnostic(
|
|
1558
|
-
_mapSetupDiagnosticCode(setupDiagnostic.kind),
|
|
1559
|
-
setupDiagnostic.message,
|
|
1560
|
-
provenance
|
|
1561
|
-
)
|
|
1562
|
-
]);
|
|
1563
|
-
}
|
|
1564
|
-
const expectedLabel = definition.valueKind === null ? "compatible argument" : capabilityLabel(definition.valueKind);
|
|
1565
|
-
return emit("C-reject", [
|
|
1566
|
-
makeDiagnostic(
|
|
1567
|
-
"TYPE_MISMATCH",
|
|
1568
|
-
`Tag "@${tagName}" received an invalid argument for ${expectedLabel}.`,
|
|
1569
|
-
provenance
|
|
1570
|
-
)
|
|
1571
|
-
]);
|
|
1305
|
+
return emit("C-pass", []);
|
|
1572
1306
|
}
|
|
1573
1307
|
var parseResultCache = /* @__PURE__ */ new Map();
|
|
1574
1308
|
function getExtensionTagNames(options) {
|
|
@@ -1612,8 +1346,8 @@ function getParseCacheKey(node, file, options) {
|
|
|
1612
1346
|
start: node.getFullStart(),
|
|
1613
1347
|
end: node.getEnd(),
|
|
1614
1348
|
fieldType: options?.fieldType ?? null,
|
|
1615
|
-
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node,
|
|
1616
|
-
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node,
|
|
1349
|
+
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node, TYPE_FORMAT_FLAGS) : null,
|
|
1350
|
+
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node, TYPE_FORMAT_FLAGS) : null,
|
|
1617
1351
|
extensions: getExtensionRegistryCacheKey(options?.extensionRegistry)
|
|
1618
1352
|
});
|
|
1619
1353
|
}
|
|
@@ -1642,8 +1376,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1642
1376
|
let placeholderProvenance;
|
|
1643
1377
|
const sourceFile = node.getSourceFile();
|
|
1644
1378
|
const sourceText = sourceFile.getFullText();
|
|
1645
|
-
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
1646
|
-
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
1647
1379
|
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
1648
1380
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
1649
1381
|
const extensionTagNames = getExtensionTagNames(options);
|
|
@@ -1708,7 +1440,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1708
1440
|
provenance2,
|
|
1709
1441
|
node,
|
|
1710
1442
|
sourceFile,
|
|
1711
|
-
supportingDeclarations,
|
|
1712
1443
|
options,
|
|
1713
1444
|
constraints,
|
|
1714
1445
|
diagnostics
|
|
@@ -1726,7 +1457,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1726
1457
|
provenance,
|
|
1727
1458
|
node,
|
|
1728
1459
|
sourceFile,
|
|
1729
|
-
supportingDeclarations,
|
|
1730
1460
|
options,
|
|
1731
1461
|
constraints,
|
|
1732
1462
|
diagnostics
|
|
@@ -1790,7 +1520,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
1790
1520
|
provenance,
|
|
1791
1521
|
node,
|
|
1792
1522
|
sourceFile,
|
|
1793
|
-
supportingDeclarations,
|
|
1794
1523
|
options,
|
|
1795
1524
|
constraints,
|
|
1796
1525
|
diagnostics
|
|
@@ -5442,7 +5171,7 @@ import {
|
|
|
5442
5171
|
import {
|
|
5443
5172
|
getTagDefinition as getTagDefinition2,
|
|
5444
5173
|
normalizeFormSpecTagName as normalizeFormSpecTagName2,
|
|
5445
|
-
|
|
5174
|
+
getRegistryLogger,
|
|
5446
5175
|
_validateExtensionSetup,
|
|
5447
5176
|
logSetupDiagnostics
|
|
5448
5177
|
} from "@formspec/analysis/internal";
|
|
@@ -5468,7 +5197,7 @@ function buildConstraintTagSources(extensions) {
|
|
|
5468
5197
|
}));
|
|
5469
5198
|
}
|
|
5470
5199
|
function createExtensionRegistry(extensions) {
|
|
5471
|
-
const registryLog =
|
|
5200
|
+
const registryLog = getRegistryLogger();
|
|
5472
5201
|
registryLog.debug("createExtensionRegistry: constructing", {
|
|
5473
5202
|
extensionCount: extensions.length,
|
|
5474
5203
|
extensionIds: extensions.map((e) => e.extensionId)
|