@orkestrel/guide 0.0.17 → 0.0.18
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/README.md +40 -20
- package/dist/src/core/index.cjs +2400 -264
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +1616 -203
- package/dist/src/core/index.d.ts +1616 -203
- package/dist/src/core/index.js +2351 -269
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +3867 -0
- package/dist/src/server/index.cjs.map +1 -0
- package/dist/src/server/index.d.cts +686 -0
- package/dist/src/server/index.d.ts +686 -0
- package/dist/src/server/index.js +3833 -0
- package/dist/src/server/index.js.map +1 -0
- package/package.json +29 -17
package/dist/src/core/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { createMarkdown, flattenText, isCodeBlockNode, isCodeSpanNode, isEmphasisNode, isHeadingNode, isImageNode, isLinkNode, isTableNode, walkNodes } from "@orkestrel/markdown";
|
|
2
|
-
import { arrayOf, arrayShape, createContract, isEmptyString, isNonEmptyArray, isNonEmptyString, isString, literalOf, literalShape, objectShape, recordOf, stringShape, unionOf, unionShape } from "@orkestrel/contract";
|
|
1
|
+
import { coalesceText, createMarkdown, flattenText, isBlockquoteNode, isCodeBlockNode, isCodeSpanNode, isEmphasisNode, isHeadingNode, isImageNode, isLinkNode, isParagraphNode, isTableNode, renderMarkdown, walkNodes } from "@orkestrel/markdown";
|
|
2
|
+
import { arrayOf, arrayShape, createContract, isEmptyString, isNonEmptyArray, isNonEmptyString, isString, literalOf, literalShape, objectShape, optionalShape, recordOf, stringShape, unionOf, unionShape } from "@orkestrel/contract";
|
|
3
3
|
//#region src/core/constants.ts
|
|
4
4
|
/**
|
|
5
|
-
* Lists the declaration keywords a documented or exported symbol carries, in
|
|
6
|
-
*
|
|
5
|
+
* Lists the declaration keywords a documented or exported symbol carries, in the order the
|
|
6
|
+
* reflection grammar names them — the frozen population `ExportKeyword`, `isExportKeyword`, and
|
|
7
|
+
* `surfaceSymbolShape` all derive from.
|
|
7
8
|
*
|
|
8
9
|
* @remarks
|
|
9
|
-
* One frozen list feeds the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* `enum` is outside this population rather than forbidden by general package
|
|
13
|
-
* policy.
|
|
10
|
+
* One frozen list feeds the type, the guard, and the shape, so a keyword cannot be admitted by one
|
|
11
|
+
* and refused by another. Comment and template payload is excluded before reflection, and `enum`
|
|
12
|
+
* is outside this population rather than forbidden by general package policy.
|
|
14
13
|
*/
|
|
15
14
|
var EXPORT_KEYWORDS = Object.freeze([
|
|
16
15
|
"type",
|
|
@@ -20,6 +19,10 @@ var EXPORT_KEYWORDS = Object.freeze([
|
|
|
20
19
|
"class"
|
|
21
20
|
]);
|
|
22
21
|
/**
|
|
22
|
+
* Lists the compared sites a {@link Drift} can describe.
|
|
23
|
+
*/
|
|
24
|
+
var DRIFT_CATEGORIES = Object.freeze(["summary", "example"]);
|
|
25
|
+
/**
|
|
23
26
|
* Names the `## Surface` heading text a guide's documented exports section is keyed on.
|
|
24
27
|
*/
|
|
25
28
|
var SURFACE = "Surface";
|
|
@@ -32,10 +35,34 @@ var METHODS = "Methods";
|
|
|
32
35
|
*/
|
|
33
36
|
var TESTS = "Tests";
|
|
34
37
|
/**
|
|
38
|
+
* Names the header text of the column a `## Surface` table's declaration keyword is read from.
|
|
39
|
+
*/
|
|
40
|
+
var KIND = "Kind";
|
|
41
|
+
/**
|
|
42
|
+
* Names the header text of the column a `## Surface` or `## Methods` table's compared
|
|
43
|
+
* description paragraph is read from.
|
|
44
|
+
*/
|
|
45
|
+
var SUMMARY = "Summary";
|
|
46
|
+
/**
|
|
35
47
|
* Names the `## By concept` heading text the manifest's run-map table is keyed on.
|
|
36
48
|
*/
|
|
37
49
|
var MANIFEST = "By concept";
|
|
38
50
|
/**
|
|
51
|
+
* Holds the default character budget a rewritten doc block's description paragraph wraps
|
|
52
|
+
* inside — the greatest number of characters a re-wrapped line may carry, counted from the
|
|
53
|
+
* line's first character with a tab counting as one, so a wrapped line reads
|
|
54
|
+
* `${indent} * ${text}` and never passes that count.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* The budget counts characters, not rendered columns. A block indented with tabs therefore
|
|
58
|
+
* measures each tab as one character, and a formatter that renders a tab wider reads the same
|
|
59
|
+
* line as longer; a caller whose formatter measures differently passes its own width instead of
|
|
60
|
+
* taking this default. A doc block's own wrapping is not recoverable from its text either — the
|
|
61
|
+
* blocks this package's own source carries are hand-wrapped, and no single greedy width
|
|
62
|
+
* reproduces them — so a rewrite cannot infer a per-block width and falls back to this budget.
|
|
63
|
+
*/
|
|
64
|
+
var WRAP_WIDTH = 100;
|
|
65
|
+
/**
|
|
39
66
|
* Lists the link `href` schemes a guides-parity link check skips as external — a link
|
|
40
67
|
* with one of these prefixes (or a bare `#` anchor, handled separately in
|
|
41
68
|
* `isExternalLink`) is never resolved against the filesystem.
|
|
@@ -63,9 +90,11 @@ var EXTERNAL_SCHEMES = Object.freeze([
|
|
|
63
90
|
* ```
|
|
64
91
|
*/
|
|
65
92
|
var isExportKeyword = literalOf(EXPORT_KEYWORDS);
|
|
93
|
+
/** Checks whether `value` names a supported drift category. */
|
|
94
|
+
var isDriftCategory = literalOf(DRIFT_CATEGORIES);
|
|
66
95
|
/**
|
|
67
96
|
* Checks whether `value` is a well-formed {@link SurfaceSymbol} — a `name`
|
|
68
|
-
* string paired with a valid {@link ExportKeyword}
|
|
97
|
+
* string paired with a valid {@link ExportKeyword}, and an optional `summary`.
|
|
69
98
|
*
|
|
70
99
|
* @param value - The value to test
|
|
71
100
|
* @returns True if `value` is a well-formed {@link SurfaceSymbol}; false otherwise
|
|
@@ -78,24 +107,80 @@ var isExportKeyword = literalOf(EXPORT_KEYWORDS);
|
|
|
78
107
|
*/
|
|
79
108
|
var isSurfaceSymbol = recordOf({
|
|
80
109
|
name: isString,
|
|
81
|
-
keyword: isExportKeyword
|
|
82
|
-
|
|
110
|
+
keyword: isExportKeyword,
|
|
111
|
+
summary: isString
|
|
112
|
+
}, ["summary"]);
|
|
113
|
+
/**
|
|
114
|
+
* Checks whether `value` is a well-formed {@link MethodEntry} — a `name` string with an
|
|
115
|
+
* optional `summary`.
|
|
116
|
+
*
|
|
117
|
+
* @param value - The value to test
|
|
118
|
+
* @returns True if `value` is a well-formed {@link MethodEntry}; false otherwise
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* isMethodEntry({ name: 'walk' }) // true
|
|
123
|
+
* isMethodEntry({ name: 1 }) // false
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
var isMethodEntry = recordOf({
|
|
127
|
+
name: isString,
|
|
128
|
+
summary: isString
|
|
129
|
+
}, ["summary"]);
|
|
130
|
+
/**
|
|
131
|
+
* Checks whether `value` is a well-formed {@link SourceExample} — a `name` and `code`
|
|
132
|
+
* string with an optional `title` and `language`.
|
|
133
|
+
*
|
|
134
|
+
* @param value - The value to test
|
|
135
|
+
* @returns True if `value` is a well-formed {@link SourceExample}; false otherwise
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* isSourceExample({ name: 'walk', code: 'walk()' }) // true
|
|
140
|
+
* isSourceExample({ name: 'walk' }) // false
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
var isSourceExample = recordOf({
|
|
144
|
+
name: isString,
|
|
145
|
+
title: isString,
|
|
146
|
+
code: isString,
|
|
147
|
+
language: isString
|
|
148
|
+
}, ["title", "language"]);
|
|
149
|
+
/**
|
|
150
|
+
* Checks whether `value` is a well-formed {@link Drift} — a compared `key` with an optional
|
|
151
|
+
* `guide` and `source` text.
|
|
152
|
+
*
|
|
153
|
+
* @param value - The value to test
|
|
154
|
+
* @returns True if `value` is a well-formed {@link Drift}; false otherwise
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* isDrift({ key: 'class Widget', category: 'summary', guide: 'A widget.' }) // true
|
|
159
|
+
* isDrift({ guide: 'A widget.' }) // false
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
var isDrift = recordOf({
|
|
163
|
+
key: isString,
|
|
164
|
+
category: isDriftCategory,
|
|
165
|
+
guide: isString,
|
|
166
|
+
source: isString
|
|
167
|
+
}, ["guide", "source"]);
|
|
83
168
|
/**
|
|
84
169
|
* Checks whether `value` is a well-formed {@link MethodGroup} — a backticked
|
|
85
|
-
* `interface` name paired with its documented
|
|
170
|
+
* `interface` name paired with its documented {@link MethodEntry} rows.
|
|
86
171
|
*
|
|
87
172
|
* @param value - The value to test
|
|
88
173
|
* @returns True if `value` is a well-formed {@link MethodGroup}; false otherwise
|
|
89
174
|
*
|
|
90
175
|
* @example
|
|
91
176
|
* ```ts
|
|
92
|
-
* isMethodGroup({ interface: 'MarkdownInterface', methods: ['walk'] }) // true
|
|
93
|
-
* isMethodGroup({ interface: 'MarkdownInterface', methods: [1] })
|
|
177
|
+
* isMethodGroup({ interface: 'MarkdownInterface', methods: [{ name: 'walk' }] }) // true
|
|
178
|
+
* isMethodGroup({ interface: 'MarkdownInterface', methods: [1] }) // false
|
|
94
179
|
* ```
|
|
95
180
|
*/
|
|
96
181
|
var isMethodGroup = recordOf({
|
|
97
182
|
interface: isString,
|
|
98
|
-
methods: arrayOf(
|
|
183
|
+
methods: arrayOf(isMethodEntry)
|
|
99
184
|
});
|
|
100
185
|
/**
|
|
101
186
|
* Checks whether `value` is a well-formed {@link ManifestEntry} — a
|
|
@@ -141,10 +226,13 @@ var isManifestEntry = recordOf({
|
|
|
141
226
|
* @param source - The TypeScript source text to project
|
|
142
227
|
* @returns One aligned terminator-free record per LF or CRLF physical line, including the final line
|
|
143
228
|
*
|
|
144
|
-
* @example
|
|
229
|
+
* @example Project source into physical code lines
|
|
145
230
|
* ```ts
|
|
231
|
+
* import { extractSourceLines } from '@orkestrel/guide'
|
|
232
|
+
*
|
|
146
233
|
* extractSourceLines('export const visible = true // note\n')
|
|
147
|
-
* // [{ source: 'export const visible = true // note', code: 'export const visible = true ', jsdoc: undefined }
|
|
234
|
+
* // [{ source: 'export const visible = true // note', code: 'export const visible = true ', jsdoc: undefined }]
|
|
235
|
+
* // … one record per remaining line
|
|
148
236
|
* ```
|
|
149
237
|
*/
|
|
150
238
|
function extractSourceLines(source) {
|
|
@@ -696,8 +784,8 @@ function selectModuleKeys(files, module) {
|
|
|
696
784
|
return keys.sort();
|
|
697
785
|
}
|
|
698
786
|
/**
|
|
699
|
-
* Computes the bijection key for a surface symbol —
|
|
700
|
-
*
|
|
787
|
+
* Computes the bijection key for a surface symbol — `${keyword} ${name}` — so a symbol-set
|
|
788
|
+
* comparison diffs (name, keyword) pairs rather than names alone.
|
|
701
789
|
*
|
|
702
790
|
* @param symbol - The symbol to key
|
|
703
791
|
* @returns The `${keyword} ${name}` key
|
|
@@ -787,10 +875,11 @@ function findUnexampled(names, fences, examples) {
|
|
|
787
875
|
});
|
|
788
876
|
}
|
|
789
877
|
/**
|
|
790
|
-
* Parses a fence's `import` statements into per-specifier imported identifier
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
*
|
|
878
|
+
* Parses a fence's brace `import` statements into per-specifier imported identifier names —
|
|
879
|
+
* `import type`, mixed multiline braces, and `x as y` aliases all count, each alias resolved to
|
|
880
|
+
* the exported name `x` because that is the name the checked barrel surface must hold. Brace
|
|
881
|
+
* bindings only: a default, namespace, side-effect, or mixed `import Default, { named }`
|
|
882
|
+
* statement is not surfaced.
|
|
794
883
|
*
|
|
795
884
|
* @param fence - A ```ts Patterns fence's verbatim body text
|
|
796
885
|
* @returns One entry per `import ... from 'specifier'` statement, in fence order
|
|
@@ -908,7 +997,7 @@ function findFirstCode(nodes) {
|
|
|
908
997
|
}
|
|
909
998
|
}
|
|
910
999
|
/**
|
|
911
|
-
* Extracts the link hrefs within one table cell's inline content.
|
|
1000
|
+
* Extracts the link hrefs within one table cell's inline content, in walk order.
|
|
912
1001
|
*
|
|
913
1002
|
* @param cell - The cell's inline nodes
|
|
914
1003
|
* @returns The cell's link hrefs, in walk order
|
|
@@ -947,38 +1036,117 @@ function normalizeIdentifier(code) {
|
|
|
947
1036
|
return (index < 0 ? code : code.slice(0, index)).trim();
|
|
948
1037
|
}
|
|
949
1038
|
/**
|
|
950
|
-
*
|
|
951
|
-
*
|
|
952
|
-
*
|
|
1039
|
+
* Extracts compared inline content — the text of a table cell or candidate entity heading
|
|
1040
|
+
* flattened with every code span kept as a code span, so `` `Widget` `` reads the same wherever
|
|
1041
|
+
* the parity reader compares it. Emphasis drops to its text, a link drops to its text, an image
|
|
1042
|
+
* drops to its alternative text, and the markdown parser has already unescaped `\|`.
|
|
1043
|
+
*
|
|
1044
|
+
* @param cell - The inline nodes to flatten
|
|
1045
|
+
* @returns The compared text, code spans included
|
|
1046
|
+
*
|
|
1047
|
+
* @example
|
|
1048
|
+
* ```ts
|
|
1049
|
+
* extractCellText([{ element: 'codeSpan', value: 'Widget' }]) // '`Widget`'
|
|
1050
|
+
* ```
|
|
1051
|
+
*/
|
|
1052
|
+
function extractCellText(cell) {
|
|
1053
|
+
let text = "";
|
|
1054
|
+
for (const node of cell) if (isCodeSpanNode(node)) text += `\`${node.value}\``;
|
|
1055
|
+
else if (isEmphasisNode(node) || isLinkNode(node) || isImageNode(node)) text += extractCellText(node.children);
|
|
1056
|
+
else text += flattenText(node);
|
|
1057
|
+
return text;
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Builds one table cell's inline content from its compared text — the inverse of
|
|
1061
|
+
* {@link extractCellText}. A single-backtick run whose text carries no inner backtick and
|
|
1062
|
+
* neither a leading nor a trailing space becomes a code span; every other character, a backtick
|
|
1063
|
+
* included, becomes literal text, which `renderMarkdown` escapes so the rendered cell parses back
|
|
1064
|
+
* to the text this function was given.
|
|
1065
|
+
*
|
|
1066
|
+
* @remarks
|
|
1067
|
+
* The compared form spells every code span with one backtick per side, because
|
|
1068
|
+
* {@link extractCellText} emits `` `${value}` `` whatever delimiter the source used. A run this
|
|
1069
|
+
* function refuses is therefore a run no parsed cell produced, and emitting it as text is what
|
|
1070
|
+
* keeps the projection total: reading the rendered cell back through {@link extractCellText}
|
|
1071
|
+
* returns the text, so a rendered row and a hand-written row compare the same. A code span whose
|
|
1072
|
+
* own text carries a backtick or a boundary space is outside the compared form's fidelity in
|
|
1073
|
+
* either direction, and this function writes it as text rather than guessing a delimiter.
|
|
1074
|
+
*
|
|
1075
|
+
* @param text - The cell's compared text, as {@link extractCellText} returns it
|
|
1076
|
+
* @returns The cell's inline nodes, in text order
|
|
1077
|
+
*
|
|
1078
|
+
* @example
|
|
1079
|
+
* ```ts
|
|
1080
|
+
* buildCell('Holds a `Widget`.')
|
|
1081
|
+
* // [{ element: 'text', value: 'Holds a ' }, { element: 'codeSpan', value: 'Widget' }, { element: 'text', value: '.' }]
|
|
1082
|
+
* ```
|
|
1083
|
+
*/
|
|
1084
|
+
function buildCell(text) {
|
|
1085
|
+
const nodes = [];
|
|
1086
|
+
const spans = /`([^`]+)`/g;
|
|
1087
|
+
let cursor = 0;
|
|
1088
|
+
let span;
|
|
1089
|
+
while ((span = spans.exec(text)) !== null) {
|
|
1090
|
+
const value = span[1];
|
|
1091
|
+
if (value === void 0) continue;
|
|
1092
|
+
if (span.index > cursor) nodes.push({
|
|
1093
|
+
element: "text",
|
|
1094
|
+
value: text.slice(cursor, span.index)
|
|
1095
|
+
});
|
|
1096
|
+
if (value.trim() === value) nodes.push({
|
|
1097
|
+
element: "codeSpan",
|
|
1098
|
+
value
|
|
1099
|
+
});
|
|
1100
|
+
else nodes.push({
|
|
1101
|
+
element: "text",
|
|
1102
|
+
value: span[0]
|
|
1103
|
+
});
|
|
1104
|
+
cursor = span.index + span[0].length;
|
|
1105
|
+
}
|
|
1106
|
+
if (cursor < text.length) nodes.push({
|
|
1107
|
+
element: "text",
|
|
1108
|
+
value: text.slice(cursor)
|
|
1109
|
+
});
|
|
1110
|
+
return coalesceText(nodes);
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Finds the index of the column whose header text is `header` so a table's columns survive
|
|
1114
|
+
* reordering. The match is exact and case-sensitive — a table without that exact header
|
|
1115
|
+
* contributes nothing to the projection reading it, so a `## Surface` table with no
|
|
1116
|
+
* {@link SUMMARY} column leaves every row's summary absent and {@link findDrift} reports each
|
|
1117
|
+
* of those rows, never agreement.
|
|
953
1118
|
*
|
|
954
1119
|
* @param table - The table to inspect
|
|
955
|
-
* @
|
|
1120
|
+
* @param header - The exact header text to locate, for example `Kind`
|
|
1121
|
+
* @returns The column's index, or `undefined` when the table has no such header
|
|
956
1122
|
*
|
|
957
1123
|
* @example
|
|
958
1124
|
* ```ts
|
|
959
|
-
*
|
|
1125
|
+
* findColumnIndex(table, 'Kind') // 1, or undefined
|
|
960
1126
|
* ```
|
|
961
1127
|
*/
|
|
962
|
-
function
|
|
1128
|
+
function findColumnIndex(table, header) {
|
|
963
1129
|
for (let index = 0; index < table.header.length; index += 1) {
|
|
964
1130
|
const cell = table.header[index];
|
|
965
1131
|
if (cell !== void 0 && flattenText({
|
|
966
1132
|
element: "paragraph",
|
|
967
1133
|
children: cell
|
|
968
|
-
}).trim() ===
|
|
1134
|
+
}).trim() === header) return index;
|
|
969
1135
|
}
|
|
970
1136
|
}
|
|
971
1137
|
/**
|
|
972
|
-
* Extracts the module-scope exports declared in one file's source text —
|
|
973
|
-
*
|
|
974
|
-
*
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
*
|
|
978
|
-
*
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
1138
|
+
* Extracts the module-scope exports declared in one file's source text — the declaration keys
|
|
1139
|
+
* {@link collectKeys} reports, each split back into the keyword and name that built it, deduped by
|
|
1140
|
+
* (keyword, name).
|
|
1141
|
+
*
|
|
1142
|
+
* @remarks
|
|
1143
|
+
* That one grammar matches `export (async)? (function(\*)?|class|const|interface|type) Name`; a
|
|
1144
|
+
* generator export (`export function* walk`) keys as the `function` keyword, its trailing `*`
|
|
1145
|
+
* stripped before the {@link ExportKeyword} check. Scanning uses {@link extractSourceLines}, so
|
|
1146
|
+
* comment and template payload is excluded while its uninterrupted column-zero head remains
|
|
1147
|
+
* required; preserved columns do not grant membership to leading/interrupted comment forms. The
|
|
1148
|
+
* population is exactly `type`, `interface`, `const`, `function`, and `class`; `enum` is outside
|
|
1149
|
+
* this reflection contract, not forbidden by general package policy.
|
|
982
1150
|
*
|
|
983
1151
|
* @param source - The file's source text
|
|
984
1152
|
* @returns The file's exported symbols, in file order
|
|
@@ -992,33 +1160,38 @@ function findKindIndex(table) {
|
|
|
992
1160
|
function extractExports(source) {
|
|
993
1161
|
const symbols = [];
|
|
994
1162
|
const seen = /* @__PURE__ */ new Set();
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
1001
|
-
const
|
|
1002
|
-
|
|
1163
|
+
const lines = extractSourceLines(source);
|
|
1164
|
+
const summaries = collectSummaries(lines);
|
|
1165
|
+
const keys = collectKeys(lines);
|
|
1166
|
+
for (const line of lines) {
|
|
1167
|
+
const key = keys.get(line);
|
|
1168
|
+
if (key === void 0 || seen.has(key)) continue;
|
|
1169
|
+
const space = key.indexOf(" ");
|
|
1170
|
+
const keyword = key.slice(0, Math.max(space, 0));
|
|
1171
|
+
if (!isExportKeyword(keyword)) continue;
|
|
1003
1172
|
seen.add(key);
|
|
1173
|
+
const name = key.slice(space + 1);
|
|
1174
|
+
const summary = summaries.get(line);
|
|
1004
1175
|
symbols.push({
|
|
1005
1176
|
name,
|
|
1006
|
-
keyword
|
|
1177
|
+
keyword,
|
|
1178
|
+
...summary === void 0 ? {} : { summary }
|
|
1007
1179
|
});
|
|
1008
1180
|
}
|
|
1009
1181
|
return symbols;
|
|
1010
1182
|
}
|
|
1011
1183
|
/**
|
|
1012
|
-
* Extracts the module-scope declarations lacking the `export` keyword in one file's
|
|
1013
|
-
*
|
|
1014
|
-
*
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1017
|
-
*
|
|
1018
|
-
*
|
|
1019
|
-
* and
|
|
1020
|
-
*
|
|
1021
|
-
*
|
|
1184
|
+
* Extracts the module-scope declarations lacking the `export` keyword in one file's source text —
|
|
1185
|
+
* the mirror image of {@link extractExports}'s grammar, anchored the same way (column 0, so an
|
|
1186
|
+
* indented inner declaration never matches).
|
|
1187
|
+
*
|
|
1188
|
+
* @remarks
|
|
1189
|
+
* Scans only the {@link ExportKeyword} keywords (`function` / `class` / `const` / `interface` /
|
|
1190
|
+
* `type`) — a module-scope `let` or `var` is outside this scanner's declaration-keyword grammar
|
|
1191
|
+
* and out of this check's contract. Scanning uses {@link extractSourceLines}, so comment and
|
|
1192
|
+
* template payload is excluded while its uninterrupted column-zero head remains required;
|
|
1193
|
+
* preserved columns do not widen membership. `enum` is likewise outside this reflection
|
|
1194
|
+
* population, not forbidden by general package policy.
|
|
1022
1195
|
*
|
|
1023
1196
|
* @param source - The file's source text
|
|
1024
1197
|
* @returns The file's hidden (non-exported) symbols, in file order
|
|
@@ -1032,7 +1205,9 @@ function extractExports(source) {
|
|
|
1032
1205
|
function extractHidden(source) {
|
|
1033
1206
|
const symbols = [];
|
|
1034
1207
|
const seen = /* @__PURE__ */ new Set();
|
|
1035
|
-
|
|
1208
|
+
const lines = extractSourceLines(source);
|
|
1209
|
+
const summaries = collectSummaries(lines);
|
|
1210
|
+
for (const line of lines) {
|
|
1036
1211
|
if (line.code.startsWith("export ")) continue;
|
|
1037
1212
|
const match = line.code.match(/^(?:async )?(function\*?|class|const|interface|type) (\w+)/);
|
|
1038
1213
|
const rawKeyword = match?.[1];
|
|
@@ -1042,9 +1217,11 @@ function extractHidden(source) {
|
|
|
1042
1217
|
const key = `${keyword} ${name}`;
|
|
1043
1218
|
if (seen.has(key)) continue;
|
|
1044
1219
|
seen.add(key);
|
|
1220
|
+
const summary = summaries.get(line);
|
|
1045
1221
|
symbols.push({
|
|
1046
1222
|
name,
|
|
1047
|
-
keyword
|
|
1223
|
+
keyword,
|
|
1224
|
+
...summary === void 0 ? {} : { summary }
|
|
1048
1225
|
});
|
|
1049
1226
|
}
|
|
1050
1227
|
return symbols;
|
|
@@ -1079,11 +1256,10 @@ function joinHead(lines, start) {
|
|
|
1079
1256
|
* inside a larger `RegExp` source rather than as syntax.
|
|
1080
1257
|
*
|
|
1081
1258
|
* @remarks
|
|
1082
|
-
*
|
|
1083
|
-
*
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1086
|
-
* text it does not name. Pure and total; never throws.
|
|
1259
|
+
* A caller-supplied name reaches a `RegExp` through this: {@link
|
|
1260
|
+
* findUnexampled} splices it into a word-boundary search, so a name carrying
|
|
1261
|
+
* `$`, `(`, `[`, or `.` matches that character literally instead of throwing or
|
|
1262
|
+
* matching text it does not name. Pure and total; never throws.
|
|
1087
1263
|
*
|
|
1088
1264
|
* @param value - The literal string to escape
|
|
1089
1265
|
* @returns `value` with every regex metacharacter backslash-escaped
|
|
@@ -1098,84 +1274,134 @@ function escapeRegExp(value) {
|
|
|
1098
1274
|
return value.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
1099
1275
|
}
|
|
1100
1276
|
/**
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1103
|
-
*
|
|
1104
|
-
* declaration.
|
|
1277
|
+
* Collects every `export class` / `export interface` declaration one file's source text declares,
|
|
1278
|
+
* each keyed `${keyword} ${name}` and carrying the body lines and the base identifiers read from
|
|
1279
|
+
* its own head, so a body and a heritage clause always come from the same declaration.
|
|
1105
1280
|
*
|
|
1106
1281
|
* @remarks
|
|
1107
|
-
* The
|
|
1108
|
-
*
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1112
|
-
*
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1115
|
-
*
|
|
1116
|
-
* everything after it is excluded, and a
|
|
1117
|
-
* `namespace.Base` is returned verbatim.
|
|
1118
|
-
*
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1121
|
-
* @param
|
|
1122
|
-
* @
|
|
1123
|
-
* @returns Its body and bases, or `undefined` when `source` declares no such head
|
|
1282
|
+
* The whole file is projected once through {@link extractSourceLines} and every head is read from
|
|
1283
|
+
* that one projection, so a scope resolving many names reads each file once rather than once per
|
|
1284
|
+
* name. A head is a column-zero `export class` / `export interface` line, an oxfmt-wrapped
|
|
1285
|
+
* signature joined through {@link joinHead}, with an optional generic parameter list and an
|
|
1286
|
+
* optional heritage clause between the identifier and the opening `{`; the identifier is the head's
|
|
1287
|
+
* own run up to that list or clause, so it enters the key as literal text and no name reaches a
|
|
1288
|
+
* `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
|
|
1289
|
+
* keeping JSDoc evidence intact. Every balanced `<...>` span is removed from the head before its
|
|
1290
|
+
* `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
|
|
1291
|
+
* reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
|
|
1292
|
+
* qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
|
|
1293
|
+
* a column-zero close answers for that key: a head that opens none records nothing, and a later
|
|
1294
|
+
* head of a key already collected adds nothing.
|
|
1295
|
+
*
|
|
1296
|
+
* @param source - The file's source text to read
|
|
1297
|
+
* @returns One entry per collected declaration, keyed `${keyword} ${name}`
|
|
1124
1298
|
*
|
|
1125
1299
|
* @example
|
|
1126
1300
|
* ```ts
|
|
1127
|
-
*
|
|
1301
|
+
* collectDeclarations('export interface X extends Y {\n\twalk(): void\n}\n').get('interface X')
|
|
1128
1302
|
* // { body: ['\twalk(): void'], bases: ['Y'] }
|
|
1129
1303
|
* ```
|
|
1130
1304
|
*/
|
|
1131
|
-
function
|
|
1132
|
-
const
|
|
1133
|
-
const
|
|
1305
|
+
function collectDeclarations(source) {
|
|
1306
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
1307
|
+
const opener = /^export (?:class|interface) /;
|
|
1308
|
+
const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{$/;
|
|
1134
1309
|
const lines = extractSourceLines(source);
|
|
1135
1310
|
const projected = lines.map((line) => line.code);
|
|
1136
1311
|
for (let index = 0; index < projected.length; index += 1) {
|
|
1137
1312
|
const line = projected[index];
|
|
1138
|
-
if (line === void 0 || !
|
|
1313
|
+
if (line === void 0 || !opener.test(line)) continue;
|
|
1139
1314
|
const head = joinHead(projected, index);
|
|
1140
|
-
if (head === void 0
|
|
1315
|
+
if (head === void 0) continue;
|
|
1316
|
+
const declared = grammar.exec(head.text);
|
|
1317
|
+
const keyword = declared?.[1];
|
|
1318
|
+
const name = declared?.[2];
|
|
1319
|
+
if (keyword === void 0 || name === void 0) continue;
|
|
1320
|
+
const key = `${keyword} ${name}`;
|
|
1321
|
+
if (declarations.has(key)) continue;
|
|
1141
1322
|
let depth = 0;
|
|
1142
1323
|
let flat = "";
|
|
1143
|
-
for (const character of head.text.slice(
|
|
1324
|
+
for (const character of head.text.slice(`export ${key}`.length, -1)) if (character === "<") depth += 1;
|
|
1144
1325
|
else if (character === ">") depth = Math.max(0, depth - 1);
|
|
1145
1326
|
else if (depth === 0) flat += character;
|
|
1146
1327
|
const clause = flat.replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
|
|
1147
1328
|
const bases = clause === void 0 ? [] : clause.split(",").map((base) => base.trim()).filter(isNonEmptyString);
|
|
1148
1329
|
for (let close = head.end + 1; close < projected.length; close += 1) {
|
|
1149
1330
|
if (projected[close] !== "}") continue;
|
|
1150
|
-
|
|
1331
|
+
declarations.set(key, {
|
|
1151
1332
|
body: lines.slice(head.end + 1, close).map((record) => record.source),
|
|
1152
1333
|
bases
|
|
1153
|
-
};
|
|
1334
|
+
});
|
|
1335
|
+
break;
|
|
1154
1336
|
}
|
|
1155
1337
|
}
|
|
1338
|
+
return declarations;
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Locates the named `export class` / `export interface` declaration in one file's source text
|
|
1342
|
+
* and returns its body lines and its base identifiers read from that one head, so a body and a
|
|
1343
|
+
* heritage clause always come from the same declaration, or `undefined` when the file declares
|
|
1344
|
+
* no such head.
|
|
1345
|
+
*
|
|
1346
|
+
* @remarks
|
|
1347
|
+
* The one named lookup over {@link collectDeclarations}, which owns the head grammar, the body
|
|
1348
|
+
* window, and the base reading. This lookup spells the map's `${keyword} ${name}` key for its
|
|
1349
|
+
* caller, so a consumer reading one name never writes that convention itself. `name` is compared
|
|
1350
|
+
* as literal text against the identifier the head itself carries, so a metacharacter in `name`
|
|
1351
|
+
* names that character rather than matching text it does not name. Every call collects the whole
|
|
1352
|
+
* file afresh: a consumer reading many names from one file calls {@link collectDeclarations} once
|
|
1353
|
+
* and reads the map, and {@link Source} holds one such map per module scope.
|
|
1354
|
+
*
|
|
1355
|
+
* @param source - The file's source text to search
|
|
1356
|
+
* @param keyword - Whether to look for a `class` or an `interface`
|
|
1357
|
+
* @param name - The declaration's identifier
|
|
1358
|
+
* @returns Its body and bases, or `undefined` when `source` declares no such head
|
|
1359
|
+
*
|
|
1360
|
+
* @example
|
|
1361
|
+
* ```ts
|
|
1362
|
+
* extractDeclaration('export interface X extends Y {\n\twalk(): void\n}\n', 'interface', 'X')
|
|
1363
|
+
* // { body: ['\twalk(): void'], bases: ['Y'] }
|
|
1364
|
+
* ```
|
|
1365
|
+
*/
|
|
1366
|
+
function extractDeclaration(source, keyword, name) {
|
|
1367
|
+
return collectDeclarations(source).get(`${keyword} ${name}`);
|
|
1156
1368
|
}
|
|
1157
1369
|
/**
|
|
1158
1370
|
* Selects the member lines declaring a callable member: plain, `async`, generator
|
|
1159
1371
|
* (`*`), and optional (`records?(`) methods all count; getters, setters,
|
|
1160
1372
|
* `static` members, and `#` privates never do (their keyword or `#` breaks
|
|
1161
|
-
* the `name(` shape).
|
|
1162
|
-
* method-like payload never
|
|
1373
|
+
* the `name(` shape). The grammar is {@link collectKeys}'s, read once over
|
|
1374
|
+
* {@link extractBodyLines}'s projection of the body, so commented method-like payload never
|
|
1375
|
+
* becomes eligible and each member keys to the owner head that projection supplies. Each member
|
|
1376
|
+
* carries its own doc block's description paragraph, read through {@link collectSummaries}; the
|
|
1377
|
+
* first declaration of a name answers for it.
|
|
1163
1378
|
*
|
|
1164
1379
|
* @param lines - A declaration's body lines
|
|
1165
|
-
* @returns The declared
|
|
1380
|
+
* @returns The declared members, deduplicated by name and sorted by name
|
|
1166
1381
|
*
|
|
1167
1382
|
* @example
|
|
1168
1383
|
* ```ts
|
|
1169
|
-
* extractMemberMethods(['\tmap(): void', '\tfilter(): void']) // ['filter', 'map']
|
|
1384
|
+
* extractMemberMethods(['\tmap(): void', '\tfilter(): void']) // [{ name: 'filter' }, { name: 'map' }]
|
|
1170
1385
|
* ```
|
|
1171
1386
|
*/
|
|
1172
1387
|
function extractMemberMethods(lines) {
|
|
1173
|
-
const methods =
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1388
|
+
const methods = /* @__PURE__ */ new Map();
|
|
1389
|
+
const projected = extractBodyLines(lines);
|
|
1390
|
+
const summaries = collectSummaries(projected);
|
|
1391
|
+
const keys = collectKeys(projected);
|
|
1392
|
+
for (const line of projected) {
|
|
1393
|
+
const key = keys.get(line) ?? "";
|
|
1394
|
+
const dot = key.indexOf(".");
|
|
1395
|
+
if (dot < 0) continue;
|
|
1396
|
+
const name = key.slice(dot + 1);
|
|
1397
|
+
if (methods.has(name)) continue;
|
|
1398
|
+
const summary = summaries.get(line);
|
|
1399
|
+
methods.set(name, {
|
|
1400
|
+
name,
|
|
1401
|
+
...summary === void 0 ? {} : { summary }
|
|
1402
|
+
});
|
|
1177
1403
|
}
|
|
1178
|
-
return Array.from(
|
|
1404
|
+
return Array.from(methods.values()).sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
|
|
1179
1405
|
}
|
|
1180
1406
|
/**
|
|
1181
1407
|
* Selects the block nodes under the named `##` heading, up to the next `##`-or-higher
|
|
@@ -1207,11 +1433,107 @@ function selectSectionBlocks(document, heading) {
|
|
|
1207
1433
|
return blocks;
|
|
1208
1434
|
}
|
|
1209
1435
|
/**
|
|
1436
|
+
* Extracts one `## Surface` table row's symbol — its column 0 code span as the name, its
|
|
1437
|
+
* {@link KIND} column as the keyword, and its {@link SUMMARY} column as the compared summary
|
|
1438
|
+
* when the table has that column. A row with no code-span name and a row whose `Kind` text is
|
|
1439
|
+
* no {@link ExportKeyword} have no symbol to key, so each returns `undefined`.
|
|
1440
|
+
*
|
|
1441
|
+
* @param table - The table to read
|
|
1442
|
+
* @param row - The index of the row within {@link TableNode.rows}
|
|
1443
|
+
* @returns The row's symbol, or `undefined` when the row keys none
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
* ```ts
|
|
1447
|
+
* extractRowSymbol(table, 0) // { name: 'walk', keyword: 'function', summary: 'Walks the tree.' }
|
|
1448
|
+
* ```
|
|
1449
|
+
*/
|
|
1450
|
+
function extractRowSymbol(table, row) {
|
|
1451
|
+
const cells = table.rows[row];
|
|
1452
|
+
if (cells === void 0) return void 0;
|
|
1453
|
+
const nameCell = cells[0];
|
|
1454
|
+
const rawName = nameCell === void 0 ? void 0 : findFirstCode(nameCell);
|
|
1455
|
+
const name = rawName === void 0 ? void 0 : normalizeIdentifier(rawName);
|
|
1456
|
+
if (name === void 0) return void 0;
|
|
1457
|
+
const column = findColumnIndex(table, KIND);
|
|
1458
|
+
const kindCell = column === void 0 ? void 0 : cells[column];
|
|
1459
|
+
const keyword = kindCell === void 0 ? "" : flattenText({
|
|
1460
|
+
element: "paragraph",
|
|
1461
|
+
children: kindCell
|
|
1462
|
+
}).trim();
|
|
1463
|
+
if (!isExportKeyword(keyword)) return void 0;
|
|
1464
|
+
const summary = extractRowSummary(table, row);
|
|
1465
|
+
return {
|
|
1466
|
+
name,
|
|
1467
|
+
keyword,
|
|
1468
|
+
...summary === void 0 ? {} : { summary }
|
|
1469
|
+
};
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Extracts one `## Methods` table row's entry — its column 0 code span as the name and its
|
|
1473
|
+
* {@link SUMMARY} column as the compared summary when the table has that column. A row with no
|
|
1474
|
+
* code-span name has no member to key, so it returns `undefined`.
|
|
1475
|
+
*
|
|
1476
|
+
* @param table - The table to read
|
|
1477
|
+
* @param row - The index of the row within {@link TableNode.rows}
|
|
1478
|
+
* @returns The row's entry, or `undefined` when the row keys none
|
|
1479
|
+
*
|
|
1480
|
+
* @example
|
|
1481
|
+
* ```ts
|
|
1482
|
+
* extractRowEntry(table, 0) // { name: 'walk', summary: 'Walks the tree.' }
|
|
1483
|
+
* ```
|
|
1484
|
+
*/
|
|
1485
|
+
function extractRowEntry(table, row) {
|
|
1486
|
+
const cells = table.rows[row];
|
|
1487
|
+
if (cells === void 0) return void 0;
|
|
1488
|
+
const cell = cells[0];
|
|
1489
|
+
const rawName = cell === void 0 ? void 0 : findFirstCode(cell);
|
|
1490
|
+
const name = rawName === void 0 ? void 0 : normalizeIdentifier(rawName);
|
|
1491
|
+
if (name === void 0) return void 0;
|
|
1492
|
+
const summary = extractRowSummary(table, row);
|
|
1493
|
+
return {
|
|
1494
|
+
name,
|
|
1495
|
+
...summary === void 0 ? {} : { summary }
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Extracts one row's compared summary — its {@link SUMMARY} column read through
|
|
1500
|
+
* {@link extractCellText} and {@link normalizeSummary}. A table with no such column and a row
|
|
1501
|
+
* whose cell is empty each carry no summary and return `undefined` rather than an empty string,
|
|
1502
|
+
* so {@link findDrift} reports the absence.
|
|
1503
|
+
*
|
|
1504
|
+
* @param table - The table to read
|
|
1505
|
+
* @param row - The index of the row within {@link TableNode.rows}
|
|
1506
|
+
* @returns The row's compared summary, or `undefined` when it carries none
|
|
1507
|
+
*
|
|
1508
|
+
* @example
|
|
1509
|
+
* ```ts
|
|
1510
|
+
* extractRowSummary(table, 0) // 'Walks the tree.'
|
|
1511
|
+
* ```
|
|
1512
|
+
*/
|
|
1513
|
+
function extractRowSummary(table, row) {
|
|
1514
|
+
const described = findColumnIndex(table, SUMMARY);
|
|
1515
|
+
const cells = table.rows[row];
|
|
1516
|
+
const cell = described === void 0 || cells === void 0 ? void 0 : cells[described];
|
|
1517
|
+
const summary = cell === void 0 ? "" : normalizeSummary(extractCellText(cell));
|
|
1518
|
+
return summary.length === 0 ? void 0 : summary;
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1210
1521
|
* Extracts every `## Surface` identifier the guide documents — each table row's column 0
|
|
1211
|
-
* code span (the name) paired with its `Kind` column (located by header text)
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
*
|
|
1522
|
+
* code span (the name) paired with its `Kind` column (located by header text), unioned with every
|
|
1523
|
+
* H3 entity heading whose trimmed compared inline content is exactly its backticked code-span
|
|
1524
|
+
* name, deduped by {@link computeSymbolKey}. A row with no code-span name has no name to key a
|
|
1525
|
+
* symbol on, so this reader skips it and {@link extractUnnamed} reports it; a row with an
|
|
1526
|
+
* unrecognized `Kind` text is skipped. A row also carries its {@link SUMMARY} column's compared
|
|
1527
|
+
* text when the table has that column; a table without it leaves every row's summary absent,
|
|
1528
|
+
* which {@link findDrift} reports.
|
|
1529
|
+
*
|
|
1530
|
+
* @remarks
|
|
1531
|
+
* The heading boundary compares {@link extractCellText} with the raw value from
|
|
1532
|
+
* {@link findFirstCode} before {@link normalizeIdentifier} strips a generic annotation.
|
|
1533
|
+
* Surrounding spaces, emphasis, and links preserve that identity. This reader refuses a heading
|
|
1534
|
+
* carrying any other visible text or an additional code span. Entries retain encounter order, and
|
|
1535
|
+
* the first-seen name + keyword wins: a genuine heading before its table row keeps the heading's
|
|
1536
|
+
* summary-less class entry, while a table row before that heading keeps its `Summary`.
|
|
1215
1537
|
*
|
|
1216
1538
|
* @param document - The parsed guide document
|
|
1217
1539
|
* @returns The documented surface, in encounter order
|
|
@@ -1226,22 +1548,9 @@ function extractSurface(document) {
|
|
|
1226
1548
|
const seen = /* @__PURE__ */ new Set();
|
|
1227
1549
|
for (const block of selectSectionBlocks(document, SURFACE)) {
|
|
1228
1550
|
if (isTableNode(block)) {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
const rawName = nameCell === void 0 ? void 0 : findFirstCode(nameCell);
|
|
1233
|
-
const name = rawName === void 0 ? void 0 : normalizeIdentifier(rawName);
|
|
1234
|
-
if (name === void 0) continue;
|
|
1235
|
-
const kindCell = column === void 0 ? void 0 : row[column];
|
|
1236
|
-
const kindText = kindCell === void 0 ? "" : flattenText({
|
|
1237
|
-
element: "paragraph",
|
|
1238
|
-
children: kindCell
|
|
1239
|
-
}).trim();
|
|
1240
|
-
if (!isExportKeyword(kindText)) continue;
|
|
1241
|
-
const symbol = {
|
|
1242
|
-
name,
|
|
1243
|
-
keyword: kindText
|
|
1244
|
-
};
|
|
1551
|
+
for (let row = 0; row < block.rows.length; row += 1) {
|
|
1552
|
+
const symbol = extractRowSymbol(block, row);
|
|
1553
|
+
if (symbol === void 0) continue;
|
|
1245
1554
|
const key = computeSymbolKey(symbol);
|
|
1246
1555
|
if (seen.has(key)) continue;
|
|
1247
1556
|
seen.add(key);
|
|
@@ -1251,10 +1560,9 @@ function extractSurface(document) {
|
|
|
1251
1560
|
}
|
|
1252
1561
|
if (isHeadingNode(block) && block.level === 3) {
|
|
1253
1562
|
const rawName = findFirstCode(block.children);
|
|
1254
|
-
|
|
1255
|
-
if (name === void 0) continue;
|
|
1563
|
+
if (rawName === void 0 || extractCellText(block.children).trim() !== `\`${rawName}\``) continue;
|
|
1256
1564
|
const symbol = {
|
|
1257
|
-
name,
|
|
1565
|
+
name: normalizeIdentifier(rawName),
|
|
1258
1566
|
keyword: "class"
|
|
1259
1567
|
};
|
|
1260
1568
|
const key = computeSymbolKey(symbol);
|
|
@@ -1268,18 +1576,50 @@ function extractSurface(document) {
|
|
|
1268
1576
|
/**
|
|
1269
1577
|
* Extracts one {@link MethodGroup} per documented behavioral interface in `## Methods` —
|
|
1270
1578
|
* an H4 with a code span sets the current interface, and the table immediately
|
|
1271
|
-
* following becomes its documented methods.
|
|
1579
|
+
* following becomes its documented methods. A row with no code-span name has no name to key a
|
|
1580
|
+
* member on, so this reader skips it and {@link extractUnnamed} reports it. Each row carries its
|
|
1581
|
+
* {@link SUMMARY} column's compared text when the table has that column.
|
|
1272
1582
|
*
|
|
1273
1583
|
* @param document - The parsed guide document
|
|
1274
1584
|
* @returns The documented method groups, in document order
|
|
1275
1585
|
*
|
|
1276
1586
|
* @example
|
|
1277
1587
|
* ```ts
|
|
1278
|
-
* extractMethods(document) // [{ interface: 'MarkdownInterface', methods: ['walk'
|
|
1588
|
+
* extractMethods(document) // [{ interface: 'MarkdownInterface', methods: [{ name: 'walk' }] }]
|
|
1279
1589
|
* ```
|
|
1280
1590
|
*/
|
|
1281
1591
|
function extractMethods(document) {
|
|
1282
1592
|
const groups = [];
|
|
1593
|
+
for (const [table, name] of collectGroups(document)) {
|
|
1594
|
+
const methods = [];
|
|
1595
|
+
for (let row = 0; row < table.rows.length; row += 1) {
|
|
1596
|
+
const entry = extractRowEntry(table, row);
|
|
1597
|
+
if (entry !== void 0) methods.push(entry);
|
|
1598
|
+
}
|
|
1599
|
+
groups.push({
|
|
1600
|
+
interface: name,
|
|
1601
|
+
methods
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
return groups;
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Collects each `## Methods` table keyed to the interface its `####` heading names — an H4
|
|
1608
|
+
* carrying a code span sets the current interface and the table immediately following claims it,
|
|
1609
|
+
* so a heading with no table and a table with no heading before it contribute nothing. The map
|
|
1610
|
+
* iterates in document order and a node keys itself, so a repeated identical table keeps its own
|
|
1611
|
+
* entry.
|
|
1612
|
+
*
|
|
1613
|
+
* @param document - The parsed guide document
|
|
1614
|
+
* @returns One entry per documented `## Methods` table, in document order
|
|
1615
|
+
*
|
|
1616
|
+
* @example
|
|
1617
|
+
* ```ts
|
|
1618
|
+
* collectGroups(document).values().next().value // 'GuideInterface'
|
|
1619
|
+
* ```
|
|
1620
|
+
*/
|
|
1621
|
+
function collectGroups(document) {
|
|
1622
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1283
1623
|
let current;
|
|
1284
1624
|
for (const block of selectSectionBlocks(document, METHODS)) {
|
|
1285
1625
|
if (isHeadingNode(block) && block.level === 4) {
|
|
@@ -1288,23 +1628,41 @@ function extractMethods(document) {
|
|
|
1288
1628
|
continue;
|
|
1289
1629
|
}
|
|
1290
1630
|
if (isTableNode(block) && current !== void 0) {
|
|
1291
|
-
|
|
1292
|
-
for (const row of block.rows) {
|
|
1293
|
-
const cell = row[0];
|
|
1294
|
-
const rawName = cell === void 0 ? void 0 : findFirstCode(cell);
|
|
1295
|
-
const name = rawName === void 0 ? void 0 : normalizeIdentifier(rawName);
|
|
1296
|
-
if (name !== void 0) methods.push(name);
|
|
1297
|
-
}
|
|
1298
|
-
groups.push({
|
|
1299
|
-
interface: current,
|
|
1300
|
-
methods
|
|
1301
|
-
});
|
|
1631
|
+
groups.set(block, current);
|
|
1302
1632
|
current = void 0;
|
|
1303
1633
|
}
|
|
1304
1634
|
}
|
|
1305
1635
|
return groups;
|
|
1306
1636
|
}
|
|
1307
1637
|
/**
|
|
1638
|
+
* Extracts every `## Surface` or `## Methods` table row whose first cell carries no code span.
|
|
1639
|
+
* {@link extractSurface} and {@link extractMethods} skip such a row, because a row with no
|
|
1640
|
+
* name gives them nothing to key a symbol or a member on, and this projection is what reports
|
|
1641
|
+
* the skip. Each entry is the row's cells read through {@link extractCellText} and joined
|
|
1642
|
+
* by ` | `, so a reader can locate the row in the guide; the `## Surface` rows come first,
|
|
1643
|
+
* then the `## Methods` rows, each in document order. {@link GuideInterface.unnamed} caches it.
|
|
1644
|
+
*
|
|
1645
|
+
* @param document - The parsed guide document
|
|
1646
|
+
* @returns One entry per row carrying no code-span name
|
|
1647
|
+
*
|
|
1648
|
+
* @example
|
|
1649
|
+
* ```ts
|
|
1650
|
+
* extractUnnamed(document) // ['Widget | class | Represents a widget.']
|
|
1651
|
+
* ```
|
|
1652
|
+
*/
|
|
1653
|
+
function extractUnnamed(document) {
|
|
1654
|
+
const unnamed = [];
|
|
1655
|
+
for (const heading of [SURFACE, METHODS]) for (const block of selectSectionBlocks(document, heading)) {
|
|
1656
|
+
if (!isTableNode(block)) continue;
|
|
1657
|
+
for (const row of block.rows) {
|
|
1658
|
+
const cell = row[0];
|
|
1659
|
+
if (cell !== void 0 && findFirstCode(cell) !== void 0) continue;
|
|
1660
|
+
unnamed.push(row.map((content) => extractCellText(content)).join(" | "));
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
return unnamed;
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1308
1666
|
* Extracts every link href in the guide document, including table cells — a full,
|
|
1309
1667
|
* depth-first walk of the whole AST.
|
|
1310
1668
|
*
|
|
@@ -1339,38 +1697,230 @@ function extractTests(document) {
|
|
|
1339
1697
|
return links;
|
|
1340
1698
|
}
|
|
1341
1699
|
/**
|
|
1342
|
-
*
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
1348
|
-
*
|
|
1349
|
-
*
|
|
1700
|
+
* Returns the canonical body of one genuine JSDoc span — the `/**` opener, the closing
|
|
1701
|
+
* marker, each line's continuation marker, and the block's leading indentation removed,
|
|
1702
|
+
* with per-line trailing whitespace trimmed and the surrounding blank lines dropped. A
|
|
1703
|
+
* line's own indentation beyond the marker is kept, so an `@example` fence body keeps the
|
|
1704
|
+
* shape it was written in.
|
|
1705
|
+
*
|
|
1706
|
+
* @param comment - One complete genuine JSDoc span's raw text
|
|
1707
|
+
* @returns The span's unwrapped body
|
|
1708
|
+
*
|
|
1709
|
+
* @example
|
|
1710
|
+
* ```ts
|
|
1711
|
+
* normalizeComment('/**' + ' Creates a widget. *' + '/') // 'Creates a widget.'
|
|
1712
|
+
* ```
|
|
1713
|
+
*/
|
|
1714
|
+
function normalizeComment(comment) {
|
|
1715
|
+
return unwrapComment(comment).join("\n").replace(/^\n+/, "").replace(/\n+$/, "");
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Unwraps one genuine JSDoc span into one content line per physical line — the `/**` opener,
|
|
1719
|
+
* the closing marker, each line's continuation marker, and per-line trailing whitespace removed,
|
|
1720
|
+
* with a line's own indentation past the marker kept. The result is aligned with
|
|
1721
|
+
* `comment.split('\n')`, so an index found in it addresses the same physical line of the span it
|
|
1722
|
+
* was built from, which is what lets a rewrite keep every line it does not replace.
|
|
1723
|
+
* {@link normalizeComment} is this projection joined and trimmed at its ends.
|
|
1724
|
+
*
|
|
1725
|
+
* @param comment - One complete genuine JSDoc span's raw text
|
|
1726
|
+
* @returns One content line per physical line of the span
|
|
1727
|
+
*
|
|
1728
|
+
* @example
|
|
1729
|
+
* ```ts
|
|
1730
|
+
* unwrapComment('/**' + '\n * Walks.\n *' + '/') // ['', 'Walks.', '']
|
|
1731
|
+
* ```
|
|
1732
|
+
*/
|
|
1733
|
+
function unwrapComment(comment) {
|
|
1734
|
+
return (/^[ \t]*\/\*([\s\S]*?)\*\/[ \t]*$/.exec(comment)?.[1] ?? comment).split("\n").map((line) => line.replace(/^[ \t]*\*[ \t]?/, "").replace(/[ \t]+$/, ""));
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Returns the canonical compared form of a description paragraph. `{@link Target}` and
|
|
1738
|
+
* `{@link Target | label}` become the code token of the target text, or of the label where one is
|
|
1739
|
+
* written; a target's module part — the inline import form `import('./module.js').` and TSDoc's
|
|
1740
|
+
* package-qualified form `@scope/pkg#` — is dropped first. Every run of whitespace, including a
|
|
1741
|
+
* collapsed continuation marker and a line break, becomes one space, the ends trim, and a code
|
|
1742
|
+
* span keeps its delimiters while its own boundary whitespace goes. The guide's side and the
|
|
1743
|
+
* source's side read through this one form.
|
|
1744
|
+
*
|
|
1745
|
+
* @remarks
|
|
1746
|
+
* The clauses land in a fixed order, because each one decides what the next one sees. Every
|
|
1747
|
+
* single-backtick code span — one backtick per side, no inner backtick, no adjacent backtick —
|
|
1748
|
+
* is located first, so a delimiter the `{@link}` expansion inserts afterwards is never mistaken
|
|
1749
|
+
* for an authored one. The expansion then runs outside those spans
|
|
1750
|
+
* only, so a `{@link}` written inside a code span stays literal on both sides. Whitespace
|
|
1751
|
+
* collapses next, which is what makes a span wrapped across two physical lines comparable at
|
|
1752
|
+
* all. The boundary trim runs last, inside each located span: the markdown parser strips one
|
|
1753
|
+
* space from each end of a code span it reads, and this trim is the symmetric rule that meets
|
|
1754
|
+
* it, so `` ` | ` ``, `` ` |` ``, and `` `|` `` all reach `` `|` `` from either side. A span
|
|
1755
|
+
* whose content is all whitespace keeps one space, because a parser strips nothing from that
|
|
1756
|
+
* one.
|
|
1757
|
+
*
|
|
1758
|
+
* A target's module part is the inline import form `import('./module.js').` or TSDoc's
|
|
1759
|
+
* package-qualified form `@scope/pkg#`, and the expansion drops it, so a cross-file link and the
|
|
1760
|
+
* code token a guide cell documents it with reach the same text. A package qualifier carries `@`
|
|
1761
|
+
* or `/`; text before a `#` carrying neither is JSDoc's member reference, so `{@link Owner#member}`
|
|
1762
|
+
* and `{@link #member}` travel whole and a guide cell documents each as written. An unscoped
|
|
1763
|
+
* package name is spelled like an owner, so `{@link pkg#Name}` travels whole too — write the
|
|
1764
|
+
* scoped or the path form where a cell must drop the package. Everything after a module part
|
|
1765
|
+
* travels: `Owner.member` keeps its owner, and a dotted target no module part precedes is
|
|
1766
|
+
* untouched. A label is text rather than a target, so `{@link Target | label}` renders its label
|
|
1767
|
+
* whole.
|
|
1768
|
+
*
|
|
1769
|
+
* A code span delimited by more than one backtick is outside the compared form's representable
|
|
1770
|
+
* set and travels untouched, as does a code span whose own text carries a backtick: the form
|
|
1771
|
+
* spells every span with one backtick per side, so neither can be written back. A summary that
|
|
1772
|
+
* needs one of those constructs takes another shape: name the construct in prose rather than
|
|
1773
|
+
* expecting the comparison to converge it.
|
|
1774
|
+
*
|
|
1775
|
+
* @param text - A doc block's description paragraph, or a guide cell's flattened text
|
|
1776
|
+
* @returns The compared form of that text
|
|
1777
|
+
*
|
|
1778
|
+
* @example
|
|
1779
|
+
* ```ts
|
|
1780
|
+
* normalizeSummary('Creates a\n{@link Widget}.') // 'Creates a `Widget`.'
|
|
1781
|
+
* normalizeSummary("Reads {@link import('./widgets.js').Widget}.") // 'Reads `Widget`.'
|
|
1782
|
+
* normalizeSummary('Reads {@link @scope/widgets#Widget}.') // 'Reads `Widget`.'
|
|
1783
|
+
* normalizeSummary('Reads {@link Widget#render}.') // 'Reads `Widget#render`.'
|
|
1784
|
+
* normalizeSummary('cells joined by ` | `.') // 'cells joined by `|`.'
|
|
1785
|
+
* ```
|
|
1786
|
+
*/
|
|
1787
|
+
function normalizeSummary(text) {
|
|
1788
|
+
const parts = text.split(/((?<!`)`[^`]+`(?!`))/);
|
|
1789
|
+
let normalized = "";
|
|
1790
|
+
for (let index = 0; index < parts.length; index += 1) {
|
|
1791
|
+
const part = parts[index] ?? "";
|
|
1792
|
+
if (index % 2 === 0) {
|
|
1793
|
+
normalized += part.replace(/\{@link\s+[^}|]*\|\s*([^}]*?)\s*\}/g, "`$1`").replace(/\{@link\s+(?:import\([^)]*\)\.|[^}|#\s]*[@/][^}|#\s]*#)?([^}|]*?)\s*\}/g, "`$1`");
|
|
1794
|
+
continue;
|
|
1795
|
+
}
|
|
1796
|
+
const value = part.slice(1, -1).replace(/\s+/g, " ").trim();
|
|
1797
|
+
normalized += `\`${value.length === 0 ? " " : value}\``;
|
|
1798
|
+
}
|
|
1799
|
+
return normalized.replace(/\s+/g, " ").trim();
|
|
1800
|
+
}
|
|
1801
|
+
/**
|
|
1802
|
+
* Wraps one paragraph into greedy lines no longer than `width` characters. Every run of
|
|
1803
|
+
* whitespace separates words, and a word longer than `width` takes its own line rather than
|
|
1804
|
+
* being split, so a long code token or URL survives the wrap intact.
|
|
1805
|
+
*
|
|
1806
|
+
* @param text - The paragraph to wrap
|
|
1807
|
+
* @param width - The greatest length a returned line may reach
|
|
1808
|
+
* @returns The wrapped lines, in order, or an empty list when `text` carries no word
|
|
1809
|
+
*
|
|
1810
|
+
* @example
|
|
1811
|
+
* ```ts
|
|
1812
|
+
* wrapText('one two three', 8) // ['one two', 'three']
|
|
1813
|
+
* ```
|
|
1814
|
+
*/
|
|
1815
|
+
function wrapText(text, width) {
|
|
1816
|
+
const lines = [];
|
|
1817
|
+
let current = "";
|
|
1818
|
+
for (const word of text.split(/\s+/)) {
|
|
1819
|
+
if (word.length === 0) continue;
|
|
1820
|
+
if (current.length === 0) current = word;
|
|
1821
|
+
else if (current.length + 1 + word.length <= width) current += ` ${word}`;
|
|
1822
|
+
else {
|
|
1823
|
+
lines.push(current);
|
|
1824
|
+
current = word;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
if (current.length > 0) lines.push(current);
|
|
1828
|
+
return lines;
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Builds one genuine JSDoc span from its content lines — the inverse of {@link unwrapComment}.
|
|
1832
|
+
* Each line is emitted at `indent` behind a continuation marker, an empty line as the bare
|
|
1833
|
+
* marker so no line carries trailing whitespace, and the leading and trailing empty lines are
|
|
1834
|
+
* dropped because the opener and the closer take those physical lines.
|
|
1835
|
+
*
|
|
1836
|
+
* @param lines - The span's content lines, as {@link unwrapComment} returns them
|
|
1837
|
+
* @param indent - The whitespace the span opens at
|
|
1838
|
+
* @returns The span's raw text, opener and closer included
|
|
1839
|
+
*
|
|
1840
|
+
* @example
|
|
1841
|
+
* ```ts
|
|
1842
|
+
* buildComment(['Walks.'], '') // '/**\n * Walks.\n *' + '/'
|
|
1843
|
+
* ```
|
|
1844
|
+
*/
|
|
1845
|
+
function buildComment(lines, indent) {
|
|
1846
|
+
const content = [...lines];
|
|
1847
|
+
while (content[0] === "") content.shift();
|
|
1848
|
+
while (content[content.length - 1] === "") content.pop();
|
|
1849
|
+
const raw = [`${indent}/**`];
|
|
1850
|
+
for (const line of content) raw.push(line.length === 0 ? `${indent} *` : `${indent} * ${line}`);
|
|
1851
|
+
raw.push(`${indent} */`);
|
|
1852
|
+
return raw.join("\n");
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Returns one doc block's unwrapped text with every fenced body replaced by aligned spaces,
|
|
1856
|
+
* so a tag search reads the block's structure and never its example code. A line opening with
|
|
1857
|
+
* three or more backticks or tildes opens a body, the first line opening with a run of the same
|
|
1858
|
+
* character at least as long closes it, an unclosed body runs to the end, and the marker lines
|
|
1859
|
+
* themselves stay. The projection preserves every line and every column, so an index found in
|
|
1860
|
+
* it addresses the same character of the text it was built from.
|
|
1861
|
+
*
|
|
1862
|
+
* @param text - One doc block's unwrapped text, as {@link normalizeComment} returns it
|
|
1863
|
+
* @returns The same text with each fenced body's characters replaced by spaces
|
|
1864
|
+
*
|
|
1865
|
+
* @example
|
|
1866
|
+
* ```ts
|
|
1867
|
+
* maskFences('@example\n~~~\n@decorator()\n~~~').split('\n')[2] // ' '
|
|
1868
|
+
* ```
|
|
1869
|
+
*/
|
|
1870
|
+
function maskFences(text) {
|
|
1871
|
+
const masked = [];
|
|
1872
|
+
let marker;
|
|
1873
|
+
for (const line of text.split("\n")) {
|
|
1874
|
+
const fence = /^[ \t]*(`{3,}|~{3,})/.exec(line)?.[1];
|
|
1875
|
+
if (marker === void 0) {
|
|
1876
|
+
masked.push(line);
|
|
1877
|
+
marker = fence;
|
|
1878
|
+
continue;
|
|
1879
|
+
}
|
|
1880
|
+
const closing = fence !== void 0 && fence.startsWith(marker);
|
|
1881
|
+
masked.push(closing ? line : " ".repeat(line.length));
|
|
1882
|
+
if (closing) marker = void 0;
|
|
1883
|
+
}
|
|
1884
|
+
return masked.join("\n");
|
|
1885
|
+
}
|
|
1886
|
+
/**
|
|
1887
|
+
* Extracts every eligible genuine JSDoc block paired with the physical record it documents.
|
|
1888
|
+
*
|
|
1889
|
+
* @remarks
|
|
1890
|
+
* An opener is eligible only when it is the first non-whitespace source material of its record; a
|
|
1891
|
+
* leading whitespace-separated span chain is last-span authoritative; intervening source material
|
|
1892
|
+
* severs association, while a leading JSDoc on the next record replaces pending state. Any other
|
|
1893
|
+
* next physical record is returned once and consumes it. This parser walks aligned records without
|
|
1894
|
+
* rescanning source syntax or applying declaration/member grammar, and every reader of a doc
|
|
1895
|
+
* block's text — the description paragraph, the `@example` blocks, the member summaries — reads it
|
|
1896
|
+
* through this one walk.
|
|
1350
1897
|
*
|
|
1351
1898
|
* @param lines - Aligned physical source-line records
|
|
1352
|
-
* @returns
|
|
1899
|
+
* @returns One record per documented physical line, in source order
|
|
1353
1900
|
*
|
|
1354
1901
|
* @example
|
|
1355
1902
|
* ```ts
|
|
1356
|
-
*
|
|
1357
|
-
* // the `export function walk() {}` SourceLine
|
|
1903
|
+
* extractSourceComments(extractSourceLines('/**' + ' Walks. *' + '/\nexport function walk() {}'))
|
|
1904
|
+
* // [{ text: 'Walks.', line: the `export function walk() {}` SourceLine }]
|
|
1358
1905
|
* ```
|
|
1359
1906
|
*/
|
|
1360
|
-
function
|
|
1361
|
-
const
|
|
1907
|
+
function extractSourceComments(lines) {
|
|
1908
|
+
const comments = [];
|
|
1362
1909
|
let block = false;
|
|
1363
1910
|
let eligible = false;
|
|
1364
|
-
let
|
|
1365
|
-
let pending
|
|
1911
|
+
let span = [];
|
|
1912
|
+
let pending;
|
|
1366
1913
|
for (const line of lines) {
|
|
1367
1914
|
const projection = line.jsdoc;
|
|
1368
1915
|
const first = projection?.indexOf("/**") ?? -1;
|
|
1369
|
-
if (pending) {
|
|
1370
|
-
if (!block && first >= 0 && line.source.slice(0, first).trim() === "") pending =
|
|
1916
|
+
if (pending !== void 0) {
|
|
1917
|
+
if (!block && first >= 0 && line.source.slice(0, first).trim() === "") pending = void 0;
|
|
1371
1918
|
else {
|
|
1372
|
-
|
|
1373
|
-
|
|
1919
|
+
comments.push({
|
|
1920
|
+
text: pending,
|
|
1921
|
+
line
|
|
1922
|
+
});
|
|
1923
|
+
pending = void 0;
|
|
1374
1924
|
}
|
|
1375
1925
|
}
|
|
1376
1926
|
if (projection === void 0) continue;
|
|
@@ -1378,29 +1928,29 @@ function extractExampleLines(lines) {
|
|
|
1378
1928
|
if (block) {
|
|
1379
1929
|
const close = projection.indexOf("*/");
|
|
1380
1930
|
const end = close < 0 ? projection.length : close + 2;
|
|
1381
|
-
|
|
1931
|
+
span.push(projection.slice(0, end));
|
|
1382
1932
|
if (close < 0) continue;
|
|
1383
1933
|
block = false;
|
|
1384
1934
|
const opener = projection.indexOf("/**", close + 2);
|
|
1385
1935
|
const endOfGap = opener < 0 ? line.source.length : opener;
|
|
1386
1936
|
const whitespace = line.source.slice(close + 2, endOfGap).trim() === "";
|
|
1387
1937
|
if (opener < 0) {
|
|
1388
|
-
pending = eligible &&
|
|
1938
|
+
pending = eligible && whitespace ? normalizeComment(span.join("\n")) : void 0;
|
|
1389
1939
|
continue;
|
|
1390
1940
|
}
|
|
1391
1941
|
eligible = eligible && whitespace;
|
|
1392
|
-
|
|
1942
|
+
span = [];
|
|
1393
1943
|
cursor = opener;
|
|
1394
1944
|
} else {
|
|
1395
1945
|
if (first < 0) continue;
|
|
1396
1946
|
eligible = line.source.slice(0, first).trim() === "";
|
|
1397
|
-
|
|
1947
|
+
span = [];
|
|
1398
1948
|
cursor = first;
|
|
1399
1949
|
}
|
|
1400
1950
|
while (cursor < projection.length) {
|
|
1401
1951
|
const close = projection.indexOf("*/", cursor + 2);
|
|
1402
1952
|
const end = close < 0 ? projection.length : close + 2;
|
|
1403
|
-
|
|
1953
|
+
span.push(projection.slice(cursor, end));
|
|
1404
1954
|
if (close < 0) {
|
|
1405
1955
|
block = true;
|
|
1406
1956
|
break;
|
|
@@ -1409,93 +1959,1024 @@ function extractExampleLines(lines) {
|
|
|
1409
1959
|
const endOfGap = opener < 0 ? line.source.length : opener;
|
|
1410
1960
|
const whitespace = line.source.slice(close + 2, endOfGap).trim() === "";
|
|
1411
1961
|
if (opener < 0) {
|
|
1412
|
-
pending = eligible &&
|
|
1962
|
+
pending = eligible && whitespace ? normalizeComment(span.join("\n")) : void 0;
|
|
1413
1963
|
break;
|
|
1414
1964
|
}
|
|
1415
1965
|
eligible = eligible && whitespace;
|
|
1416
|
-
|
|
1966
|
+
span = [];
|
|
1417
1967
|
cursor = opener;
|
|
1418
1968
|
}
|
|
1419
1969
|
}
|
|
1420
|
-
return
|
|
1970
|
+
return comments;
|
|
1421
1971
|
}
|
|
1422
1972
|
/**
|
|
1423
|
-
*
|
|
1424
|
-
*
|
|
1425
|
-
* {@link
|
|
1426
|
-
*
|
|
1973
|
+
* Selects the next physical record after an eligible genuine JSDoc whose final
|
|
1974
|
+
* authoritative span carries an `@example` tag opening a line at its first non-blank column —
|
|
1975
|
+
* the {@link extractSourceComments} walk filtered to the blocks that carry one. Title
|
|
1976
|
+
* text is allowed, and {@link maskFences} keeps a fenced body's own lines out of the search.
|
|
1427
1977
|
*
|
|
1428
|
-
* @param
|
|
1429
|
-
* @returns The
|
|
1978
|
+
* @param lines - Aligned physical source-line records
|
|
1979
|
+
* @returns The immediately following candidate lines, in source order
|
|
1430
1980
|
*
|
|
1431
1981
|
* @example
|
|
1432
1982
|
* ```ts
|
|
1433
|
-
*
|
|
1434
|
-
*
|
|
1435
|
-
* extractExamples('export function walk() {}\n') // []
|
|
1983
|
+
* extractExampleLines(extractSourceLines('/**' + ' @example *' + '/\nexport function walk() {}'))
|
|
1984
|
+
* // the `export function walk() {}` SourceLine
|
|
1436
1985
|
* ```
|
|
1437
1986
|
*/
|
|
1438
|
-
function
|
|
1439
|
-
|
|
1440
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1441
|
-
for (const line of extractExampleLines(extractSourceLines(source))) {
|
|
1442
|
-
const name = line.code.match(/^export (?:async )?function\*? (\w+)/)?.[1];
|
|
1443
|
-
if (isNonEmptyString(name) && !seen.has(name)) {
|
|
1444
|
-
seen.add(name);
|
|
1445
|
-
names.push(name);
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
return names;
|
|
1987
|
+
function extractExampleLines(lines) {
|
|
1988
|
+
return extractSourceComments(lines).filter((comment) => /^[ \t]*@example(?=[ \t]|$)/m.test(maskFences(comment.text))).map((comment) => comment.line);
|
|
1449
1989
|
}
|
|
1450
1990
|
/**
|
|
1451
|
-
*
|
|
1452
|
-
*
|
|
1453
|
-
*
|
|
1454
|
-
*
|
|
1455
|
-
* projected code.
|
|
1991
|
+
* Collects the description paragraph of every documented physical record — a doc block's
|
|
1992
|
+
* text before its first block tag, in {@link normalizeSummary}'s compared form — keyed by the
|
|
1993
|
+
* record it documents. A record whose block carries no description contributes no entry, so
|
|
1994
|
+
* an absent summary stays absent rather than becoming an empty string.
|
|
1456
1995
|
*
|
|
1457
|
-
* @param lines -
|
|
1458
|
-
* @returns
|
|
1996
|
+
* @param lines - Aligned physical source-line records
|
|
1997
|
+
* @returns One entry per documented record carrying a description paragraph
|
|
1459
1998
|
*
|
|
1460
1999
|
* @example
|
|
1461
2000
|
* ```ts
|
|
1462
|
-
*
|
|
2001
|
+
* collectSummaries(extractSourceLines('/**' + ' Walks. *' + '/\nexport function walk() {}')).size // 1
|
|
1463
2002
|
* ```
|
|
1464
2003
|
*/
|
|
1465
|
-
function
|
|
1466
|
-
const
|
|
1467
|
-
const
|
|
1468
|
-
|
|
1469
|
-
const
|
|
1470
|
-
if (
|
|
1471
|
-
seen.add(name);
|
|
1472
|
-
methods.push(name);
|
|
1473
|
-
}
|
|
2004
|
+
function collectSummaries(lines) {
|
|
2005
|
+
const summaries = /* @__PURE__ */ new Map();
|
|
2006
|
+
for (const comment of extractSourceComments(lines)) {
|
|
2007
|
+
const tag = maskFences(comment.text).search(/^[ \t]*@\w/m);
|
|
2008
|
+
const summary = normalizeSummary(tag < 0 ? comment.text : comment.text.slice(0, tag));
|
|
2009
|
+
if (summary.length > 0) summaries.set(comment.line, summary);
|
|
1474
2010
|
}
|
|
1475
|
-
return
|
|
2011
|
+
return summaries;
|
|
1476
2012
|
}
|
|
1477
2013
|
/**
|
|
1478
|
-
* Extracts
|
|
1479
|
-
*
|
|
2014
|
+
* Extracts the aligned physical records of a declaration's body, read inside an owner head this
|
|
2015
|
+
* function supplies, so a callable member in the body carries the `Owner.member` key
|
|
2016
|
+
* {@link collectKeys} reports for it, and that head's own record opens the projection. A body
|
|
2017
|
+
* read on its own carries no head, and the member grammar attaches a member to the head
|
|
2018
|
+
* enclosing it.
|
|
1480
2019
|
*
|
|
1481
|
-
* @
|
|
1482
|
-
*
|
|
2020
|
+
* @remarks
|
|
2021
|
+
* The supplied head is an `export interface` line, so the projection opens with that head's own
|
|
2022
|
+
* record and every body line follows it in order. A column-zero `}` among the body lines closes
|
|
2023
|
+
* the supplied head and leaves every later member unkeyed; a body {@link extractDeclaration}
|
|
2024
|
+
* returns carries none, because that reader ends a body at the first one.
|
|
2025
|
+
*
|
|
2026
|
+
* @param lines - A declaration's body lines
|
|
2027
|
+
* @returns The supplied head's record, then one record per body line
|
|
1483
2028
|
*
|
|
1484
2029
|
* @example
|
|
1485
2030
|
* ```ts
|
|
1486
|
-
*
|
|
2031
|
+
* extractBodyLines(['\twalk(): void'])[1]?.code // '\twalk(): void'
|
|
1487
2032
|
* ```
|
|
1488
2033
|
*/
|
|
1489
|
-
function
|
|
1490
|
-
|
|
1491
|
-
for (const node of walkNodes(document)) if (isCodeBlockNode(node)) fences.push({
|
|
1492
|
-
language: node.lang,
|
|
1493
|
-
code: node.code
|
|
1494
|
-
});
|
|
1495
|
-
return fences;
|
|
2034
|
+
function extractBodyLines(lines) {
|
|
2035
|
+
return extractSourceLines(["export interface Owner {", ...lines].join("\n"));
|
|
1496
2036
|
}
|
|
1497
|
-
|
|
1498
|
-
|
|
2037
|
+
/**
|
|
2038
|
+
* Collects the compared key of every physical record a key names — a {@link computeSymbolKey}
|
|
2039
|
+
* symbol key for a column-zero `export` declaration head, an `Owner.member` key for a one-tab
|
|
2040
|
+
* callable member inside one — keyed by the record itself. The owner closes at the first
|
|
2041
|
+
* column-zero `}` or at a column-zero `export` declaration carrying another keyword, and a
|
|
2042
|
+
* record no key names contributes no entry.
|
|
2043
|
+
*
|
|
2044
|
+
* @remarks
|
|
2045
|
+
* This is the package's one key grammar, and each keyed reader projects its own part back out of
|
|
2046
|
+
* it: {@link extractExports} splits a declaration key at its one space,
|
|
2047
|
+
* {@link extractMemberMethods} and {@link extractExampleMethods} split a member key at its dot,
|
|
2048
|
+
* and {@link locateComment} matches a caller's key against the whole map. A change to the head
|
|
2049
|
+
* shape or to the member shape reaches every one of them at once.
|
|
2050
|
+
*
|
|
2051
|
+
* An owner opens at a column-zero `export class` or `export interface` head and closes at the
|
|
2052
|
+
* first column-zero `}`, so a member declared past that brace keys nothing. A column-zero `export` declaration carrying any other keyword closes the owner it follows,
|
|
2053
|
+
* because a member belongs to the head enclosing it. Reading runs over {@link extractSourceLines}'s
|
|
2054
|
+
* projection, so a head or
|
|
2055
|
+
* a member written inside a comment or a template literal keys nothing.
|
|
2056
|
+
*
|
|
2057
|
+
* @param lines - Aligned physical source-line records
|
|
2058
|
+
* @returns One entry per record a key names, in file order
|
|
2059
|
+
*
|
|
2060
|
+
* @example
|
|
2061
|
+
* ```ts
|
|
2062
|
+
* const keys = collectKeys(extractSourceLines('export class Widget {\n\twalk(): void\n}'))
|
|
2063
|
+
* Array.from(keys.values()) // ['class Widget', 'Widget.walk']
|
|
2064
|
+
* ```
|
|
2065
|
+
*/
|
|
2066
|
+
function collectKeys(lines) {
|
|
2067
|
+
const keys = /* @__PURE__ */ new Map();
|
|
2068
|
+
let owner;
|
|
2069
|
+
for (const line of lines) {
|
|
2070
|
+
const head = /^export (?:async )?(function\*?|class|const|interface|type) (\w+)/.exec(line.code);
|
|
2071
|
+
const keyword = head?.[1]?.replace(/\*$/, "");
|
|
2072
|
+
const name = head?.[2];
|
|
2073
|
+
if (isNonEmptyString(keyword) && isNonEmptyString(name) && isExportKeyword(keyword)) {
|
|
2074
|
+
keys.set(line, computeSymbolKey({
|
|
2075
|
+
name,
|
|
2076
|
+
keyword
|
|
2077
|
+
}));
|
|
2078
|
+
owner = keyword === "class" || keyword === "interface" ? name : void 0;
|
|
2079
|
+
continue;
|
|
2080
|
+
}
|
|
2081
|
+
if (line.code === "}") {
|
|
2082
|
+
owner = void 0;
|
|
2083
|
+
continue;
|
|
2084
|
+
}
|
|
2085
|
+
const member = /^\t(?:async )?\*?(\w+)\??(?:<.*>)?\(/.exec(line.code)?.[1];
|
|
2086
|
+
if (owner !== void 0 && isNonEmptyString(member)) keys.set(line, `${owner}.${member}`);
|
|
2087
|
+
}
|
|
2088
|
+
return keys;
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* Collects the `@example` blocks one doc block's unwrapped text carries, each named for the
|
|
2092
|
+
* declaration or member the block documents. The text after the tag becomes the block's
|
|
2093
|
+
* `title`; a body opening with a fence contributes that fence's language and its verbatim
|
|
2094
|
+
* body, and a body with no fence contributes its own trimmed text as the code.
|
|
2095
|
+
*
|
|
2096
|
+
* @param comment - One doc block's unwrapped text, as {@link normalizeComment} returns it
|
|
2097
|
+
* @param name - The declaration or member the block documents
|
|
2098
|
+
* @returns The block's `@example` entries, in block order
|
|
2099
|
+
*
|
|
2100
|
+
* @example
|
|
2101
|
+
* ```ts
|
|
2102
|
+
* collectExamples('@example Walking\n```ts\nwalk()\n```', 'walk')
|
|
2103
|
+
* // [{ name: 'walk', title: 'Walking', code: 'walk()', language: 'ts' }]
|
|
2104
|
+
* ```
|
|
2105
|
+
*/
|
|
2106
|
+
function collectExamples(comment, name) {
|
|
2107
|
+
const examples = [];
|
|
2108
|
+
const masked = maskFences(comment);
|
|
2109
|
+
const tags = /^[ \t]*@example(?=[ \t]|$)[ \t]*(.*)$/gm;
|
|
2110
|
+
let tag;
|
|
2111
|
+
while ((tag = tags.exec(masked)) !== null) {
|
|
2112
|
+
const title = (tag[1] ?? "").trim();
|
|
2113
|
+
const start = tag.index + tag[0].length;
|
|
2114
|
+
const rest = comment.slice(start).replace(/^\n/, "");
|
|
2115
|
+
const next = masked.slice(start).replace(/^\n/, "").search(/^[ \t]*@\w+/m);
|
|
2116
|
+
const body = (next < 0 ? rest : rest.slice(0, next)).replace(/^\n+/, "").replace(/\n+$/, "");
|
|
2117
|
+
const fence = /^```(\S*)\n([\s\S]*?)\n?```/.exec(body);
|
|
2118
|
+
const language = fence?.[1] ?? "";
|
|
2119
|
+
const code = fence?.[2] ?? body;
|
|
2120
|
+
examples.push({
|
|
2121
|
+
name,
|
|
2122
|
+
...title.length === 0 ? {} : { title },
|
|
2123
|
+
code,
|
|
2124
|
+
...language.length === 0 ? {} : { language }
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
return examples;
|
|
2128
|
+
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Extracts the `@example` blocks carried by the exported declaration heads in one file's source
|
|
2131
|
+
* text, each named for the declaration its block documents. Shared adjacency comes from
|
|
2132
|
+
* {@link extractSourceComments} and each block is read by {@link collectExamples}; head
|
|
2133
|
+
* membership is the {@link collectKeys} key of the documented record under every keyword that
|
|
2134
|
+
* grammar admits at column zero, so comment and template payload cannot qualify and the head
|
|
2135
|
+
* grammar stays the one every reader here shares. A member key carries a dot and a head key
|
|
2136
|
+
* does not, so a member's block belongs to {@link extractExampleMethods} instead. A head
|
|
2137
|
+
* carrying several blocks contributes each.
|
|
2138
|
+
*
|
|
2139
|
+
* @param source - The file's source text
|
|
2140
|
+
* @returns The exported declaration heads' `@example` blocks, in file order, deduplicated by name and title
|
|
2141
|
+
*
|
|
2142
|
+
* @example
|
|
2143
|
+
* ```ts
|
|
2144
|
+
* const block = ['/**', ' * @example', ' * new Widget()', ' *' + '/', 'export class Widget {}', ''].join('\n')
|
|
2145
|
+
* extractExamples(block) // [{ name: 'Widget', code: 'new Widget()' }]
|
|
2146
|
+
* extractExamples('export class Widget {}\n') // []
|
|
2147
|
+
* ```
|
|
2148
|
+
*/
|
|
2149
|
+
function extractExamples(source) {
|
|
2150
|
+
const examples = [];
|
|
2151
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2152
|
+
const lines = extractSourceLines(source);
|
|
2153
|
+
const keys = collectKeys(lines);
|
|
2154
|
+
for (const comment of extractSourceComments(lines)) {
|
|
2155
|
+
const key = keys.get(comment.line);
|
|
2156
|
+
if (key === void 0 || key.includes(".")) continue;
|
|
2157
|
+
const name = key.slice(key.indexOf(" ") + 1);
|
|
2158
|
+
for (const example of collectExamples(comment.text, name)) {
|
|
2159
|
+
const entry = `${name}\n${example.title ?? ""}`;
|
|
2160
|
+
if (seen.has(entry)) continue;
|
|
2161
|
+
seen.add(entry);
|
|
2162
|
+
examples.push(example);
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
return examples;
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* Extracts the `@example` blocks carried by the callable members of a declaration body (per
|
|
2169
|
+
* {@link collectKeys}' grammar, the same one {@link extractMemberMethods} reads), each named for
|
|
2170
|
+
* the member its block documents. Shared adjacency comes from {@link extractSourceComments} and
|
|
2171
|
+
* each block is read by {@link collectExamples}; member membership is the key
|
|
2172
|
+
* {@link extractBodyLines}'s projection gives the documented record.
|
|
2173
|
+
*
|
|
2174
|
+
* @param lines - A declaration's body lines
|
|
2175
|
+
* @returns The members' `@example` blocks, deduplicated by name and title and sorted by name
|
|
2176
|
+
*
|
|
2177
|
+
* @example
|
|
2178
|
+
* ```ts
|
|
2179
|
+
* extractExampleMethods(['\t/**', '\t * @example', '\t * walk()', '\t *' + '/', '\twalk(): void'])
|
|
2180
|
+
* // [{ name: 'walk', code: 'walk()' }]
|
|
2181
|
+
* ```
|
|
2182
|
+
*/
|
|
2183
|
+
function extractExampleMethods(lines) {
|
|
2184
|
+
const examples = [];
|
|
2185
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2186
|
+
const projected = extractBodyLines(lines);
|
|
2187
|
+
const keys = collectKeys(projected);
|
|
2188
|
+
for (const comment of extractSourceComments(projected)) {
|
|
2189
|
+
const key = keys.get(comment.line) ?? "";
|
|
2190
|
+
const dot = key.indexOf(".");
|
|
2191
|
+
if (dot < 0) continue;
|
|
2192
|
+
const name = key.slice(dot + 1);
|
|
2193
|
+
for (const example of collectExamples(comment.text, name)) {
|
|
2194
|
+
const entry = `${name}\n${example.title ?? ""}`;
|
|
2195
|
+
if (seen.has(entry)) continue;
|
|
2196
|
+
seen.add(entry);
|
|
2197
|
+
examples.push(example);
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
return examples.sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
|
|
2201
|
+
}
|
|
2202
|
+
/**
|
|
2203
|
+
* Extracts every fenced code block anywhere in the guide document. A full AST walk
|
|
2204
|
+
* includes fences nested inside blockquotes and lists, and the same walk carries each
|
|
2205
|
+
* fence's nearest preceding heading as its `title` — the key an `@example` block pairs on.
|
|
2206
|
+
* A heading's text is flattened, so a title written with a code span pairs with a plain
|
|
2207
|
+
* `@example` title.
|
|
2208
|
+
*
|
|
2209
|
+
* @param document - The parsed guide document
|
|
2210
|
+
* @returns Every fence's language, verbatim code, and title, in document order
|
|
2211
|
+
*
|
|
2212
|
+
* @example
|
|
2213
|
+
* ```ts
|
|
2214
|
+
* extractFences(document) // [{ language: 'ts', code: "import { X } from './x.js'\nX()" }]
|
|
2215
|
+
* ```
|
|
2216
|
+
*/
|
|
2217
|
+
function extractFences(document) {
|
|
2218
|
+
return Array.from(collectFences(document).values());
|
|
2219
|
+
}
|
|
2220
|
+
/**
|
|
2221
|
+
* Collects each fenced code block keyed by its own node, paired with the {@link GuideFence}
|
|
2222
|
+
* {@link extractFences} reports for it — the node-addressed form a rewrite needs, so a caller
|
|
2223
|
+
* that located a fence by title can read that node's source region back from the parser. The map
|
|
2224
|
+
* iterates in document order and a node keys itself, so a repeated identical fence keeps its own
|
|
2225
|
+
* entry.
|
|
2226
|
+
*
|
|
2227
|
+
* @param document - The parsed guide document
|
|
2228
|
+
* @returns One entry per fenced code block, in document order
|
|
2229
|
+
*
|
|
2230
|
+
* @example
|
|
2231
|
+
* ```ts
|
|
2232
|
+
* Array.from(collectFences(document).values()) // [{ language: 'ts', code: 'walk()' }]
|
|
2233
|
+
* ```
|
|
2234
|
+
*/
|
|
2235
|
+
function collectFences(document) {
|
|
2236
|
+
const fences = /* @__PURE__ */ new Map();
|
|
2237
|
+
let title = "";
|
|
2238
|
+
for (const node of walkNodes(document)) {
|
|
2239
|
+
if (isHeadingNode(node)) {
|
|
2240
|
+
title = flattenText(node).trim();
|
|
2241
|
+
continue;
|
|
2242
|
+
}
|
|
2243
|
+
if (isCodeBlockNode(node)) fences.set(node, {
|
|
2244
|
+
language: node.lang,
|
|
2245
|
+
code: node.code,
|
|
2246
|
+
...title.length === 0 ? {} : { title }
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
return fences;
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Extracts the guide's tagline — the text of the blockquote following the document's H1,
|
|
2253
|
+
* with every code span kept as a code span and whitespace collapsed. A heading before the
|
|
2254
|
+
* blockquote ends the window, so a blockquote elsewhere in the document is not the tagline.
|
|
2255
|
+
*
|
|
2256
|
+
* @param document - The parsed guide document
|
|
2257
|
+
* @returns The tagline, or `undefined` when no blockquote follows an H1 before the next heading
|
|
2258
|
+
*
|
|
2259
|
+
* @example
|
|
2260
|
+
* ```ts
|
|
2261
|
+
* extractTagline(document) // 'A pure, I/O-free guides-parity toolkit'
|
|
2262
|
+
* ```
|
|
2263
|
+
*/
|
|
2264
|
+
function extractTagline(document) {
|
|
2265
|
+
let opened = false;
|
|
2266
|
+
for (const block of document.children) {
|
|
2267
|
+
if (isHeadingNode(block)) {
|
|
2268
|
+
if (opened) return void 0;
|
|
2269
|
+
opened = block.level === 1;
|
|
2270
|
+
continue;
|
|
2271
|
+
}
|
|
2272
|
+
if (!opened || !isBlockquoteNode(block)) continue;
|
|
2273
|
+
const text = normalizeSummary(block.children.filter(isParagraphNode).map((paragraph) => extractCellText(paragraph.children)).join(" "));
|
|
2274
|
+
return text.length === 0 ? void 0 : text;
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
/**
|
|
2278
|
+
* Computes the drift between one compared key's guide text and source text. A pair agrees
|
|
2279
|
+
* only when both sides carry the same text, and every other state is a drift: guide text
|
|
2280
|
+
* alone reports the guide's side, source text alone reports the source's, and neither side
|
|
2281
|
+
* carrying text reports the key by itself. A side carrying no text is absent from the result,
|
|
2282
|
+
* so a documented symbol with no doc block reports as a drift naming the guide's text alone,
|
|
2283
|
+
* and a row a table has no `Summary` column for against a declaration with no doc block
|
|
2284
|
+
* reports as `{ key }`.
|
|
2285
|
+
*
|
|
2286
|
+
* @param key - The compared pair's key
|
|
2287
|
+
* @param category - The compared site the drift came from
|
|
2288
|
+
* @param guide - The guide's text there, or `undefined` when it carries none
|
|
2289
|
+
* @param source - The source's text there, or `undefined` when it carries none
|
|
2290
|
+
* @returns The drift, or `undefined` when both sides carry the same text
|
|
2291
|
+
*
|
|
2292
|
+
* @example
|
|
2293
|
+
* ```ts
|
|
2294
|
+
* computeDrift('function walk', 'summary', 'Walks the tree.', 'Walks a tree.')
|
|
2295
|
+
* // { key: 'function walk', category: 'summary', guide: 'Walks the tree.', source: 'Walks a tree.' }
|
|
2296
|
+
* ```
|
|
2297
|
+
*/
|
|
2298
|
+
function computeDrift(key, category, guide, source) {
|
|
2299
|
+
if (guide !== void 0 && guide === source) return void 0;
|
|
2300
|
+
return {
|
|
2301
|
+
key,
|
|
2302
|
+
category,
|
|
2303
|
+
...guide === void 0 ? {} : { guide },
|
|
2304
|
+
...source === void 0 ? {} : { source }
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
/**
|
|
2308
|
+
* Compares documented and declared membership exactly after sorting copies, preserving duplicates.
|
|
2309
|
+
*
|
|
2310
|
+
* @param spec - The guide inventory key the finding belongs to
|
|
2311
|
+
* @param name - The declaration whose membership is compared
|
|
2312
|
+
* @param documented - The documented member names
|
|
2313
|
+
* @param declared - The declared member names
|
|
2314
|
+
* @returns The membership finding, or `undefined` when the sorted populations match
|
|
2315
|
+
*
|
|
2316
|
+
* @example Compare declaration membership
|
|
2317
|
+
* ```ts
|
|
2318
|
+
* import { compareMembership } from '@orkestrel/guide'
|
|
2319
|
+
*
|
|
2320
|
+
* compareMembership('guides/widget.md', 'WidgetInterface', ['open'], ['open']) // undefined
|
|
2321
|
+
* ```
|
|
2322
|
+
*/
|
|
2323
|
+
function compareMembership(spec, name, documented, declared) {
|
|
2324
|
+
const left = [...documented].sort();
|
|
2325
|
+
const right = [...declared].sort();
|
|
2326
|
+
if (JSON.stringify(left) === JSON.stringify(right)) return void 0;
|
|
2327
|
+
return {
|
|
2328
|
+
spec,
|
|
2329
|
+
text: `${spec} ${name} documents ${JSON.stringify(left)} and declares ${JSON.stringify(right)}.`
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* Computes a category-separated identity for a guide finding.
|
|
2334
|
+
*
|
|
2335
|
+
* @param spec - The guide inventory key the drift belongs to
|
|
2336
|
+
* @param drift - The categorized disagreement
|
|
2337
|
+
* @returns The inventory key, category, and compared key separated by line feeds
|
|
2338
|
+
*
|
|
2339
|
+
* @example Identify categorized drift
|
|
2340
|
+
* ```ts
|
|
2341
|
+
* import { identifyDrift } from '@orkestrel/guide'
|
|
2342
|
+
*
|
|
2343
|
+
* identifyDrift('guides/widget.md', { category: 'summary', key: 'function open' })
|
|
2344
|
+
* // 'guides/widget.md\nsummary\nfunction open'
|
|
2345
|
+
* ```
|
|
2346
|
+
*/
|
|
2347
|
+
function identifyDrift(spec, drift) {
|
|
2348
|
+
return `${spec}\n${drift.category}\n${drift.key}`;
|
|
2349
|
+
}
|
|
2350
|
+
/**
|
|
2351
|
+
* Formats present parity text as a JSON string and absent text as `absent`.
|
|
2352
|
+
*
|
|
2353
|
+
* @param value - The compared side's text, or `undefined` when absent
|
|
2354
|
+
* @returns The developer-facing side text
|
|
2355
|
+
*
|
|
2356
|
+
* @example Format a parity side
|
|
2357
|
+
* ```ts
|
|
2358
|
+
* import { formatSide } from '@orkestrel/guide'
|
|
2359
|
+
*
|
|
2360
|
+
* formatSide('Walks.') // '"Walks."'
|
|
2361
|
+
* formatSide(undefined) // 'absent'
|
|
2362
|
+
* ```
|
|
2363
|
+
*/
|
|
2364
|
+
function formatSide(value) {
|
|
2365
|
+
return value === void 0 ? "absent" : JSON.stringify(value);
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Formats a categorized drift with its guide and source sides.
|
|
2369
|
+
*
|
|
2370
|
+
* @param drift - The categorized disagreement to format
|
|
2371
|
+
* @returns The complete developer-facing drift text
|
|
2372
|
+
*
|
|
2373
|
+
* @example Format categorized drift
|
|
2374
|
+
* ```ts
|
|
2375
|
+
* import { formatDrift } from '@orkestrel/guide'
|
|
2376
|
+
*
|
|
2377
|
+
* formatDrift({ category: 'summary', key: 'function walk', guide: 'Walks.', source: 'Walks a tree.' })
|
|
2378
|
+
* // 'summary function walk: guide "Walks." source "Walks a tree."'
|
|
2379
|
+
* ```
|
|
2380
|
+
*/
|
|
2381
|
+
function formatDrift(drift) {
|
|
2382
|
+
return `${drift.category} ${drift.key}: guide ${formatSide(drift.guide)} source ${formatSide(drift.source)}`;
|
|
2383
|
+
}
|
|
2384
|
+
/**
|
|
2385
|
+
* Finds every disagreement between a guide and the source it documents, naming both sites:
|
|
2386
|
+
* each `## Surface` row against its declaration's description paragraph, each `## Methods`
|
|
2387
|
+
* row against its member's, and the first titled guide fence of a heading against the
|
|
2388
|
+
* `@example` block of the same title. An example's compared text is its language on the first
|
|
2389
|
+
* line and its body beneath, so a fence that names another language drifts on its own.
|
|
2390
|
+
*
|
|
2391
|
+
* @remarks
|
|
2392
|
+
* Only a pair present on both sides is compared, so a symbol, a member, or a title one side
|
|
2393
|
+
* lacks entirely is left to the bijection checks that own it and is never reported twice.
|
|
2394
|
+
* {@link computeDrift} rules each compared pair, so a pair whose sides carry different text, a
|
|
2395
|
+
* pair where one side carries none, and a pair where neither side carries text are all drift.
|
|
2396
|
+
* The pairing is per title across the whole document, not per heading: the first fence a title
|
|
2397
|
+
* reaches is the compared one, and every later fence of that title is outside the comparison,
|
|
2398
|
+
* whether it sits under the same heading or under a second heading of the same text.
|
|
2399
|
+
*
|
|
2400
|
+
* @param guide - The parsed guide
|
|
2401
|
+
* @param source - The reflected source the guide documents
|
|
2402
|
+
* @returns One entry per disagreement: Surface rows, then Methods rows, then examples
|
|
2403
|
+
*
|
|
2404
|
+
* @example
|
|
2405
|
+
* ```ts
|
|
2406
|
+
* findDrift(guide, source) // [{ key: 'function walk', category: 'summary', guide: 'Walks.', source: 'Walks a tree.' }]
|
|
2407
|
+
* ```
|
|
2408
|
+
*/
|
|
2409
|
+
function findDrift(guide, source) {
|
|
2410
|
+
const drifts = [];
|
|
2411
|
+
const declared = new Map(source.surface().map((symbol) => [computeSymbolKey(symbol), symbol]));
|
|
2412
|
+
for (const symbol of guide.surface()) {
|
|
2413
|
+
const key = computeSymbolKey(symbol);
|
|
2414
|
+
const match = declared.get(key);
|
|
2415
|
+
if (match === void 0) continue;
|
|
2416
|
+
const drift = computeDrift(key, "summary", symbol.summary, match.summary);
|
|
2417
|
+
if (drift !== void 0) drifts.push(drift);
|
|
2418
|
+
}
|
|
2419
|
+
for (const group of guide.methods()) {
|
|
2420
|
+
const members = new Map(source.methods(group.interface).map((entry) => [entry.name, entry]));
|
|
2421
|
+
for (const entry of group.methods) {
|
|
2422
|
+
const member = members.get(entry.name);
|
|
2423
|
+
if (member === void 0) continue;
|
|
2424
|
+
const drift = computeDrift(`${group.interface}.${entry.name}`, "summary", entry.summary, member.summary);
|
|
2425
|
+
if (drift !== void 0) drifts.push(drift);
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
const examples = collectTitles(guide, source);
|
|
2429
|
+
const compared = /* @__PURE__ */ new Set();
|
|
2430
|
+
for (const fence of guide.fences()) {
|
|
2431
|
+
if (fence.title === void 0 || compared.has(fence.title)) continue;
|
|
2432
|
+
compared.add(fence.title);
|
|
2433
|
+
const example = examples.get(fence.title);
|
|
2434
|
+
if (example === void 0) continue;
|
|
2435
|
+
const drift = computeDrift(fence.title, "example", `${fence.language ?? ""}\n${fence.code}`, `${example.language ?? ""}\n${example.code}`);
|
|
2436
|
+
if (drift !== void 0) drifts.push(drift);
|
|
2437
|
+
}
|
|
2438
|
+
return drifts;
|
|
2439
|
+
}
|
|
2440
|
+
/**
|
|
2441
|
+
* Collects the titled `@example` blocks a guide's documented surface reaches — the module's
|
|
2442
|
+
* exported declaration heads, plus the own members of every documented `class` and `interface` —
|
|
2443
|
+
* keyed by title, the first block of a title answering for it.
|
|
2444
|
+
*
|
|
2445
|
+
* @param guide - The parsed guide naming the documented declarations
|
|
2446
|
+
* @param source - The reflected source to read the blocks from
|
|
2447
|
+
* @returns One entry per distinct `@example` title
|
|
2448
|
+
*
|
|
2449
|
+
* @example
|
|
2450
|
+
* ```ts
|
|
2451
|
+
* collectTitles(guide, source).get('Walk a tree') // { name: 'walk', title: 'Walk a tree', code: 'walk()' }
|
|
2452
|
+
* ```
|
|
2453
|
+
*/
|
|
2454
|
+
function collectTitles(guide, source) {
|
|
2455
|
+
const titled = /* @__PURE__ */ new Map();
|
|
2456
|
+
const owners = guide.surface().filter((symbol) => symbol.keyword === "class" || symbol.keyword === "interface");
|
|
2457
|
+
const examples = [...source.examples(), ...owners.flatMap((symbol) => source.examples(symbol.name))];
|
|
2458
|
+
for (const example of examples) {
|
|
2459
|
+
if (example.title === void 0 || titled.has(example.title)) continue;
|
|
2460
|
+
titled.set(example.title, example);
|
|
2461
|
+
}
|
|
2462
|
+
return titled;
|
|
2463
|
+
}
|
|
2464
|
+
/**
|
|
2465
|
+
* Builds a copy of `table` with one cell's inline content rebuilt from `text` through
|
|
2466
|
+
* {@link buildCell}. Every other cell keeps its own nodes, so a rewrite touches the one cell it
|
|
2467
|
+
* names and the header and the alignment row travel unchanged.
|
|
2468
|
+
*
|
|
2469
|
+
* @param table - The table to copy
|
|
2470
|
+
* @param row - The index of the row to rewrite within {@link TableNode.rows}
|
|
2471
|
+
* @param column - The index of the cell to rewrite within that row
|
|
2472
|
+
* @param text - The cell's new compared text
|
|
2473
|
+
* @returns The rewritten table
|
|
2474
|
+
*
|
|
2475
|
+
* @example
|
|
2476
|
+
* ```ts
|
|
2477
|
+
* buildTable(table, 0, 2, 'Walks the tree.').rows[0]?.[2] // [{ element: 'text', value: 'Walks the tree.' }]
|
|
2478
|
+
* ```
|
|
2479
|
+
*/
|
|
2480
|
+
function buildTable(table, row, column, text) {
|
|
2481
|
+
return {
|
|
2482
|
+
element: "table",
|
|
2483
|
+
header: table.header,
|
|
2484
|
+
rows: table.rows.map((cells, index) => index === row ? cells.map((cell, position) => position === column ? buildCell(text) : cell) : cells),
|
|
2485
|
+
align: table.align
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
/**
|
|
2489
|
+
* Builds the fenced code block one `@example` block renders as — its code inside a fence
|
|
2490
|
+
* carrying its language, and an untagged fence when the block names none.
|
|
2491
|
+
*
|
|
2492
|
+
* @param example - The block to render
|
|
2493
|
+
* @returns The fence node
|
|
2494
|
+
*
|
|
2495
|
+
* @example
|
|
2496
|
+
* ```ts
|
|
2497
|
+
* buildFence({ name: 'walk', code: 'walk()', language: 'ts' }) // { element: 'codeBlock', code: 'walk()', lang: 'ts' }
|
|
2498
|
+
* ```
|
|
2499
|
+
*/
|
|
2500
|
+
function buildFence(example) {
|
|
2501
|
+
return {
|
|
2502
|
+
element: "codeBlock",
|
|
2503
|
+
code: example.code,
|
|
2504
|
+
...example.language === void 0 ? {} : { lang: example.language }
|
|
2505
|
+
};
|
|
2506
|
+
}
|
|
2507
|
+
/**
|
|
2508
|
+
* Splices `replacement` into `source` over the region `span` addresses, and returns the result.
|
|
2509
|
+
* The text before the region and the text after it travel byte for byte, so a rewrite that
|
|
2510
|
+
* addresses one node's region changes nothing else in the document.
|
|
2511
|
+
*
|
|
2512
|
+
* @param source - The text to rewrite
|
|
2513
|
+
* @param span - The half-open region to replace: the region `MarkdownInterface.span` reports
|
|
2514
|
+
* for a markdown node, or the one {@link locateComment} reports for a doc block
|
|
2515
|
+
* @param replacement - The text to write over that region
|
|
2516
|
+
* @returns The rewritten text
|
|
2517
|
+
*
|
|
2518
|
+
* @example
|
|
2519
|
+
* ```ts
|
|
2520
|
+
* spliceSpan('one two three', { start: 4, end: 7 }, 'TWO') // 'one TWO three'
|
|
2521
|
+
* ```
|
|
2522
|
+
*/
|
|
2523
|
+
function spliceSpan(source, span, replacement) {
|
|
2524
|
+
return source.slice(0, span.start) + replacement + source.slice(span.end);
|
|
2525
|
+
}
|
|
2526
|
+
/**
|
|
2527
|
+
* Renders a `## Surface` table from the symbols a source declares — a `Name`, {@link KIND}, and
|
|
2528
|
+
* {@link SUMMARY} table with one row per symbol, the name as a code span, the keyword as its
|
|
2529
|
+
* text, and the summary through {@link buildCell}. A symbol carrying no summary renders an empty
|
|
2530
|
+
* cell, which {@link extractSurface} reads back as an absent summary.
|
|
2531
|
+
*
|
|
2532
|
+
* @remarks
|
|
2533
|
+
* The render carries no `## Surface` heading, because a guide documents its surface in several
|
|
2534
|
+
* tables under their own sub-headings and one of them is what this function produces. Reading the
|
|
2535
|
+
* render back therefore parses it under that heading. `renderMarkdown` pads every cell to one
|
|
2536
|
+
* space, so the render is not the committed column-aligned bytes; the checkout's formatter
|
|
2537
|
+
* re-aligns the table and the reader compares parsed entries rather than bytes.
|
|
2538
|
+
*
|
|
2539
|
+
* @param symbols - The symbols to document, in row order
|
|
2540
|
+
* @returns The table's markdown source, with no trailing newline
|
|
2541
|
+
*
|
|
2542
|
+
* @example
|
|
2543
|
+
* ```ts
|
|
2544
|
+
* renderSurface([{ name: 'walk', keyword: 'function', summary: 'Walks the tree.' }])
|
|
2545
|
+
* // '| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks the tree. |'
|
|
2546
|
+
* ```
|
|
2547
|
+
*/
|
|
2548
|
+
function renderSurface(symbols) {
|
|
2549
|
+
return renderMarkdown({
|
|
2550
|
+
element: "table",
|
|
2551
|
+
header: [
|
|
2552
|
+
[{
|
|
2553
|
+
element: "text",
|
|
2554
|
+
value: "Name"
|
|
2555
|
+
}],
|
|
2556
|
+
[{
|
|
2557
|
+
element: "text",
|
|
2558
|
+
value: KIND
|
|
2559
|
+
}],
|
|
2560
|
+
[{
|
|
2561
|
+
element: "text",
|
|
2562
|
+
value: SUMMARY
|
|
2563
|
+
}]
|
|
2564
|
+
],
|
|
2565
|
+
rows: symbols.map((symbol) => [
|
|
2566
|
+
[{
|
|
2567
|
+
element: "codeSpan",
|
|
2568
|
+
value: symbol.name
|
|
2569
|
+
}],
|
|
2570
|
+
[{
|
|
2571
|
+
element: "text",
|
|
2572
|
+
value: symbol.keyword
|
|
2573
|
+
}],
|
|
2574
|
+
buildCell(symbol.summary ?? "")
|
|
2575
|
+
]),
|
|
2576
|
+
align: [
|
|
2577
|
+
null,
|
|
2578
|
+
null,
|
|
2579
|
+
null
|
|
2580
|
+
]
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
/**
|
|
2584
|
+
* Renders one `## Methods` group — the `####` heading naming the interface as a code span, then
|
|
2585
|
+
* a `Name` and {@link SUMMARY} table with one row per documented member. A member carrying no
|
|
2586
|
+
* summary renders an empty cell, which {@link extractMethods} reads back as an absent summary.
|
|
2587
|
+
*
|
|
2588
|
+
* @remarks
|
|
2589
|
+
* The render carries no `## Methods` heading, for the reason {@link renderSurface} states:
|
|
2590
|
+
* a guide documents one group per interface under that one section heading.
|
|
2591
|
+
*
|
|
2592
|
+
* @param group - The interface and its members
|
|
2593
|
+
* @returns The heading and table's markdown source, with no trailing newline
|
|
2594
|
+
*
|
|
2595
|
+
* @example
|
|
2596
|
+
* ```ts
|
|
2597
|
+
* renderMethods({ interface: 'WidgetInterface', methods: [{ name: 'walk', summary: 'Walks.' }] })
|
|
2598
|
+
* // '#### `WidgetInterface`\n\n| Name | Summary |\n| --- | --- |\n| `walk` | Walks. |'
|
|
2599
|
+
* ```
|
|
2600
|
+
*/
|
|
2601
|
+
function renderMethods(group) {
|
|
2602
|
+
return renderMarkdown({
|
|
2603
|
+
element: "document",
|
|
2604
|
+
children: [{
|
|
2605
|
+
element: "heading",
|
|
2606
|
+
level: 4,
|
|
2607
|
+
children: [{
|
|
2608
|
+
element: "codeSpan",
|
|
2609
|
+
value: group.interface
|
|
2610
|
+
}]
|
|
2611
|
+
}, {
|
|
2612
|
+
element: "table",
|
|
2613
|
+
header: [[{
|
|
2614
|
+
element: "text",
|
|
2615
|
+
value: "Name"
|
|
2616
|
+
}], [{
|
|
2617
|
+
element: "text",
|
|
2618
|
+
value: SUMMARY
|
|
2619
|
+
}]],
|
|
2620
|
+
rows: group.methods.map((entry) => [[{
|
|
2621
|
+
element: "codeSpan",
|
|
2622
|
+
value: entry.name
|
|
2623
|
+
}], buildCell(entry.summary ?? "")]),
|
|
2624
|
+
align: [null, null]
|
|
2625
|
+
}]
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2628
|
+
/**
|
|
2629
|
+
* Renders one `@example` block as the guide fence it pairs with — an H3 heading carrying the
|
|
2630
|
+
* block's title, then a fence carrying its language and its code. An untitled block renders the
|
|
2631
|
+
* fence alone, because a fence pairs on its nearest preceding heading and an untitled block
|
|
2632
|
+
* claims none.
|
|
2633
|
+
*
|
|
2634
|
+
* @remarks
|
|
2635
|
+
* The title renders as literal text rather than markdown, so a title carrying backticks or
|
|
2636
|
+
* emphasis reads back through {@link extractFences} as the text the `@example` tag carried.
|
|
2637
|
+
* The heading level is 3 because a guide documents its examples one level under a `##` section;
|
|
2638
|
+
* {@link extractFences} pairs on the nearest preceding heading of any level, so the level is
|
|
2639
|
+
* presentation rather than pairing.
|
|
2640
|
+
*
|
|
2641
|
+
* @param example - The block to render
|
|
2642
|
+
* @returns The heading and fence's markdown source, with no trailing newline
|
|
2643
|
+
*
|
|
2644
|
+
* @example
|
|
2645
|
+
* ```ts
|
|
2646
|
+
* renderExample({ name: 'walk', title: 'Walk a tree', code: 'walk()', language: 'ts' })
|
|
2647
|
+
* // an H3 heading of 'Walk a tree', then a fence tagged `ts` carrying `walk()`
|
|
2648
|
+
* ```
|
|
2649
|
+
*/
|
|
2650
|
+
function renderExample(example) {
|
|
2651
|
+
const fence = buildFence(example);
|
|
2652
|
+
return renderMarkdown({
|
|
2653
|
+
element: "document",
|
|
2654
|
+
children: example.title === void 0 ? [fence] : [{
|
|
2655
|
+
element: "heading",
|
|
2656
|
+
level: 3,
|
|
2657
|
+
children: [{
|
|
2658
|
+
element: "text",
|
|
2659
|
+
value: example.title
|
|
2660
|
+
}]
|
|
2661
|
+
}, fence]
|
|
2662
|
+
});
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* Replaces one compared cell in a guide's text and returns the whole guide back. `key` names the
|
|
2666
|
+
* row the way {@link findDrift} names it — a {@link computeSymbolKey} key for a `## Surface` row,
|
|
2667
|
+
* an `Owner.member` key for a `## Methods` row — and the row's {@link SUMMARY} cell becomes
|
|
2668
|
+
* `summary`. Only the table's own source region is rewritten, so every byte outside it travels
|
|
2669
|
+
* unchanged; a key reaching no cell returns `undefined`, and a row already carrying the summary
|
|
2670
|
+
* returns the guide byte for byte.
|
|
2671
|
+
*
|
|
2672
|
+
* @remarks
|
|
2673
|
+
* A row the key does not reach, a table carrying no {@link SUMMARY} column, and a document whose
|
|
2674
|
+
* parse recorded no region for the table are each a miss, and a miss returns `undefined` rather
|
|
2675
|
+
* than throwing, so a caller reports the key it could not place — the one meaning `undefined`
|
|
2676
|
+
* carries in every replacer here. A row already carrying `summary` returns the guide byte for
|
|
2677
|
+
* byte, because a rewrite would re-pad the whole table for no change; that identity reads both
|
|
2678
|
+
* sides through {@link normalizeSummary}, so a caller passing text the compared form still moves
|
|
2679
|
+
* is a fixed point on the second run rather than a row rewritten forever. The rewritten table
|
|
2680
|
+
* renders one-space padded whatever padding it carried, so the checkout's formatter re-aligns it.
|
|
2681
|
+
*
|
|
2682
|
+
* @param guide - The guide's markdown source
|
|
2683
|
+
* @param key - The compared key naming the row
|
|
2684
|
+
* @param summary - The row's new compared text
|
|
2685
|
+
* @returns The guide's text with that cell replaced, or `undefined` when the key reaches no cell
|
|
2686
|
+
*
|
|
2687
|
+
* @example
|
|
2688
|
+
* ```ts
|
|
2689
|
+
* replaceCell('## Surface\n\n| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks. |', 'function walk', 'Walks a tree.')
|
|
2690
|
+
* // '## Surface\n\n| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks a tree. |'
|
|
2691
|
+
* ```
|
|
2692
|
+
*/
|
|
2693
|
+
function replaceCell(guide, key, summary) {
|
|
2694
|
+
const markdown = createMarkdown(guide);
|
|
2695
|
+
const document = markdown.document;
|
|
2696
|
+
let located;
|
|
2697
|
+
let index = -1;
|
|
2698
|
+
for (const block of selectSectionBlocks(document, SURFACE)) {
|
|
2699
|
+
if (located !== void 0 || !isTableNode(block)) continue;
|
|
2700
|
+
for (let row = 0; row < block.rows.length && located === void 0; row += 1) {
|
|
2701
|
+
const symbol = extractRowSymbol(block, row);
|
|
2702
|
+
if (symbol === void 0 || computeSymbolKey(symbol) !== key) continue;
|
|
2703
|
+
located = block;
|
|
2704
|
+
index = row;
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
for (const [table, owner] of collectGroups(document)) {
|
|
2708
|
+
if (located !== void 0) break;
|
|
2709
|
+
for (let row = 0; row < table.rows.length && located === void 0; row += 1) {
|
|
2710
|
+
const entry = extractRowEntry(table, row);
|
|
2711
|
+
if (entry === void 0 || `${owner}.${entry.name}` !== key) continue;
|
|
2712
|
+
located = table;
|
|
2713
|
+
index = row;
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
if (located === void 0) return void 0;
|
|
2717
|
+
const column = findColumnIndex(located, SUMMARY);
|
|
2718
|
+
if (column === void 0) return void 0;
|
|
2719
|
+
if ((extractRowSummary(located, index) ?? "") === normalizeSummary(summary)) return guide;
|
|
2720
|
+
const span = markdown.span(located);
|
|
2721
|
+
if (span === void 0) return void 0;
|
|
2722
|
+
return spliceSpan(guide, span, renderMarkdown(buildTable(located, index, column, summary)));
|
|
2723
|
+
}
|
|
2724
|
+
/**
|
|
2725
|
+
* Replaces one titled fence in a guide's text and returns the whole guide back. The first fence
|
|
2726
|
+
* carrying `title` — the pairing {@link findDrift} compares on — takes `example`'s language and
|
|
2727
|
+
* code. Only the fence's own source region is rewritten, so every byte outside it travels
|
|
2728
|
+
* unchanged; a title no fence carries returns `undefined`, and a fence already carrying that
|
|
2729
|
+
* body returns the guide byte for byte.
|
|
2730
|
+
*
|
|
2731
|
+
* @remarks
|
|
2732
|
+
* A title no fence carries and a document whose parse recorded no region for the fence are each a
|
|
2733
|
+
* miss, and a miss returns `undefined` rather than throwing — the one meaning `undefined` carries
|
|
2734
|
+
* in every replacer here. A fence already carrying that language and code returns the guide
|
|
2735
|
+
* byte for byte. A later fence of the same title is outside the pairing and is never rewritten,
|
|
2736
|
+
* which is the rule {@link findDrift} compares under.
|
|
2737
|
+
*
|
|
2738
|
+
* @param guide - The guide's markdown source
|
|
2739
|
+
* @param title - The heading text the fence pairs on
|
|
2740
|
+
* @param example - The block whose language and code the fence takes
|
|
2741
|
+
* @returns The guide's text with that fence replaced, or `undefined` when no fence carries the title
|
|
2742
|
+
*
|
|
2743
|
+
* @example
|
|
2744
|
+
* ```ts
|
|
2745
|
+
* replaceFence(guide, 'Walk', { name: 'walk', title: 'Walk', code: 'walk()', language: 'ts' })
|
|
2746
|
+
* // the guide's text with the fence under its `### Walk` heading carrying `walk()`
|
|
2747
|
+
* ```
|
|
2748
|
+
*/
|
|
2749
|
+
function replaceFence(guide, title, example) {
|
|
2750
|
+
const markdown = createMarkdown(guide);
|
|
2751
|
+
let located;
|
|
2752
|
+
let current;
|
|
2753
|
+
for (const [node, fence] of collectFences(markdown.document)) {
|
|
2754
|
+
if (located !== void 0 || fence.title !== title) continue;
|
|
2755
|
+
located = node;
|
|
2756
|
+
current = fence;
|
|
2757
|
+
}
|
|
2758
|
+
if (located === void 0 || current === void 0) return void 0;
|
|
2759
|
+
if (current.code === example.code && current.language === example.language) return guide;
|
|
2760
|
+
const span = markdown.span(located);
|
|
2761
|
+
if (span === void 0) return void 0;
|
|
2762
|
+
return spliceSpan(guide, span, renderMarkdown(buildFence(example)));
|
|
2763
|
+
}
|
|
2764
|
+
/**
|
|
2765
|
+
* Replaces one doc block's description paragraph with `summary` and returns the whole block back.
|
|
2766
|
+
* The paragraph is the block's text before its first block tag, and it re-wraps inside `width`;
|
|
2767
|
+
* the blank line before the first tag, every tag line, the block's indentation, and its
|
|
2768
|
+
* continuation markers all survive. A block already carrying the summary returns byte for byte,
|
|
2769
|
+
* and a text that is no doc block and a summary carrying no word each return `undefined`.
|
|
2770
|
+
*
|
|
2771
|
+
* @remarks
|
|
2772
|
+
* A miss returns `undefined`, the one meaning `undefined` carries in every replacer here, so a
|
|
2773
|
+
* caller reports the block it could not rewrite. Text that opens with no
|
|
2774
|
+
* `/**` is no doc block: a single-star `/*` comment reaches this function only by a caller's
|
|
2775
|
+
* mistake, and reshaping it into a doc block would be a silent edit. A `summary` carrying no word
|
|
2776
|
+
* names no paragraph to write, and deleting the block's description on that argument would erase
|
|
2777
|
+
* documentation on the strength of an absent value — a caller with nothing to write writes
|
|
2778
|
+
* nothing.
|
|
2779
|
+
*
|
|
2780
|
+
* A block already carrying `summary` returns byte for byte, which is what keeps a propagation
|
|
2781
|
+
* that finds no drift from rewriting the file: a doc block's own wrapping is not recoverable from
|
|
2782
|
+
* its text, so re-wrapping an unchanged paragraph would move most blocks this package's source
|
|
2783
|
+
* carries. That identity reads both sides through {@link normalizeSummary}, and it holds for a
|
|
2784
|
+
* block carrying no tag as much as for a block carrying several. A block written on one physical
|
|
2785
|
+
* line stays on one line while `summary` still fits inside `width`, and expands otherwise.
|
|
2786
|
+
*
|
|
2787
|
+
* `width` counts characters from the line's first, a tab counting as one, so a wrapped line reads
|
|
2788
|
+
* `${indent} * ${text}` and never passes that count. A caller whose formatter measures a tab as
|
|
2789
|
+
* more than one column passes a smaller width rather than taking the default.
|
|
2790
|
+
*
|
|
2791
|
+
* @param comment - One complete genuine JSDoc span's raw text, as it sits in the file
|
|
2792
|
+
* @param summary - The block's new description paragraph
|
|
2793
|
+
* @param width - The character budget a re-wrapped line stays inside. Default: {@link WRAP_WIDTH}
|
|
2794
|
+
* @returns The block's raw text with that paragraph replaced, or `undefined` for a text that is
|
|
2795
|
+
* no doc block and for a `summary` carrying no word
|
|
2796
|
+
*
|
|
2797
|
+
* @example
|
|
2798
|
+
* ```ts
|
|
2799
|
+
* replaceSummary('/**' + ' Walks. *' + '/', 'Walks a tree.') // '/**' + ' Walks a tree. *' + '/'
|
|
2800
|
+
* ```
|
|
2801
|
+
*/
|
|
2802
|
+
function replaceSummary(comment, summary, width = 100) {
|
|
2803
|
+
if (!/^[ \t]*\/\*\*/.test(comment)) return void 0;
|
|
2804
|
+
const content = unwrapComment(comment);
|
|
2805
|
+
const indent = /^[ \t]*/.exec(comment)?.[0] ?? "";
|
|
2806
|
+
const wrapped = wrapText(summary, width - indent.length - 3);
|
|
2807
|
+
if (wrapped.length === 0) return void 0;
|
|
2808
|
+
const masked = maskFences(content.join("\n")).split("\n");
|
|
2809
|
+
let tag = -1;
|
|
2810
|
+
for (let index = 0; index < masked.length && tag < 0; index += 1) if (/^[ \t]*@\w/.test(masked[index] ?? "")) tag = index;
|
|
2811
|
+
if (normalizeSummary(content.slice(0, tag < 0 ? content.length : tag).join("\n")) === normalizeSummary(summary)) return comment;
|
|
2812
|
+
const tail = tag < 0 ? [] : content.slice(tag);
|
|
2813
|
+
if (tail.length === 0 && wrapped.length === 1 && content.length === 1) {
|
|
2814
|
+
const single = `${indent}/** ${wrapped[0] ?? ""} */`;
|
|
2815
|
+
if (single.length <= width) return single;
|
|
2816
|
+
}
|
|
2817
|
+
const lines = [...wrapped];
|
|
2818
|
+
if (tail.length > 0) lines.push("");
|
|
2819
|
+
return buildComment([...lines, ...tail], indent);
|
|
2820
|
+
}
|
|
2821
|
+
/**
|
|
2822
|
+
* Replaces the body of one titled `@example` tag in a doc block's raw text and returns the whole
|
|
2823
|
+
* block back. The tag carrying `example`'s title takes a fence of its language and its code;
|
|
2824
|
+
* every other tag, the description paragraph, the block's indentation, and its continuation
|
|
2825
|
+
* markers all survive. A text that is no doc block, a title no tag carries, and a language or
|
|
2826
|
+
* code the emitted three-backtick fence cannot enclose or the doc block cannot hold each return
|
|
2827
|
+
* `undefined`.
|
|
2828
|
+
*
|
|
2829
|
+
* @remarks
|
|
2830
|
+
* A miss returns `undefined`, the one meaning `undefined` carries in every replacer here, so a
|
|
2831
|
+
* caller reports the block it could not rewrite. Text that opens with no
|
|
2832
|
+
* `/**` is no doc block, for the reason {@link replaceSummary} states. A block carrying no
|
|
2833
|
+
* `@example` tag of that title has nowhere to write, so an untitled tag and a tag carrying
|
|
2834
|
+
* another title are each left alone, and an `example` naming no title misses a block whose tags
|
|
2835
|
+
* all carry one. Code carrying a run of three or more backticks is a body the emitted fence
|
|
2836
|
+
* cannot enclose: the fence is three backticks, {@link maskFences} ends a body at the first line
|
|
2837
|
+
* opening a run at least as long, and {@link collectExamples} reads to the first such run
|
|
2838
|
+
* whatever column it sits at, so writing that body would truncate it and turn a following
|
|
2839
|
+
* `@`-line into a tag. A language or code carrying the doc-comment terminator is a body the
|
|
2840
|
+
* block itself cannot hold: the terminator closes the block where it lands and the file stops
|
|
2841
|
+
* parsing there. Refusing keeps the rewrite total over the bodies it can spell.
|
|
2842
|
+
*
|
|
2843
|
+
* A tag already carrying that language and code returns byte for byte. {@link maskFences} keeps
|
|
2844
|
+
* the current body's own lines out of the tag search, so a fenced body carrying a tag-shaped line
|
|
2845
|
+
* does not end the body early. The body ends at its last line carrying text, so the blank line
|
|
2846
|
+
* separating it from the next tag survives.
|
|
2847
|
+
*
|
|
2848
|
+
* @param comment - One complete genuine JSDoc span's raw text, as it sits in the file
|
|
2849
|
+
* @param example - The block whose language and code the tag's body takes
|
|
2850
|
+
* @returns The block's raw text with that body replaced, or `undefined` for a text that is no
|
|
2851
|
+
* doc block, for a title no `@example` tag carries, and for a language or code the emitted
|
|
2852
|
+
* fence cannot enclose or the doc block cannot hold — a body carrying the doc-comment terminator
|
|
2853
|
+
*
|
|
2854
|
+
* @example
|
|
2855
|
+
* ```ts
|
|
2856
|
+
* replaceExample('/**' + '\n * @example Walk\n * old()\n *' + '/', { name: 'walk', title: 'Walk', code: 'walk()', language: 'ts' })
|
|
2857
|
+
* // the same block, its `@example Walk` body now a fence tagged `ts` carrying `walk()`
|
|
2858
|
+
* ```
|
|
2859
|
+
*/
|
|
2860
|
+
function replaceExample(comment, example) {
|
|
2861
|
+
if (!/^[ \t]*\/\*\*/.test(comment)) return void 0;
|
|
2862
|
+
if ([example.language ?? "", ...example.code.split("\n")].some((line) => line.includes("```") || line.includes("*/"))) return void 0;
|
|
2863
|
+
const content = unwrapComment(comment);
|
|
2864
|
+
const masked = maskFences(content.join("\n")).split("\n");
|
|
2865
|
+
const title = example.title ?? "";
|
|
2866
|
+
let start = -1;
|
|
2867
|
+
for (let index = 0; index < masked.length && start < 0; index += 1) {
|
|
2868
|
+
const tag = /^[ \t]*@example(?=[ \t]|$)[ \t]*(.*)$/.exec(masked[index] ?? "");
|
|
2869
|
+
if (tag !== null && (tag[1] ?? "").trim() === title) start = index;
|
|
2870
|
+
}
|
|
2871
|
+
if (start < 0) return void 0;
|
|
2872
|
+
const current = collectExamples(content.join("\n"), example.name).find((entry) => (entry.title ?? "") === title);
|
|
2873
|
+
if (current !== void 0 && current.code === example.code && current.language === example.language) return comment;
|
|
2874
|
+
let end = content.length;
|
|
2875
|
+
for (let index = start + 1; index < masked.length && end === content.length; index += 1) if (/^[ \t]*@\w/.test(masked[index] ?? "")) end = index;
|
|
2876
|
+
while (end > start + 1 && (content[end - 1] ?? "").length === 0) end -= 1;
|
|
2877
|
+
const indent = /^[ \t]*/.exec(comment)?.[0] ?? "";
|
|
2878
|
+
const body = [
|
|
2879
|
+
`\`\`\`${example.language ?? ""}`,
|
|
2880
|
+
...example.code.split("\n"),
|
|
2881
|
+
"```"
|
|
2882
|
+
];
|
|
2883
|
+
return buildComment([
|
|
2884
|
+
...content.slice(0, start + 1),
|
|
2885
|
+
...body,
|
|
2886
|
+
...content.slice(end)
|
|
2887
|
+
], indent);
|
|
2888
|
+
}
|
|
2889
|
+
/**
|
|
2890
|
+
* Locates the doc block a compared key attaches to inside one file's text and returns the block's
|
|
2891
|
+
* own character region, so a caller can `slice` the block, rewrite it through
|
|
2892
|
+
* {@link replaceSummary} or {@link replaceExample}, and write the result back through
|
|
2893
|
+
* {@link spliceSpan}. `key` names the pair the way {@link findDrift} names it — a
|
|
2894
|
+
* {@link computeSymbolKey} key for a declaration, an `Owner.member` key for an interface or class
|
|
2895
|
+
* member; the region covers the block's own indentation, and no block carrying the key returns
|
|
2896
|
+
* `undefined`.
|
|
2897
|
+
*
|
|
2898
|
+
* @remarks
|
|
2899
|
+
* Attachment is {@link extractSourceComments}'s, not a second reading of the file: that walk
|
|
2900
|
+
* pairs each eligible block with the physical record it documents, and this function keeps the
|
|
2901
|
+
* record {@link collectKeys} gives `key`. The keys are that one grammar's — the map
|
|
2902
|
+
* {@link extractExports} and {@link extractMemberMethods} each read their own part out of — so
|
|
2903
|
+
* this function runs no head pattern, no member pattern, and no owner-close rule of its own, and
|
|
2904
|
+
* a change to any of them reaches the locator too. Every block {@link collectSummaries} reports
|
|
2905
|
+
* a summary for is reachable by its key, and a block carrying only block tags is reachable too although it carries no summary.
|
|
2906
|
+
* A block it misses is one the comparison never had: a block a blank line separates from its
|
|
2907
|
+
* declaration attaches to the blank line, and a block written inside a template literal or a
|
|
2908
|
+
* string is no genuine span at all. The first block whose record carries the key answers for it,
|
|
2909
|
+
* as the first declaration of a name does everywhere else.
|
|
2910
|
+
*
|
|
2911
|
+
* The region runs from the start of the opener's line, the block's indentation included, to the
|
|
2912
|
+
* character past its closing marker — the raw text {@link replaceSummary} and
|
|
2913
|
+
* {@link replaceExample} each document as the span "as it sits in the file", so a caller slices,
|
|
2914
|
+
* rewrites, and splices with no adjustment and the rewrite keeps the indentation it found. A
|
|
2915
|
+
* block that source material precedes on its own line starts at the opener instead. The region
|
|
2916
|
+
* is read off the aligned JSDoc projection rather than searched for in the text, so an opener
|
|
2917
|
+
* written inside a string never yields one, and line offsets come from
|
|
2918
|
+
* {@link extractSourceLines}'s own records under its stated LF-or-CRLF terminator rule, so a
|
|
2919
|
+
* CRLF file reports the offsets its own bytes carry.
|
|
2920
|
+
*
|
|
2921
|
+
* @param text - One file's whole source text
|
|
2922
|
+
* @param key - The compared key naming the declaration or the member
|
|
2923
|
+
* @returns The block's half-open character region, or `undefined` when no block carries the key
|
|
2924
|
+
*
|
|
2925
|
+
* @example
|
|
2926
|
+
* ```ts
|
|
2927
|
+
* const text = '/**' + ' Walks. *' + '/\nexport function walk(): void {}\n'
|
|
2928
|
+
* locateComment(text, 'function walk') // { start: 0, end: 13 }
|
|
2929
|
+
* ```
|
|
2930
|
+
*/
|
|
2931
|
+
function locateComment(text, key) {
|
|
2932
|
+
const lines = extractSourceLines(text);
|
|
2933
|
+
const keys = collectKeys(lines);
|
|
2934
|
+
const offsets = [];
|
|
2935
|
+
const positions = /* @__PURE__ */ new Map();
|
|
2936
|
+
let offset = 0;
|
|
2937
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
2938
|
+
const line = lines[index];
|
|
2939
|
+
if (line === void 0) continue;
|
|
2940
|
+
offsets.push(offset);
|
|
2941
|
+
positions.set(line, index);
|
|
2942
|
+
const after = offset + line.source.length;
|
|
2943
|
+
offset = after + (text.startsWith("\r\n", after) ? 2 : 1);
|
|
2944
|
+
}
|
|
2945
|
+
for (const comment of extractSourceComments(lines)) {
|
|
2946
|
+
if (keys.get(comment.line) !== key) continue;
|
|
2947
|
+
const close = (positions.get(comment.line) ?? 0) - 1;
|
|
2948
|
+
const closing = lines[close]?.jsdoc;
|
|
2949
|
+
const end = closing === void 0 ? -1 : closing.lastIndexOf("*/");
|
|
2950
|
+
if (end < 0) continue;
|
|
2951
|
+
let first = close;
|
|
2952
|
+
while (first > 0 && lines[first - 1]?.jsdoc !== void 0) first -= 1;
|
|
2953
|
+
let inside = false;
|
|
2954
|
+
let line = -1;
|
|
2955
|
+
let column = -1;
|
|
2956
|
+
for (let index = first; index <= close; index += 1) {
|
|
2957
|
+
const projection = lines[index]?.jsdoc ?? "";
|
|
2958
|
+
let cursor = 0;
|
|
2959
|
+
while (cursor < projection.length) {
|
|
2960
|
+
const at = projection.indexOf(inside ? "*/" : "/**", cursor);
|
|
2961
|
+
if (at < 0) break;
|
|
2962
|
+
if (!inside) {
|
|
2963
|
+
line = index;
|
|
2964
|
+
column = at;
|
|
2965
|
+
}
|
|
2966
|
+
cursor = at + (inside ? 2 : 3);
|
|
2967
|
+
inside = !inside;
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
if (line < 0) continue;
|
|
2971
|
+
const start = (lines[line]?.source ?? "").slice(0, column).trim() === "" ? 0 : column;
|
|
2972
|
+
return {
|
|
2973
|
+
start: (offsets[line] ?? 0) + start,
|
|
2974
|
+
end: (offsets[close] ?? 0) + end + 2
|
|
2975
|
+
};
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
//#endregion
|
|
2979
|
+
//#region src/core/parsers.ts
|
|
1499
2980
|
/**
|
|
1500
2981
|
* Parses a `## By concept` manifest table into its {@link ManifestEntry} rows —
|
|
1501
2982
|
* each row's Concept cell (flattened text), Spec / Tests cells (a single link
|
|
@@ -1551,7 +3032,7 @@ function parseManifest(markdown, directory) {
|
|
|
1551
3032
|
//#region src/core/shapers.ts
|
|
1552
3033
|
/**
|
|
1553
3034
|
* Shapes a {@link SurfaceSymbol} — a documented / exported symbol's `name`
|
|
1554
|
-
* paired with its {@link ExportKeyword}
|
|
3035
|
+
* paired with its {@link ExportKeyword} and its optional compared `summary`.
|
|
1555
3036
|
*
|
|
1556
3037
|
* @example
|
|
1557
3038
|
* ```ts
|
|
@@ -1564,7 +3045,63 @@ function parseManifest(markdown, directory) {
|
|
|
1564
3045
|
*/
|
|
1565
3046
|
var surfaceSymbolShape = objectShape({
|
|
1566
3047
|
name: stringShape(),
|
|
1567
|
-
keyword: literalShape(EXPORT_KEYWORDS)
|
|
3048
|
+
keyword: literalShape(EXPORT_KEYWORDS),
|
|
3049
|
+
summary: optionalShape(stringShape())
|
|
3050
|
+
});
|
|
3051
|
+
/**
|
|
3052
|
+
* Shapes a {@link MethodEntry} — one documented method's `name` paired with its optional
|
|
3053
|
+
* compared `summary`.
|
|
3054
|
+
*
|
|
3055
|
+
* @example
|
|
3056
|
+
* ```ts
|
|
3057
|
+
* import { createContract } from '@orkestrel/contract'
|
|
3058
|
+
* import { methodEntryShape } from '@orkestrel/guide'
|
|
3059
|
+
*
|
|
3060
|
+
* const methodEntry = createContract(methodEntryShape)
|
|
3061
|
+
* methodEntry.is({ name: 'walk' }) // true
|
|
3062
|
+
* ```
|
|
3063
|
+
*/
|
|
3064
|
+
var methodEntryShape = objectShape({
|
|
3065
|
+
name: stringShape(),
|
|
3066
|
+
summary: optionalShape(stringShape())
|
|
3067
|
+
});
|
|
3068
|
+
/**
|
|
3069
|
+
* Shapes a {@link SourceExample} — one `@example` block's `name`, its optional pairing
|
|
3070
|
+
* `title`, its `code`, and its optional fence `language`.
|
|
3071
|
+
*
|
|
3072
|
+
* @example
|
|
3073
|
+
* ```ts
|
|
3074
|
+
* import { createContract } from '@orkestrel/contract'
|
|
3075
|
+
* import { sourceExampleShape } from '@orkestrel/guide'
|
|
3076
|
+
*
|
|
3077
|
+
* const sourceExample = createContract(sourceExampleShape)
|
|
3078
|
+
* sourceExample.is({ name: 'walk', code: 'walk()' }) // true
|
|
3079
|
+
* ```
|
|
3080
|
+
*/
|
|
3081
|
+
var sourceExampleShape = objectShape({
|
|
3082
|
+
name: stringShape(),
|
|
3083
|
+
title: optionalShape(stringShape()),
|
|
3084
|
+
code: stringShape(),
|
|
3085
|
+
language: optionalShape(stringShape())
|
|
3086
|
+
});
|
|
3087
|
+
/**
|
|
3088
|
+
* Shapes a {@link Drift} — one disagreement's compared `key` with the optional text each
|
|
3089
|
+
* side carries there.
|
|
3090
|
+
*
|
|
3091
|
+
* @example
|
|
3092
|
+
* ```ts
|
|
3093
|
+
* import { createContract } from '@orkestrel/contract'
|
|
3094
|
+
* import { driftShape } from '@orkestrel/guide'
|
|
3095
|
+
*
|
|
3096
|
+
* const drift = createContract(driftShape)
|
|
3097
|
+
* drift.is({ key: 'class Widget', category: 'summary', guide: 'A widget.' }) // true
|
|
3098
|
+
* ```
|
|
3099
|
+
*/
|
|
3100
|
+
var driftShape = objectShape({
|
|
3101
|
+
key: stringShape(),
|
|
3102
|
+
category: literalShape(DRIFT_CATEGORIES),
|
|
3103
|
+
guide: optionalShape(stringShape()),
|
|
3104
|
+
source: optionalShape(stringShape())
|
|
1568
3105
|
});
|
|
1569
3106
|
/**
|
|
1570
3107
|
* Shapes a {@link MethodGroup} — a backticked `interface` name paired with
|
|
@@ -1581,7 +3118,7 @@ var surfaceSymbolShape = objectShape({
|
|
|
1581
3118
|
*/
|
|
1582
3119
|
var methodGroupShape = objectShape({
|
|
1583
3120
|
interface: stringShape(),
|
|
1584
|
-
methods: arrayShape(
|
|
3121
|
+
methods: arrayShape(methodEntryShape)
|
|
1585
3122
|
});
|
|
1586
3123
|
/**
|
|
1587
3124
|
* Shapes a {@link ManifestEntry} — one `## By concept` manifest row, `source`
|
|
@@ -1606,8 +3143,8 @@ var manifestEntryShape = objectShape({
|
|
|
1606
3143
|
//#region src/core/Guide.ts
|
|
1607
3144
|
/**
|
|
1608
3145
|
* Presents a pure, structured view over one parsed guide — the documented
|
|
1609
|
-
* projections (`sections` / `surface` / `methods` / `
|
|
1610
|
-
* `fences`) are extracted once at construction and cached.
|
|
3146
|
+
* projections (`sections` / `tagline` / `surface` / `methods` / `unnamed` / `links` /
|
|
3147
|
+
* `tests` / `fences`) are extracted once at construction and cached.
|
|
1611
3148
|
*
|
|
1612
3149
|
* @remarks
|
|
1613
3150
|
* Parses `source` once through `@orkestrel/markdown` and never touches the
|
|
@@ -1625,16 +3162,20 @@ var manifestEntryShape = objectShape({
|
|
|
1625
3162
|
*/
|
|
1626
3163
|
var Guide = class {
|
|
1627
3164
|
#sections;
|
|
3165
|
+
#tagline;
|
|
1628
3166
|
#surface;
|
|
1629
3167
|
#methods;
|
|
3168
|
+
#unnamed;
|
|
1630
3169
|
#links;
|
|
1631
3170
|
#tests;
|
|
1632
3171
|
#fences;
|
|
1633
3172
|
constructor(source) {
|
|
1634
3173
|
const document = createMarkdown(source).document;
|
|
1635
3174
|
this.#sections = document.children.filter(isHeadingNode).filter((heading) => heading.level === 2).map((heading) => flattenText(heading).trim());
|
|
3175
|
+
this.#tagline = extractTagline(document);
|
|
1636
3176
|
this.#surface = extractSurface(document);
|
|
1637
3177
|
this.#methods = extractMethods(document);
|
|
3178
|
+
this.#unnamed = extractUnnamed(document);
|
|
1638
3179
|
this.#links = extractLinks(document);
|
|
1639
3180
|
this.#tests = extractTests(document);
|
|
1640
3181
|
this.#fences = extractFences(document);
|
|
@@ -1642,12 +3183,18 @@ var Guide = class {
|
|
|
1642
3183
|
sections() {
|
|
1643
3184
|
return this.#sections;
|
|
1644
3185
|
}
|
|
3186
|
+
tagline() {
|
|
3187
|
+
return this.#tagline;
|
|
3188
|
+
}
|
|
1645
3189
|
surface() {
|
|
1646
3190
|
return this.#surface;
|
|
1647
3191
|
}
|
|
1648
3192
|
methods() {
|
|
1649
3193
|
return this.#methods;
|
|
1650
3194
|
}
|
|
3195
|
+
unnamed() {
|
|
3196
|
+
return this.#unnamed;
|
|
3197
|
+
}
|
|
1651
3198
|
links() {
|
|
1652
3199
|
return this.#links;
|
|
1653
3200
|
}
|
|
@@ -1667,7 +3214,10 @@ var Guide = class {
|
|
|
1667
3214
|
* filesystem. `Source` never touches disk:
|
|
1668
3215
|
* the consumer gathers the inventory however their environment allows
|
|
1669
3216
|
* (`node:fs` in a Node script, `import.meta.glob` in a browser/vitest run) and
|
|
1670
|
-
* passes it in as `files`.
|
|
3217
|
+
* passes it in as `files`.
|
|
3218
|
+
*
|
|
3219
|
+
* @remarks
|
|
3220
|
+
* Conventional barrel traversal recurses through both
|
|
1671
3221
|
* exact workspace-root `index.ts` and nested `/index.ts` targets. `'.'` is the
|
|
1672
3222
|
* canonical workspace-root module, module spellings normalize once at
|
|
1673
3223
|
* construction, and exact opaque inventory keys are never rewritten; keys with
|
|
@@ -1678,11 +3228,16 @@ var Guide = class {
|
|
|
1678
3228
|
* from; a base the scope does not declare contributes nothing. One declaration
|
|
1679
3229
|
* answers for a name: the first file in sorted key order that declares the head
|
|
1680
3230
|
* supplies its members and its bases, and a second file declaring the same name
|
|
1681
|
-
* adds nothing.
|
|
1682
|
-
*
|
|
1683
|
-
*
|
|
1684
|
-
*
|
|
1685
|
-
*
|
|
3231
|
+
* adds nothing. Every reading derives once per instance from the immutable
|
|
3232
|
+
* inventory and is reused — the scope's declaration map on the first `methods`
|
|
3233
|
+
* or `examples` lookup, then each name's members and each example collection
|
|
3234
|
+
* under the name asked for — so a reader asking twice reads the files once and
|
|
3235
|
+
* receives the same records, and a second instance over the same inventory
|
|
3236
|
+
* derives the same readings of its own. Source projection preserves columns
|
|
3237
|
+
* without widening direct/hidden column-zero heads. Literal ECMAScript Unicode
|
|
3238
|
+
* identifiers participate in bounded slash-state recognition without escape
|
|
3239
|
+
* decoding. Regex recognition is bounded: slash after bare `}` is division, so
|
|
3240
|
+
* a post-brace regex statement requires an explicit `;`. General semicolonless
|
|
1686
3241
|
* declaration/ASI classification is also outside the finite projector, so a
|
|
1687
3242
|
* slash-leading statement after such a declaration requires an explicit `;`.
|
|
1688
3243
|
*
|
|
@@ -1700,17 +3255,19 @@ var Guide = class {
|
|
|
1700
3255
|
* })
|
|
1701
3256
|
* source.exports() // [{ name: 'Guide', keyword: 'class' }, { name: 'GuideInterface', keyword: 'interface' }]
|
|
1702
3257
|
* source.surface() // [{ name: 'Guide', keyword: 'class' }, { name: 'GuideInterface', keyword: 'interface' }]
|
|
1703
|
-
* source.methods('GuideInterface') // ['sections']
|
|
3258
|
+
* source.methods('GuideInterface') // [{ name: 'sections' }]
|
|
1704
3259
|
* source.exists('src/core/Guide.ts') // true
|
|
1705
3260
|
* ```
|
|
1706
3261
|
*/
|
|
1707
3262
|
var Source = class {
|
|
1708
3263
|
#files;
|
|
1709
3264
|
#directories;
|
|
3265
|
+
#methods = /* @__PURE__ */ new Map();
|
|
3266
|
+
#examples = /* @__PURE__ */ new Map();
|
|
1710
3267
|
#exports;
|
|
1711
3268
|
#surface;
|
|
1712
3269
|
#hidden;
|
|
1713
|
-
#
|
|
3270
|
+
#declarations;
|
|
1714
3271
|
constructor(options) {
|
|
1715
3272
|
this.#files = options.files;
|
|
1716
3273
|
this.#directories = normalizeDirectories(options.module);
|
|
@@ -1724,10 +3281,11 @@ var Source = class {
|
|
|
1724
3281
|
return this.#surface;
|
|
1725
3282
|
}
|
|
1726
3283
|
methods(name) {
|
|
1727
|
-
const
|
|
1728
|
-
if (
|
|
1729
|
-
const
|
|
1730
|
-
|
|
3284
|
+
const cached = this.#methods.get(name);
|
|
3285
|
+
if (cached !== void 0) return cached;
|
|
3286
|
+
const members = this.#scanMethods(name);
|
|
3287
|
+
this.#methods.set(name, members);
|
|
3288
|
+
return members;
|
|
1731
3289
|
}
|
|
1732
3290
|
exists(relative) {
|
|
1733
3291
|
return Object.keys(this.#files).some((key) => key === relative || key.startsWith(`${relative}/`));
|
|
@@ -1737,25 +3295,32 @@ var Source = class {
|
|
|
1737
3295
|
return this.#hidden;
|
|
1738
3296
|
}
|
|
1739
3297
|
examples(name) {
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
return
|
|
3298
|
+
const cached = this.#examples.get(name);
|
|
3299
|
+
if (cached !== void 0) return cached;
|
|
3300
|
+
const examples = name === void 0 ? this.#scanExamples() : this.#exampleMembers(name);
|
|
3301
|
+
this.#examples.set(name, examples);
|
|
3302
|
+
return examples;
|
|
3303
|
+
}
|
|
3304
|
+
#scanMethods(name) {
|
|
3305
|
+
const declared = this.#members("interface", name, /* @__PURE__ */ new Set());
|
|
3306
|
+
if (declared !== void 0) return declared;
|
|
3307
|
+
const inherited = this.#members("class", name, /* @__PURE__ */ new Set());
|
|
3308
|
+
return inherited === void 0 ? [] : inherited.filter((entry) => entry.name !== "constructor");
|
|
1745
3309
|
}
|
|
1746
3310
|
#scanExamples() {
|
|
1747
|
-
const
|
|
3311
|
+
const examples = [];
|
|
1748
3312
|
const seen = /* @__PURE__ */ new Set();
|
|
1749
3313
|
for (const key of selectModuleKeys(this.#files, this.#directories)) {
|
|
1750
3314
|
const text = this.#files[key];
|
|
1751
3315
|
if (text === void 0) continue;
|
|
1752
|
-
for (const
|
|
1753
|
-
|
|
1754
|
-
seen.
|
|
1755
|
-
|
|
3316
|
+
for (const example of extractExamples(text)) {
|
|
3317
|
+
const identity = `${example.name}\n${example.title ?? ""}`;
|
|
3318
|
+
if (seen.has(identity)) continue;
|
|
3319
|
+
seen.add(identity);
|
|
3320
|
+
examples.push(example);
|
|
1756
3321
|
}
|
|
1757
3322
|
}
|
|
1758
|
-
return
|
|
3323
|
+
return examples;
|
|
1759
3324
|
}
|
|
1760
3325
|
#scanSurface() {
|
|
1761
3326
|
const symbols = [];
|
|
@@ -1793,8 +3358,13 @@ var Source = class {
|
|
|
1793
3358
|
}
|
|
1794
3359
|
}
|
|
1795
3360
|
#exampleMembers(name) {
|
|
1796
|
-
const members = /* @__PURE__ */ new
|
|
1797
|
-
|
|
3361
|
+
const members = /* @__PURE__ */ new Map();
|
|
3362
|
+
for (const example of [...extractExampleMethods(this.#locate("interface", name)?.body ?? []), ...extractExampleMethods(this.#locate("class", name)?.body ?? [])]) {
|
|
3363
|
+
const identity = `${example.name}\n${example.title ?? ""}`;
|
|
3364
|
+
if (members.has(identity)) continue;
|
|
3365
|
+
members.set(identity, example);
|
|
3366
|
+
}
|
|
3367
|
+
return Array.from(members.values()).sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
|
|
1798
3368
|
}
|
|
1799
3369
|
#scanSymbols(scan) {
|
|
1800
3370
|
const symbols = [];
|
|
@@ -1816,19 +3386,27 @@ var Source = class {
|
|
|
1816
3386
|
visited.add(name);
|
|
1817
3387
|
const declaration = this.#locate(keyword, name);
|
|
1818
3388
|
if (declaration === void 0) return void 0;
|
|
1819
|
-
const methods = new
|
|
1820
|
-
for (const
|
|
1821
|
-
|
|
3389
|
+
const methods = /* @__PURE__ */ new Map();
|
|
3390
|
+
for (const entry of extractMemberMethods(declaration.body)) methods.set(entry.name, entry);
|
|
3391
|
+
for (const base of declaration.bases) for (const member of this.#members(keyword, base, visited) ?? []) if (!methods.has(member.name)) methods.set(member.name, member);
|
|
3392
|
+
return Array.from(methods.values()).sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
|
|
1822
3393
|
}
|
|
1823
3394
|
#locate(keyword, name) {
|
|
3395
|
+
if (this.#declarations === void 0) this.#declarations = this.#scanDeclarations();
|
|
3396
|
+
return this.#declarations.get(`${keyword} ${name}`);
|
|
3397
|
+
}
|
|
3398
|
+
#scanDeclarations() {
|
|
3399
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
1824
3400
|
for (const key of selectModuleKeys(this.#files, this.#directories)) {
|
|
1825
3401
|
const text = this.#files[key];
|
|
1826
3402
|
if (text === void 0) continue;
|
|
1827
|
-
const declaration
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
3403
|
+
for (const [identity, declaration] of collectDeclarations(text)) {
|
|
3404
|
+
if (declarations.has(identity)) continue;
|
|
3405
|
+
if (declaration.body.length === 0 && declaration.bases.length === 0) continue;
|
|
3406
|
+
declarations.set(identity, declaration);
|
|
3407
|
+
}
|
|
1831
3408
|
}
|
|
3409
|
+
return declarations;
|
|
1832
3410
|
}
|
|
1833
3411
|
};
|
|
1834
3412
|
//#endregion
|
|
@@ -1887,6 +3465,440 @@ var SourceManager = class {
|
|
|
1887
3465
|
}
|
|
1888
3466
|
};
|
|
1889
3467
|
//#endregion
|
|
3468
|
+
//#region src/core/Parity.ts
|
|
3469
|
+
/**
|
|
3470
|
+
* Composes generic guide-parity inspection and explicit in-memory rewrites over a caller inventory.
|
|
3471
|
+
*/
|
|
3472
|
+
var Parity = class Parity {
|
|
3473
|
+
#options;
|
|
3474
|
+
#rows;
|
|
3475
|
+
constructor(options) {
|
|
3476
|
+
this.#options = {
|
|
3477
|
+
files: { ...options.files },
|
|
3478
|
+
entries: options.entries.map((entry) => ({ ...entry })),
|
|
3479
|
+
modules: { ...options.modules },
|
|
3480
|
+
languages: [...options.languages],
|
|
3481
|
+
language: options.language,
|
|
3482
|
+
...options.pitch === void 0 ? {} : { pitch: { ...options.pitch } }
|
|
3483
|
+
};
|
|
3484
|
+
this.#rows = this.#createRows(this.#options.files);
|
|
3485
|
+
}
|
|
3486
|
+
rows() {
|
|
3487
|
+
return this.#rows;
|
|
3488
|
+
}
|
|
3489
|
+
inspect() {
|
|
3490
|
+
const input = [];
|
|
3491
|
+
const sections = [];
|
|
3492
|
+
const surface = [];
|
|
3493
|
+
const methods = [];
|
|
3494
|
+
const declarations = [];
|
|
3495
|
+
const links = [];
|
|
3496
|
+
const tests = [];
|
|
3497
|
+
const fences = [];
|
|
3498
|
+
const exampleFences = [];
|
|
3499
|
+
const exampleFunctions = [];
|
|
3500
|
+
const exampleMethods = [];
|
|
3501
|
+
const exampleTitles = [];
|
|
3502
|
+
const examples = {
|
|
3503
|
+
fences: exampleFences,
|
|
3504
|
+
functions: exampleFunctions,
|
|
3505
|
+
methods: exampleMethods,
|
|
3506
|
+
titles: exampleTitles
|
|
3507
|
+
};
|
|
3508
|
+
const imports = [];
|
|
3509
|
+
const drift = [];
|
|
3510
|
+
const pitch = [];
|
|
3511
|
+
this.#inspectInput(input);
|
|
3512
|
+
for (const row of this.#rows) {
|
|
3513
|
+
this.#inspectSections(row, sections);
|
|
3514
|
+
this.#inspectSurface(row, surface);
|
|
3515
|
+
this.#inspectMethods(row, methods);
|
|
3516
|
+
this.#inspectDeclarations(row, declarations);
|
|
3517
|
+
this.#inspectLinks(row, links, tests);
|
|
3518
|
+
this.#inspectFences(row, fences);
|
|
3519
|
+
this.#inspectExamples(row, exampleFences, exampleFunctions, exampleMethods, exampleTitles);
|
|
3520
|
+
this.#inspectImports(row, imports);
|
|
3521
|
+
this.#inspectDrift(row, drift);
|
|
3522
|
+
}
|
|
3523
|
+
this.#inspectPitch(pitch);
|
|
3524
|
+
return {
|
|
3525
|
+
input,
|
|
3526
|
+
sections,
|
|
3527
|
+
surface,
|
|
3528
|
+
methods,
|
|
3529
|
+
declarations,
|
|
3530
|
+
links,
|
|
3531
|
+
tests,
|
|
3532
|
+
fences,
|
|
3533
|
+
examples,
|
|
3534
|
+
imports,
|
|
3535
|
+
drift,
|
|
3536
|
+
pitch
|
|
3537
|
+
};
|
|
3538
|
+
}
|
|
3539
|
+
document() {
|
|
3540
|
+
return this.#rewrite((row, drift, files) => this.#rewriteGuide(row, drift, files));
|
|
3541
|
+
}
|
|
3542
|
+
annotate() {
|
|
3543
|
+
return this.#rewrite((row, drift, files) => this.#rewriteSource(row, drift, files));
|
|
3544
|
+
}
|
|
3545
|
+
#rewrite(apply) {
|
|
3546
|
+
const files = new Map(Object.entries(this.#options.files));
|
|
3547
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
3548
|
+
const requested = /* @__PURE__ */ new Set();
|
|
3549
|
+
for (const row of this.#rows) for (const drift of findDrift(row.guide, row.source)) {
|
|
3550
|
+
const identity = identifyDrift(row.entry.spec, drift);
|
|
3551
|
+
requested.add(identity);
|
|
3552
|
+
const reason = apply(row, drift, files);
|
|
3553
|
+
if (reason !== void 0) reasons.set(identity, reason);
|
|
3554
|
+
}
|
|
3555
|
+
const inventory = Object.fromEntries(files);
|
|
3556
|
+
const remaining = [];
|
|
3557
|
+
const result = new Parity({
|
|
3558
|
+
...this.#options,
|
|
3559
|
+
files: inventory
|
|
3560
|
+
});
|
|
3561
|
+
remaining.push(...result.inspect().input);
|
|
3562
|
+
for (const row of result.rows()) for (const drift of findDrift(row.guide, row.source)) {
|
|
3563
|
+
const identity = identifyDrift(row.entry.spec, drift);
|
|
3564
|
+
if (!requested.has(identity)) continue;
|
|
3565
|
+
remaining.push({
|
|
3566
|
+
spec: row.entry.spec,
|
|
3567
|
+
text: `${formatDrift(drift)}; ${reasons.get(identity) ?? "the requested destination still disagrees"}`
|
|
3568
|
+
});
|
|
3569
|
+
}
|
|
3570
|
+
return {
|
|
3571
|
+
changes: Array.from(files.entries()).filter(([path, content]) => this.#options.files[path] !== content).sort(([left], [right]) => left.localeCompare(right)).map(([path, content]) => ({
|
|
3572
|
+
path,
|
|
3573
|
+
content
|
|
3574
|
+
})),
|
|
3575
|
+
findings: remaining
|
|
3576
|
+
};
|
|
3577
|
+
}
|
|
3578
|
+
#createRows(files) {
|
|
3579
|
+
const rows = [];
|
|
3580
|
+
for (const entry of this.#options.entries) {
|
|
3581
|
+
const text = files[entry.spec];
|
|
3582
|
+
if (text === void 0) continue;
|
|
3583
|
+
rows.push({
|
|
3584
|
+
entry,
|
|
3585
|
+
guide: new Guide(text),
|
|
3586
|
+
source: new Source({
|
|
3587
|
+
files,
|
|
3588
|
+
module: entry.source
|
|
3589
|
+
})
|
|
3590
|
+
});
|
|
3591
|
+
}
|
|
3592
|
+
return rows;
|
|
3593
|
+
}
|
|
3594
|
+
#inspectInput(findings) {
|
|
3595
|
+
if (this.#options.entries.length === 0) findings.push({ text: "The manifest has no guide entries." });
|
|
3596
|
+
for (const entry of this.#options.entries) {
|
|
3597
|
+
if (this.#options.files[entry.spec] !== void 0) continue;
|
|
3598
|
+
findings.push({
|
|
3599
|
+
spec: entry.spec,
|
|
3600
|
+
text: `${entry.spec} is absent from the inventory.`
|
|
3601
|
+
});
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
#inspectSections(row, findings) {
|
|
3605
|
+
const sections = row.guide.sections();
|
|
3606
|
+
for (const heading of [
|
|
3607
|
+
SURFACE,
|
|
3608
|
+
METHODS,
|
|
3609
|
+
TESTS
|
|
3610
|
+
]) {
|
|
3611
|
+
if (sections.includes(heading)) continue;
|
|
3612
|
+
findings.push({
|
|
3613
|
+
spec: row.entry.spec,
|
|
3614
|
+
text: `${row.entry.spec} has no ## ${heading} section.`
|
|
3615
|
+
});
|
|
3616
|
+
}
|
|
3617
|
+
if (row.guide.methods().length === 0) findings.push({
|
|
3618
|
+
spec: row.entry.spec,
|
|
3619
|
+
text: `${row.entry.spec} has no documented method groups.`
|
|
3620
|
+
});
|
|
3621
|
+
}
|
|
3622
|
+
#inspectSurface(row, findings) {
|
|
3623
|
+
if (row.guide.surface().length === 0) findings.push({
|
|
3624
|
+
spec: row.entry.spec,
|
|
3625
|
+
text: `${row.entry.spec} has no documented surface.`
|
|
3626
|
+
});
|
|
3627
|
+
for (const unnamed of row.guide.unnamed()) findings.push({
|
|
3628
|
+
spec: row.entry.spec,
|
|
3629
|
+
text: `${row.entry.spec} has an unnamed row: ${unnamed}`
|
|
3630
|
+
});
|
|
3631
|
+
for (const key of findMissingSymbols(row.source.exports(), row.source.surface())) findings.push({
|
|
3632
|
+
spec: row.entry.spec,
|
|
3633
|
+
text: `${row.entry.spec} does not re-export ${key}.`
|
|
3634
|
+
});
|
|
3635
|
+
for (const key of findMissingSymbols(row.source.surface(), row.source.exports())) findings.push({
|
|
3636
|
+
spec: row.entry.spec,
|
|
3637
|
+
text: `${row.entry.spec} barrel exposes no direct ${key}.`
|
|
3638
|
+
});
|
|
3639
|
+
for (const key of findMissingSymbols(row.source.surface(), row.guide.surface())) findings.push({
|
|
3640
|
+
spec: row.entry.spec,
|
|
3641
|
+
text: `${row.entry.spec} does not document ${key}.`
|
|
3642
|
+
});
|
|
3643
|
+
for (const key of findMissingSymbols(row.guide.surface(), row.source.surface())) findings.push({
|
|
3644
|
+
spec: row.entry.spec,
|
|
3645
|
+
text: `${row.entry.spec} documents no barrel ${key}.`
|
|
3646
|
+
});
|
|
3647
|
+
for (const symbol of row.source.hidden()) findings.push({
|
|
3648
|
+
spec: row.entry.spec,
|
|
3649
|
+
text: `${row.entry.spec} source hides ${computeSymbolKey(symbol)}.`
|
|
3650
|
+
});
|
|
3651
|
+
}
|
|
3652
|
+
#inspectMethods(row, findings) {
|
|
3653
|
+
for (const group of row.guide.methods()) {
|
|
3654
|
+
const documented = group.methods.map((entry) => entry.name);
|
|
3655
|
+
const declared = row.source.methods(group.interface).map((entry) => entry.name);
|
|
3656
|
+
if (documented.length === 0) findings.push({
|
|
3657
|
+
spec: row.entry.spec,
|
|
3658
|
+
text: `${row.entry.spec} ${group.interface} has no documented methods.`
|
|
3659
|
+
});
|
|
3660
|
+
for (const name of findMissing(declared, documented)) findings.push({
|
|
3661
|
+
spec: row.entry.spec,
|
|
3662
|
+
text: `${row.entry.spec} does not document ${group.interface}.${name}.`
|
|
3663
|
+
});
|
|
3664
|
+
for (const name of findMissing(documented, declared)) findings.push({
|
|
3665
|
+
spec: row.entry.spec,
|
|
3666
|
+
text: `${row.entry.spec} documents no source ${group.interface}.${name}.`
|
|
3667
|
+
});
|
|
3668
|
+
const entity = group.interface.replace(/Interface$/, "");
|
|
3669
|
+
if (entity === group.interface) continue;
|
|
3670
|
+
for (const name of findMissing(row.source.methods(entity).map((entry) => entry.name), documented)) findings.push({
|
|
3671
|
+
spec: row.entry.spec,
|
|
3672
|
+
text: `${row.entry.spec} ${entity}.${name} is outside the ${group.interface} contract.`
|
|
3673
|
+
});
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3676
|
+
#inspectDeclarations(row, findings) {
|
|
3677
|
+
const groups = row.guide.methods();
|
|
3678
|
+
const documented = groups.map((group) => group.interface);
|
|
3679
|
+
const declared = new Set(row.source.surface().map((symbol) => symbol.name));
|
|
3680
|
+
for (const group of groups) {
|
|
3681
|
+
const finding = compareMembership(row.entry.spec, group.interface, group.methods.map((entry) => entry.name), row.source.methods(group.interface).map((entry) => entry.name));
|
|
3682
|
+
if (finding !== void 0) findings.push(finding);
|
|
3683
|
+
}
|
|
3684
|
+
for (const symbol of row.source.surface()) {
|
|
3685
|
+
if (symbol.keyword !== "interface" && symbol.keyword !== "class") continue;
|
|
3686
|
+
const members = row.source.methods(symbol.name).map((entry) => entry.name);
|
|
3687
|
+
if (members.length === 0) continue;
|
|
3688
|
+
const contract = `${symbol.name}Interface`;
|
|
3689
|
+
if (symbol.keyword === "class" && declared.has(contract)) {
|
|
3690
|
+
const finding = compareMembership(row.entry.spec, symbol.name, row.source.methods(contract).map((entry) => entry.name), members);
|
|
3691
|
+
if (finding !== void 0) findings.push(finding);
|
|
3692
|
+
continue;
|
|
3693
|
+
}
|
|
3694
|
+
if (documented.includes(symbol.name)) continue;
|
|
3695
|
+
findings.push({
|
|
3696
|
+
spec: row.entry.spec,
|
|
3697
|
+
text: `${row.entry.spec} ${symbol.name} declares members and carries no method table.`
|
|
3698
|
+
});
|
|
3699
|
+
}
|
|
3700
|
+
}
|
|
3701
|
+
#inspectLinks(row, links, tests) {
|
|
3702
|
+
if (row.guide.links().length === 0) links.push({
|
|
3703
|
+
spec: row.entry.spec,
|
|
3704
|
+
text: `${row.entry.spec} has no links.`
|
|
3705
|
+
});
|
|
3706
|
+
for (const href of row.guide.links()) {
|
|
3707
|
+
if (isExternalLink(href)) continue;
|
|
3708
|
+
const path = resolveLink(row.entry.spec, href);
|
|
3709
|
+
if (row.source.exists(path)) continue;
|
|
3710
|
+
links.push({
|
|
3711
|
+
spec: row.entry.spec,
|
|
3712
|
+
text: `${row.entry.spec} has a broken link: ${href}.`
|
|
3713
|
+
});
|
|
3714
|
+
}
|
|
3715
|
+
if (row.guide.tests().length === 0) tests.push({
|
|
3716
|
+
spec: row.entry.spec,
|
|
3717
|
+
text: `${row.entry.spec} has no test links.`
|
|
3718
|
+
});
|
|
3719
|
+
for (const href of row.guide.tests()) {
|
|
3720
|
+
const path = resolveLink(row.entry.spec, href);
|
|
3721
|
+
if (row.source.exists(path)) continue;
|
|
3722
|
+
tests.push({
|
|
3723
|
+
spec: row.entry.spec,
|
|
3724
|
+
text: `${row.entry.spec} has a missing test: ${href}.`
|
|
3725
|
+
});
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3728
|
+
#inspectFences(row, findings) {
|
|
3729
|
+
for (const fence of findUnlisted(row.guide.fences(), this.#options.languages)) findings.push({
|
|
3730
|
+
spec: row.entry.spec,
|
|
3731
|
+
text: `${row.entry.spec} has an unlisted fence language under ${fence.title ?? "no heading"}: ${fence.language ?? "absent"}.`
|
|
3732
|
+
});
|
|
3733
|
+
}
|
|
3734
|
+
#inspectExamples(row, fencesFindings, functionFindings, methodFindings, titleFindings) {
|
|
3735
|
+
const fences = row.guide.fences().filter((fence) => fence.language === this.#options.language).map((fence) => fence.code);
|
|
3736
|
+
if (fences.length === 0) fencesFindings.push({
|
|
3737
|
+
spec: row.entry.spec,
|
|
3738
|
+
text: `${row.entry.spec} has no ${this.#options.language} example fence.`
|
|
3739
|
+
});
|
|
3740
|
+
const functions = row.guide.surface().filter((symbol) => symbol.keyword === "function").map((symbol) => symbol.name);
|
|
3741
|
+
for (const name of findUnexampled(functions, fences, row.source.examples().map((example) => example.name))) functionFindings.push({
|
|
3742
|
+
spec: row.entry.spec,
|
|
3743
|
+
text: `${row.entry.spec} has no example for ${name}.`
|
|
3744
|
+
});
|
|
3745
|
+
for (const group of row.guide.methods()) {
|
|
3746
|
+
const entity = group.interface.replace(/Interface$/, "");
|
|
3747
|
+
const examples = row.source.examples(group.interface).map((example) => example.name);
|
|
3748
|
+
if (entity !== group.interface) examples.push(...row.source.examples(entity).map((example) => example.name));
|
|
3749
|
+
for (const name of findUnexampled(group.methods.map((entry) => entry.name), fences, examples)) methodFindings.push({
|
|
3750
|
+
spec: row.entry.spec,
|
|
3751
|
+
text: `${row.entry.spec} has no example for ${group.interface}.${name}.`
|
|
3752
|
+
});
|
|
3753
|
+
}
|
|
3754
|
+
const guide = row.guide.fences().map((fence) => fence.title).filter(isNonEmptyString);
|
|
3755
|
+
const source = row.source.examples().map((example) => example.title).filter(isNonEmptyString);
|
|
3756
|
+
if (!guide.some((title) => source.includes(title))) titleFindings.push({
|
|
3757
|
+
spec: row.entry.spec,
|
|
3758
|
+
text: `${row.entry.spec} has no top-level example-title pair: guide ${JSON.stringify(guide)} source ${JSON.stringify(source)}.`
|
|
3759
|
+
});
|
|
3760
|
+
}
|
|
3761
|
+
#inspectImports(row, findings) {
|
|
3762
|
+
const sources = new SourceManager({
|
|
3763
|
+
files: this.#options.files,
|
|
3764
|
+
modules: this.#options.modules
|
|
3765
|
+
});
|
|
3766
|
+
let compared = false;
|
|
3767
|
+
for (const fence of row.guide.fences()) {
|
|
3768
|
+
if (fence.language !== this.#options.language) continue;
|
|
3769
|
+
for (const imported of extractFenceImports(fence.code)) {
|
|
3770
|
+
const source = sources.source(imported.specifier);
|
|
3771
|
+
if (source === void 0) continue;
|
|
3772
|
+
compared = true;
|
|
3773
|
+
const surface = source.surface().map((symbol) => symbol.name);
|
|
3774
|
+
for (const name of findMissing(imported.names, surface)) findings.push({
|
|
3775
|
+
spec: row.entry.spec,
|
|
3776
|
+
text: `${row.entry.spec} imports missing ${name} from ${imported.specifier}.`
|
|
3777
|
+
});
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
if (!compared) findings.push({
|
|
3781
|
+
spec: row.entry.spec,
|
|
3782
|
+
text: `${row.entry.spec} has no mapped self import.`
|
|
3783
|
+
});
|
|
3784
|
+
}
|
|
3785
|
+
#inspectDrift(row, findings) {
|
|
3786
|
+
for (const drift of findDrift(row.guide, row.source)) findings.push({
|
|
3787
|
+
spec: row.entry.spec,
|
|
3788
|
+
text: formatDrift(drift)
|
|
3789
|
+
});
|
|
3790
|
+
}
|
|
3791
|
+
#inspectPitch(findings) {
|
|
3792
|
+
const pitch = this.#options.pitch;
|
|
3793
|
+
if (pitch === void 0) return;
|
|
3794
|
+
const readme = this.#options.files[pitch.readme];
|
|
3795
|
+
const spec = this.#options.files[pitch.spec];
|
|
3796
|
+
if (readme === void 0) {
|
|
3797
|
+
findings.push({
|
|
3798
|
+
spec: pitch.readme,
|
|
3799
|
+
text: `${pitch.readme} is absent from the inventory.`
|
|
3800
|
+
});
|
|
3801
|
+
return;
|
|
3802
|
+
}
|
|
3803
|
+
if (spec === void 0) {
|
|
3804
|
+
findings.push({
|
|
3805
|
+
spec: pitch.spec,
|
|
3806
|
+
text: `${pitch.spec} is absent from the inventory.`
|
|
3807
|
+
});
|
|
3808
|
+
return;
|
|
3809
|
+
}
|
|
3810
|
+
const left = new Guide(readme).tagline();
|
|
3811
|
+
const right = new Guide(spec).tagline();
|
|
3812
|
+
if (left !== void 0 && left === right) return;
|
|
3813
|
+
findings.push({
|
|
3814
|
+
spec: pitch.spec,
|
|
3815
|
+
text: `${pitch.spec} pitch: README ${formatSide(left)} guide ${formatSide(right)}.`
|
|
3816
|
+
});
|
|
3817
|
+
}
|
|
3818
|
+
#rewriteGuide(row, drift, files) {
|
|
3819
|
+
if (drift.source === void 0) return "source authority is absent";
|
|
3820
|
+
const current = files.get(row.entry.spec);
|
|
3821
|
+
if (current === void 0) return "the guide inventory text is absent";
|
|
3822
|
+
if (drift.category === "summary") {
|
|
3823
|
+
const replacement = replaceCell(current, drift.key, drift.source);
|
|
3824
|
+
if (replacement === void 0) return "the guide summary cell or its provenance is unavailable";
|
|
3825
|
+
files.set(row.entry.spec, replacement);
|
|
3826
|
+
return;
|
|
3827
|
+
}
|
|
3828
|
+
const example = collectTitles(row.guide, row.source).get(drift.key);
|
|
3829
|
+
if (example === void 0) return "the paired source example is unavailable";
|
|
3830
|
+
const replacement = replaceFence(current, drift.key, example);
|
|
3831
|
+
if (replacement === void 0) return "the titled guide fence or its provenance is unavailable";
|
|
3832
|
+
files.set(row.entry.spec, replacement);
|
|
3833
|
+
}
|
|
3834
|
+
#rewriteSource(row, drift, files) {
|
|
3835
|
+
if (drift.guide === void 0) return "guide authority is absent";
|
|
3836
|
+
if (drift.category === "summary") {
|
|
3837
|
+
const located = this.#locateSource(row.entry, drift.key, files);
|
|
3838
|
+
if (located === void 0) return "the source doc block or its provenance is unavailable";
|
|
3839
|
+
const replacement = replaceSummary(located.text.slice(located.span.start, located.span.end), drift.guide);
|
|
3840
|
+
if (replacement === void 0) return "the source summary cannot be represented safely";
|
|
3841
|
+
files.set(located.path, spliceSpan(located.text, located.span, replacement));
|
|
3842
|
+
return;
|
|
3843
|
+
}
|
|
3844
|
+
const fence = row.guide.fences().find((entry) => entry.title === drift.key);
|
|
3845
|
+
const located = this.#locateExample(row, drift.key, files);
|
|
3846
|
+
if (fence === void 0 || located === void 0) return "the paired source example or its provenance is unavailable";
|
|
3847
|
+
const replacement = replaceExample(located.text.slice(located.span.start, located.span.end), {
|
|
3848
|
+
name: located.example.name,
|
|
3849
|
+
title: drift.key,
|
|
3850
|
+
code: fence.code,
|
|
3851
|
+
...fence.language === void 0 ? {} : { language: fence.language }
|
|
3852
|
+
});
|
|
3853
|
+
if (replacement === void 0) return "the guide example cannot be represented safely";
|
|
3854
|
+
files.set(located.path, spliceSpan(located.text, located.span, replacement));
|
|
3855
|
+
}
|
|
3856
|
+
#locateSource(entry, key, files) {
|
|
3857
|
+
const inventory = Object.fromEntries(files);
|
|
3858
|
+
for (const path of selectModuleKeys(inventory, normalizeDirectories(entry.source))) {
|
|
3859
|
+
const text = files.get(path);
|
|
3860
|
+
if (text === void 0) continue;
|
|
3861
|
+
const span = locateComment(text, key);
|
|
3862
|
+
if (span !== void 0) return {
|
|
3863
|
+
path,
|
|
3864
|
+
text,
|
|
3865
|
+
span
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
}
|
|
3869
|
+
#locateExample(row, title, files) {
|
|
3870
|
+
const target = collectTitles(row.guide, row.source).get(title);
|
|
3871
|
+
if (target === void 0) return void 0;
|
|
3872
|
+
const keys = [];
|
|
3873
|
+
for (const symbol of row.source.exports()) if (symbol.name === target.name) keys.push(computeSymbolKey(symbol));
|
|
3874
|
+
for (const owner of row.guide.surface()) {
|
|
3875
|
+
if (owner.keyword !== "class" && owner.keyword !== "interface") continue;
|
|
3876
|
+
if (row.source.examples(owner.name).some((example) => example.name === target.name && example.title === title)) keys.push(`${owner.name}.${target.name}`);
|
|
3877
|
+
}
|
|
3878
|
+
const inventory = Object.fromEntries(files);
|
|
3879
|
+
for (const path of selectModuleKeys(inventory, normalizeDirectories(row.entry.source))) {
|
|
3880
|
+
const text = files.get(path);
|
|
3881
|
+
if (text === void 0) continue;
|
|
3882
|
+
let selected;
|
|
3883
|
+
for (const key of keys) {
|
|
3884
|
+
const span = locateComment(text, key);
|
|
3885
|
+
if (span === void 0) continue;
|
|
3886
|
+
const example = collectExamples(normalizeComment(text.slice(span.start, span.end)), target.name).find((entry) => entry.title === title);
|
|
3887
|
+
if (example === void 0) continue;
|
|
3888
|
+
if (selected === void 0 || span.start < selected.span.start) selected = {
|
|
3889
|
+
span,
|
|
3890
|
+
example
|
|
3891
|
+
};
|
|
3892
|
+
}
|
|
3893
|
+
if (selected !== void 0) return {
|
|
3894
|
+
path,
|
|
3895
|
+
text,
|
|
3896
|
+
...selected
|
|
3897
|
+
};
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
};
|
|
3901
|
+
//#endregion
|
|
1890
3902
|
//#region src/core/factories.ts
|
|
1891
3903
|
/**
|
|
1892
3904
|
* Creates a structured {@link GuideInterface} view over one guide's markdown
|
|
@@ -1896,12 +3908,13 @@ var SourceManager = class {
|
|
|
1896
3908
|
* @param source - The guide's markdown source text
|
|
1897
3909
|
* @returns A working {@link GuideInterface}
|
|
1898
3910
|
*
|
|
1899
|
-
* @example
|
|
3911
|
+
* @example Construct a Guide from markdown text
|
|
1900
3912
|
* ```ts
|
|
1901
3913
|
* import { createGuide } from '@orkestrel/guide'
|
|
1902
3914
|
*
|
|
1903
3915
|
* const guide = createGuide('## Surface\n\n| Name | Kind |\n| --- | --- |\n| `X` | class |')
|
|
1904
3916
|
* guide.surface() // [{ name: 'X', keyword: 'class' }]
|
|
3917
|
+
* guide.sections() // ['Surface']
|
|
1905
3918
|
* ```
|
|
1906
3919
|
*/
|
|
1907
3920
|
function createGuide(source) {
|
|
@@ -1914,15 +3927,23 @@ function createGuide(source) {
|
|
|
1914
3927
|
* @param options - The file inventory and module scope to reflect
|
|
1915
3928
|
* @returns A `SourceInterface` reflecting the given module scope
|
|
1916
3929
|
*
|
|
1917
|
-
* @example
|
|
3930
|
+
* @example Construct a Source from an inline files record
|
|
1918
3931
|
* ```ts
|
|
1919
3932
|
* import { createSource } from '@orkestrel/guide'
|
|
1920
3933
|
*
|
|
1921
3934
|
* const source = createSource({
|
|
1922
|
-
* files: {
|
|
3935
|
+
* files: {
|
|
3936
|
+
* 'src/core/index.ts': "export * from './Guide.js'\nexport * from './types.js'\n",
|
|
3937
|
+
* 'src/core/Guide.ts': 'export class Guide {}\n',
|
|
3938
|
+
* 'src/core/types.ts': 'export interface GuideInterface {\n\tsections(): void\n}\n',
|
|
3939
|
+
* },
|
|
1923
3940
|
* module: 'src/core',
|
|
1924
3941
|
* })
|
|
1925
|
-
* source.exports() // [{ name: 'Guide', keyword: 'class' }]
|
|
3942
|
+
* source.exports() // [{ name: 'Guide', keyword: 'class' }, { name: 'GuideInterface', keyword: 'interface' }]
|
|
3943
|
+
* source.surface() // [{ name: 'Guide', keyword: 'class' }, { name: 'GuideInterface', keyword: 'interface' }]
|
|
3944
|
+
* source.methods('GuideInterface') // [{ name: 'sections' }]
|
|
3945
|
+
* source.exists('src/core/Guide.ts') // true
|
|
3946
|
+
* source.exists('src/core') // true — a directory any inventory key sits beneath
|
|
1926
3947
|
* ```
|
|
1927
3948
|
*/
|
|
1928
3949
|
function createSource(options) {
|
|
@@ -1935,15 +3956,22 @@ function createSource(options) {
|
|
|
1935
3956
|
* @param options - The shared file inventory and specifier-to-module policy
|
|
1936
3957
|
* @returns A source manager over the supplied policy
|
|
1937
3958
|
*
|
|
1938
|
-
* @example
|
|
3959
|
+
* @example Resolve a fence's import specifier to the right Source
|
|
1939
3960
|
* ```ts
|
|
1940
3961
|
* import { createSourceManager } from '@orkestrel/guide'
|
|
1941
3962
|
*
|
|
1942
3963
|
* const sources = createSourceManager({
|
|
1943
|
-
* files: {
|
|
1944
|
-
*
|
|
3964
|
+
* files: {
|
|
3965
|
+
* 'src/core/index.ts': "export * from './Guide.js'\n",
|
|
3966
|
+
* 'src/core/Guide.ts': 'export class Guide {}\n',
|
|
3967
|
+
* },
|
|
3968
|
+
* modules: { '@scope/package': 'src/core', '@scope/package/core': 'src/core' },
|
|
1945
3969
|
* })
|
|
1946
|
-
*
|
|
3970
|
+
*
|
|
3971
|
+
* sources.source('@scope/package')?.surface() // [{ name: 'Guide', keyword: 'class' }]
|
|
3972
|
+
* sources.source('node:fs') // undefined — a foreign import, which a fence check skips
|
|
3973
|
+
* sources.source('@scope/package') === sources.source('@scope/package/core') // true
|
|
3974
|
+
* sources.sources() // [the one shared view both specifiers name]
|
|
1947
3975
|
* ```
|
|
1948
3976
|
*/
|
|
1949
3977
|
function createSourceManager(options) {
|
|
@@ -1968,6 +3996,60 @@ function createSurfaceSymbolContract() {
|
|
|
1968
3996
|
return createContract(surfaceSymbolShape);
|
|
1969
3997
|
}
|
|
1970
3998
|
/**
|
|
3999
|
+
* Compiles the {@link methodEntryShape} into a {@link ContractInterface} for
|
|
4000
|
+
* {@link MethodEntry} — a guard, coercing parser, JSON Schema, and seeded
|
|
4001
|
+
* generator from one shape declaration (AGENTS.md § Design laws).
|
|
4002
|
+
*
|
|
4003
|
+
* @returns A `MethodEntry` contract bundling `schema` / `is` / `parse` / `generate`
|
|
4004
|
+
*
|
|
4005
|
+
* @example
|
|
4006
|
+
* ```ts
|
|
4007
|
+
* import { createMethodEntryContract } from '@orkestrel/guide'
|
|
4008
|
+
*
|
|
4009
|
+
* const methodEntry = createMethodEntryContract()
|
|
4010
|
+
* methodEntry.is({ name: 'walk' }) // true
|
|
4011
|
+
* ```
|
|
4012
|
+
*/
|
|
4013
|
+
function createMethodEntryContract() {
|
|
4014
|
+
return createContract(methodEntryShape);
|
|
4015
|
+
}
|
|
4016
|
+
/**
|
|
4017
|
+
* Compiles the {@link sourceExampleShape} into a {@link ContractInterface} for
|
|
4018
|
+
* {@link SourceExample} — a guard, coercing parser, JSON Schema, and seeded
|
|
4019
|
+
* generator from one shape declaration (AGENTS.md § Design laws).
|
|
4020
|
+
*
|
|
4021
|
+
* @returns A `SourceExample` contract bundling `schema` / `is` / `parse` / `generate`
|
|
4022
|
+
*
|
|
4023
|
+
* @example
|
|
4024
|
+
* ```ts
|
|
4025
|
+
* import { createSourceExampleContract } from '@orkestrel/guide'
|
|
4026
|
+
*
|
|
4027
|
+
* const sourceExample = createSourceExampleContract()
|
|
4028
|
+
* sourceExample.is({ name: 'walk', code: 'walk()' }) // true
|
|
4029
|
+
* ```
|
|
4030
|
+
*/
|
|
4031
|
+
function createSourceExampleContract() {
|
|
4032
|
+
return createContract(sourceExampleShape);
|
|
4033
|
+
}
|
|
4034
|
+
/**
|
|
4035
|
+
* Compiles the {@link driftShape} into a {@link ContractInterface} for
|
|
4036
|
+
* {@link Drift} — a guard, coercing parser, JSON Schema, and seeded
|
|
4037
|
+
* generator from one shape declaration (AGENTS.md § Design laws).
|
|
4038
|
+
*
|
|
4039
|
+
* @returns A `Drift` contract bundling `schema` / `is` / `parse` / `generate`
|
|
4040
|
+
*
|
|
4041
|
+
* @example
|
|
4042
|
+
* ```ts
|
|
4043
|
+
* import { createDriftContract } from '@orkestrel/guide'
|
|
4044
|
+
*
|
|
4045
|
+
* const drift = createDriftContract()
|
|
4046
|
+
* drift.is({ key: 'class Widget', category: 'summary', guide: 'A widget.' }) // true
|
|
4047
|
+
* ```
|
|
4048
|
+
*/
|
|
4049
|
+
function createDriftContract() {
|
|
4050
|
+
return createContract(driftShape);
|
|
4051
|
+
}
|
|
4052
|
+
/**
|
|
1971
4053
|
* Compiles the {@link methodGroupShape} into a {@link ContractInterface} for
|
|
1972
4054
|
* {@link MethodGroup} — a guard, coercing parser, JSON Schema, and seeded
|
|
1973
4055
|
* generator from one shape declaration (AGENTS.md § Design laws).
|
|
@@ -1979,7 +4061,7 @@ function createSurfaceSymbolContract() {
|
|
|
1979
4061
|
* import { createMethodGroupContract } from '@orkestrel/guide'
|
|
1980
4062
|
*
|
|
1981
4063
|
* const methodGroup = createMethodGroupContract()
|
|
1982
|
-
* methodGroup.is({ interface: 'MarkdownInterface', methods: ['walk'] }) // true
|
|
4064
|
+
* methodGroup.is({ interface: 'MarkdownInterface', methods: [{ name: 'walk' }] }) // true
|
|
1983
4065
|
* ```
|
|
1984
4066
|
*/
|
|
1985
4067
|
function createMethodGroupContract() {
|
|
@@ -2004,6 +4086,6 @@ function createManifestEntryContract() {
|
|
|
2004
4086
|
return createContract(manifestEntryShape);
|
|
2005
4087
|
}
|
|
2006
4088
|
//#endregion
|
|
2007
|
-
export { EXPORT_KEYWORDS, EXTERNAL_SCHEMES, Guide, MANIFEST, METHODS, SURFACE, Source, SourceManager, TESTS, computeModuleKey, computeSymbolKey, createGuide, createManifestEntryContract, createMethodGroupContract, createSource, createSourceManager, createSurfaceSymbolContract, escapeRegExp, extractCellLinks, extractDeclaration, extractExampleLines, extractExampleMethods, extractExamples, extractExports, extractFenceImports, extractFences, extractHidden, extractLinks, extractMemberMethods, extractMethods, extractSourceLines, extractSurface, extractTests,
|
|
4089
|
+
export { DRIFT_CATEGORIES, EXPORT_KEYWORDS, EXTERNAL_SCHEMES, Guide, KIND, MANIFEST, METHODS, Parity, SUMMARY, SURFACE, Source, SourceManager, TESTS, WRAP_WIDTH, buildCell, buildComment, buildFence, buildTable, collectDeclarations, collectExamples, collectFences, collectGroups, collectKeys, collectSummaries, collectTitles, compareMembership, computeDrift, computeModuleKey, computeSymbolKey, createDriftContract, createGuide, createManifestEntryContract, createMethodEntryContract, createMethodGroupContract, createSource, createSourceExampleContract, createSourceManager, createSurfaceSymbolContract, driftShape, escapeRegExp, extractBodyLines, extractCellLinks, extractCellText, extractDeclaration, extractExampleLines, extractExampleMethods, extractExamples, extractExports, extractFenceImports, extractFences, extractHidden, extractLinks, extractMemberMethods, extractMethods, extractRowEntry, extractRowSummary, extractRowSymbol, extractSourceComments, extractSourceLines, extractSurface, extractTagline, extractTests, extractUnnamed, findColumnIndex, findDrift, findFirstCode, findMissing, findMissingSymbols, findUnexampled, findUnlisted, formatDrift, formatSide, hasCanonicalSegments, identifyDrift, isDrift, isDriftCategory, isExportKeyword, isExternalLink, isManifestEntry, isMethodEntry, isMethodGroup, isSourceExample, isSurfaceSymbol, joinHead, locateComment, manifestEntryShape, maskFences, methodEntryShape, methodGroupShape, normalizeComment, normalizeDirectories, normalizeIdentifier, normalizeSummary, parseManifest, renderExample, renderMethods, renderSurface, replaceCell, replaceExample, replaceFence, replaceSummary, resolveLink, resolvePath, selectModuleKeys, selectSectionBlocks, sourceExampleShape, spliceSpan, surfaceSymbolShape, unwrapComment, wrapText };
|
|
2008
4090
|
|
|
2009
4091
|
//# sourceMappingURL=index.js.map
|