@formspec/build 0.1.0-alpha.32 → 0.1.0-alpha.33
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 +5 -1
- package/dist/analyzer/class-analyzer.d.ts.map +1 -1
- package/dist/analyzer/tsdoc-parser.d.ts +6 -3
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +65 -7
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +68 -4
- package/dist/browser.js.map +1 -1
- package/dist/cli.cjs +317 -165
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +300 -140
- package/dist/cli.js.map +1 -1
- package/dist/extensions/registry.d.ts.map +1 -1
- package/dist/generators/discovered-schema.d.ts.map +1 -1
- package/dist/index.cjs +312 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +299 -140
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +270 -127
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +276 -125
- package/dist/internals.js.map +1 -1
- package/package.json +4 -4
package/dist/cli.cjs
CHANGED
|
@@ -1877,13 +1877,26 @@ var init_generator2 = __esm({
|
|
|
1877
1877
|
});
|
|
1878
1878
|
|
|
1879
1879
|
// src/extensions/registry.ts
|
|
1880
|
+
function buildConstraintTagSources(extensions) {
|
|
1881
|
+
return extensions.map((extension) => ({
|
|
1882
|
+
extensionId: extension.extensionId,
|
|
1883
|
+
...extension.constraintTags !== void 0 ? {
|
|
1884
|
+
constraintTags: extension.constraintTags.map((tag) => ({
|
|
1885
|
+
tagName: (0, import_internal.normalizeFormSpecTagName)(tag.tagName)
|
|
1886
|
+
}))
|
|
1887
|
+
} : {}
|
|
1888
|
+
}));
|
|
1889
|
+
}
|
|
1880
1890
|
function createExtensionRegistry(extensions) {
|
|
1891
|
+
const reservedTagSources = buildConstraintTagSources(extensions);
|
|
1881
1892
|
const typeMap = /* @__PURE__ */ new Map();
|
|
1882
1893
|
const typeNameMap = /* @__PURE__ */ new Map();
|
|
1883
1894
|
const constraintMap = /* @__PURE__ */ new Map();
|
|
1884
1895
|
const constraintTagMap = /* @__PURE__ */ new Map();
|
|
1885
1896
|
const builtinBroadeningMap = /* @__PURE__ */ new Map();
|
|
1886
1897
|
const annotationMap = /* @__PURE__ */ new Map();
|
|
1898
|
+
const metadataSlotMap = /* @__PURE__ */ new Map();
|
|
1899
|
+
const metadataTagMap = /* @__PURE__ */ new Map();
|
|
1887
1900
|
for (const ext of extensions) {
|
|
1888
1901
|
if (ext.types !== void 0) {
|
|
1889
1902
|
for (const type of ext.types) {
|
|
@@ -1926,10 +1939,11 @@ function createExtensionRegistry(extensions) {
|
|
|
1926
1939
|
}
|
|
1927
1940
|
if (ext.constraintTags !== void 0) {
|
|
1928
1941
|
for (const tag of ext.constraintTags) {
|
|
1929
|
-
|
|
1930
|
-
|
|
1942
|
+
const canonicalTagName = (0, import_internal.normalizeFormSpecTagName)(tag.tagName);
|
|
1943
|
+
if (constraintTagMap.has(canonicalTagName)) {
|
|
1944
|
+
throw new Error(`Duplicate custom constraint tag: "@${canonicalTagName}"`);
|
|
1931
1945
|
}
|
|
1932
|
-
constraintTagMap.set(
|
|
1946
|
+
constraintTagMap.set(canonicalTagName, {
|
|
1933
1947
|
extensionId: ext.extensionId,
|
|
1934
1948
|
registration: tag
|
|
1935
1949
|
});
|
|
@@ -1944,20 +1958,65 @@ function createExtensionRegistry(extensions) {
|
|
|
1944
1958
|
annotationMap.set(qualifiedId, annotation);
|
|
1945
1959
|
}
|
|
1946
1960
|
}
|
|
1961
|
+
if (ext.metadataSlots !== void 0) {
|
|
1962
|
+
for (const slot of ext.metadataSlots) {
|
|
1963
|
+
if (metadataSlotMap.has(slot.slotId)) {
|
|
1964
|
+
throw new Error(`Duplicate metadata slot ID: "${slot.slotId}"`);
|
|
1965
|
+
}
|
|
1966
|
+
metadataSlotMap.set(slot.slotId, true);
|
|
1967
|
+
const canonicalTagName = (0, import_internal.normalizeFormSpecTagName)(slot.tagName);
|
|
1968
|
+
if (slot.allowBare === false && (slot.qualifiers?.length ?? 0) === 0) {
|
|
1969
|
+
throw new Error(
|
|
1970
|
+
`Metadata tag "@${canonicalTagName}" must allow bare usage or declare at least one qualifier.`
|
|
1971
|
+
);
|
|
1972
|
+
}
|
|
1973
|
+
if (metadataTagMap.has(canonicalTagName)) {
|
|
1974
|
+
throw new Error(`Duplicate metadata tag: "@${canonicalTagName}"`);
|
|
1975
|
+
}
|
|
1976
|
+
if (BUILTIN_METADATA_TAGS.has(canonicalTagName)) {
|
|
1977
|
+
throw new Error(
|
|
1978
|
+
`Metadata tag "@${canonicalTagName}" conflicts with built-in metadata tags.`
|
|
1979
|
+
);
|
|
1980
|
+
}
|
|
1981
|
+
if (constraintTagMap.has(canonicalTagName)) {
|
|
1982
|
+
throw new Error(
|
|
1983
|
+
`Metadata tag "@${canonicalTagName}" conflicts with existing FormSpec tag "@${canonicalTagName}".`
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
if (Object.hasOwn(import_internals3.BUILTIN_CONSTRAINT_DEFINITIONS, (0, import_internals3.normalizeConstraintTagName)(canonicalTagName))) {
|
|
1987
|
+
throw new Error(
|
|
1988
|
+
`Metadata tag "@${canonicalTagName}" conflicts with existing FormSpec tag "@${(0, import_internals3.normalizeConstraintTagName)(canonicalTagName)}".`
|
|
1989
|
+
);
|
|
1990
|
+
}
|
|
1991
|
+
const existingTag = (0, import_internal.getTagDefinition)(canonicalTagName, reservedTagSources);
|
|
1992
|
+
if (existingTag !== null) {
|
|
1993
|
+
throw BUILTIN_METADATA_TAGS.has(existingTag.canonicalName) ? new Error(
|
|
1994
|
+
`Metadata tag "@${canonicalTagName}" conflicts with built-in metadata tags.`
|
|
1995
|
+
) : new Error(
|
|
1996
|
+
`Metadata tag "@${canonicalTagName}" conflicts with existing FormSpec tag "@${existingTag.canonicalName}".`
|
|
1997
|
+
);
|
|
1998
|
+
}
|
|
1999
|
+
metadataTagMap.set(canonicalTagName, true);
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
1947
2002
|
}
|
|
1948
2003
|
return {
|
|
1949
2004
|
extensions,
|
|
1950
2005
|
findType: (typeId) => typeMap.get(typeId),
|
|
1951
2006
|
findTypeByName: (typeName) => typeNameMap.get(typeName),
|
|
1952
2007
|
findConstraint: (constraintId) => constraintMap.get(constraintId),
|
|
1953
|
-
findConstraintTag: (tagName) => constraintTagMap.get(tagName),
|
|
2008
|
+
findConstraintTag: (tagName) => constraintTagMap.get((0, import_internal.normalizeFormSpecTagName)(tagName)),
|
|
1954
2009
|
findBuiltinConstraintBroadening: (typeId, tagName) => builtinBroadeningMap.get(`${typeId}:${tagName}`),
|
|
1955
2010
|
findAnnotation: (annotationId) => annotationMap.get(annotationId)
|
|
1956
2011
|
};
|
|
1957
2012
|
}
|
|
2013
|
+
var import_internals3, import_internal, BUILTIN_METADATA_TAGS;
|
|
1958
2014
|
var init_registry = __esm({
|
|
1959
2015
|
"src/extensions/registry.ts"() {
|
|
1960
2016
|
"use strict";
|
|
2017
|
+
import_internals3 = require("@formspec/core/internals");
|
|
2018
|
+
import_internal = require("@formspec/analysis/internal");
|
|
2019
|
+
BUILTIN_METADATA_TAGS = /* @__PURE__ */ new Set(["apiName", "displayName"]);
|
|
1961
2020
|
}
|
|
1962
2021
|
});
|
|
1963
2022
|
|
|
@@ -2040,7 +2099,7 @@ var init_schema2 = __esm({
|
|
|
2040
2099
|
// src/analyzer/tsdoc-parser.ts
|
|
2041
2100
|
function createFormSpecTSDocConfig(extensionTagNames = []) {
|
|
2042
2101
|
const config = new import_tsdoc.TSDocConfiguration();
|
|
2043
|
-
for (const tagName of Object.keys(
|
|
2102
|
+
for (const tagName of Object.keys(import_internals4.BUILTIN_CONSTRAINT_DEFINITIONS)) {
|
|
2044
2103
|
config.addTagDefinition(
|
|
2045
2104
|
new import_tsdoc.TSDocTagDefinition({
|
|
2046
2105
|
tagName: "@" + tagName,
|
|
@@ -2049,7 +2108,7 @@ function createFormSpecTSDocConfig(extensionTagNames = []) {
|
|
|
2049
2108
|
})
|
|
2050
2109
|
);
|
|
2051
2110
|
}
|
|
2052
|
-
for (const tagName of ["displayName", "format", "placeholder"]) {
|
|
2111
|
+
for (const tagName of ["apiName", "displayName", "format", "placeholder"]) {
|
|
2053
2112
|
config.addTagDefinition(
|
|
2054
2113
|
new import_tsdoc.TSDocTagDefinition({
|
|
2055
2114
|
tagName: "@" + tagName,
|
|
@@ -2082,6 +2141,16 @@ function sharedTagValueOptions(options) {
|
|
|
2082
2141
|
...options?.fieldType !== void 0 ? { fieldType: options.fieldType } : {}
|
|
2083
2142
|
};
|
|
2084
2143
|
}
|
|
2144
|
+
function getExtensionTypeNames(registry) {
|
|
2145
|
+
if (registry === void 0) {
|
|
2146
|
+
return /* @__PURE__ */ new Set();
|
|
2147
|
+
}
|
|
2148
|
+
return new Set(
|
|
2149
|
+
registry.extensions.flatMap(
|
|
2150
|
+
(ext) => (ext.types ?? []).flatMap((t) => t.tsTypeNames ?? [t.typeName])
|
|
2151
|
+
)
|
|
2152
|
+
);
|
|
2153
|
+
}
|
|
2085
2154
|
function collectImportedNames(sourceFile) {
|
|
2086
2155
|
const importedNames = /* @__PURE__ */ new Set();
|
|
2087
2156
|
for (const statement of sourceFile.statements) {
|
|
@@ -2121,6 +2190,9 @@ function isNonReferenceIdentifier(node) {
|
|
|
2121
2190
|
return false;
|
|
2122
2191
|
}
|
|
2123
2192
|
function statementReferencesImportedName(statement, importedNames) {
|
|
2193
|
+
if (importedNames.size === 0) {
|
|
2194
|
+
return false;
|
|
2195
|
+
}
|
|
2124
2196
|
let referencesImportedName = false;
|
|
2125
2197
|
const visit = (node) => {
|
|
2126
2198
|
if (referencesImportedName) {
|
|
@@ -2135,14 +2207,17 @@ function statementReferencesImportedName(statement, importedNames) {
|
|
|
2135
2207
|
visit(statement);
|
|
2136
2208
|
return referencesImportedName;
|
|
2137
2209
|
}
|
|
2138
|
-
function buildSupportingDeclarations(sourceFile) {
|
|
2210
|
+
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
2139
2211
|
const importedNames = collectImportedNames(sourceFile);
|
|
2212
|
+
const importedNamesToSkip = new Set(
|
|
2213
|
+
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2214
|
+
);
|
|
2140
2215
|
return sourceFile.statements.filter((statement) => {
|
|
2141
2216
|
if (ts.isImportDeclaration(statement)) return false;
|
|
2142
2217
|
if (ts.isImportEqualsDeclaration(statement)) return false;
|
|
2143
2218
|
if (ts.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
|
|
2144
2219
|
return false;
|
|
2145
|
-
if (
|
|
2220
|
+
if (statementReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2146
2221
|
return false;
|
|
2147
2222
|
}
|
|
2148
2223
|
return true;
|
|
@@ -2188,12 +2263,12 @@ function supportsConstraintCapability(type, checker, capability) {
|
|
|
2188
2263
|
if (capability === void 0) {
|
|
2189
2264
|
return true;
|
|
2190
2265
|
}
|
|
2191
|
-
if ((0,
|
|
2266
|
+
if ((0, import_internal2.hasTypeSemanticCapability)(type, checker, capability)) {
|
|
2192
2267
|
return true;
|
|
2193
2268
|
}
|
|
2194
2269
|
if (capability === "string-like") {
|
|
2195
2270
|
const itemType = getArrayElementType(type, checker);
|
|
2196
|
-
return itemType !== null && (0,
|
|
2271
|
+
return itemType !== null && (0, import_internal2.hasTypeSemanticCapability)(itemType, checker, capability);
|
|
2197
2272
|
}
|
|
2198
2273
|
return false;
|
|
2199
2274
|
}
|
|
@@ -2283,7 +2358,7 @@ function hasBuiltinConstraintBroadening(tagName, options) {
|
|
|
2283
2358
|
return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
|
|
2284
2359
|
}
|
|
2285
2360
|
function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, provenance, supportingDeclarations, options) {
|
|
2286
|
-
if (!(0,
|
|
2361
|
+
if (!(0, import_internals4.isBuiltinConstraintName)(tagName)) {
|
|
2287
2362
|
return [];
|
|
2288
2363
|
}
|
|
2289
2364
|
const checker = options?.checker;
|
|
@@ -2291,11 +2366,11 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2291
2366
|
if (checker === void 0 || subjectType === void 0) {
|
|
2292
2367
|
return [];
|
|
2293
2368
|
}
|
|
2294
|
-
const placement = (0,
|
|
2369
|
+
const placement = (0, import_internal2.resolveDeclarationPlacement)(node);
|
|
2295
2370
|
if (placement === null) {
|
|
2296
2371
|
return [];
|
|
2297
2372
|
}
|
|
2298
|
-
const definition = (0,
|
|
2373
|
+
const definition = (0, import_internal2.getTagDefinition)(tagName, options?.extensionRegistry?.extensions);
|
|
2299
2374
|
if (definition === null) {
|
|
2300
2375
|
return [];
|
|
2301
2376
|
}
|
|
@@ -2329,7 +2404,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2329
2404
|
)
|
|
2330
2405
|
];
|
|
2331
2406
|
}
|
|
2332
|
-
const resolution = (0,
|
|
2407
|
+
const resolution = (0, import_internal2.resolvePathTargetType)(subjectType, checker, target.path.segments);
|
|
2333
2408
|
if (resolution.kind === "missing-property") {
|
|
2334
2409
|
return [
|
|
2335
2410
|
makeDiagnostic(
|
|
@@ -2386,7 +2461,7 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2386
2461
|
const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2387
2462
|
const hostType = options?.hostType ?? subjectType;
|
|
2388
2463
|
const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
|
|
2389
|
-
const result = (0,
|
|
2464
|
+
const result = (0, import_internal2.checkSyntheticTagApplication)({
|
|
2390
2465
|
tagName,
|
|
2391
2466
|
placement,
|
|
2392
2467
|
hostType: hostTypeText,
|
|
@@ -2399,6 +2474,14 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2399
2474
|
extensionId: extension.extensionId,
|
|
2400
2475
|
...extension.constraintTags !== void 0 ? {
|
|
2401
2476
|
constraintTags: extension.constraintTags.map((tag) => ({ tagName: tag.tagName }))
|
|
2477
|
+
} : {},
|
|
2478
|
+
...extension.metadataSlots !== void 0 ? {
|
|
2479
|
+
metadataSlots: extension.metadataSlots
|
|
2480
|
+
} : {},
|
|
2481
|
+
...extension.types !== void 0 ? {
|
|
2482
|
+
customTypes: extension.types.map((t) => ({
|
|
2483
|
+
tsTypeNames: t.tsTypeNames ?? [t.typeName]
|
|
2484
|
+
}))
|
|
2402
2485
|
} : {}
|
|
2403
2486
|
}))
|
|
2404
2487
|
} : {}
|
|
@@ -2418,7 +2501,10 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
|
|
|
2418
2501
|
function getParser(options) {
|
|
2419
2502
|
const extensionTagNames = [
|
|
2420
2503
|
...options?.extensionRegistry?.extensions.flatMap(
|
|
2421
|
-
(extension) => (extension.constraintTags ?? []).map((tag) => tag.tagName)
|
|
2504
|
+
(extension) => (extension.constraintTags ?? []).map((tag) => (0, import_internal2.normalizeFormSpecTagName)(tag.tagName))
|
|
2505
|
+
) ?? [],
|
|
2506
|
+
...options?.extensionRegistry?.extensions.flatMap(
|
|
2507
|
+
(extension) => (extension.metadataSlots ?? []).map((slot) => (0, import_internal2.normalizeFormSpecTagName)(slot.tagName))
|
|
2422
2508
|
) ?? []
|
|
2423
2509
|
].sort();
|
|
2424
2510
|
const cacheKey = extensionTagNames.join("|");
|
|
@@ -2438,7 +2524,16 @@ function getExtensionRegistryCacheKey(registry) {
|
|
|
2438
2524
|
(extension) => JSON.stringify({
|
|
2439
2525
|
extensionId: extension.extensionId,
|
|
2440
2526
|
typeNames: extension.types?.map((type) => type.typeName) ?? [],
|
|
2441
|
-
constraintTags: extension.constraintTags?.map((tag) => tag.tagName) ?? []
|
|
2527
|
+
constraintTags: extension.constraintTags?.map((tag) => (0, import_internal2.normalizeFormSpecTagName)(tag.tagName)) ?? [],
|
|
2528
|
+
metadataSlots: extension.metadataSlots?.map((slot) => ({
|
|
2529
|
+
tagName: (0, import_internal2.normalizeFormSpecTagName)(slot.tagName),
|
|
2530
|
+
declarationKinds: [...slot.declarationKinds].sort(),
|
|
2531
|
+
allowBare: slot.allowBare !== false,
|
|
2532
|
+
qualifiers: (slot.qualifiers ?? []).map((qualifier) => ({
|
|
2533
|
+
qualifier: qualifier.qualifier,
|
|
2534
|
+
...qualifier.sourceQualifier !== void 0 ? { sourceQualifier: qualifier.sourceQualifier } : {}
|
|
2535
|
+
})).sort((left, right) => left.qualifier.localeCompare(right.qualifier))
|
|
2536
|
+
})) ?? []
|
|
2442
2537
|
})
|
|
2443
2538
|
).join("|");
|
|
2444
2539
|
}
|
|
@@ -2473,7 +2568,8 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2473
2568
|
const rawTextTags = [];
|
|
2474
2569
|
const sourceFile = node.getSourceFile();
|
|
2475
2570
|
const sourceText = sourceFile.getFullText();
|
|
2476
|
-
const
|
|
2571
|
+
const extensionTypeNames = getExtensionTypeNames(options?.extensionRegistry);
|
|
2572
|
+
const supportingDeclarations = buildSupportingDeclarations(sourceFile, extensionTypeNames);
|
|
2477
2573
|
const commentRanges = ts.getLeadingCommentRanges(sourceText, node.getFullStart());
|
|
2478
2574
|
const rawTextFallbacks = collectRawTextFallbacks(node, file);
|
|
2479
2575
|
if (commentRanges) {
|
|
@@ -2490,7 +2586,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2490
2586
|
import_tsdoc.TextRange.fromStringRange(sourceText, range.pos, range.end)
|
|
2491
2587
|
);
|
|
2492
2588
|
const docComment = parserContext.docComment;
|
|
2493
|
-
const parsedComment = (0,
|
|
2589
|
+
const parsedComment = (0, import_internal2.parseCommentBlock)(
|
|
2494
2590
|
commentText,
|
|
2495
2591
|
sharedCommentSyntaxOptions(options, range.pos)
|
|
2496
2592
|
);
|
|
@@ -2511,7 +2607,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2511
2607
|
}
|
|
2512
2608
|
}
|
|
2513
2609
|
for (const block of docComment.customBlocks) {
|
|
2514
|
-
const tagName = (0,
|
|
2610
|
+
const tagName = (0, import_internals4.normalizeConstraintTagName)(block.blockTag.tagName.substring(1));
|
|
2515
2611
|
const parsedTag = nextParsedTag(tagName);
|
|
2516
2612
|
if (tagName === "displayName" || tagName === "format" || tagName === "placeholder") {
|
|
2517
2613
|
const text2 = getBestBlockPayloadText(parsedTag, commentText, range.pos, block);
|
|
@@ -2543,7 +2639,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2543
2639
|
}
|
|
2544
2640
|
if (TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
2545
2641
|
const text = getBestBlockPayloadText(parsedTag, commentText, range.pos, block);
|
|
2546
|
-
const expectedType = (0,
|
|
2642
|
+
const expectedType = (0, import_internals4.isBuiltinConstraintName)(tagName) ? import_internals4.BUILTIN_CONSTRAINT_DEFINITIONS[tagName] : void 0;
|
|
2547
2643
|
if (text === "" && expectedType !== "boolean") continue;
|
|
2548
2644
|
const provenance = parsedTag !== null ? provenanceForParsedTag(parsedTag, sourceFile, file) : provenanceForComment(range, sourceFile, file, tagName);
|
|
2549
2645
|
const compilerDiagnostics = buildCompilerBackedConstraintDiagnostics(
|
|
@@ -2559,7 +2655,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2559
2655
|
diagnostics.push(...compilerDiagnostics);
|
|
2560
2656
|
continue;
|
|
2561
2657
|
}
|
|
2562
|
-
const constraintNode = (0,
|
|
2658
|
+
const constraintNode = (0, import_internal2.parseConstraintTagValue)(
|
|
2563
2659
|
tagName,
|
|
2564
2660
|
text,
|
|
2565
2661
|
provenance,
|
|
@@ -2629,7 +2725,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2629
2725
|
if (text === "") continue;
|
|
2630
2726
|
const provenance = provenanceForParsedTag(rawTextTag.tag, sourceFile, file);
|
|
2631
2727
|
if (rawTextTag.tag.normalizedTagName === "defaultValue") {
|
|
2632
|
-
const defaultValueNode = (0,
|
|
2728
|
+
const defaultValueNode = (0, import_internal2.parseDefaultValueTagValue)(text, provenance);
|
|
2633
2729
|
annotations.push(defaultValueNode);
|
|
2634
2730
|
continue;
|
|
2635
2731
|
}
|
|
@@ -2646,7 +2742,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2646
2742
|
diagnostics.push(...compilerDiagnostics);
|
|
2647
2743
|
continue;
|
|
2648
2744
|
}
|
|
2649
|
-
const constraintNode = (0,
|
|
2745
|
+
const constraintNode = (0, import_internal2.parseConstraintTagValue)(
|
|
2650
2746
|
rawTextTag.tag.normalizedTagName,
|
|
2651
2747
|
text,
|
|
2652
2748
|
provenance,
|
|
@@ -2663,7 +2759,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2663
2759
|
if (text === "") continue;
|
|
2664
2760
|
const provenance = fallback.provenance;
|
|
2665
2761
|
if (tagName === "defaultValue") {
|
|
2666
|
-
const defaultValueNode = (0,
|
|
2762
|
+
const defaultValueNode = (0, import_internal2.parseDefaultValueTagValue)(text, provenance);
|
|
2667
2763
|
annotations.push(defaultValueNode);
|
|
2668
2764
|
continue;
|
|
2669
2765
|
}
|
|
@@ -2680,7 +2776,7 @@ function parseTSDocTags(node, file = "", options) {
|
|
|
2680
2776
|
diagnostics.push(...compilerDiagnostics);
|
|
2681
2777
|
continue;
|
|
2682
2778
|
}
|
|
2683
|
-
const constraintNode = (0,
|
|
2779
|
+
const constraintNode = (0, import_internal2.parseConstraintTagValue)(
|
|
2684
2780
|
tagName,
|
|
2685
2781
|
text,
|
|
2686
2782
|
provenance,
|
|
@@ -2706,7 +2802,7 @@ function extractDisplayNameMetadata(node) {
|
|
|
2706
2802
|
if (range.kind !== ts.SyntaxKind.MultiLineCommentTrivia) continue;
|
|
2707
2803
|
const commentText = sourceText.substring(range.pos, range.end);
|
|
2708
2804
|
if (!commentText.startsWith("/**")) continue;
|
|
2709
|
-
const parsed = (0,
|
|
2805
|
+
const parsed = (0, import_internal2.parseCommentBlock)(commentText);
|
|
2710
2806
|
for (const tag of parsed.tags) {
|
|
2711
2807
|
if (tag.normalizedTagName !== "displayName") {
|
|
2712
2808
|
continue;
|
|
@@ -2762,7 +2858,7 @@ function getSharedPayloadText(tag, commentText, commentOffset) {
|
|
|
2762
2858
|
if (tag.payloadSpan === null) {
|
|
2763
2859
|
return "";
|
|
2764
2860
|
}
|
|
2765
|
-
return (0,
|
|
2861
|
+
return (0, import_internal2.sliceCommentSpan)(commentText, tag.payloadSpan, {
|
|
2766
2862
|
offset: commentOffset
|
|
2767
2863
|
}).trim();
|
|
2768
2864
|
}
|
|
@@ -2774,7 +2870,7 @@ function getBestBlockPayloadText(tag, commentText, commentOffset, block) {
|
|
|
2774
2870
|
function collectRawTextFallbacks(node, file) {
|
|
2775
2871
|
const fallbacks = /* @__PURE__ */ new Map();
|
|
2776
2872
|
for (const tag of ts.getJSDocTags(node)) {
|
|
2777
|
-
const tagName = (0,
|
|
2873
|
+
const tagName = (0, import_internals4.normalizeConstraintTagName)(tag.tagName.text);
|
|
2778
2874
|
if (!TAGS_REQUIRING_RAW_TEXT.has(tagName)) continue;
|
|
2779
2875
|
const commentText = getTagCommentText(tag)?.trim() ?? "";
|
|
2780
2876
|
if (commentText === "") continue;
|
|
@@ -2788,7 +2884,7 @@ function collectRawTextFallbacks(node, file) {
|
|
|
2788
2884
|
return fallbacks;
|
|
2789
2885
|
}
|
|
2790
2886
|
function isMemberTargetDisplayName(text) {
|
|
2791
|
-
return (0,
|
|
2887
|
+
return (0, import_internal2.parseTagSyntax)("displayName", text).target !== null;
|
|
2792
2888
|
}
|
|
2793
2889
|
function provenanceForComment(range, sourceFile, file, tagName) {
|
|
2794
2890
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(range.pos);
|
|
@@ -2830,15 +2926,15 @@ function getTagCommentText(tag) {
|
|
|
2830
2926
|
}
|
|
2831
2927
|
return ts.getTextOfJSDocComment(tag.comment);
|
|
2832
2928
|
}
|
|
2833
|
-
var ts,
|
|
2929
|
+
var ts, import_internal2, import_tsdoc, import_internals4, import_internals5, TAGS_REQUIRING_RAW_TEXT, SYNTHETIC_TYPE_FORMAT_FLAGS, parserCache, parseResultCache;
|
|
2834
2930
|
var init_tsdoc_parser = __esm({
|
|
2835
2931
|
"src/analyzer/tsdoc-parser.ts"() {
|
|
2836
2932
|
"use strict";
|
|
2837
2933
|
ts = __toESM(require("typescript"), 1);
|
|
2838
|
-
|
|
2934
|
+
import_internal2 = require("@formspec/analysis/internal");
|
|
2839
2935
|
import_tsdoc = require("@microsoft/tsdoc");
|
|
2840
|
-
import_internals3 = require("@formspec/core/internals");
|
|
2841
2936
|
import_internals4 = require("@formspec/core/internals");
|
|
2937
|
+
import_internals5 = require("@formspec/core/internals");
|
|
2842
2938
|
TAGS_REQUIRING_RAW_TEXT = /* @__PURE__ */ new Set(["pattern", "enumOptions", "defaultValue"]);
|
|
2843
2939
|
SYNTHETIC_TYPE_FORMAT_FLAGS = ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
2844
2940
|
parserCache = /* @__PURE__ */ new Map();
|
|
@@ -2919,76 +3015,50 @@ function makeParseOptions(extensionRegistry, fieldType, checker, subjectType, ho
|
|
|
2919
3015
|
...hostType !== void 0 && { hostType }
|
|
2920
3016
|
};
|
|
2921
3017
|
}
|
|
2922
|
-
function
|
|
2923
|
-
return
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
let apiName;
|
|
2927
|
-
let displayName;
|
|
2928
|
-
let apiNamePlural;
|
|
2929
|
-
let displayNamePlural;
|
|
2930
|
-
for (const tag of getLeadingParsedTags(node)) {
|
|
2931
|
-
const value = tag.argumentText.trim();
|
|
2932
|
-
if (value === "") {
|
|
2933
|
-
continue;
|
|
2934
|
-
}
|
|
2935
|
-
if (tag.normalizedTagName === "apiName") {
|
|
2936
|
-
if (tag.target === null) {
|
|
2937
|
-
apiName ??= value;
|
|
2938
|
-
} else if (tag.target.kind === "variant") {
|
|
2939
|
-
if (tag.target.rawText === "singular") {
|
|
2940
|
-
apiName ??= value;
|
|
2941
|
-
} else if (tag.target.rawText === "plural") {
|
|
2942
|
-
apiNamePlural ??= value;
|
|
2943
|
-
}
|
|
2944
|
-
}
|
|
2945
|
-
continue;
|
|
2946
|
-
}
|
|
2947
|
-
if (tag.normalizedTagName === "displayName") {
|
|
2948
|
-
if (tag.target === null) {
|
|
2949
|
-
displayName ??= value;
|
|
2950
|
-
} else if (tag.target.kind === "variant") {
|
|
2951
|
-
if (tag.target.rawText === "singular") {
|
|
2952
|
-
displayName ??= value;
|
|
2953
|
-
} else if (tag.target.rawText === "plural") {
|
|
2954
|
-
displayNamePlural ??= value;
|
|
2955
|
-
}
|
|
2956
|
-
}
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
|
-
const resolvedApiName = makeExplicitScalarMetadata(apiName);
|
|
2960
|
-
const resolvedDisplayName = makeExplicitScalarMetadata(displayName);
|
|
2961
|
-
const resolvedApiNamePlural = makeExplicitScalarMetadata(apiNamePlural);
|
|
2962
|
-
const resolvedDisplayNamePlural = makeExplicitScalarMetadata(displayNamePlural);
|
|
2963
|
-
const metadata = {
|
|
2964
|
-
...resolvedApiName !== void 0 && { apiName: resolvedApiName },
|
|
2965
|
-
...resolvedDisplayName !== void 0 && { displayName: resolvedDisplayName },
|
|
2966
|
-
...resolvedApiNamePlural !== void 0 && { apiNamePlural: resolvedApiNamePlural },
|
|
2967
|
-
...resolvedDisplayNamePlural !== void 0 && {
|
|
2968
|
-
displayNamePlural: resolvedDisplayNamePlural
|
|
2969
|
-
}
|
|
3018
|
+
function createAnalyzerMetadataPolicy(input) {
|
|
3019
|
+
return {
|
|
3020
|
+
raw: input,
|
|
3021
|
+
normalized: normalizeMetadataPolicy(input)
|
|
2970
3022
|
};
|
|
2971
|
-
return Object.keys(metadata).length === 0 ? void 0 : metadata;
|
|
2972
3023
|
}
|
|
2973
|
-
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, buildContext) {
|
|
2974
|
-
const
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
getDeclarationMetadataPolicy(metadataPolicy, declarationKind),
|
|
2987
|
-
makeMetadataContext("tsdoc", declarationKind, logicalName, buildContext)
|
|
3024
|
+
function resolveNodeMetadata(metadataPolicy, declarationKind, logicalName, node, checker, extensionRegistry, buildContext) {
|
|
3025
|
+
const analysis = (0, import_internal3.analyzeMetadataForNodeWithChecker)({
|
|
3026
|
+
checker,
|
|
3027
|
+
node,
|
|
3028
|
+
logicalName,
|
|
3029
|
+
metadata: metadataPolicy.raw,
|
|
3030
|
+
extensions: extensionRegistry?.extensions,
|
|
3031
|
+
...buildContext !== void 0 && { buildContext }
|
|
3032
|
+
});
|
|
3033
|
+
const resolvedMetadata = analysis?.resolvedMetadata;
|
|
3034
|
+
const declarationPolicy = getDeclarationMetadataPolicy(
|
|
3035
|
+
metadataPolicy.normalized,
|
|
3036
|
+
declarationKind
|
|
2988
3037
|
);
|
|
3038
|
+
if (resolvedMetadata?.apiName === void 0 && declarationPolicy.apiName.mode === "require-explicit") {
|
|
3039
|
+
throw new Error(
|
|
3040
|
+
`Metadata policy requires explicit apiName for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
3041
|
+
);
|
|
3042
|
+
}
|
|
3043
|
+
if (resolvedMetadata?.displayName === void 0 && declarationPolicy.displayName.mode === "require-explicit") {
|
|
3044
|
+
throw new Error(
|
|
3045
|
+
`Metadata policy requires explicit displayName for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
3046
|
+
);
|
|
3047
|
+
}
|
|
3048
|
+
if (resolvedMetadata?.apiNamePlural === void 0 && declarationPolicy.apiName.pluralization.mode === "require-explicit") {
|
|
3049
|
+
throw new Error(
|
|
3050
|
+
`Metadata policy requires explicit apiNamePlural for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
3051
|
+
);
|
|
3052
|
+
}
|
|
3053
|
+
if (resolvedMetadata?.displayNamePlural === void 0 && declarationPolicy.displayName.pluralization.mode === "require-explicit") {
|
|
3054
|
+
throw new Error(
|
|
3055
|
+
`Metadata policy requires explicit displayNamePlural for ${declarationKind} "${logicalName}" on the tsdoc surface.`
|
|
3056
|
+
);
|
|
3057
|
+
}
|
|
3058
|
+
return resolvedMetadata;
|
|
2989
3059
|
}
|
|
2990
3060
|
function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
2991
|
-
const normalizedMetadataPolicy =
|
|
3061
|
+
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
2992
3062
|
const declarationType = checker.getTypeAtLocation(declaration);
|
|
2993
3063
|
const logicalName = ts3.isClassDeclaration(declaration) ? declaration.name?.text ?? "AnonymousClass" : declaration.name.text;
|
|
2994
3064
|
const docResult = extractJSDocParseResult(
|
|
@@ -2996,12 +3066,20 @@ function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRe
|
|
|
2996
3066
|
file,
|
|
2997
3067
|
makeParseOptions(extensionRegistry, void 0, checker, declarationType, declarationType)
|
|
2998
3068
|
);
|
|
2999
|
-
const metadata = resolveNodeMetadata(
|
|
3000
|
-
|
|
3069
|
+
const metadata = resolveNodeMetadata(
|
|
3070
|
+
normalizedMetadataPolicy,
|
|
3071
|
+
"type",
|
|
3072
|
+
logicalName,
|
|
3001
3073
|
declaration,
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3074
|
+
checker,
|
|
3075
|
+
extensionRegistry,
|
|
3076
|
+
{
|
|
3077
|
+
checker,
|
|
3078
|
+
declaration,
|
|
3079
|
+
subjectType: declarationType,
|
|
3080
|
+
hostType: declarationType
|
|
3081
|
+
}
|
|
3082
|
+
);
|
|
3005
3083
|
return {
|
|
3006
3084
|
...metadata !== void 0 && { metadata },
|
|
3007
3085
|
annotations: docResult.annotations,
|
|
@@ -3009,7 +3087,7 @@ function analyzeDeclarationRootInfo(declaration, checker, file = "", extensionRe
|
|
|
3009
3087
|
};
|
|
3010
3088
|
}
|
|
3011
3089
|
function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3012
|
-
const normalizedMetadataPolicy =
|
|
3090
|
+
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3013
3091
|
const name = classDecl.name?.text ?? "AnonymousClass";
|
|
3014
3092
|
const fields = [];
|
|
3015
3093
|
const fieldLayouts = [];
|
|
@@ -3064,12 +3142,20 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3064
3142
|
diagnostics,
|
|
3065
3143
|
normalizedMetadataPolicy
|
|
3066
3144
|
);
|
|
3067
|
-
const metadata = resolveNodeMetadata(
|
|
3145
|
+
const metadata = resolveNodeMetadata(
|
|
3146
|
+
normalizedMetadataPolicy,
|
|
3147
|
+
"type",
|
|
3148
|
+
name,
|
|
3149
|
+
classDecl,
|
|
3068
3150
|
checker,
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3151
|
+
extensionRegistry,
|
|
3152
|
+
{
|
|
3153
|
+
checker,
|
|
3154
|
+
declaration: classDecl,
|
|
3155
|
+
subjectType: classType,
|
|
3156
|
+
hostType: classType
|
|
3157
|
+
}
|
|
3158
|
+
);
|
|
3073
3159
|
return {
|
|
3074
3160
|
name,
|
|
3075
3161
|
...metadata !== void 0 && { metadata },
|
|
@@ -3083,7 +3169,7 @@ function analyzeClassToIR(classDecl, checker, file = "", extensionRegistry, meta
|
|
|
3083
3169
|
};
|
|
3084
3170
|
}
|
|
3085
3171
|
function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegistry, metadataPolicy) {
|
|
3086
|
-
const normalizedMetadataPolicy =
|
|
3172
|
+
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3087
3173
|
const name = interfaceDecl.name.text;
|
|
3088
3174
|
const fields = [];
|
|
3089
3175
|
const typeRegistry = {};
|
|
@@ -3125,12 +3211,20 @@ function analyzeInterfaceToIR(interfaceDecl, checker, file = "", extensionRegist
|
|
|
3125
3211
|
normalizedMetadataPolicy
|
|
3126
3212
|
);
|
|
3127
3213
|
const fieldLayouts = specializedFields.map(() => ({}));
|
|
3128
|
-
const metadata = resolveNodeMetadata(
|
|
3214
|
+
const metadata = resolveNodeMetadata(
|
|
3215
|
+
normalizedMetadataPolicy,
|
|
3216
|
+
"type",
|
|
3217
|
+
name,
|
|
3218
|
+
interfaceDecl,
|
|
3129
3219
|
checker,
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3220
|
+
extensionRegistry,
|
|
3221
|
+
{
|
|
3222
|
+
checker,
|
|
3223
|
+
declaration: interfaceDecl,
|
|
3224
|
+
subjectType: interfaceType,
|
|
3225
|
+
hostType: interfaceType
|
|
3226
|
+
}
|
|
3227
|
+
);
|
|
3134
3228
|
return {
|
|
3135
3229
|
name,
|
|
3136
3230
|
...metadata !== void 0 && { metadata },
|
|
@@ -3154,7 +3248,7 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3154
3248
|
};
|
|
3155
3249
|
}
|
|
3156
3250
|
const typeLiteral = typeAlias.type;
|
|
3157
|
-
const normalizedMetadataPolicy =
|
|
3251
|
+
const normalizedMetadataPolicy = createAnalyzerMetadataPolicy(metadataPolicy);
|
|
3158
3252
|
const name = typeAlias.name.text;
|
|
3159
3253
|
const fields = [];
|
|
3160
3254
|
const typeRegistry = {};
|
|
@@ -3195,12 +3289,20 @@ function analyzeTypeAliasToIR(typeAlias, checker, file = "", extensionRegistry,
|
|
|
3195
3289
|
diagnostics,
|
|
3196
3290
|
normalizedMetadataPolicy
|
|
3197
3291
|
);
|
|
3198
|
-
const metadata = resolveNodeMetadata(
|
|
3292
|
+
const metadata = resolveNodeMetadata(
|
|
3293
|
+
normalizedMetadataPolicy,
|
|
3294
|
+
"type",
|
|
3295
|
+
name,
|
|
3296
|
+
typeAlias,
|
|
3199
3297
|
checker,
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3298
|
+
extensionRegistry,
|
|
3299
|
+
{
|
|
3300
|
+
checker,
|
|
3301
|
+
declaration: typeAlias,
|
|
3302
|
+
subjectType: aliasType,
|
|
3303
|
+
hostType: aliasType
|
|
3304
|
+
}
|
|
3305
|
+
);
|
|
3204
3306
|
return {
|
|
3205
3307
|
ok: true,
|
|
3206
3308
|
analysis: {
|
|
@@ -3241,7 +3343,7 @@ function getLeadingParsedTags(node) {
|
|
|
3241
3343
|
if (!commentText.startsWith("/**")) {
|
|
3242
3344
|
continue;
|
|
3243
3345
|
}
|
|
3244
|
-
parsedTags.push(...(0,
|
|
3346
|
+
parsedTags.push(...(0, import_internal3.parseCommentBlock)(commentText, { offset: range.pos }).tags);
|
|
3245
3347
|
}
|
|
3246
3348
|
return parsedTags;
|
|
3247
3349
|
}
|
|
@@ -3453,6 +3555,8 @@ function resolveDiscriminatorApiName(boundType, checker, metadataPolicy) {
|
|
|
3453
3555
|
"type",
|
|
3454
3556
|
getDiscriminatorLogicalName(boundType, declaration, checker),
|
|
3455
3557
|
declaration,
|
|
3558
|
+
checker,
|
|
3559
|
+
void 0,
|
|
3456
3560
|
{
|
|
3457
3561
|
checker,
|
|
3458
3562
|
declaration,
|
|
@@ -3689,12 +3793,20 @@ function analyzeFieldToIR(prop, checker, file, typeRegistry, visiting, diagnosti
|
|
|
3689
3793
|
annotations.push(defaultAnnotation);
|
|
3690
3794
|
}
|
|
3691
3795
|
({ type, annotations } = applyEnumMemberDisplayNames(type, annotations));
|
|
3692
|
-
const metadata = resolveNodeMetadata(
|
|
3796
|
+
const metadata = resolveNodeMetadata(
|
|
3797
|
+
metadataPolicy,
|
|
3798
|
+
"field",
|
|
3799
|
+
name,
|
|
3800
|
+
prop,
|
|
3693
3801
|
checker,
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3802
|
+
extensionRegistry,
|
|
3803
|
+
{
|
|
3804
|
+
checker,
|
|
3805
|
+
declaration: prop,
|
|
3806
|
+
subjectType: tsType,
|
|
3807
|
+
hostType
|
|
3808
|
+
}
|
|
3809
|
+
);
|
|
3698
3810
|
return {
|
|
3699
3811
|
kind: "field",
|
|
3700
3812
|
name,
|
|
@@ -3741,12 +3853,20 @@ function analyzeInterfacePropertyToIR(prop, checker, file, typeRegistry, visitin
|
|
|
3741
3853
|
let annotations = [];
|
|
3742
3854
|
annotations.push(...docResult.annotations);
|
|
3743
3855
|
({ type, annotations } = applyEnumMemberDisplayNames(type, annotations));
|
|
3744
|
-
const metadata = resolveNodeMetadata(
|
|
3856
|
+
const metadata = resolveNodeMetadata(
|
|
3857
|
+
metadataPolicy,
|
|
3858
|
+
"field",
|
|
3859
|
+
name,
|
|
3860
|
+
prop,
|
|
3745
3861
|
checker,
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3862
|
+
extensionRegistry,
|
|
3863
|
+
{
|
|
3864
|
+
checker,
|
|
3865
|
+
declaration: prop,
|
|
3866
|
+
subjectType: tsType,
|
|
3867
|
+
hostType
|
|
3868
|
+
}
|
|
3869
|
+
);
|
|
3750
3870
|
return {
|
|
3751
3871
|
kind: "field",
|
|
3752
3872
|
name,
|
|
@@ -3875,7 +3995,7 @@ function getTypeNodeRegistrationName(typeNode) {
|
|
|
3875
3995
|
}
|
|
3876
3996
|
return null;
|
|
3877
3997
|
}
|
|
3878
|
-
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy =
|
|
3998
|
+
function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
3879
3999
|
const customType = resolveRegisteredCustomType(sourceNode, extensionRegistry, checker);
|
|
3880
4000
|
if (customType) {
|
|
3881
4001
|
return customType;
|
|
@@ -3965,7 +4085,7 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
|
|
|
3965
4085
|
}
|
|
3966
4086
|
return { kind: "primitive", primitiveKind: "string" };
|
|
3967
4087
|
}
|
|
3968
|
-
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy =
|
|
4088
|
+
function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
3969
4089
|
if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null))) {
|
|
3970
4090
|
return null;
|
|
3971
4091
|
}
|
|
@@ -3985,11 +4105,19 @@ function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiti
|
|
|
3985
4105
|
file,
|
|
3986
4106
|
makeParseOptions(extensionRegistry)
|
|
3987
4107
|
);
|
|
3988
|
-
const metadata = resolveNodeMetadata(
|
|
4108
|
+
const metadata = resolveNodeMetadata(
|
|
4109
|
+
metadataPolicy,
|
|
4110
|
+
"type",
|
|
4111
|
+
aliasName,
|
|
4112
|
+
aliasDecl,
|
|
3989
4113
|
checker,
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
4114
|
+
extensionRegistry,
|
|
4115
|
+
{
|
|
4116
|
+
checker,
|
|
4117
|
+
declaration: aliasDecl,
|
|
4118
|
+
subjectType: aliasType
|
|
4119
|
+
}
|
|
4120
|
+
);
|
|
3993
4121
|
typeRegistry[aliasName] = {
|
|
3994
4122
|
name: aliasName,
|
|
3995
4123
|
...metadata !== void 0 && { metadata },
|
|
@@ -4028,7 +4156,7 @@ function shouldEmitPrimitiveAliasDefinition(typeNode, checker) {
|
|
|
4028
4156
|
const resolved = checker.getTypeFromTypeNode(aliasDecl.type);
|
|
4029
4157
|
return !!(resolved.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null));
|
|
4030
4158
|
}
|
|
4031
|
-
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy =
|
|
4159
|
+
function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4032
4160
|
const nestedAliasDecl = type.aliasSymbol?.declarations?.find(ts3.isTypeAliasDeclaration);
|
|
4033
4161
|
if (nestedAliasDecl !== void 0) {
|
|
4034
4162
|
return resolveAliasedPrimitiveTarget(
|
|
@@ -4054,7 +4182,7 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
|
|
|
4054
4182
|
diagnostics
|
|
4055
4183
|
);
|
|
4056
4184
|
}
|
|
4057
|
-
function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy =
|
|
4185
|
+
function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4058
4186
|
const typeName = getNamedTypeName(type);
|
|
4059
4187
|
const namedDecl = getNamedTypeDeclaration(type);
|
|
4060
4188
|
if (typeName && typeName in typeRegistry) {
|
|
@@ -4089,11 +4217,19 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4089
4217
|
return result;
|
|
4090
4218
|
}
|
|
4091
4219
|
const annotations = namedDecl ? extractJSDocAnnotationNodes(namedDecl, file, makeParseOptions(extensionRegistry)) : void 0;
|
|
4092
|
-
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4220
|
+
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4221
|
+
metadataPolicy,
|
|
4222
|
+
"type",
|
|
4223
|
+
typeName,
|
|
4224
|
+
namedDecl,
|
|
4093
4225
|
checker,
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4226
|
+
extensionRegistry,
|
|
4227
|
+
{
|
|
4228
|
+
checker,
|
|
4229
|
+
declaration: namedDecl,
|
|
4230
|
+
subjectType: type
|
|
4231
|
+
}
|
|
4232
|
+
) : void 0;
|
|
4097
4233
|
typeRegistry[typeName] = {
|
|
4098
4234
|
name: typeName,
|
|
4099
4235
|
...metadata !== void 0 && { metadata },
|
|
@@ -4178,7 +4314,7 @@ function resolveUnionType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4178
4314
|
}
|
|
4179
4315
|
return registerNamed({ kind: "union", members });
|
|
4180
4316
|
}
|
|
4181
|
-
function resolveArrayType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy =
|
|
4317
|
+
function resolveArrayType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4182
4318
|
const typeArgs = isTypeReference(type) ? type.typeArguments : void 0;
|
|
4183
4319
|
const elementType = typeArgs?.[0];
|
|
4184
4320
|
const elementSourceNode = extractArrayElementTypeNode(sourceNode, checker);
|
|
@@ -4195,7 +4331,7 @@ function resolveArrayType(type, checker, file, typeRegistry, visiting, sourceNod
|
|
|
4195
4331
|
) : { kind: "primitive", primitiveKind: "string" };
|
|
4196
4332
|
return { kind: "array", items };
|
|
4197
4333
|
}
|
|
4198
|
-
function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metadataPolicy =
|
|
4334
|
+
function tryResolveRecordType(type, checker, file, typeRegistry, visiting, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4199
4335
|
if (type.getProperties().length > 0) {
|
|
4200
4336
|
return null;
|
|
4201
4337
|
}
|
|
@@ -4256,7 +4392,7 @@ function shouldEmitResolvedObjectProperty(property, declaration) {
|
|
|
4256
4392
|
}
|
|
4257
4393
|
return true;
|
|
4258
4394
|
}
|
|
4259
|
-
function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy =
|
|
4395
|
+
function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
|
|
4260
4396
|
const collectedDiagnostics = diagnostics ?? [];
|
|
4261
4397
|
const typeName = getNamedTypeName(type);
|
|
4262
4398
|
const namedTypeName = typeName ?? void 0;
|
|
@@ -4332,11 +4468,19 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4332
4468
|
return recordNode;
|
|
4333
4469
|
}
|
|
4334
4470
|
const annotations = namedDecl ? extractJSDocAnnotationNodes(namedDecl, file, makeParseOptions(extensionRegistry)) : void 0;
|
|
4335
|
-
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4471
|
+
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4472
|
+
metadataPolicy,
|
|
4473
|
+
"type",
|
|
4474
|
+
registryTypeName,
|
|
4475
|
+
namedDecl,
|
|
4336
4476
|
checker,
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4477
|
+
extensionRegistry,
|
|
4478
|
+
{
|
|
4479
|
+
checker,
|
|
4480
|
+
declaration: namedDecl,
|
|
4481
|
+
subjectType: type
|
|
4482
|
+
}
|
|
4483
|
+
) : void 0;
|
|
4340
4484
|
typeRegistry[registryTypeName] = {
|
|
4341
4485
|
name: registryTypeName,
|
|
4342
4486
|
...metadata !== void 0 && { metadata },
|
|
@@ -4432,11 +4576,19 @@ function resolveObjectType(type, checker, file, typeRegistry, visiting, sourceNo
|
|
|
4432
4576
|
};
|
|
4433
4577
|
if (registryTypeName !== void 0 && shouldRegisterNamedType) {
|
|
4434
4578
|
const annotations = namedDecl ? extractJSDocAnnotationNodes(namedDecl, file, makeParseOptions(extensionRegistry)) : void 0;
|
|
4435
|
-
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4579
|
+
const metadata = namedDecl !== void 0 ? resolveNodeMetadata(
|
|
4580
|
+
metadataPolicy,
|
|
4581
|
+
"type",
|
|
4582
|
+
registryTypeName,
|
|
4583
|
+
namedDecl,
|
|
4436
4584
|
checker,
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4585
|
+
extensionRegistry,
|
|
4586
|
+
{
|
|
4587
|
+
checker,
|
|
4588
|
+
declaration: namedDecl,
|
|
4589
|
+
subjectType: type
|
|
4590
|
+
}
|
|
4591
|
+
) : void 0;
|
|
4440
4592
|
typeRegistry[registryTypeName] = {
|
|
4441
4593
|
name: registryTypeName,
|
|
4442
4594
|
...metadata !== void 0 && { metadata },
|
|
@@ -4713,12 +4865,12 @@ function detectFormSpecReference(typeNode) {
|
|
|
4713
4865
|
}
|
|
4714
4866
|
return null;
|
|
4715
4867
|
}
|
|
4716
|
-
var ts3,
|
|
4868
|
+
var ts3, import_internal3, RESOLVING_TYPE_PLACEHOLDER, MAX_ALIAS_CHAIN_DEPTH;
|
|
4717
4869
|
var init_class_analyzer = __esm({
|
|
4718
4870
|
"src/analyzer/class-analyzer.ts"() {
|
|
4719
4871
|
"use strict";
|
|
4720
4872
|
ts3 = __toESM(require("typescript"), 1);
|
|
4721
|
-
|
|
4873
|
+
import_internal3 = require("@formspec/analysis/internal");
|
|
4722
4874
|
init_jsdoc_constraints();
|
|
4723
4875
|
init_tsdoc_parser();
|
|
4724
4876
|
init_metadata();
|
|
@@ -4874,7 +5026,7 @@ var init_program = __esm({
|
|
|
4874
5026
|
|
|
4875
5027
|
// src/validate/constraint-validator.ts
|
|
4876
5028
|
function validateFieldNode(ctx, field) {
|
|
4877
|
-
const analysis = (0,
|
|
5029
|
+
const analysis = (0, import_internal4.analyzeConstraintTargets)(
|
|
4878
5030
|
field.name,
|
|
4879
5031
|
field.type,
|
|
4880
5032
|
field.constraints,
|
|
@@ -4892,7 +5044,7 @@ function validateFieldNode(ctx, field) {
|
|
|
4892
5044
|
}
|
|
4893
5045
|
function validateObjectProperty(ctx, parentName, property) {
|
|
4894
5046
|
const qualifiedName = `${parentName}.${property.name}`;
|
|
4895
|
-
const analysis = (0,
|
|
5047
|
+
const analysis = (0, import_internal4.analyzeConstraintTargets)(
|
|
4896
5048
|
qualifiedName,
|
|
4897
5049
|
property.type,
|
|
4898
5050
|
property.constraints,
|
|
@@ -4943,11 +5095,11 @@ function validateIR(ir, options) {
|
|
|
4943
5095
|
valid: ctx.diagnostics.every((diagnostic) => diagnostic.severity !== "error")
|
|
4944
5096
|
};
|
|
4945
5097
|
}
|
|
4946
|
-
var
|
|
5098
|
+
var import_internal4;
|
|
4947
5099
|
var init_constraint_validator = __esm({
|
|
4948
5100
|
"src/validate/constraint-validator.ts"() {
|
|
4949
5101
|
"use strict";
|
|
4950
|
-
|
|
5102
|
+
import_internal4 = require("@formspec/analysis/internal");
|
|
4951
5103
|
}
|
|
4952
5104
|
});
|
|
4953
5105
|
|
|
@@ -5213,7 +5365,7 @@ function toStandaloneJsonSchema(root, typeRegistry, options) {
|
|
|
5213
5365
|
{
|
|
5214
5366
|
kind: "form-ir",
|
|
5215
5367
|
name: root.name,
|
|
5216
|
-
irVersion:
|
|
5368
|
+
irVersion: import_internals6.IR_VERSION,
|
|
5217
5369
|
elements: [syntheticField],
|
|
5218
5370
|
...root.metadata !== void 0 && { metadata: root.metadata },
|
|
5219
5371
|
...root.annotations !== void 0 && root.annotations.length > 0 && { rootAnnotations: root.annotations },
|
|
@@ -5272,7 +5424,7 @@ function generateSchemasFromResolvedType(options, skipNamedDeclaration = false,
|
|
|
5272
5424
|
typeRegistry,
|
|
5273
5425
|
/* @__PURE__ */ new Set(),
|
|
5274
5426
|
options.sourceNode,
|
|
5275
|
-
|
|
5427
|
+
createAnalyzerMetadataPolicy(options.metadata),
|
|
5276
5428
|
options.extensionRegistry,
|
|
5277
5429
|
diagnostics
|
|
5278
5430
|
);
|
|
@@ -5404,7 +5556,7 @@ function generateSchemasFromReturnType(options) {
|
|
|
5404
5556
|
name: fallbackName
|
|
5405
5557
|
});
|
|
5406
5558
|
}
|
|
5407
|
-
var ts7,
|
|
5559
|
+
var ts7, import_internals6;
|
|
5408
5560
|
var init_discovered_schema = __esm({
|
|
5409
5561
|
"src/generators/discovered-schema.ts"() {
|
|
5410
5562
|
"use strict";
|
|
@@ -5412,7 +5564,7 @@ var init_discovered_schema = __esm({
|
|
|
5412
5564
|
init_class_analyzer();
|
|
5413
5565
|
init_class_schema();
|
|
5414
5566
|
init_ir_generator();
|
|
5415
|
-
|
|
5567
|
+
import_internals6 = require("@formspec/core/internals");
|
|
5416
5568
|
init_metadata();
|
|
5417
5569
|
}
|
|
5418
5570
|
});
|