@formspec/build 0.1.0-alpha.59 → 0.1.0-alpha.63
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 +8 -8
package/dist/cli.js
CHANGED
|
@@ -2139,7 +2139,7 @@ import {
|
|
|
2139
2139
|
import {
|
|
2140
2140
|
getTagDefinition,
|
|
2141
2141
|
normalizeFormSpecTagName,
|
|
2142
|
-
|
|
2142
|
+
getRegistryLogger,
|
|
2143
2143
|
_validateExtensionSetup,
|
|
2144
2144
|
logSetupDiagnostics
|
|
2145
2145
|
} from "@formspec/analysis/internal";
|
|
@@ -2164,7 +2164,7 @@ function buildConstraintTagSources(extensions) {
|
|
|
2164
2164
|
}));
|
|
2165
2165
|
}
|
|
2166
2166
|
function createExtensionRegistry(extensions) {
|
|
2167
|
-
const registryLog =
|
|
2167
|
+
const registryLog = getRegistryLogger();
|
|
2168
2168
|
registryLog.debug("createExtensionRegistry: constructing", {
|
|
2169
2169
|
extensionCount: extensions.length,
|
|
2170
2170
|
extensionIds: extensions.map((e) => e.extensionId)
|
|
@@ -2537,9 +2537,11 @@ var init_builtin_brands = __esm({
|
|
|
2537
2537
|
// src/analyzer/tsdoc-parser.ts
|
|
2538
2538
|
import * as ts3 from "typescript";
|
|
2539
2539
|
import {
|
|
2540
|
-
|
|
2540
|
+
_capabilityLabel,
|
|
2541
|
+
_supportsConstraintCapability,
|
|
2541
2542
|
choosePreferredPayloadText,
|
|
2542
2543
|
extractPathTarget as extractSharedPathTarget,
|
|
2544
|
+
getBroadenedCustomTypeId,
|
|
2543
2545
|
getTagDefinition as getTagDefinition2,
|
|
2544
2546
|
hasTypeSemanticCapability,
|
|
2545
2547
|
normalizeFormSpecTagName as normalizeFormSpecTagName2,
|
|
@@ -2561,10 +2563,8 @@ import "@formspec/core/internals";
|
|
|
2561
2563
|
import { noopLogger as noopLogger4 } from "@formspec/core";
|
|
2562
2564
|
import {
|
|
2563
2565
|
_emitSetupDiagnostics,
|
|
2564
|
-
_mapSetupDiagnosticCode,
|
|
2565
2566
|
getBuildLogger,
|
|
2566
2567
|
getBroadeningLogger,
|
|
2567
|
-
getSyntheticLogger as getSyntheticLogger2,
|
|
2568
2568
|
getTypedParserLogger,
|
|
2569
2569
|
extractEffectiveArgumentText,
|
|
2570
2570
|
mapTypedParserDiagnosticCode,
|
|
@@ -2574,151 +2574,34 @@ import {
|
|
|
2574
2574
|
nowMicros,
|
|
2575
2575
|
logTagApplication
|
|
2576
2576
|
} from "@formspec/analysis/internal";
|
|
2577
|
-
function sharedTagValueOptions(options) {
|
|
2577
|
+
function sharedTagValueOptions(options, pathResolvedCustomTypeId) {
|
|
2578
2578
|
return {
|
|
2579
2579
|
...options?.extensionRegistry !== void 0 ? { registry: options.extensionRegistry } : {},
|
|
2580
|
-
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2580
|
+
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {},
|
|
2581
|
+
...pathResolvedCustomTypeId !== void 0 ? { pathResolvedCustomTypeId } : {}
|
|
2581
2582
|
};
|
|
2582
2583
|
}
|
|
2583
|
-
function
|
|
2584
|
-
if (registry === void 0)
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
return new Set(
|
|
2588
|
-
registry.extensions.flatMap(
|
|
2589
|
-
(ext) => (ext.types ?? []).flatMap((t) => t.tsTypeNames ?? [t.typeName])
|
|
2590
|
-
)
|
|
2591
|
-
);
|
|
2584
|
+
function customTypeIdForResolvedType(resolvedType, checker, registry) {
|
|
2585
|
+
if (registry === void 0) return void 0;
|
|
2586
|
+
const lookup = resolveCustomTypeFromTsType(resolvedType, checker, registry);
|
|
2587
|
+
return lookup === null ? void 0 : customTypeIdFromLookup(lookup);
|
|
2592
2588
|
}
|
|
2593
|
-
function
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
if (clause.name !== void 0) {
|
|
2599
|
-
importedNames.add(clause.name.text);
|
|
2600
|
-
}
|
|
2601
|
-
if (clause.namedBindings !== void 0) {
|
|
2602
|
-
if (ts3.isNamedImports(clause.namedBindings)) {
|
|
2603
|
-
for (const specifier of clause.namedBindings.elements) {
|
|
2604
|
-
importedNames.add(specifier.name.text);
|
|
2605
|
-
}
|
|
2606
|
-
} else if (ts3.isNamespaceImport(clause.namedBindings)) {
|
|
2607
|
-
importedNames.add(clause.namedBindings.name.text);
|
|
2608
|
-
}
|
|
2609
|
-
}
|
|
2610
|
-
continue;
|
|
2611
|
-
}
|
|
2612
|
-
if (ts3.isImportEqualsDeclaration(statement)) {
|
|
2613
|
-
importedNames.add(statement.name.text);
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
return importedNames;
|
|
2617
|
-
}
|
|
2618
|
-
function isNonReferenceIdentifier(node) {
|
|
2619
|
-
const parent = node.parent;
|
|
2620
|
-
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) {
|
|
2621
|
-
return true;
|
|
2622
|
-
}
|
|
2623
|
-
if ((ts3.isPropertyAssignment(parent) || ts3.isPropertyAccessExpression(parent)) && parent.name === node) {
|
|
2624
|
-
return true;
|
|
2625
|
-
}
|
|
2626
|
-
if (ts3.isQualifiedName(parent) && parent.right === node) {
|
|
2627
|
-
return true;
|
|
2628
|
-
}
|
|
2629
|
-
return false;
|
|
2630
|
-
}
|
|
2631
|
-
function astReferencesImportedName(root, importedNames) {
|
|
2632
|
-
if (importedNames.size === 0) {
|
|
2633
|
-
return false;
|
|
2634
|
-
}
|
|
2635
|
-
let found = false;
|
|
2636
|
-
const visit = (node) => {
|
|
2637
|
-
if (found) return;
|
|
2638
|
-
if (ts3.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2639
|
-
found = true;
|
|
2640
|
-
return;
|
|
2641
|
-
}
|
|
2642
|
-
ts3.forEachChild(node, visit);
|
|
2643
|
-
};
|
|
2644
|
-
visit(root);
|
|
2645
|
-
return found;
|
|
2646
|
-
}
|
|
2647
|
-
function getObjectMembers(statement) {
|
|
2648
|
-
if (ts3.isInterfaceDeclaration(statement)) {
|
|
2649
|
-
return statement.members;
|
|
2650
|
-
}
|
|
2651
|
-
if (ts3.isTypeLiteralNode(statement.type)) {
|
|
2652
|
-
return statement.type.members;
|
|
2653
|
-
}
|
|
2654
|
-
return void 0;
|
|
2655
|
-
}
|
|
2656
|
-
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
2657
|
-
const members = getObjectMembers(statement);
|
|
2658
|
-
if (members === void 0) {
|
|
2659
|
-
return null;
|
|
2660
|
-
}
|
|
2661
|
-
const replacements = [];
|
|
2662
|
-
for (const member of members) {
|
|
2663
|
-
if (!ts3.isPropertySignature(member)) {
|
|
2664
|
-
if (astReferencesImportedName(member, importedNames)) {
|
|
2665
|
-
return null;
|
|
2666
|
-
}
|
|
2667
|
-
continue;
|
|
2668
|
-
}
|
|
2669
|
-
const typeAnnotation = member.type;
|
|
2670
|
-
if (typeAnnotation === void 0) continue;
|
|
2671
|
-
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
2672
|
-
replacements.push({
|
|
2673
|
-
start: typeAnnotation.getStart(sourceFile),
|
|
2674
|
-
end: typeAnnotation.getEnd()
|
|
2675
|
-
});
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2678
|
-
if (replacements.length === 0) {
|
|
2679
|
-
return statement.getText(sourceFile);
|
|
2680
|
-
}
|
|
2681
|
-
const stmtStart = statement.getStart(sourceFile);
|
|
2682
|
-
let result = statement.getText(sourceFile);
|
|
2683
|
-
for (const { start, end } of [...replacements].reverse()) {
|
|
2684
|
-
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
2589
|
+
function resolvePathTargetCustomTypeId(parsedTag, subjectType, checker, registry) {
|
|
2590
|
+
if (parsedTag === null) return void 0;
|
|
2591
|
+
const target = parsedTag.target;
|
|
2592
|
+
if (target?.kind !== "path" || !target.valid || target.path === null) {
|
|
2593
|
+
return void 0;
|
|
2685
2594
|
}
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
2689
|
-
const importedNames = collectImportedNames(sourceFile);
|
|
2690
|
-
const importedNamesToSkip = new Set(
|
|
2691
|
-
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2692
|
-
);
|
|
2693
|
-
const result = [];
|
|
2694
|
-
for (const statement of sourceFile.statements) {
|
|
2695
|
-
if (ts3.isImportDeclaration(statement)) continue;
|
|
2696
|
-
if (ts3.isImportEqualsDeclaration(statement)) continue;
|
|
2697
|
-
if (ts3.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2698
|
-
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2699
|
-
result.push(statement.getText(sourceFile));
|
|
2700
|
-
continue;
|
|
2701
|
-
}
|
|
2702
|
-
if (ts3.isInterfaceDeclaration(statement) || ts3.isTypeAliasDeclaration(statement)) {
|
|
2703
|
-
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2704
|
-
if (rewritten !== null) {
|
|
2705
|
-
result.push(rewritten);
|
|
2706
|
-
}
|
|
2707
|
-
}
|
|
2595
|
+
if (subjectType === void 0 || checker === void 0) {
|
|
2596
|
+
return void 0;
|
|
2708
2597
|
}
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
for (const diagnostic of additions) {
|
|
2713
|
-
if ((diagnostic.code === "UNSUPPORTED_CUSTOM_TYPE_OVERRIDE" || diagnostic.code === "SYNTHETIC_SETUP_FAILURE") && target.some(
|
|
2714
|
-
(existing) => existing.code === diagnostic.code && existing.message === diagnostic.message
|
|
2715
|
-
)) {
|
|
2716
|
-
continue;
|
|
2717
|
-
}
|
|
2718
|
-
target.push(diagnostic);
|
|
2598
|
+
const resolution = resolvePathTargetType(subjectType, checker, target.path.segments);
|
|
2599
|
+
if (resolution.kind !== "resolved") {
|
|
2600
|
+
return void 0;
|
|
2719
2601
|
}
|
|
2602
|
+
return customTypeIdForResolvedType(resolution.type, checker, registry);
|
|
2720
2603
|
}
|
|
2721
|
-
function processConstraintTag(tagName, text, parsedTag, provenance, node, sourceFile,
|
|
2604
|
+
function processConstraintTag(tagName, text, parsedTag, provenance, node, sourceFile, options, constraints, diagnostics) {
|
|
2722
2605
|
const compilerDiagnostics = buildCompilerBackedConstraintDiagnostics(
|
|
2723
2606
|
node,
|
|
2724
2607
|
sourceFile,
|
|
@@ -2726,74 +2609,30 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
|
|
|
2726
2609
|
parsedTag,
|
|
2727
2610
|
text,
|
|
2728
2611
|
provenance,
|
|
2729
|
-
supportingDeclarations,
|
|
2730
2612
|
options
|
|
2731
2613
|
);
|
|
2732
2614
|
if (compilerDiagnostics.length > 0) {
|
|
2733
|
-
|
|
2615
|
+
diagnostics.push(...compilerDiagnostics);
|
|
2734
2616
|
return;
|
|
2735
2617
|
}
|
|
2618
|
+
const pathResolvedCustomTypeId = resolvePathTargetCustomTypeId(
|
|
2619
|
+
parsedTag,
|
|
2620
|
+
options?.subjectType,
|
|
2621
|
+
options?.checker,
|
|
2622
|
+
options?.extensionRegistry
|
|
2623
|
+
);
|
|
2736
2624
|
const constraintNode = parseConstraintTagValue(
|
|
2737
2625
|
tagName,
|
|
2738
2626
|
text,
|
|
2739
2627
|
provenance,
|
|
2740
|
-
sharedTagValueOptions(options)
|
|
2628
|
+
sharedTagValueOptions(options, pathResolvedCustomTypeId)
|
|
2741
2629
|
);
|
|
2742
2630
|
if (constraintNode) {
|
|
2743
2631
|
constraints.push(constraintNode);
|
|
2744
2632
|
}
|
|
2745
2633
|
}
|
|
2746
|
-
function renderSyntheticArgumentExpression(valueKind, argumentText) {
|
|
2747
|
-
const trimmed = argumentText.trim();
|
|
2748
|
-
if (trimmed === "") {
|
|
2749
|
-
return null;
|
|
2750
|
-
}
|
|
2751
|
-
switch (valueKind) {
|
|
2752
|
-
case "number":
|
|
2753
|
-
case "integer":
|
|
2754
|
-
case "signedInteger":
|
|
2755
|
-
if (trimmed === "Infinity" || trimmed === "-Infinity" || trimmed === "NaN") {
|
|
2756
|
-
return trimmed;
|
|
2757
|
-
}
|
|
2758
|
-
return Number.isFinite(Number(trimmed)) ? trimmed : JSON.stringify(trimmed);
|
|
2759
|
-
case "string":
|
|
2760
|
-
return JSON.stringify(argumentText);
|
|
2761
|
-
case "json":
|
|
2762
|
-
try {
|
|
2763
|
-
JSON.parse(trimmed);
|
|
2764
|
-
return `(${trimmed})`;
|
|
2765
|
-
} catch {
|
|
2766
|
-
return JSON.stringify(trimmed);
|
|
2767
|
-
}
|
|
2768
|
-
case "boolean":
|
|
2769
|
-
return trimmed === "true" || trimmed === "false" ? trimmed : JSON.stringify(trimmed);
|
|
2770
|
-
case "condition":
|
|
2771
|
-
return "undefined as unknown as FormSpecCondition";
|
|
2772
|
-
case null:
|
|
2773
|
-
return null;
|
|
2774
|
-
default: {
|
|
2775
|
-
return String(valueKind);
|
|
2776
|
-
}
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
function getArrayElementType(type, checker) {
|
|
2780
|
-
if (!checker.isArrayType(type)) {
|
|
2781
|
-
return null;
|
|
2782
|
-
}
|
|
2783
|
-
return checker.getTypeArguments(type)[0] ?? null;
|
|
2784
|
-
}
|
|
2785
2634
|
function supportsConstraintCapability(type, checker, capability) {
|
|
2786
|
-
|
|
2787
|
-
return true;
|
|
2788
|
-
}
|
|
2789
|
-
if (hasTypeSemanticCapability(type, checker, capability)) {
|
|
2790
|
-
return true;
|
|
2791
|
-
}
|
|
2792
|
-
if (capability === "string-like") {
|
|
2793
|
-
const itemType = getArrayElementType(type, checker);
|
|
2794
|
-
return itemType !== null && hasTypeSemanticCapability(itemType, checker, capability);
|
|
2795
|
-
}
|
|
2796
|
-
return false;
|
|
2635
|
+
return _supportsConstraintCapability(capability, type, checker);
|
|
2797
2636
|
}
|
|
2798
2637
|
function stripHintNullishUnion(type) {
|
|
2799
2638
|
if (!type.isUnion()) {
|
|
@@ -2918,53 +2757,11 @@ function placementLabel(placement) {
|
|
|
2918
2757
|
}
|
|
2919
2758
|
}
|
|
2920
2759
|
}
|
|
2921
|
-
function capabilityLabel(capability) {
|
|
2922
|
-
switch (capability) {
|
|
2923
|
-
case "numeric-comparable":
|
|
2924
|
-
return "number";
|
|
2925
|
-
case "string-like":
|
|
2926
|
-
return "string";
|
|
2927
|
-
case "array-like":
|
|
2928
|
-
return "array";
|
|
2929
|
-
case "enum-member-addressable":
|
|
2930
|
-
return "enum";
|
|
2931
|
-
case "json-like":
|
|
2932
|
-
return "JSON-compatible";
|
|
2933
|
-
case "object-like":
|
|
2934
|
-
return "object";
|
|
2935
|
-
case "condition-like":
|
|
2936
|
-
return "conditional";
|
|
2937
|
-
case void 0:
|
|
2938
|
-
return "compatible";
|
|
2939
|
-
default:
|
|
2940
|
-
return capability;
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
function getBroadenedCustomTypeId(fieldType) {
|
|
2944
|
-
if (fieldType?.kind === "custom") {
|
|
2945
|
-
return fieldType.typeId;
|
|
2946
|
-
}
|
|
2947
|
-
if (fieldType?.kind !== "union") {
|
|
2948
|
-
return void 0;
|
|
2949
|
-
}
|
|
2950
|
-
const customMembers = fieldType.members.filter(
|
|
2951
|
-
(member) => member.kind === "custom"
|
|
2952
|
-
);
|
|
2953
|
-
if (customMembers.length !== 1) {
|
|
2954
|
-
return void 0;
|
|
2955
|
-
}
|
|
2956
|
-
const nonCustomMembers = fieldType.members.filter((member) => member.kind !== "custom");
|
|
2957
|
-
const allOtherMembersAreNull = nonCustomMembers.every(
|
|
2958
|
-
(member) => member.kind === "primitive" && member.primitiveKind === "null"
|
|
2959
|
-
);
|
|
2960
|
-
const customMember = customMembers[0];
|
|
2961
|
-
return allOtherMembersAreNull && customMember !== void 0 ? customMember.typeId : void 0;
|
|
2962
|
-
}
|
|
2963
2760
|
function hasBuiltinConstraintBroadening(tagName, options) {
|
|
2964
2761
|
const broadenedTypeId = getBroadenedCustomTypeId(options?.fieldType);
|
|
2965
2762
|
return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
|
|
2966
2763
|
}
|
|
2967
|
-
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance,
|
|
2764
|
+
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance, options) {
|
|
2968
2765
|
if (!isBuiltinConstraintName(tagName)) {
|
|
2969
2766
|
return [];
|
|
2970
2767
|
}
|
|
@@ -2984,16 +2781,14 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2984
2781
|
const nonNullPlacement = placement;
|
|
2985
2782
|
const log2 = getBuildLogger();
|
|
2986
2783
|
const broadeningLog = getBroadeningLogger();
|
|
2987
|
-
const syntheticLog = getSyntheticLogger2();
|
|
2988
2784
|
const typedParserLog = getTypedParserLogger();
|
|
2989
2785
|
const logsEnabled = log2 !== noopLogger4 || broadeningLog !== noopLogger4;
|
|
2990
|
-
const syntheticTraceEnabled = syntheticLog !== noopLogger4;
|
|
2991
2786
|
const typedParserTraceEnabled = typedParserLog !== noopLogger4;
|
|
2992
2787
|
const logStart = logsEnabled ? nowMicros() : 0;
|
|
2993
2788
|
const subjectTypeKind = logsEnabled ? describeTypeKind(subjectType, checker) : "";
|
|
2994
|
-
function emit(outcome,
|
|
2789
|
+
function emit(outcome, result) {
|
|
2995
2790
|
if (!logsEnabled) {
|
|
2996
|
-
return
|
|
2791
|
+
return result;
|
|
2997
2792
|
}
|
|
2998
2793
|
const entry = {
|
|
2999
2794
|
consumer: "build",
|
|
@@ -3007,7 +2802,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3007
2802
|
if (outcome === "bypass" || outcome === "D1" || outcome === "D2") {
|
|
3008
2803
|
logTagApplication(broadeningLog, entry);
|
|
3009
2804
|
}
|
|
3010
|
-
return
|
|
2805
|
+
return result;
|
|
3011
2806
|
}
|
|
3012
2807
|
if (!definition.placements.includes(placement)) {
|
|
3013
2808
|
return emit("A-reject", [
|
|
@@ -3051,7 +2846,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3051
2846
|
]);
|
|
3052
2847
|
}
|
|
3053
2848
|
if (resolution.kind === "unresolvable") {
|
|
3054
|
-
const actualType = checker.typeToString(resolution.type, node,
|
|
2849
|
+
const actualType = checker.typeToString(resolution.type, node, TYPE_FORMAT_FLAGS);
|
|
3055
2850
|
return emit("B-reject", [
|
|
3056
2851
|
makeDiagnostic(
|
|
3057
2852
|
"TYPE_MISMATCH",
|
|
@@ -3065,21 +2860,21 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3065
2860
|
}
|
|
3066
2861
|
const hasBroadening = (() => {
|
|
3067
2862
|
if (target === null) {
|
|
3068
|
-
if (_isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities
|
|
2863
|
+
if (_isIntegerBrandedType(stripNullishUnion2(subjectType)) && definition.capabilities[0] === "numeric-comparable") {
|
|
3069
2864
|
return true;
|
|
3070
2865
|
}
|
|
3071
2866
|
return hasBuiltinConstraintBroadening(tagName, options);
|
|
3072
2867
|
}
|
|
3073
2868
|
const registry = options?.extensionRegistry;
|
|
3074
2869
|
if (registry === void 0) return false;
|
|
3075
|
-
const
|
|
3076
|
-
return
|
|
2870
|
+
const typeId = customTypeIdForResolvedType(evaluatedType, checker, registry);
|
|
2871
|
+
return typeId !== void 0 && registry.findBuiltinConstraintBroadening(typeId, tagName) !== void 0;
|
|
3077
2872
|
})();
|
|
3078
2873
|
if (!hasBroadening) {
|
|
3079
2874
|
const requiredCapability = definition.capabilities[0];
|
|
3080
2875
|
if (requiredCapability !== void 0 && !supportsConstraintCapability(evaluatedType, checker, requiredCapability)) {
|
|
3081
|
-
const actualType = checker.typeToString(evaluatedType, node,
|
|
3082
|
-
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${
|
|
2876
|
+
const actualType = checker.typeToString(evaluatedType, node, TYPE_FORMAT_FLAGS);
|
|
2877
|
+
const baseMessage = `Target "${targetLabel}": constraint "${tagName}" is only valid on ${_capabilityLabel(requiredCapability)} targets, but field type is "${actualType}"`;
|
|
3083
2878
|
const hint = target === null ? buildPathTargetHint(
|
|
3084
2879
|
subjectType,
|
|
3085
2880
|
checker,
|
|
@@ -3127,68 +2922,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
3127
2922
|
valueKind: typedParseResult.value.kind
|
|
3128
2923
|
});
|
|
3129
2924
|
}
|
|
3130
|
-
|
|
3131
|
-
definition.valueKind,
|
|
3132
|
-
effectiveArgumentText
|
|
3133
|
-
);
|
|
3134
|
-
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
3135
|
-
const hostType = options?.hostType ?? subjectType;
|
|
3136
|
-
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
3137
|
-
if (syntheticTraceEnabled) {
|
|
3138
|
-
syntheticLog.trace("invoking synthetic checker", {
|
|
3139
|
-
consumer: "build",
|
|
3140
|
-
tag: tagName,
|
|
3141
|
-
placement,
|
|
3142
|
-
subjectTypeKind,
|
|
3143
|
-
subjectTypeText
|
|
3144
|
-
});
|
|
3145
|
-
}
|
|
3146
|
-
const result = checkSyntheticTagApplication({
|
|
3147
|
-
tagName,
|
|
3148
|
-
placement,
|
|
3149
|
-
hostType: hostTypeText,
|
|
3150
|
-
subjectType: subjectTypeText,
|
|
3151
|
-
...target?.kind === "path" ? { target: { kind: "path", text: target.rawText } } : {},
|
|
3152
|
-
...argumentExpression !== null ? { argumentExpression } : {},
|
|
3153
|
-
supportingDeclarations,
|
|
3154
|
-
...options?.extensionRegistry !== void 0 ? {
|
|
3155
|
-
extensions: options.extensionRegistry.extensions.map((extension) => ({
|
|
3156
|
-
extensionId: extension.extensionId,
|
|
3157
|
-
...extension.constraintTags !== void 0 ? {
|
|
3158
|
-
constraintTags: extension.constraintTags.map((tag) => ({ tagName: tag.tagName }))
|
|
3159
|
-
} : {},
|
|
3160
|
-
...extension.metadataSlots !== void 0 ? {
|
|
3161
|
-
metadataSlots: extension.metadataSlots
|
|
3162
|
-
} : {},
|
|
3163
|
-
...extension.types !== void 0 ? {
|
|
3164
|
-
customTypes: extension.types.map((t) => ({
|
|
3165
|
-
tsTypeNames: t.tsTypeNames ?? [t.typeName]
|
|
3166
|
-
}))
|
|
3167
|
-
} : {}
|
|
3168
|
-
}))
|
|
3169
|
-
} : {}
|
|
3170
|
-
});
|
|
3171
|
-
if (result.diagnostics.length === 0) {
|
|
3172
|
-
return emit("D-pass", []);
|
|
3173
|
-
}
|
|
3174
|
-
const setupDiagnostic = result.diagnostics.find((diagnostic) => diagnostic.kind !== "typescript");
|
|
3175
|
-
if (setupDiagnostic !== void 0) {
|
|
3176
|
-
return emit("C-reject", [
|
|
3177
|
-
makeDiagnostic(
|
|
3178
|
-
_mapSetupDiagnosticCode(setupDiagnostic.kind),
|
|
3179
|
-
setupDiagnostic.message,
|
|
3180
|
-
provenance
|
|
3181
|
-
)
|
|
3182
|
-
]);
|
|
3183
|
-
}
|
|
3184
|
-
const expectedLabel = definition.valueKind === null ? "compatible argument" : capabilityLabel(definition.valueKind);
|
|
3185
|
-
return emit("C-reject", [
|
|
3186
|
-
makeDiagnostic(
|
|
3187
|
-
"TYPE_MISMATCH",
|
|
3188
|
-
`Tag "@${tagName}" received an invalid argument for ${expectedLabel}.`,
|
|
3189
|
-
provenance
|
|
3190
|
-
)
|
|
3191
|
-
]);
|
|
2925
|
+
return emit("C-pass", []);
|
|
3192
2926
|
}
|
|
3193
2927
|
function getExtensionTagNames(options) {
|
|
3194
2928
|
return [
|
|
@@ -3231,8 +2965,8 @@ function getParseCacheKey(node, file, options) {
|
|
|
3231
2965
|
start: node.getFullStart(),
|
|
3232
2966
|
end: node.getEnd(),
|
|
3233
2967
|
fieldType: options?.fieldType ?? null,
|
|
3234
|
-
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node,
|
|
3235
|
-
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node,
|
|
2968
|
+
subjectType: checker !== void 0 && options?.subjectType !== void 0 ? checker.typeToString(options.subjectType, node, TYPE_FORMAT_FLAGS) : null,
|
|
2969
|
+
hostType: checker !== void 0 && options?.hostType !== void 0 ? checker.typeToString(options.hostType, node, TYPE_FORMAT_FLAGS) : null,
|
|
3236
2970
|
extensions: getExtensionRegistryCacheKey(options?.extensionRegistry)
|
|
3237
2971
|
});
|
|
3238
2972
|
}
|
|
@@ -3261,8 +2995,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3261
2995
|
let placeholderProvenance;
|
|
3262
2996
|
const sourceFile = node.getSourceFile();
|
|
3263
2997
|
const sourceText = sourceFile.getFullText();
|
|
3264
|
-
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
3265
|
-
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
3266
2998
|
const commentRanges = ts3.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
3267
2999
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
3268
3000
|
const extensionTagNames = getExtensionTagNames(options);
|
|
@@ -3327,7 +3059,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3327
3059
|
provenance2,
|
|
3328
3060
|
node,
|
|
3329
3061
|
sourceFile,
|
|
3330
|
-
supportingDeclarations,
|
|
3331
3062
|
options,
|
|
3332
3063
|
constraints,
|
|
3333
3064
|
diagnostics
|
|
@@ -3345,7 +3076,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3345
3076
|
provenance,
|
|
3346
3077
|
node,
|
|
3347
3078
|
sourceFile,
|
|
3348
|
-
supportingDeclarations,
|
|
3349
3079
|
options,
|
|
3350
3080
|
constraints,
|
|
3351
3081
|
diagnostics
|
|
@@ -3409,7 +3139,6 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
3409
3139
|
provenance,
|
|
3410
3140
|
node,
|
|
3411
3141
|
sourceFile,
|
|
3412
|
-
supportingDeclarations,
|
|
3413
3142
|
options,
|
|
3414
3143
|
constraints,
|
|
3415
3144
|
diagnostics
|
|
@@ -3510,13 +3239,13 @@ function getTagCommentText(tag) {
|
|
|
3510
3239
|
}
|
|
3511
3240
|
return ts3.getTextOfJSDocComment(tag.comment);
|
|
3512
3241
|
}
|
|
3513
|
-
var
|
|
3242
|
+
var TYPE_FORMAT_FLAGS, MAX_HINT_CANDIDATES, MAX_HINT_DEPTH, parseResultCache;
|
|
3514
3243
|
var init_tsdoc_parser = __esm({
|
|
3515
3244
|
"src/analyzer/tsdoc-parser.ts"() {
|
|
3516
3245
|
"use strict";
|
|
3517
3246
|
init_resolve_custom_type();
|
|
3518
3247
|
init_builtin_brands();
|
|
3519
|
-
|
|
3248
|
+
TYPE_FORMAT_FLAGS = ts3.TypeFormatFlags.NoTruncation | ts3.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
3520
3249
|
MAX_HINT_CANDIDATES = 5;
|
|
3521
3250
|
MAX_HINT_DEPTH = 3;
|
|
3522
3251
|
parseResultCache = /* @__PURE__ */ new Map();
|