@orkestrel/guide 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/index.cjs +1297 -765
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +2796 -2498
- package/dist/src/core/index.d.ts +2796 -2498
- package/dist/src/core/index.js +1283 -766
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +227 -15
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +122 -0
- package/dist/src/server/index.d.ts +122 -0
- package/dist/src/server/index.js +223 -17
- package/dist/src/server/index.js.map +1 -1
- package/package.json +14 -14
package/dist/src/core/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { INTRINSICS, arrayOf, arrayShape, createContract, holds, isBoundedJSONRecord, isEmptyString, isNonEmptyArray, isNonEmptyString, isString, literalOf, literalShape, objectShape, optionalShape, recordOf, stringShape, unionOf, unionShape } from "@orkestrel/contract";
|
|
1
2
|
import { coalesceText, createMarkdown, flattenText, isBlockquoteNode, isCodeBlockNode, isCodeSpanNode, isEmphasisNode, isHeadingNode, isImageNode, isLinkNode, isParagraphNode, isTableNode, renderMarkdown, walkNodes } from "@orkestrel/markdown";
|
|
2
|
-
|
|
3
|
-
//#region src/core/constants.ts
|
|
3
|
+
// src/core/constants.ts
|
|
4
4
|
/**
|
|
5
5
|
* Lists the declaration keywords a documented or exported symbol carries, in the order the
|
|
6
6
|
* reflection grammar names them — the frozen population `ExportKeyword`, `isExportKeyword`, and
|
|
@@ -21,12 +21,32 @@ var EXPORT_KEYWORDS = Object.freeze([
|
|
|
21
21
|
/**
|
|
22
22
|
* Lists the compared sites a {@link Drift} can describe.
|
|
23
23
|
*/
|
|
24
|
-
var DRIFT_CATEGORIES = Object.freeze([
|
|
24
|
+
var DRIFT_CATEGORIES = Object.freeze([
|
|
25
|
+
"summary",
|
|
26
|
+
"signature",
|
|
27
|
+
"example"
|
|
28
|
+
]);
|
|
25
29
|
/**
|
|
26
30
|
* Names the `## Surface` heading text a guide's documented exports section is keyed on.
|
|
27
31
|
*/
|
|
28
32
|
var SURFACE = "Surface";
|
|
29
33
|
/**
|
|
34
|
+
* Lists the codes a {@link GuideError} carries: a refused Surface `header` or empty `signature`
|
|
35
|
+
* cell, a name two modules of one manifest entry declare (`collision`), and the compiler faults —
|
|
36
|
+
* a failed `compile`, an `empty` emit, a `timeout`, and an output `overflow`.
|
|
37
|
+
*/
|
|
38
|
+
var GUIDE_CODES = Object.freeze([
|
|
39
|
+
"header",
|
|
40
|
+
"signature",
|
|
41
|
+
"collision",
|
|
42
|
+
"compile",
|
|
43
|
+
"empty",
|
|
44
|
+
"timeout",
|
|
45
|
+
"overflow"
|
|
46
|
+
]);
|
|
47
|
+
/** Names the cross-copy identity marker of a Guide error. */
|
|
48
|
+
var GUIDE_ERROR_BRAND = Symbol.for("@orkestrel/guide.GuideError");
|
|
49
|
+
/**
|
|
30
50
|
* Names the `## Methods` heading text a guide's documented interface-methods section is keyed on.
|
|
31
51
|
*/
|
|
32
52
|
var METHODS = "Methods";
|
|
@@ -39,11 +59,28 @@ var TESTS = "Tests";
|
|
|
39
59
|
*/
|
|
40
60
|
var KIND = "Kind";
|
|
41
61
|
/**
|
|
62
|
+
* Names the header text of the column a `## Surface` table's TypeScript signature is read from.
|
|
63
|
+
*/
|
|
64
|
+
var SIGNATURE = "Signature";
|
|
65
|
+
/**
|
|
42
66
|
* Names the header text of the column a `## Surface` or `## Methods` table's compared
|
|
43
67
|
* description paragraph is read from.
|
|
44
68
|
*/
|
|
45
69
|
var SUMMARY = "Summary";
|
|
46
70
|
/**
|
|
71
|
+
* Names the header text of a `## Surface` or `## Methods` table's first column, the symbol name.
|
|
72
|
+
*/
|
|
73
|
+
var NAME = "Name";
|
|
74
|
+
/**
|
|
75
|
+
* Lists the uniform `## Surface` table header, column by column, that guide construction requires.
|
|
76
|
+
*/
|
|
77
|
+
var SURFACE_HEADER = Object.freeze([
|
|
78
|
+
NAME,
|
|
79
|
+
KIND,
|
|
80
|
+
SIGNATURE,
|
|
81
|
+
SUMMARY
|
|
82
|
+
]);
|
|
83
|
+
/**
|
|
47
84
|
* Names the `## By concept` heading text the manifest's run-map table is keyed on.
|
|
48
85
|
*/
|
|
49
86
|
var MANIFEST = "By concept";
|
|
@@ -73,8 +110,38 @@ var EXTERNAL_SCHEMES = Object.freeze([
|
|
|
73
110
|
"mailto:",
|
|
74
111
|
"tel:"
|
|
75
112
|
]);
|
|
76
|
-
|
|
77
|
-
|
|
113
|
+
// src/core/errors.ts
|
|
114
|
+
/** Carries a coded refusal of a guide, a manifest entry, or a module compile. */
|
|
115
|
+
var GuideError = class extends Error {
|
|
116
|
+
name = "GuideError";
|
|
117
|
+
code;
|
|
118
|
+
context;
|
|
119
|
+
constructor(message, code, options) {
|
|
120
|
+
super(message, options);
|
|
121
|
+
this.code = code;
|
|
122
|
+
this.context = options?.context;
|
|
123
|
+
INTRINSICS.define(this, GUIDE_ERROR_BRAND, { value: this });
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Checks whether a value carries the Guide error brand and declared members across package copies.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* isGuideError(new GuideError('Invalid Surface header', 'header')) // true
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
function isGuideError(value) {
|
|
135
|
+
return holds(() => {
|
|
136
|
+
if (!(value instanceof INTRINSICS.error)) return false;
|
|
137
|
+
if (INTRINSICS.prototype(value) === INTRINSICS.error.prototype) return false;
|
|
138
|
+
if (INTRINSICS.describe(value, GUIDE_ERROR_BRAND)?.value !== value) return false;
|
|
139
|
+
const code = INTRINSICS.reflect.read(value, "code");
|
|
140
|
+
const context = INTRINSICS.reflect.read(value, "context");
|
|
141
|
+
return GUIDE_CODES.some((candidate) => candidate === code) && (context === void 0 || isBoundedJSONRecord(context)) && typeof INTRINSICS.reflect.read(value, "name") === "string" && typeof INTRINSICS.reflect.read(value, "message") === "string";
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// src/core/validators.ts
|
|
78
145
|
/**
|
|
79
146
|
* Checks whether `value` is one of the documented {@link ExportKeyword}
|
|
80
147
|
* literals — the guard behind extracting a Surface table's `Kind` cell into a
|
|
@@ -94,7 +161,7 @@ var isExportKeyword = literalOf(EXPORT_KEYWORDS);
|
|
|
94
161
|
var isDriftCategory = literalOf(DRIFT_CATEGORIES);
|
|
95
162
|
/**
|
|
96
163
|
* Checks whether `value` is a well-formed {@link SurfaceSymbol} — a `name`
|
|
97
|
-
* string paired with a valid {@link ExportKeyword}, and
|
|
164
|
+
* string paired with a valid {@link ExportKeyword}, and optional `signature` and `summary` strings.
|
|
98
165
|
*
|
|
99
166
|
* @param value - The value to test
|
|
100
167
|
* @returns True if `value` is a well-formed {@link SurfaceSymbol}; false otherwise
|
|
@@ -108,8 +175,9 @@ var isDriftCategory = literalOf(DRIFT_CATEGORIES);
|
|
|
108
175
|
var isSurfaceSymbol = recordOf({
|
|
109
176
|
name: isString,
|
|
110
177
|
keyword: isExportKeyword,
|
|
178
|
+
signature: isString,
|
|
111
179
|
summary: isString
|
|
112
|
-
}, ["summary"]);
|
|
180
|
+
}, ["signature", "summary"]);
|
|
113
181
|
/**
|
|
114
182
|
* Checks whether `value` is a well-formed {@link MethodEntry} — a `name` string with an
|
|
115
183
|
* optional `summary`.
|
|
@@ -202,8 +270,7 @@ var isManifestEntry = recordOf({
|
|
|
202
270
|
source: unionOf(isString, arrayOf(isString)),
|
|
203
271
|
tests: isString
|
|
204
272
|
});
|
|
205
|
-
|
|
206
|
-
//#region src/core/helpers.ts
|
|
273
|
+
// src/core/helpers.ts
|
|
207
274
|
/**
|
|
208
275
|
* Extracts aligned physical source-line records in one character traversal.
|
|
209
276
|
* Real line and block comments and complete template tokens become spaces in
|
|
@@ -237,462 +304,468 @@ var isManifestEntry = recordOf({
|
|
|
237
304
|
*/
|
|
238
305
|
function extractSourceLines(source) {
|
|
239
306
|
const lines = [];
|
|
240
|
-
|
|
241
|
-
let jsdocCharacters = [];
|
|
307
|
+
const tokens = [];
|
|
242
308
|
const identifier = /#?[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*/uy;
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
let mode = "code";
|
|
247
|
-
let escaped = false;
|
|
248
|
-
let regexClass = false;
|
|
249
|
-
let operandExpected = true;
|
|
250
|
-
let memberExpected = false;
|
|
251
|
-
let pendingRole;
|
|
252
|
-
let restricted;
|
|
253
|
-
let separated = false;
|
|
254
|
-
let blockTemplate = false;
|
|
255
|
-
let lineTemplate = false;
|
|
256
|
-
let jsdoc = false;
|
|
257
|
-
let jsdocPresent = false;
|
|
258
|
-
for (let offset = 0; offset < source.length; offset += 1) {
|
|
259
|
-
const character = source[offset];
|
|
260
|
-
if (character === void 0) continue;
|
|
309
|
+
const numeric = /[A-Za-z0-9_$.]+/y;
|
|
310
|
+
const final = source.split("").reduce((state, character, offset) => {
|
|
311
|
+
if (offset < state.offset) return state;
|
|
261
312
|
const next = source[offset + 1];
|
|
262
313
|
const crlf = character === "\r" && next === "\n";
|
|
263
314
|
if (character === "\n" || crlf) {
|
|
264
|
-
const
|
|
265
|
-
const
|
|
315
|
+
const parts = tokens.slice(state.token);
|
|
316
|
+
const code = parts.map((part) => part.code).join("");
|
|
266
317
|
lines.push({
|
|
267
|
-
source: source.slice(start, offset),
|
|
318
|
+
source: source.slice(state.start, offset),
|
|
268
319
|
code,
|
|
269
|
-
jsdoc: present ?
|
|
320
|
+
jsdoc: state.present || state.jsdoc ? parts.map((part) => part.jsdoc ?? " ".repeat(part.code.length)).join("") : void 0
|
|
270
321
|
});
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
operandExpected = true;
|
|
291
|
-
regexClass = false;
|
|
292
|
-
} else if (mode === "single" || mode === "double") {
|
|
293
|
-
if (!escaped) {
|
|
294
|
-
mode = "code";
|
|
295
|
-
operandExpected = true;
|
|
296
|
-
}
|
|
297
|
-
} else if (mode === "templateSingle" || mode === "templateDouble") {
|
|
298
|
-
if (!escaped) {
|
|
299
|
-
mode = "templateCode";
|
|
300
|
-
operandExpected = true;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
escaped = false;
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
if (mode === "line" || mode === "templateLine") {
|
|
307
|
-
characters.push(" ");
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
if (mode === "block" || mode === "templateBlock") {
|
|
311
|
-
characters.push(" ");
|
|
312
|
-
if (jsdoc) jsdocCharacters.push(character);
|
|
313
|
-
if (character === "*" && next === "/") {
|
|
314
|
-
characters.push(" ");
|
|
315
|
-
if (jsdoc) {
|
|
316
|
-
jsdocCharacters.push("/");
|
|
317
|
-
jsdoc = false;
|
|
318
|
-
}
|
|
319
|
-
offset += 1;
|
|
320
|
-
mode = blockTemplate ? "templateCode" : "code";
|
|
321
|
-
}
|
|
322
|
-
continue;
|
|
322
|
+
const regular = state.mode === "single" || state.mode === "double";
|
|
323
|
+
const quoted = state.mode === "templateSingle" || state.mode === "templateDouble";
|
|
324
|
+
const reset = state.mode === "regex" || state.mode === "templateLine" || state.mode === "templateRegex";
|
|
325
|
+
const mode = state.mode === "line" ? state.line ? "templateCode" : "code" : state.mode === "regex" ? "code" : state.mode === "templateLine" || state.mode === "templateRegex" ? "templateCode" : regular && !state.escaped ? "code" : quoted && !state.escaped ? "templateCode" : state.mode;
|
|
326
|
+
return {
|
|
327
|
+
...state,
|
|
328
|
+
offset: offset + (crlf ? 2 : 1),
|
|
329
|
+
start: offset + (crlf ? 2 : 1),
|
|
330
|
+
token: tokens.length,
|
|
331
|
+
mode,
|
|
332
|
+
escaped: false,
|
|
333
|
+
regex: reset ? false : state.regex,
|
|
334
|
+
operand: state.restricted !== void 0 || reset || (regular || quoted) && !state.escaped ? true : state.operand,
|
|
335
|
+
member: state.restricted !== void 0 ? false : state.member,
|
|
336
|
+
role: state.restricted !== void 0 ? void 0 : state.role,
|
|
337
|
+
restricted: void 0,
|
|
338
|
+
separated: state.mode !== "template" ? true : state.separated,
|
|
339
|
+
present: state.jsdoc
|
|
340
|
+
};
|
|
323
341
|
}
|
|
324
|
-
if (mode === "
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
escaped = false;
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
if (character === "\\") {
|
|
331
|
-
escaped = true;
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
if (mode === "single" && character === "'" || mode === "double" && character === "\"") {
|
|
335
|
-
mode = "code";
|
|
336
|
-
operandExpected = false;
|
|
337
|
-
}
|
|
338
|
-
continue;
|
|
342
|
+
if (state.mode === "line" || state.mode === "templateLine") {
|
|
343
|
+
tokens.push({ code: " " });
|
|
344
|
+
return state;
|
|
339
345
|
}
|
|
340
|
-
if (mode === "
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
else if (character === "/" && !regexClass) {
|
|
353
|
-
mode = "code";
|
|
354
|
-
operandExpected = false;
|
|
355
|
-
}
|
|
356
|
-
continue;
|
|
346
|
+
if (state.mode === "block" || state.mode === "templateBlock") {
|
|
347
|
+
const closes = character === "*" && next === "/";
|
|
348
|
+
tokens.push({
|
|
349
|
+
code: closes ? " " : " ",
|
|
350
|
+
...state.jsdoc ? { jsdoc: closes ? "*/" : character } : {}
|
|
351
|
+
});
|
|
352
|
+
return closes ? {
|
|
353
|
+
...state,
|
|
354
|
+
offset: offset + 2,
|
|
355
|
+
jsdoc: false,
|
|
356
|
+
mode: state.block ? "templateCode" : "code"
|
|
357
|
+
} : state;
|
|
357
358
|
}
|
|
358
|
-
if (mode === "templateSingle" || mode === "templateDouble") {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
359
|
+
if (state.mode === "single" || state.mode === "double" || state.mode === "templateSingle" || state.mode === "templateDouble") {
|
|
360
|
+
const template = state.mode === "templateSingle" || state.mode === "templateDouble";
|
|
361
|
+
tokens.push({ code: template ? " " : character });
|
|
362
|
+
if (state.escaped) return {
|
|
363
|
+
...state,
|
|
364
|
+
escaped: false
|
|
365
|
+
};
|
|
366
|
+
if (character === "\\") return {
|
|
367
|
+
...state,
|
|
368
|
+
escaped: true
|
|
369
|
+
};
|
|
370
|
+
return (state.mode === "single" || state.mode === "templateSingle" ? character === "'" : character === "\"") ? {
|
|
371
|
+
...state,
|
|
372
|
+
mode: template ? "templateCode" : "code",
|
|
373
|
+
operand: false
|
|
374
|
+
} : state;
|
|
373
375
|
}
|
|
374
|
-
if (mode === "templateRegex") {
|
|
375
|
-
|
|
376
|
-
if (escaped) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
if (character === "\\") {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
if (character === "[")
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
376
|
+
if (state.mode === "regex" || state.mode === "templateRegex") {
|
|
377
|
+
tokens.push({ code: state.mode === "templateRegex" ? " " : character });
|
|
378
|
+
if (state.escaped) return {
|
|
379
|
+
...state,
|
|
380
|
+
escaped: false
|
|
381
|
+
};
|
|
382
|
+
if (character === "\\") return {
|
|
383
|
+
...state,
|
|
384
|
+
escaped: true
|
|
385
|
+
};
|
|
386
|
+
if (character === "[") return {
|
|
387
|
+
...state,
|
|
388
|
+
regex: true
|
|
389
|
+
};
|
|
390
|
+
if (character === "]") return {
|
|
391
|
+
...state,
|
|
392
|
+
regex: false
|
|
393
|
+
};
|
|
394
|
+
if (character === "/" && !state.regex) return {
|
|
395
|
+
...state,
|
|
396
|
+
mode: state.mode === "templateRegex" ? "templateCode" : "code",
|
|
397
|
+
operand: false
|
|
398
|
+
};
|
|
399
|
+
return state;
|
|
391
400
|
}
|
|
392
|
-
if (mode === "template") {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
401
|
+
if (state.mode === "template") {
|
|
402
|
+
const interpolation = !state.escaped && character === "$" && next === "{";
|
|
403
|
+
tokens.push({ code: interpolation ? " " : " " });
|
|
404
|
+
if (state.escaped) return {
|
|
405
|
+
...state,
|
|
406
|
+
escaped: false
|
|
407
|
+
};
|
|
408
|
+
if (character === "\\") return {
|
|
409
|
+
...state,
|
|
410
|
+
escaped: true
|
|
411
|
+
};
|
|
412
|
+
if (interpolation) return {
|
|
413
|
+
...state,
|
|
414
|
+
offset: offset + 2,
|
|
415
|
+
templates: state.templates === void 0 ? void 0 : {
|
|
416
|
+
...state.templates,
|
|
417
|
+
depth: 1
|
|
418
|
+
},
|
|
419
|
+
mode: "templateCode",
|
|
420
|
+
operand: true,
|
|
421
|
+
member: false,
|
|
422
|
+
role: void 0
|
|
423
|
+
};
|
|
413
424
|
if (character === "`") {
|
|
414
|
-
templates.
|
|
415
|
-
|
|
416
|
-
|
|
425
|
+
const templates = state.templates?.previous;
|
|
426
|
+
return {
|
|
427
|
+
...state,
|
|
428
|
+
templates,
|
|
429
|
+
mode: templates === void 0 ? "code" : "templateCode",
|
|
430
|
+
operand: false
|
|
431
|
+
};
|
|
417
432
|
}
|
|
418
|
-
|
|
433
|
+
return state;
|
|
419
434
|
}
|
|
420
|
-
const
|
|
435
|
+
const template = state.mode === "templateCode";
|
|
421
436
|
if (character === "/" && next === "/") {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
437
|
+
tokens.push({ code: " " });
|
|
438
|
+
return {
|
|
439
|
+
...state,
|
|
440
|
+
offset: offset + 2,
|
|
441
|
+
line: template,
|
|
442
|
+
mode: template ? "templateLine" : "line"
|
|
443
|
+
};
|
|
427
444
|
}
|
|
428
445
|
if (character === "/" && next === "*") {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (character === "'") {
|
|
443
|
-
characters.push(templateCode ? " " : character);
|
|
444
|
-
mode = templateCode ? "templateSingle" : "single";
|
|
445
|
-
escaped = false;
|
|
446
|
-
separated = false;
|
|
447
|
-
restricted = void 0;
|
|
448
|
-
continue;
|
|
449
|
-
}
|
|
450
|
-
if (character === "\"") {
|
|
451
|
-
characters.push(templateCode ? " " : character);
|
|
452
|
-
mode = templateCode ? "templateDouble" : "double";
|
|
453
|
-
escaped = false;
|
|
454
|
-
separated = false;
|
|
455
|
-
restricted = void 0;
|
|
456
|
-
continue;
|
|
446
|
+
const jsdoc = !template && source[offset + 2] === "*";
|
|
447
|
+
tokens.push({
|
|
448
|
+
code: " ",
|
|
449
|
+
...jsdoc ? { jsdoc: "/*" } : {}
|
|
450
|
+
});
|
|
451
|
+
return {
|
|
452
|
+
...state,
|
|
453
|
+
offset: offset + 2,
|
|
454
|
+
block: template,
|
|
455
|
+
mode: template ? "templateBlock" : "block",
|
|
456
|
+
jsdoc: jsdoc || state.jsdoc,
|
|
457
|
+
present: jsdoc || state.present
|
|
458
|
+
};
|
|
457
459
|
}
|
|
458
|
-
if (character === "`") {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
460
|
+
if (character === "'" || character === "\"" || character === "`") {
|
|
461
|
+
tokens.push({ code: template || character === "`" ? " " : character });
|
|
462
|
+
return {
|
|
463
|
+
...state,
|
|
464
|
+
mode: character === "`" ? "template" : character === "'" ? template ? "templateSingle" : "single" : template ? "templateDouble" : "double",
|
|
465
|
+
templates: character === "`" ? {
|
|
466
|
+
depth: 0,
|
|
467
|
+
previous: state.templates
|
|
468
|
+
} : state.templates,
|
|
469
|
+
escaped: false,
|
|
470
|
+
separated: false,
|
|
471
|
+
restricted: void 0
|
|
472
|
+
};
|
|
466
473
|
}
|
|
467
|
-
const visible =
|
|
468
|
-
if (character === "/" && next === "=" && !
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
474
|
+
const visible = template ? " " : character;
|
|
475
|
+
if (character === "/" && next === "=" && !state.operand) {
|
|
476
|
+
tokens.push({ code: template ? " " : "/=" });
|
|
477
|
+
return {
|
|
478
|
+
...state,
|
|
479
|
+
offset: offset + 2,
|
|
480
|
+
operand: true,
|
|
481
|
+
member: false,
|
|
482
|
+
role: void 0,
|
|
483
|
+
separated: false,
|
|
484
|
+
restricted: void 0
|
|
485
|
+
};
|
|
477
486
|
}
|
|
478
487
|
if (character === "/") {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
488
|
+
tokens.push({ code: visible });
|
|
489
|
+
return state.operand ? {
|
|
490
|
+
...state,
|
|
491
|
+
mode: template ? "templateRegex" : "regex",
|
|
492
|
+
escaped: false,
|
|
493
|
+
regex: false,
|
|
494
|
+
separated: false,
|
|
495
|
+
restricted: void 0
|
|
496
|
+
} : {
|
|
497
|
+
...state,
|
|
498
|
+
operand: true,
|
|
499
|
+
member: false,
|
|
500
|
+
role: void 0,
|
|
501
|
+
separated: false,
|
|
502
|
+
restricted: void 0
|
|
503
|
+
};
|
|
492
504
|
}
|
|
493
505
|
identifier.lastIndex = offset;
|
|
494
|
-
const
|
|
495
|
-
if (
|
|
496
|
-
const token =
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
506
|
+
const matched = identifier.exec(source);
|
|
507
|
+
if (matched !== null) {
|
|
508
|
+
const token = matched[0];
|
|
509
|
+
tokens.push({ code: template ? " ".repeat(token.length) : token });
|
|
510
|
+
const stepped = {
|
|
511
|
+
...state,
|
|
512
|
+
offset: offset + token.length,
|
|
513
|
+
restricted: void 0,
|
|
514
|
+
separated: false
|
|
515
|
+
};
|
|
516
|
+
const frame = state.parentheses;
|
|
517
|
+
if (token.startsWith("#")) return {
|
|
518
|
+
...stepped,
|
|
519
|
+
operand: false,
|
|
520
|
+
member: false,
|
|
521
|
+
role: void 0
|
|
522
|
+
};
|
|
523
|
+
if (state.member) return {
|
|
524
|
+
...stepped,
|
|
525
|
+
member: false,
|
|
526
|
+
operand: false,
|
|
527
|
+
role: void 0
|
|
528
|
+
};
|
|
529
|
+
if (state.restricted === "label") return {
|
|
530
|
+
...stepped,
|
|
531
|
+
operand: false,
|
|
532
|
+
role: void 0,
|
|
533
|
+
restricted: "complete"
|
|
534
|
+
};
|
|
535
|
+
if (/^(?:if|while|with)$/.test(token)) return {
|
|
536
|
+
...stepped,
|
|
537
|
+
role: "statement",
|
|
538
|
+
operand: true
|
|
539
|
+
};
|
|
540
|
+
if (token === "for") return {
|
|
541
|
+
...stepped,
|
|
542
|
+
role: "for",
|
|
543
|
+
operand: true
|
|
544
|
+
};
|
|
545
|
+
if (token === "export") return {
|
|
546
|
+
...stepped,
|
|
547
|
+
role: "export",
|
|
548
|
+
operand: true
|
|
549
|
+
};
|
|
550
|
+
if (token === "default" && state.role === "export") return {
|
|
551
|
+
...stepped,
|
|
552
|
+
role: void 0,
|
|
553
|
+
operand: true
|
|
554
|
+
};
|
|
555
|
+
if (/^(?:switch|catch)$/.test(token)) return {
|
|
556
|
+
...stepped,
|
|
557
|
+
role: "block",
|
|
558
|
+
operand: true
|
|
559
|
+
};
|
|
560
|
+
if (token === "await" && state.role === "for") return {
|
|
561
|
+
...stepped,
|
|
562
|
+
operand: true
|
|
563
|
+
};
|
|
564
|
+
if (/^(?:return|throw|case|delete|void|typeof|new|await|yield|else|do|extends|in|instanceof)$/.test(token)) return {
|
|
565
|
+
...stepped,
|
|
566
|
+
role: void 0,
|
|
567
|
+
operand: true
|
|
568
|
+
};
|
|
569
|
+
if (/^(?:break|continue)$/.test(token)) return {
|
|
570
|
+
...stepped,
|
|
571
|
+
role: void 0,
|
|
572
|
+
operand: false,
|
|
573
|
+
restricted: "label"
|
|
574
|
+
};
|
|
575
|
+
if (token === "debugger") return {
|
|
576
|
+
...stepped,
|
|
577
|
+
role: void 0,
|
|
578
|
+
operand: false,
|
|
579
|
+
restricted: "complete"
|
|
580
|
+
};
|
|
581
|
+
if (token === "of" && frame?.role === "for" && frame.phase === "left" && !frame.binding && !state.operand) return {
|
|
582
|
+
...stepped,
|
|
583
|
+
parentheses: {
|
|
584
|
+
...frame,
|
|
585
|
+
phase: "right"
|
|
586
|
+
},
|
|
587
|
+
operand: true,
|
|
588
|
+
role: void 0
|
|
589
|
+
};
|
|
590
|
+
if (/^(?:const|let|var)$/.test(token) && frame?.role === "for" && frame.phase === "left") return {
|
|
591
|
+
...stepped,
|
|
592
|
+
parentheses: {
|
|
593
|
+
...frame,
|
|
594
|
+
binding: true
|
|
595
|
+
},
|
|
596
|
+
operand: true,
|
|
597
|
+
role: void 0
|
|
598
|
+
};
|
|
599
|
+
return {
|
|
600
|
+
...stepped,
|
|
601
|
+
parentheses: frame?.binding === true ? {
|
|
602
|
+
...frame,
|
|
603
|
+
binding: false
|
|
604
|
+
} : frame,
|
|
605
|
+
operand: false,
|
|
606
|
+
role: void 0
|
|
607
|
+
};
|
|
564
608
|
}
|
|
565
609
|
if (/[0-9]/.test(character)) {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
separated = false;
|
|
579
|
-
offset = end - 1;
|
|
580
|
-
continue;
|
|
581
|
-
}
|
|
582
|
-
if (character === "!" && next === "=" && source[offset + 2] === "=" || character === "=" && next === "=" && source[offset + 2] === "=") {
|
|
583
|
-
characters.push(visible, templateCode ? " " : source.slice(offset + 1, offset + 3));
|
|
584
|
-
offset += 2;
|
|
585
|
-
operandExpected = true;
|
|
586
|
-
memberExpected = false;
|
|
587
|
-
pendingRole = void 0;
|
|
588
|
-
restricted = void 0;
|
|
589
|
-
separated = false;
|
|
590
|
-
continue;
|
|
610
|
+
numeric.lastIndex = offset;
|
|
611
|
+
const token = numeric.exec(source)?.[0] ?? character;
|
|
612
|
+
tokens.push({ code: template ? " ".repeat(token.length) : token });
|
|
613
|
+
return {
|
|
614
|
+
...state,
|
|
615
|
+
offset: offset + token.length,
|
|
616
|
+
operand: false,
|
|
617
|
+
member: false,
|
|
618
|
+
role: void 0,
|
|
619
|
+
restricted: void 0,
|
|
620
|
+
separated: false
|
|
621
|
+
};
|
|
591
622
|
}
|
|
592
623
|
if ((character === "!" || character === "=") && next === "=") {
|
|
593
|
-
|
|
594
|
-
offset
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
624
|
+
const width = source[offset + 2] === "=" ? 3 : 2;
|
|
625
|
+
tokens.push({ code: template ? " ".repeat(width) : source.slice(offset, offset + width) });
|
|
626
|
+
return {
|
|
627
|
+
...state,
|
|
628
|
+
offset: offset + width,
|
|
629
|
+
operand: true,
|
|
630
|
+
member: false,
|
|
631
|
+
role: void 0,
|
|
632
|
+
restricted: void 0,
|
|
633
|
+
separated: false
|
|
634
|
+
};
|
|
601
635
|
}
|
|
602
636
|
if (character === "+" && next === "+" || character === "-" && next === "-") {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
637
|
+
tokens.push({ code: template ? " " : character + next });
|
|
638
|
+
return {
|
|
639
|
+
...state,
|
|
640
|
+
offset: offset + 2,
|
|
641
|
+
operand: state.separated ? true : state.operand,
|
|
642
|
+
member: false,
|
|
643
|
+
role: void 0,
|
|
644
|
+
restricted: void 0,
|
|
645
|
+
separated: false
|
|
646
|
+
};
|
|
611
647
|
}
|
|
612
648
|
if (character === "." && next === "." && source[offset + 2] === ".") {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
649
|
+
tokens.push({ code: template ? " " : "..." });
|
|
650
|
+
return {
|
|
651
|
+
...state,
|
|
652
|
+
offset: offset + 3,
|
|
653
|
+
operand: true,
|
|
654
|
+
member: false,
|
|
655
|
+
role: void 0,
|
|
656
|
+
restricted: void 0,
|
|
657
|
+
separated: false
|
|
658
|
+
};
|
|
621
659
|
}
|
|
622
660
|
if (character === "?" && next === ".") {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
661
|
+
tokens.push({ code: template ? " " : "?." });
|
|
662
|
+
return {
|
|
663
|
+
...state,
|
|
664
|
+
offset: offset + 2,
|
|
665
|
+
operand: false,
|
|
666
|
+
member: true,
|
|
667
|
+
role: void 0,
|
|
668
|
+
restricted: void 0,
|
|
669
|
+
separated: false
|
|
670
|
+
};
|
|
631
671
|
}
|
|
632
|
-
|
|
633
|
-
if (/\s/.test(character))
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
672
|
+
tokens.push({ code: visible });
|
|
673
|
+
if (/\s/.test(character)) return state;
|
|
674
|
+
const stepped = {
|
|
675
|
+
...state,
|
|
676
|
+
separated: false,
|
|
677
|
+
restricted: void 0,
|
|
678
|
+
role: void 0,
|
|
679
|
+
member: false
|
|
680
|
+
};
|
|
681
|
+
const frame = state.parentheses;
|
|
682
|
+
if (character === "(") return {
|
|
683
|
+
...stepped,
|
|
684
|
+
parentheses: {
|
|
685
|
+
role: state.role ?? "plain",
|
|
639
686
|
phase: "left",
|
|
640
|
-
binding: false
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
687
|
+
binding: false,
|
|
688
|
+
previous: frame
|
|
689
|
+
},
|
|
690
|
+
operand: true
|
|
691
|
+
};
|
|
692
|
+
if (character === ")") return {
|
|
693
|
+
...stepped,
|
|
694
|
+
parentheses: frame?.previous,
|
|
695
|
+
operand: frame?.role === "statement" || frame?.role === "for"
|
|
696
|
+
};
|
|
697
|
+
if (character === ";") return {
|
|
698
|
+
...stepped,
|
|
699
|
+
parentheses: frame?.role === "for" && frame.phase === "left" ? {
|
|
700
|
+
...frame,
|
|
701
|
+
phase: "classic"
|
|
702
|
+
} : frame,
|
|
703
|
+
operand: true
|
|
704
|
+
};
|
|
705
|
+
if (character === ".") return {
|
|
706
|
+
...stepped,
|
|
707
|
+
operand: false,
|
|
708
|
+
member: true
|
|
709
|
+
};
|
|
710
|
+
const parentheses = (character === "]" || character === "}") && frame?.role === "for" && frame.phase === "left" && frame.binding ? {
|
|
711
|
+
...frame,
|
|
712
|
+
binding: false
|
|
713
|
+
} : frame;
|
|
714
|
+
if (character === "]") return {
|
|
715
|
+
...stepped,
|
|
716
|
+
parentheses,
|
|
717
|
+
operand: false
|
|
718
|
+
};
|
|
719
|
+
const top = state.templates;
|
|
720
|
+
if (character === "}") return {
|
|
721
|
+
...stepped,
|
|
722
|
+
parentheses,
|
|
723
|
+
operand: false,
|
|
724
|
+
templates: template && top !== void 0 ? {
|
|
725
|
+
...top,
|
|
726
|
+
depth: top.depth - 1
|
|
727
|
+
} : top,
|
|
728
|
+
mode: template && top?.depth === 1 ? "template" : state.mode
|
|
729
|
+
};
|
|
730
|
+
if (character === "{") return {
|
|
731
|
+
...stepped,
|
|
732
|
+
parentheses,
|
|
733
|
+
operand: true,
|
|
734
|
+
templates: template && top !== void 0 ? {
|
|
735
|
+
...top,
|
|
736
|
+
depth: top.depth + 1
|
|
737
|
+
} : top
|
|
738
|
+
};
|
|
739
|
+
return {
|
|
740
|
+
...stepped,
|
|
741
|
+
parentheses,
|
|
742
|
+
operand: character !== "!" ? true : state.operand
|
|
743
|
+
};
|
|
744
|
+
}, {
|
|
745
|
+
offset: 0,
|
|
746
|
+
start: 0,
|
|
747
|
+
token: 0,
|
|
748
|
+
mode: "code",
|
|
749
|
+
escaped: false,
|
|
750
|
+
regex: false,
|
|
751
|
+
operand: true,
|
|
752
|
+
member: false,
|
|
753
|
+
role: void 0,
|
|
754
|
+
restricted: void 0,
|
|
755
|
+
separated: false,
|
|
756
|
+
block: false,
|
|
757
|
+
line: false,
|
|
758
|
+
jsdoc: false,
|
|
759
|
+
present: false,
|
|
760
|
+
parentheses: void 0,
|
|
761
|
+
templates: void 0
|
|
762
|
+
});
|
|
763
|
+
const parts = tokens.slice(final.token);
|
|
764
|
+
const code = parts.map((part) => part.code).join("");
|
|
692
765
|
lines.push({
|
|
693
|
-
source: source.slice(start),
|
|
766
|
+
source: source.slice(final.start),
|
|
694
767
|
code,
|
|
695
|
-
jsdoc: present ?
|
|
768
|
+
jsdoc: final.present || final.jsdoc ? parts.map((part) => part.jsdoc ?? " ".repeat(part.code.length)).join("") : void 0
|
|
696
769
|
});
|
|
697
770
|
return lines;
|
|
698
771
|
}
|
|
@@ -844,7 +917,7 @@ function findUnlisted(fences, languages) {
|
|
|
844
917
|
*
|
|
845
918
|
* @example
|
|
846
919
|
* ```ts
|
|
847
|
-
* findMissingSymbols([{ name: 'X', keyword: 'class' }], []) // ['class X']
|
|
920
|
+
* findMissingSymbols([{ name: 'X', keyword: 'class', signature: '`new () => X`' }], []) // ['class X']
|
|
848
921
|
* ```
|
|
849
922
|
*/
|
|
850
923
|
function findMissingSymbols(symbols, source) {
|
|
@@ -908,9 +981,7 @@ function findUnexampled(names, fences, examples) {
|
|
|
908
981
|
*/
|
|
909
982
|
function extractFenceImports(fence) {
|
|
910
983
|
const results = [];
|
|
911
|
-
const
|
|
912
|
-
let match;
|
|
913
|
-
while ((match = pattern.exec(fence)) !== null) {
|
|
984
|
+
for (const match of fence.matchAll(/import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/gs)) {
|
|
914
985
|
const body = match[1];
|
|
915
986
|
const specifier = match[2];
|
|
916
987
|
if (body === void 0 || specifier === void 0) continue;
|
|
@@ -1067,11 +1138,11 @@ function normalizeIdentifier(code) {
|
|
|
1067
1138
|
* ```
|
|
1068
1139
|
*/
|
|
1069
1140
|
function extractCellText(cell) {
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1141
|
+
return Iterator.from(cell).map((node) => {
|
|
1142
|
+
if (isCodeSpanNode(node)) return `\`${node.value}\``;
|
|
1143
|
+
if (isEmphasisNode(node) || isLinkNode(node) || isImageNode(node)) return extractCellText(node.children);
|
|
1144
|
+
return flattenText(node);
|
|
1145
|
+
}).toArray().join("");
|
|
1075
1146
|
}
|
|
1076
1147
|
/**
|
|
1077
1148
|
* Builds one table cell's inline content from its compared text — the inverse of
|
|
@@ -1100,26 +1171,22 @@ function extractCellText(cell) {
|
|
|
1100
1171
|
*/
|
|
1101
1172
|
function buildCell(text) {
|
|
1102
1173
|
const nodes = [];
|
|
1103
|
-
const
|
|
1104
|
-
let cursor = 0;
|
|
1105
|
-
let span;
|
|
1106
|
-
while ((span = spans.exec(text)) !== null) {
|
|
1174
|
+
const cursor = Iterator.from(text.matchAll(/`([^`]+)`/g)).reduce((previous, span) => {
|
|
1107
1175
|
const value = span[1];
|
|
1108
|
-
if (value === void 0)
|
|
1109
|
-
if (span.index >
|
|
1176
|
+
if (value === void 0) return previous;
|
|
1177
|
+
if (span.index > previous) nodes.push({
|
|
1110
1178
|
element: "text",
|
|
1111
|
-
value: text.slice(
|
|
1179
|
+
value: text.slice(previous, span.index)
|
|
1112
1180
|
});
|
|
1113
|
-
|
|
1181
|
+
nodes.push(value.trim() === value ? {
|
|
1114
1182
|
element: "codeSpan",
|
|
1115
1183
|
value
|
|
1116
|
-
}
|
|
1117
|
-
else nodes.push({
|
|
1184
|
+
} : {
|
|
1118
1185
|
element: "text",
|
|
1119
1186
|
value: span[0]
|
|
1120
1187
|
});
|
|
1121
|
-
|
|
1122
|
-
}
|
|
1188
|
+
return span.index + span[0].length;
|
|
1189
|
+
}, 0);
|
|
1123
1190
|
if (cursor < text.length) nodes.push({
|
|
1124
1191
|
element: "text",
|
|
1125
1192
|
value: text.slice(cursor)
|
|
@@ -1143,7 +1210,7 @@ function buildCell(text) {
|
|
|
1143
1210
|
* ```
|
|
1144
1211
|
*/
|
|
1145
1212
|
function findColumnIndex(table, header) {
|
|
1146
|
-
for (
|
|
1213
|
+
for (const index of table.header.keys()) {
|
|
1147
1214
|
const cell = table.header[index];
|
|
1148
1215
|
if (cell !== void 0 && flattenText({
|
|
1149
1216
|
element: "paragraph",
|
|
@@ -1244,6 +1311,293 @@ function extractHidden(source) {
|
|
|
1244
1311
|
return symbols;
|
|
1245
1312
|
}
|
|
1246
1313
|
/**
|
|
1314
|
+
* Computes the bracket depth of every character of projected declaration code: an opening `(`,
|
|
1315
|
+
* `[`, `{`, or `<` and its closing partner carry the depth outside the pair, the characters
|
|
1316
|
+
* between them one more, and every character of a quoted string, its quotes included, `-1`.
|
|
1317
|
+
*
|
|
1318
|
+
* @remarks
|
|
1319
|
+
* The `>` of an `=>` arrow closes nothing. A backslash escapes the next character inside a
|
|
1320
|
+
* quoted string. Template literal text is outside the reading, because
|
|
1321
|
+
* {@link extractSourceLines} masks it to spaces in the code this function reads.
|
|
1322
|
+
*
|
|
1323
|
+
* @param code - The projected code of one declaration
|
|
1324
|
+
* @returns One depth per UTF-16 code unit of `code`
|
|
1325
|
+
*
|
|
1326
|
+
* @example
|
|
1327
|
+
* ```ts
|
|
1328
|
+
* computeDepths("f(a, 'b')") // [0, 0, 1, 1, 1, -1, -1, -1, 0]
|
|
1329
|
+
* ```
|
|
1330
|
+
*/
|
|
1331
|
+
function computeDepths(code) {
|
|
1332
|
+
const depths = [];
|
|
1333
|
+
code.split("").reduce((state, character, index) => {
|
|
1334
|
+
if (state.quote !== void 0) {
|
|
1335
|
+
depths.push(-1);
|
|
1336
|
+
if (state.escaped) return {
|
|
1337
|
+
...state,
|
|
1338
|
+
escaped: false
|
|
1339
|
+
};
|
|
1340
|
+
if (character === "\\") return {
|
|
1341
|
+
...state,
|
|
1342
|
+
escaped: true
|
|
1343
|
+
};
|
|
1344
|
+
return character === state.quote ? {
|
|
1345
|
+
...state,
|
|
1346
|
+
quote: void 0
|
|
1347
|
+
} : state;
|
|
1348
|
+
}
|
|
1349
|
+
if (character === "'" || character === "\"") {
|
|
1350
|
+
depths.push(-1);
|
|
1351
|
+
return {
|
|
1352
|
+
...state,
|
|
1353
|
+
quote: character
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
if (")]}".includes(character) || character === ">" && code[index - 1] !== "=") {
|
|
1357
|
+
const depth = Math.max(0, state.depth - 1);
|
|
1358
|
+
depths.push(depth);
|
|
1359
|
+
return {
|
|
1360
|
+
...state,
|
|
1361
|
+
depth
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
depths.push(state.depth);
|
|
1365
|
+
return "([{<".includes(character) ? {
|
|
1366
|
+
...state,
|
|
1367
|
+
depth: state.depth + 1
|
|
1368
|
+
} : state;
|
|
1369
|
+
}, {
|
|
1370
|
+
depth: 0,
|
|
1371
|
+
quote: void 0,
|
|
1372
|
+
escaped: false
|
|
1373
|
+
});
|
|
1374
|
+
return depths;
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Finds the index of the bracket closing the opener at `start`: the first later character whose
|
|
1378
|
+
* {@link computeDepths} depth equals the opener's.
|
|
1379
|
+
*
|
|
1380
|
+
* @param depths - The depths {@link computeDepths} returned for the code
|
|
1381
|
+
* @param start - The index of an opening `(`, `[`, `{`, or `<`
|
|
1382
|
+
* @returns The closing bracket's index, or `undefined` when the opener never closes
|
|
1383
|
+
*
|
|
1384
|
+
* @example
|
|
1385
|
+
* ```ts
|
|
1386
|
+
* findClosing(computeDepths('<T>(x: T)'), 3) // 8
|
|
1387
|
+
* ```
|
|
1388
|
+
*/
|
|
1389
|
+
function findClosing(depths, start) {
|
|
1390
|
+
const depth = depths[start];
|
|
1391
|
+
if (depth === void 0 || depth < 0) return void 0;
|
|
1392
|
+
const index = depths.findIndex((value, position) => position > start && value === depth);
|
|
1393
|
+
return index < 0 ? void 0 : index;
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Finds every index at which `separator` sits at `depth` outside quoted text, in code order.
|
|
1397
|
+
*
|
|
1398
|
+
* @param code - The projected code to search
|
|
1399
|
+
* @param depths - The depths {@link computeDepths} returned for `code`
|
|
1400
|
+
* @param separator - The single character to find
|
|
1401
|
+
* @param depth - The bracket depth the separator must sit at
|
|
1402
|
+
* @returns The separator indices, in code order
|
|
1403
|
+
*
|
|
1404
|
+
* @example
|
|
1405
|
+
* ```ts
|
|
1406
|
+
* findSeparators('a, f(b, c)', computeDepths('a, f(b, c)'), ',', 0) // [1]
|
|
1407
|
+
* ```
|
|
1408
|
+
*/
|
|
1409
|
+
function findSeparators(code, depths, separator, depth) {
|
|
1410
|
+
return depths.keys().filter((index) => depths[index] === depth && code[index] === separator).toArray();
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Renders one emitted interface member as its signature entry: a property as its name, an
|
|
1414
|
+
* optional one with `?`, a method as `name()` or `name?()`, an accessor as its name, and a call,
|
|
1415
|
+
* construct, or index signature as its own text with whitespace collapsed.
|
|
1416
|
+
*
|
|
1417
|
+
* @remarks
|
|
1418
|
+
* `code` is the member's projected code and `source` its text at the same columns, both without
|
|
1419
|
+
* the terminating `;`. A leading `readonly` modifier never enters a name. A computed name keeps
|
|
1420
|
+
* its brackets, and a quoted name keeps its quotes.
|
|
1421
|
+
*
|
|
1422
|
+
* @param code - The member's projected code
|
|
1423
|
+
* @param source - The member's source text, aligned with `code`
|
|
1424
|
+
* @returns The member's entry, or `undefined` when the member is empty
|
|
1425
|
+
*
|
|
1426
|
+
* @example
|
|
1427
|
+
* ```ts
|
|
1428
|
+
* renderMember('readonly name?: string', 'readonly name?: string') // 'name?'
|
|
1429
|
+
* renderMember('walk(depth: number): void', 'walk(depth: number): void') // 'walk()'
|
|
1430
|
+
* renderMember('[key: string]: number', '[key: string]: number') // '[key: string]: number'
|
|
1431
|
+
* ```
|
|
1432
|
+
*/
|
|
1433
|
+
function renderMember(code, source) {
|
|
1434
|
+
const text = source.replace(/\s+/g, " ").trim();
|
|
1435
|
+
if (text.length === 0) return void 0;
|
|
1436
|
+
const leading = code.length - code.trimStart().length;
|
|
1437
|
+
const modifier = leading + (/^readonly\s+/.exec(code.slice(leading))?.[0].length ?? 0);
|
|
1438
|
+
const rest = code.slice(modifier);
|
|
1439
|
+
if (/^(?:new\s*)?[(<]/.test(rest)) return text;
|
|
1440
|
+
const depths = computeDepths(rest);
|
|
1441
|
+
const bracket = rest.startsWith("[") ? findClosing(depths, 0) : void 0;
|
|
1442
|
+
if (bracket !== void 0 && findSeparators(rest, depths, ":", 1).some((index) => index < bracket)) return text;
|
|
1443
|
+
const accessor = /^(?:get|set)\s+(?=[^\s(:?<])/.exec(rest)?.[0].length ?? 0;
|
|
1444
|
+
const named = rest.slice(accessor);
|
|
1445
|
+
const computed = named.startsWith("[") ? findClosing(computeDepths(named), 0) : void 0;
|
|
1446
|
+
const length = computed === void 0 ? /^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^\s?(:<]+)/.exec(named)?.[0].length ?? 0 : computed + 1;
|
|
1447
|
+
if (length === 0) return text;
|
|
1448
|
+
const offset = modifier + accessor;
|
|
1449
|
+
const tail = named.slice(length);
|
|
1450
|
+
const optional = tail.startsWith("?");
|
|
1451
|
+
const method = accessor === 0 && /^\??\s*[(<]/.test(tail);
|
|
1452
|
+
return `${source.slice(offset, offset + length)}${optional ? "?" : ""}${method ? "()" : ""}`;
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Extracts one emitted declaration's signature: the symbol its column-zero `export` head names,
|
|
1456
|
+
* carrying the type text the compiler emitted for it.
|
|
1457
|
+
*
|
|
1458
|
+
* @remarks
|
|
1459
|
+
* `code` is the declaration's projected code and `source` its text at the same columns, each
|
|
1460
|
+
* physical line trimmed and the lines joined with single spaces. The forms:
|
|
1461
|
+
*
|
|
1462
|
+
* - `function`: `<T>(params) => RET` from `NAME<T>(params): RET`.
|
|
1463
|
+
* - `class`: `new <T>(params) => YIELD` per `constructor(params)`, several as an intersection of
|
|
1464
|
+
* parenthesized signatures, none as `new <T>() => YIELD`. `YIELD` is the first `implements`
|
|
1465
|
+
* type, else the class's own name with its type parameter names. Every other member is ignored.
|
|
1466
|
+
* - `interface`: `{ entries }` from {@link renderMember} over its own members, in emitted order,
|
|
1467
|
+
* each entry once, or `{}` when it declares none. The `extends` clause is not read.
|
|
1468
|
+
* - `type`: the text after `=` to the terminating `;`, type parameters omitted.
|
|
1469
|
+
* - `const`: the text after `NAME:` to the `;`, or after `NAME =` for a literal the compiler
|
|
1470
|
+
* emitted as the constant's type.
|
|
1471
|
+
*
|
|
1472
|
+
* @param code - The declaration's projected code
|
|
1473
|
+
* @param source - The declaration's source text, aligned with `code`
|
|
1474
|
+
* @returns The declared symbol with its signature, or `undefined` when no supported head opens it
|
|
1475
|
+
*
|
|
1476
|
+
* @example
|
|
1477
|
+
* ```ts
|
|
1478
|
+
* const text = 'export declare function walk<T>(node: T): void;'
|
|
1479
|
+
* extractSignature(text, text) // { name: 'walk', keyword: 'function', signature: '<T>(node: T) => void' }
|
|
1480
|
+
* ```
|
|
1481
|
+
*/
|
|
1482
|
+
function extractSignature(code, source) {
|
|
1483
|
+
const head = /^export (?:declare )?(?:abstract )?(function|class|interface|type|const(?! enum\b)) ([^\s<(:=;{]+)/.exec(code);
|
|
1484
|
+
const keyword = head?.[1];
|
|
1485
|
+
const name = head?.[2];
|
|
1486
|
+
if (head === null || name === void 0 || !isExportKeyword(keyword)) return void 0;
|
|
1487
|
+
const depths = computeDepths(code);
|
|
1488
|
+
const start = head[0].length;
|
|
1489
|
+
const generic = code[start] === "<" ? findClosing(depths, start) : void 0;
|
|
1490
|
+
const typed = generic === void 0 ? start : generic + 1;
|
|
1491
|
+
const generics = source.slice(start, typed);
|
|
1492
|
+
const end = findSeparators(code, depths, ";", 0).find((index) => index >= typed) ?? code.length;
|
|
1493
|
+
if (keyword === "function") {
|
|
1494
|
+
const close = code[typed] === "(" ? findClosing(depths, typed) : void 0;
|
|
1495
|
+
if (close === void 0) return void 0;
|
|
1496
|
+
const colon = /^\s*:/.exec(code.slice(close + 1))?.[0].length;
|
|
1497
|
+
if (colon === void 0) return void 0;
|
|
1498
|
+
const returns = source.slice(close + 1 + colon, end).trim();
|
|
1499
|
+
return {
|
|
1500
|
+
name,
|
|
1501
|
+
keyword,
|
|
1502
|
+
signature: `${generics}(${source.slice(typed + 1, close)}) => ${returns}`
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
if (keyword === "const" || keyword === "type") {
|
|
1506
|
+
const assigned = (keyword === "const" ? /^\s*[:=]/ : /^\s*=/).exec(code.slice(typed));
|
|
1507
|
+
if (assigned === null) return void 0;
|
|
1508
|
+
return {
|
|
1509
|
+
name,
|
|
1510
|
+
keyword,
|
|
1511
|
+
signature: source.slice(typed + assigned[0].length, end).trim()
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
const open = findSeparators(code, depths, "{", 0).find((index) => index >= typed);
|
|
1515
|
+
const close = open === void 0 ? void 0 : findClosing(depths, open);
|
|
1516
|
+
if (open === void 0 || close === void 0) return void 0;
|
|
1517
|
+
const boundaries = [
|
|
1518
|
+
open,
|
|
1519
|
+
...findSeparators(code, depths, ";", 1).filter((index) => index > open && index < close),
|
|
1520
|
+
close
|
|
1521
|
+
];
|
|
1522
|
+
const members = boundaries.slice(0, -1).map((boundary, position) => {
|
|
1523
|
+
const next = boundaries[position + 1] ?? close;
|
|
1524
|
+
return {
|
|
1525
|
+
code: code.slice(boundary + 1, next),
|
|
1526
|
+
source: source.slice(boundary + 1, next)
|
|
1527
|
+
};
|
|
1528
|
+
});
|
|
1529
|
+
if (keyword === "interface") {
|
|
1530
|
+
const entries = Array.from(new Set(members.map((member) => renderMember(member.code, member.source)).filter((entry) => entry !== void 0)));
|
|
1531
|
+
return {
|
|
1532
|
+
name,
|
|
1533
|
+
keyword,
|
|
1534
|
+
signature: entries.length === 0 ? "{}" : `{ ${entries.join(", ")} }`
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
const heritage = /\bimplements\b/.exec(code.slice(typed, open));
|
|
1538
|
+
const implemented = heritage === null || depths[typed + heritage.index] !== 0 ? void 0 : typed + heritage.index + heritage[0].length;
|
|
1539
|
+
const comma = implemented === void 0 ? void 0 : findSeparators(code, depths, ",", 0).find((index) => index > implemented && index < open);
|
|
1540
|
+
const parameters = generic === void 0 ? [] : [start, ...findSeparators(code, depths, ",", 1).filter((index) => index < generic)].map((boundary, position, list) => /^\s*(?:(?:const|in|out)\s+)*([^\s=,>]+)/.exec(code.slice(boundary + 1, list[position + 1] ?? generic))?.[1] ?? "");
|
|
1541
|
+
const yielded = implemented === void 0 ? `${name}${parameters.length === 0 ? "" : `<${parameters.join(", ")}>`}` : source.slice(implemented, comma ?? open).trim();
|
|
1542
|
+
const constructors = members.filter((member) => /^\s*(?:(?:public|private|protected)\s+)?constructor\s*\(/.test(member.code)).map((member) => {
|
|
1543
|
+
const parenthesis = member.code.indexOf("(");
|
|
1544
|
+
const closed = findClosing(computeDepths(member.code), parenthesis) ?? member.code.length;
|
|
1545
|
+
return `new ${generics}(${member.source.slice(parenthesis + 1, closed)}) => ${yielded}`;
|
|
1546
|
+
});
|
|
1547
|
+
return {
|
|
1548
|
+
name,
|
|
1549
|
+
keyword,
|
|
1550
|
+
signature: constructors.length === 0 ? `new ${generics}() => ${yielded}` : constructors.length === 1 ? constructors[0] ?? "" : constructors.map((entry) => `(${entry})`).join(" & ")
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Extracts every signature one compiler-emitted declaration file declares: each column-zero
|
|
1555
|
+
* `export` head read through {@link extractSignature}, an overload set's emitted heads joined in
|
|
1556
|
+
* order as an intersection of parenthesized signatures.
|
|
1557
|
+
*
|
|
1558
|
+
* @remarks
|
|
1559
|
+
* The text is read through {@link extractSourceLines}, so comment and template payload never
|
|
1560
|
+
* opens or closes a bracket. Each physical line is trimmed and a declaration's lines are joined
|
|
1561
|
+
* with single spaces, so a multi-line emitted type reads as one line. A head the projector does
|
|
1562
|
+
* not support, such as an `enum` or a re-export, contributes nothing. Every other repeated head
|
|
1563
|
+
* keeps its first signature.
|
|
1564
|
+
*
|
|
1565
|
+
* @param declaration - The emitted `.d.ts` text
|
|
1566
|
+
* @returns The declared symbols with their signatures, in first-seen order
|
|
1567
|
+
*
|
|
1568
|
+
* @example
|
|
1569
|
+
* ```ts
|
|
1570
|
+
* extractSignatures('export declare function open(id: string): boolean;\nexport declare function open(ids: readonly string[]): boolean;\n')
|
|
1571
|
+
* // [{ name: 'open', keyword: 'function', signature: '((id: string) => boolean) & ((ids: readonly string[]) => boolean)' }]
|
|
1572
|
+
* ```
|
|
1573
|
+
*/
|
|
1574
|
+
function extractSignatures(declaration) {
|
|
1575
|
+
const records = extractSourceLines(declaration).map((line) => {
|
|
1576
|
+
const start = line.code.length - line.code.trimStart().length;
|
|
1577
|
+
const end = line.code.trimEnd().length;
|
|
1578
|
+
return {
|
|
1579
|
+
code: line.code.slice(start, end),
|
|
1580
|
+
source: line.source.slice(start, end),
|
|
1581
|
+
head: start === 0 && line.code.startsWith("export ")
|
|
1582
|
+
};
|
|
1583
|
+
}).filter((record) => record.code.length > 0);
|
|
1584
|
+
const heads = records.keys().filter((index) => records[index]?.head === true).toArray();
|
|
1585
|
+
const symbols = heads.map((head, position) => {
|
|
1586
|
+
const segment = records.slice(head, heads[position + 1] ?? records.length);
|
|
1587
|
+
return extractSignature(segment.map((record) => record.code).join(" "), segment.map((record) => record.source).join(" "));
|
|
1588
|
+
}).filter((symbol) => symbol !== void 0);
|
|
1589
|
+
return Array.from(new Set(symbols.map(computeSymbolKey))).flatMap((key) => {
|
|
1590
|
+
const declared = symbols.filter((symbol) => computeSymbolKey(symbol) === key);
|
|
1591
|
+
const [first] = declared;
|
|
1592
|
+
if (first === void 0) return [];
|
|
1593
|
+
if (first.keyword !== "function" || declared.length === 1) return [first];
|
|
1594
|
+
return [{
|
|
1595
|
+
...first,
|
|
1596
|
+
signature: declared.map((symbol) => `(${symbol.signature ?? ""})`).join(" & ")
|
|
1597
|
+
}];
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1247
1601
|
* Joins the declaration head starting at `start` into one space-separated
|
|
1248
1602
|
* line, consuming lines until the first that opens a body: one that ends with
|
|
1249
1603
|
* `{`, or one that closes an empty body with `{}` or `{ }`.
|
|
@@ -1266,7 +1620,10 @@ function extractHidden(source) {
|
|
|
1266
1620
|
*/
|
|
1267
1621
|
function joinHead(lines, start) {
|
|
1268
1622
|
const parts = [];
|
|
1269
|
-
for (
|
|
1623
|
+
for (const distance of Array.prototype.keys.call({ get length() {
|
|
1624
|
+
return Math.max(0, Math.ceil(lines.length - start));
|
|
1625
|
+
} })) {
|
|
1626
|
+
const index = start + distance;
|
|
1270
1627
|
const line = lines[index];
|
|
1271
1628
|
if (line === void 0) break;
|
|
1272
1629
|
const text = line.trimEnd();
|
|
@@ -1342,7 +1699,7 @@ function collectDeclarations(source) {
|
|
|
1342
1699
|
const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{(?:\s*\})?$/;
|
|
1343
1700
|
const lines = extractSourceLines(source);
|
|
1344
1701
|
const projected = lines.map((line) => line.code);
|
|
1345
|
-
for (
|
|
1702
|
+
for (const index of projected.keys()) {
|
|
1346
1703
|
const line = projected[index];
|
|
1347
1704
|
if (line === void 0 || !opener.test(line)) continue;
|
|
1348
1705
|
const head = joinHead(projected, index);
|
|
@@ -1354,12 +1711,14 @@ function collectDeclarations(source) {
|
|
|
1354
1711
|
const key = `${keyword} ${name}`;
|
|
1355
1712
|
const known = declarations.get(key);
|
|
1356
1713
|
if (known !== void 0 && (known.body.length > 0 || known.bases.length > 0)) continue;
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1714
|
+
const visible = [];
|
|
1715
|
+
Iterator.from(head.text.slice(`export ${key}`.length, head.text.lastIndexOf("{"))).reduce((depth, character) => {
|
|
1716
|
+
if (character === "<") return depth + 1;
|
|
1717
|
+
if (character === ">") return Math.max(0, depth - 1);
|
|
1718
|
+
if (depth === 0) visible.push(character);
|
|
1719
|
+
return depth;
|
|
1720
|
+
}, 0);
|
|
1721
|
+
const clause = visible.join("").replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
|
|
1363
1722
|
const bases = clause === void 0 ? [] : clause.split(",").map((base) => base.trim()).filter(isNonEmptyString);
|
|
1364
1723
|
if (head.text.endsWith("}")) {
|
|
1365
1724
|
declarations.set(key, {
|
|
@@ -1368,14 +1727,11 @@ function collectDeclarations(source) {
|
|
|
1368
1727
|
});
|
|
1369
1728
|
continue;
|
|
1370
1729
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
});
|
|
1377
|
-
break;
|
|
1378
|
-
}
|
|
1730
|
+
const close = Array.prototype.keys.call({ length: projected.length - head.end - 1 }).map((distance) => head.end + 1 + distance).find((candidate) => projected[candidate] === "}");
|
|
1731
|
+
if (close !== void 0) declarations.set(key, {
|
|
1732
|
+
body: lines.slice(head.end + 1, close).map((record) => record.source),
|
|
1733
|
+
bases
|
|
1734
|
+
});
|
|
1379
1735
|
}
|
|
1380
1736
|
return declarations;
|
|
1381
1737
|
}
|
|
@@ -1460,24 +1816,123 @@ function extractMemberMethods(lines) {
|
|
|
1460
1816
|
* ```
|
|
1461
1817
|
*/
|
|
1462
1818
|
function selectSectionBlocks(document, heading) {
|
|
1463
|
-
const
|
|
1464
|
-
let active = false;
|
|
1819
|
+
const scanned = [];
|
|
1465
1820
|
for (const block of document.children) {
|
|
1821
|
+
const active = scanned.at(-1)?.active ?? false;
|
|
1466
1822
|
if (isHeadingNode(block) && block.level <= 2) {
|
|
1467
1823
|
if (block.level === 2 && flattenText(block).trim() === heading) {
|
|
1468
|
-
|
|
1824
|
+
scanned.push({
|
|
1825
|
+
block,
|
|
1826
|
+
active: true,
|
|
1827
|
+
heading: true
|
|
1828
|
+
});
|
|
1469
1829
|
continue;
|
|
1470
1830
|
}
|
|
1471
1831
|
if (active) break;
|
|
1472
1832
|
}
|
|
1473
|
-
|
|
1833
|
+
scanned.push({
|
|
1834
|
+
block,
|
|
1835
|
+
active,
|
|
1836
|
+
heading: false
|
|
1837
|
+
});
|
|
1474
1838
|
}
|
|
1475
|
-
return
|
|
1839
|
+
return scanned.filter((entry) => entry.active && !entry.heading).map((entry) => entry.block);
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Validates every `## Surface` table a guide carries: each header must be exactly
|
|
1843
|
+
* {@link SURFACE_HEADER}, and each row that keys a symbol must carry a non-empty `Signature` cell.
|
|
1844
|
+
*
|
|
1845
|
+
* @remarks
|
|
1846
|
+
* Reads each `## Surface` section through {@link selectSectionBlocks}, a repeated section
|
|
1847
|
+
* included, and refuses at the first offending table in document order, through {@link GuideError} with code
|
|
1848
|
+
* `header` for a nonuniform header and `signature` for a keyed empty cell. Header and row text in
|
|
1849
|
+
* the message is JSON-encoded and capped at 200 characters.
|
|
1850
|
+
*
|
|
1851
|
+
* @param document - The parsed guide document
|
|
1852
|
+
* @throws {@link GuideError} at the first nonuniform header or keyed empty Signature cell
|
|
1853
|
+
*
|
|
1854
|
+
* @example
|
|
1855
|
+
* ```ts
|
|
1856
|
+
* validateSurface(createMarkdown('## Surface\n\n| Name | Kind |\n| --- | --- |').document)
|
|
1857
|
+
* // throws GuideError: ## Surface table 1 has header "Name | Kind"; expected "Name | Kind | Signature | Summary".
|
|
1858
|
+
* ```
|
|
1859
|
+
*/
|
|
1860
|
+
function validateSurface(document) {
|
|
1861
|
+
const expected = SURFACE_HEADER.join(" | ");
|
|
1862
|
+
const signed = SURFACE_HEADER.indexOf(SIGNATURE);
|
|
1863
|
+
const tables = new Set(document.children.flatMap((block, start) => isHeadingNode(block) && block.level === 2 && flattenText(block).trim() === "Surface" ? selectSectionBlocks({
|
|
1864
|
+
...document,
|
|
1865
|
+
children: document.children.slice(start)
|
|
1866
|
+
}, SURFACE) : []).filter(isTableNode));
|
|
1867
|
+
for (const [index, table] of Array.from(tables).entries()) {
|
|
1868
|
+
const header = table.header.map((children) => flattenText({
|
|
1869
|
+
element: "paragraph",
|
|
1870
|
+
children
|
|
1871
|
+
}).trim());
|
|
1872
|
+
if (header.length !== SURFACE_HEADER.length || !SURFACE_HEADER.every((name, column) => header[column] === name)) throw new GuideError(`## Surface table ${index + 1} has header ${JSON.stringify(header.join(" | ").slice(0, 200))}; expected ${JSON.stringify(expected)}.`, "header");
|
|
1873
|
+
for (const position of table.rows.keys()) {
|
|
1874
|
+
const symbol = extractRowSymbol(table, position);
|
|
1875
|
+
if (symbol === void 0) continue;
|
|
1876
|
+
const cell = table.rows[position]?.[signed];
|
|
1877
|
+
if (cell !== void 0 && flattenText({
|
|
1878
|
+
element: "paragraph",
|
|
1879
|
+
children: cell
|
|
1880
|
+
}).trim().length > 0) continue;
|
|
1881
|
+
throw new GuideError(`## Surface table ${index + 1} row ${position + 1} (${JSON.stringify(`${symbol.keyword} ${symbol.name}`.slice(0, 200))}) has an empty Signature cell; expected a non-empty TypeScript signature code span under ${JSON.stringify(expected)}.`, "signature");
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Validates that the modules one manifest entry spans declare disjoint exports: one name exported
|
|
1887
|
+
* from two modules, whatever its keyword, is one capability split across environments.
|
|
1888
|
+
*
|
|
1889
|
+
* @remarks
|
|
1890
|
+
* Each source file answers for the most specific listed module directory that contains it, so a
|
|
1891
|
+
* nested module listed beside its parent never collides with itself. Logic that serves several
|
|
1892
|
+
* environments lives once in its layer's `core` directory, such as `src/core` or `app/core`;
|
|
1893
|
+
* environments whose internals differ each export a distinct name. Every colliding name is
|
|
1894
|
+
* reported in one refusal, in key order, each with every module that declares it; name and module
|
|
1895
|
+
* text is JSON-encoded and capped at 200 characters.
|
|
1896
|
+
*
|
|
1897
|
+
* @param files - The workspace-relative inventory the modules are read from
|
|
1898
|
+
* @param module - The manifest entry's source scope
|
|
1899
|
+
* @throws {@link GuideError} with code `collision` naming each name and the modules that declare it
|
|
1900
|
+
*
|
|
1901
|
+
* @example
|
|
1902
|
+
* ```ts
|
|
1903
|
+
* validateModules(
|
|
1904
|
+
* { 'src/core/a.ts': 'export function open() {}', 'src/server/a.ts': 'export function open() {}' },
|
|
1905
|
+
* ['src/core', 'src/server'],
|
|
1906
|
+
* )
|
|
1907
|
+
* // throws GuideError: "open" is declared in "src/core" and "src/server"; …
|
|
1908
|
+
* ```
|
|
1909
|
+
*/
|
|
1910
|
+
function validateModules(files, module) {
|
|
1911
|
+
const directories = normalizeDirectories(module);
|
|
1912
|
+
const declared = selectModuleKeys(files, directories).flatMap((key) => {
|
|
1913
|
+
const owner = directories.filter((directory) => directory === "." || key.startsWith(`${directory}/`)).reduce((current, directory) => directory.length > current.length ? directory : current, "");
|
|
1914
|
+
return extractExports(files[key] ?? "").map((symbol) => ({
|
|
1915
|
+
key: symbol.name,
|
|
1916
|
+
owner
|
|
1917
|
+
}));
|
|
1918
|
+
});
|
|
1919
|
+
const collisions = Array.from(new Set(declared.map((entry) => entry.key))).sort().map((key) => ({
|
|
1920
|
+
key,
|
|
1921
|
+
owners: directories.filter((directory) => declared.some((entry) => entry.key === key && entry.owner === directory))
|
|
1922
|
+
})).filter((collision) => collision.owners.length > 1);
|
|
1923
|
+
if (collisions.length === 0) return;
|
|
1924
|
+
const named = collisions.map((collision) => `${JSON.stringify(collision.key.slice(0, 200))} is declared in ${collision.owners.map((owner) => JSON.stringify(owner.slice(0, 200))).join(" and ")}`);
|
|
1925
|
+
const cores = Array.from(new Set(collisions.flatMap((collision) => collision.owners.filter((owner) => owner !== ".").map((owner) => `${owner.replace(/\/.*$/u, "").slice(0, 200)}/core`)))).sort();
|
|
1926
|
+
throw new GuideError(`${named.join("; ")}; one name exported from two environments is a conflict. Declare logic both environments share once in ${cores.join(" or ")}, and give each environment's own logic a distinct name.`, "collision", { context: { collisions: collisions.map((collision) => ({
|
|
1927
|
+
name: collision.key,
|
|
1928
|
+
modules: collision.owners
|
|
1929
|
+
})) } });
|
|
1476
1930
|
}
|
|
1477
1931
|
/**
|
|
1478
1932
|
* Extracts one `## Surface` table row's symbol — its column 0 code span as the name, its
|
|
1479
|
-
* {@link KIND} column as the keyword, and its {@link SUMMARY}
|
|
1480
|
-
* when
|
|
1933
|
+
* {@link KIND} column as the keyword, and its exact `Signature` and {@link SUMMARY} columns as
|
|
1934
|
+
* normalized text when those columns exist. Empty cells remain absent. A row with no code-span
|
|
1935
|
+
* name and a row whose `Kind` text is
|
|
1481
1936
|
* no {@link ExportKeyword} have no symbol to key, so each returns `undefined`.
|
|
1482
1937
|
*
|
|
1483
1938
|
* @param table - The table to read
|
|
@@ -1504,9 +1959,13 @@ function extractRowSymbol(table, row) {
|
|
|
1504
1959
|
}).trim();
|
|
1505
1960
|
if (!isExportKeyword(keyword)) return void 0;
|
|
1506
1961
|
const summary = extractRowSummary(table, row);
|
|
1962
|
+
const signed = findColumnIndex(table, SIGNATURE);
|
|
1963
|
+
const signatureCell = signed === void 0 ? void 0 : cells[signed];
|
|
1964
|
+
const signature = signatureCell === void 0 ? "" : normalizeSummary(extractCellText(signatureCell));
|
|
1507
1965
|
return {
|
|
1508
1966
|
name,
|
|
1509
1967
|
keyword,
|
|
1968
|
+
...signature.length === 0 ? {} : { signature },
|
|
1510
1969
|
...summary === void 0 ? {} : { summary }
|
|
1511
1970
|
};
|
|
1512
1971
|
}
|
|
@@ -1567,7 +2026,8 @@ function extractRowSummary(table, row) {
|
|
|
1567
2026
|
* symbol on, so this reader skips it and {@link extractUnnamed} reports it; a row with an
|
|
1568
2027
|
* unrecognized `Kind` text is skipped. A row also carries its {@link SUMMARY} column's compared
|
|
1569
2028
|
* text when the table has that column; a table without it leaves every row's summary absent,
|
|
1570
|
-
* which {@link findDrift} reports.
|
|
2029
|
+
* which {@link findDrift} reports. The exact `Signature` column contributes normalized signature
|
|
2030
|
+
* text, including code spans, when present and non-empty; no other header supplies it.
|
|
1571
2031
|
*
|
|
1572
2032
|
* @remarks
|
|
1573
2033
|
* The heading boundary compares {@link extractCellText} with the raw value from
|
|
@@ -1575,7 +2035,7 @@ function extractRowSummary(table, row) {
|
|
|
1575
2035
|
* Surrounding spaces, emphasis, and links preserve that identity. This reader refuses a heading
|
|
1576
2036
|
* carrying any other visible text or an additional code span. Entries retain encounter order, and
|
|
1577
2037
|
* the first-seen name + keyword wins: a genuine heading before its table row keeps the heading's
|
|
1578
|
-
*
|
|
2038
|
+
* class entry without signature or summary, while a preceding table row keeps both cells.
|
|
1579
2039
|
*
|
|
1580
2040
|
* @param document - The parsed guide document
|
|
1581
2041
|
* @returns The documented surface, in encounter order
|
|
@@ -1590,7 +2050,7 @@ function extractSurface(document) {
|
|
|
1590
2050
|
const seen = /* @__PURE__ */ new Set();
|
|
1591
2051
|
for (const block of selectSectionBlocks(document, SURFACE)) {
|
|
1592
2052
|
if (isTableNode(block)) {
|
|
1593
|
-
for (
|
|
2053
|
+
for (const row of block.rows.keys()) {
|
|
1594
2054
|
const symbol = extractRowSymbol(block, row);
|
|
1595
2055
|
if (symbol === void 0) continue;
|
|
1596
2056
|
const key = computeSymbolKey(symbol);
|
|
@@ -1634,7 +2094,7 @@ function extractMethods(document) {
|
|
|
1634
2094
|
const groups = [];
|
|
1635
2095
|
for (const [table, name] of collectGroups(document)) {
|
|
1636
2096
|
const methods = [];
|
|
1637
|
-
for (
|
|
2097
|
+
for (const row of table.rows.keys()) {
|
|
1638
2098
|
const entry = extractRowEntry(table, row);
|
|
1639
2099
|
if (entry !== void 0) methods.push(entry);
|
|
1640
2100
|
}
|
|
@@ -1661,20 +2121,19 @@ function extractMethods(document) {
|
|
|
1661
2121
|
* ```
|
|
1662
2122
|
*/
|
|
1663
2123
|
function collectGroups(document) {
|
|
1664
|
-
const groups =
|
|
1665
|
-
|
|
1666
|
-
for (const block of selectSectionBlocks(document, METHODS)) {
|
|
2124
|
+
const groups = [];
|
|
2125
|
+
selectSectionBlocks(document, METHODS).reduce((current, block) => {
|
|
1667
2126
|
if (isHeadingNode(block) && block.level === 4) {
|
|
1668
|
-
const
|
|
1669
|
-
|
|
1670
|
-
continue;
|
|
2127
|
+
const name = findFirstCode(block.children);
|
|
2128
|
+
return name === void 0 ? void 0 : normalizeIdentifier(name);
|
|
1671
2129
|
}
|
|
1672
2130
|
if (isTableNode(block) && current !== void 0) {
|
|
1673
|
-
groups.
|
|
1674
|
-
|
|
2131
|
+
groups.push([block, current]);
|
|
2132
|
+
return;
|
|
1675
2133
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
2134
|
+
return current;
|
|
2135
|
+
}, void 0);
|
|
2136
|
+
return new Map(groups);
|
|
1678
2137
|
}
|
|
1679
2138
|
/**
|
|
1680
2139
|
* Extracts every `## Surface` or `## Methods` table row whose first cell carries no code span.
|
|
@@ -1827,18 +2286,11 @@ function unwrapComment(comment) {
|
|
|
1827
2286
|
* ```
|
|
1828
2287
|
*/
|
|
1829
2288
|
function normalizeSummary(text) {
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
for (let index = 0; index < parts.length; index += 1) {
|
|
1833
|
-
const part = parts[index] ?? "";
|
|
1834
|
-
if (index % 2 === 0) {
|
|
1835
|
-
normalized += part.replace(/\{@link\s+[^}|]*\|\s*([^}]*?)\s*\}/g, "`$1`").replace(/\{@link\s+(?:import\([^)]*\)\.|[^}|#\s]*[@/][^}|#\s]*#)?([^}|]*?)\s*\}/g, "`$1`");
|
|
1836
|
-
continue;
|
|
1837
|
-
}
|
|
2289
|
+
return text.split(/((?<!`)`[^`]+`(?!`))/).map((part, index) => {
|
|
2290
|
+
if (index % 2 === 0) return part.replace(/\{@link\s+[^}|]*\|\s*([^}]*?)\s*\}/g, "`$1`").replace(/\{@link\s+(?:import\([^)]*\)\.|[^}|#\s]*[@/][^}|#\s]*#)?([^}|]*?)\s*\}/g, "`$1`");
|
|
1838
2291
|
const value = part.slice(1, -1).replace(/\s+/g, " ").trim();
|
|
1839
|
-
|
|
1840
|
-
}
|
|
1841
|
-
return normalized.replace(/\s+/g, " ").trim();
|
|
2292
|
+
return `\`${value.length === 0 ? " " : value}\``;
|
|
2293
|
+
}).join("").replace(/\s+/g, " ").trim();
|
|
1842
2294
|
}
|
|
1843
2295
|
/**
|
|
1844
2296
|
* Wraps one paragraph into greedy lines no longer than `width` characters. Every run of
|
|
@@ -1855,18 +2307,27 @@ function normalizeSummary(text) {
|
|
|
1855
2307
|
* ```
|
|
1856
2308
|
*/
|
|
1857
2309
|
function wrapText(text, width) {
|
|
2310
|
+
const words = text.split(/\s+/).filter((word) => word.length > 0);
|
|
1858
2311
|
const lines = [];
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
|
|
2312
|
+
const final = words.reduce((previous, word, index) => {
|
|
2313
|
+
if (index === previous.start) return {
|
|
2314
|
+
start: index,
|
|
2315
|
+
length: word.length
|
|
2316
|
+
};
|
|
2317
|
+
if (previous.length + 1 + word.length <= width) return {
|
|
2318
|
+
start: previous.start,
|
|
2319
|
+
length: previous.length + 1 + word.length
|
|
2320
|
+
};
|
|
2321
|
+
lines.push(words.slice(previous.start, index).join(" "));
|
|
2322
|
+
return {
|
|
2323
|
+
start: index,
|
|
2324
|
+
length: word.length
|
|
2325
|
+
};
|
|
2326
|
+
}, {
|
|
2327
|
+
start: 0,
|
|
2328
|
+
length: 0
|
|
2329
|
+
});
|
|
2330
|
+
if (words.length > 0) lines.push(words.slice(final.start).join(" "));
|
|
1870
2331
|
return lines;
|
|
1871
2332
|
}
|
|
1872
2333
|
/**
|
|
@@ -1911,18 +2372,16 @@ function buildComment(lines, indent) {
|
|
|
1911
2372
|
*/
|
|
1912
2373
|
function maskFences(text) {
|
|
1913
2374
|
const masked = [];
|
|
1914
|
-
|
|
1915
|
-
for (const line of text.split("\n")) {
|
|
2375
|
+
text.split("\n").reduce((marker, line) => {
|
|
1916
2376
|
const fence = /^[ \t]*(`{3,}|~{3,})/.exec(line)?.[1];
|
|
1917
2377
|
if (marker === void 0) {
|
|
1918
2378
|
masked.push(line);
|
|
1919
|
-
|
|
1920
|
-
continue;
|
|
2379
|
+
return fence;
|
|
1921
2380
|
}
|
|
1922
|
-
const
|
|
1923
|
-
masked.push(
|
|
1924
|
-
|
|
1925
|
-
}
|
|
2381
|
+
const closed = fence !== void 0 && fence.startsWith(marker);
|
|
2382
|
+
masked.push(closed ? line : " ".repeat(line.length));
|
|
2383
|
+
return closed ? void 0 : marker;
|
|
2384
|
+
}, void 0);
|
|
1926
2385
|
return masked.join("\n");
|
|
1927
2386
|
}
|
|
1928
2387
|
/**
|
|
@@ -1948,67 +2407,67 @@ function maskFences(text) {
|
|
|
1948
2407
|
*/
|
|
1949
2408
|
function extractSourceComments(lines) {
|
|
1950
2409
|
const comments = [];
|
|
1951
|
-
|
|
1952
|
-
let eligible = false;
|
|
1953
|
-
let span = [];
|
|
1954
|
-
let pending;
|
|
1955
|
-
for (const line of lines) {
|
|
2410
|
+
Iterator.from(lines).reduce((previous, line) => {
|
|
1956
2411
|
const projection = line.jsdoc;
|
|
1957
2412
|
const first = projection?.indexOf("/**") ?? -1;
|
|
1958
|
-
if (pending !== void 0) {
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
if (block)
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2413
|
+
if (previous.pending !== void 0 && !(!previous.block && first >= 0 && line.source.slice(0, first).trim() === "")) comments.push({
|
|
2414
|
+
text: previous.pending,
|
|
2415
|
+
line
|
|
2416
|
+
});
|
|
2417
|
+
const state = {
|
|
2418
|
+
...previous,
|
|
2419
|
+
pending: void 0
|
|
2420
|
+
};
|
|
2421
|
+
if (projection === void 0) return state;
|
|
2422
|
+
const close = state.block ? projection.indexOf("*/") : -1;
|
|
2423
|
+
const end = close < 0 ? projection.length : close + 2;
|
|
2424
|
+
if (state.block) state.span.push(projection.slice(0, end));
|
|
2425
|
+
if (state.block && close < 0) return state;
|
|
2426
|
+
const opener = state.block ? projection.indexOf("/**", close + 2) : first;
|
|
2427
|
+
const whitespace = state.block ? line.source.slice(close + 2, opener < 0 ? line.source.length : opener).trim() === "" : line.source.slice(0, first).trim() === "";
|
|
2428
|
+
const eligible = state.block ? state.eligible && whitespace : whitespace;
|
|
2429
|
+
if (opener < 0) return state.block ? {
|
|
2430
|
+
...state,
|
|
2431
|
+
block: false,
|
|
2432
|
+
pending: eligible ? normalizeComment(state.span.join("\n")) : void 0
|
|
2433
|
+
} : state;
|
|
2434
|
+
const spans = /\/\*(?=\*)[\s\S]*?(?:\*\/|$)/g;
|
|
2435
|
+
spans.lastIndex = opener;
|
|
2436
|
+
return Iterator.from(projection.matchAll(spans)).reduce((current, match) => {
|
|
2437
|
+
const cursor = match.index;
|
|
2438
|
+
const closing = projection.indexOf("*/", cursor + 2);
|
|
2439
|
+
const finish = closing < 0 ? projection.length : closing + 2;
|
|
2440
|
+
const span = [projection.slice(cursor, finish)];
|
|
2441
|
+
if (closing < 0) return {
|
|
2442
|
+
...current,
|
|
2443
|
+
span,
|
|
2444
|
+
block: true
|
|
2445
|
+
};
|
|
2446
|
+
const next = projection.indexOf("/**", closing + 2);
|
|
2447
|
+
const gap = line.source.slice(closing + 2, next < 0 ? line.source.length : next).trim() === "";
|
|
2448
|
+
if (next < 0) return {
|
|
2449
|
+
...current,
|
|
2450
|
+
span,
|
|
2451
|
+
block: false,
|
|
2452
|
+
pending: current.eligible && gap ? normalizeComment(span.join("\n")) : void 0
|
|
2453
|
+
};
|
|
2454
|
+
return {
|
|
2455
|
+
...current,
|
|
2456
|
+
span,
|
|
2457
|
+
block: false,
|
|
2458
|
+
eligible: current.eligible && gap
|
|
2459
|
+
};
|
|
2460
|
+
}, {
|
|
2461
|
+
...state,
|
|
2462
|
+
block: false,
|
|
2463
|
+
eligible
|
|
2464
|
+
});
|
|
2465
|
+
}, {
|
|
2466
|
+
block: false,
|
|
2467
|
+
eligible: false,
|
|
2468
|
+
span: [],
|
|
2469
|
+
pending: void 0
|
|
2470
|
+
});
|
|
2012
2471
|
return comments;
|
|
2013
2472
|
}
|
|
2014
2473
|
/**
|
|
@@ -2107,28 +2566,24 @@ function extractBodyLines(lines) {
|
|
|
2107
2566
|
* ```
|
|
2108
2567
|
*/
|
|
2109
2568
|
function collectKeys(lines) {
|
|
2110
|
-
const keys =
|
|
2111
|
-
|
|
2112
|
-
for (const line of lines) {
|
|
2569
|
+
const keys = [];
|
|
2570
|
+
Iterator.from(lines).reduce((owner, line) => {
|
|
2113
2571
|
const head = /^export (?:async )?(?:abstract )?(function\*?|class|const|interface|type) (\w+)/.exec(line.code);
|
|
2114
2572
|
const keyword = head?.[1]?.replace(/\*$/, "");
|
|
2115
2573
|
const name = head?.[2];
|
|
2116
2574
|
if (isNonEmptyString(keyword) && isNonEmptyString(name) && isExportKeyword(keyword)) {
|
|
2117
|
-
keys.
|
|
2575
|
+
keys.push([line, computeSymbolKey({
|
|
2118
2576
|
name,
|
|
2119
2577
|
keyword
|
|
2120
|
-
}));
|
|
2121
|
-
|
|
2122
|
-
continue;
|
|
2123
|
-
}
|
|
2124
|
-
if (line.code === "}") {
|
|
2125
|
-
owner = void 0;
|
|
2126
|
-
continue;
|
|
2578
|
+
})]);
|
|
2579
|
+
return keyword === "class" || keyword === "interface" ? name : void 0;
|
|
2127
2580
|
}
|
|
2581
|
+
if (line.code === "}") return void 0;
|
|
2128
2582
|
const member = /^\t(?:async )?\*?(\w+)\??(?:<.*>)?\(/.exec(line.code)?.[1];
|
|
2129
|
-
if (owner !== void 0 && isNonEmptyString(member)) keys.
|
|
2130
|
-
|
|
2131
|
-
|
|
2583
|
+
if (owner !== void 0 && isNonEmptyString(member)) keys.push([line, `${owner}.${member}`]);
|
|
2584
|
+
return owner;
|
|
2585
|
+
}, void 0);
|
|
2586
|
+
return new Map(keys);
|
|
2132
2587
|
}
|
|
2133
2588
|
/**
|
|
2134
2589
|
* Collects the `@example` blocks one doc block's unwrapped text carries, each named for the
|
|
@@ -2149,9 +2604,7 @@ function collectKeys(lines) {
|
|
|
2149
2604
|
function collectExamples(comment, name) {
|
|
2150
2605
|
const examples = [];
|
|
2151
2606
|
const masked = maskFences(comment);
|
|
2152
|
-
const
|
|
2153
|
-
let tag;
|
|
2154
|
-
while ((tag = tags.exec(masked)) !== null) {
|
|
2607
|
+
for (const tag of masked.matchAll(/^[ \t]*@example(?=[ \t]|$)[ \t]*(.*)$/gm)) {
|
|
2155
2608
|
const title = (tag[1] ?? "").trim();
|
|
2156
2609
|
const start = tag.index + tag[0].length;
|
|
2157
2610
|
const rest = comment.slice(start).replace(/^\n/, "");
|
|
@@ -2276,20 +2729,17 @@ function extractFences(document) {
|
|
|
2276
2729
|
* ```
|
|
2277
2730
|
*/
|
|
2278
2731
|
function collectFences(document) {
|
|
2279
|
-
const fences =
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
if (
|
|
2283
|
-
title = flattenText(node).trim();
|
|
2284
|
-
continue;
|
|
2285
|
-
}
|
|
2286
|
-
if (isCodeBlockNode(node)) fences.set(node, {
|
|
2732
|
+
const fences = [];
|
|
2733
|
+
Iterator.from(walkNodes(document)).reduce((title, node) => {
|
|
2734
|
+
if (isHeadingNode(node)) return flattenText(node).trim();
|
|
2735
|
+
if (isCodeBlockNode(node)) fences.push([node, {
|
|
2287
2736
|
language: node.lang,
|
|
2288
2737
|
code: node.code,
|
|
2289
2738
|
...title.length === 0 ? {} : { title }
|
|
2290
|
-
});
|
|
2291
|
-
|
|
2292
|
-
|
|
2739
|
+
}]);
|
|
2740
|
+
return title;
|
|
2741
|
+
}, "");
|
|
2742
|
+
return new Map(fences);
|
|
2293
2743
|
}
|
|
2294
2744
|
/**
|
|
2295
2745
|
* Extracts the guide's tagline — the text of the blockquote following the document's H1,
|
|
@@ -2305,17 +2755,30 @@ function collectFences(document) {
|
|
|
2305
2755
|
* ```
|
|
2306
2756
|
*/
|
|
2307
2757
|
function extractTagline(document) {
|
|
2308
|
-
|
|
2758
|
+
const scanned = [];
|
|
2309
2759
|
for (const block of document.children) {
|
|
2760
|
+
const opened = scanned.at(-1)?.opened ?? false;
|
|
2310
2761
|
if (isHeadingNode(block)) {
|
|
2311
|
-
if (opened)
|
|
2312
|
-
|
|
2762
|
+
if (opened) break;
|
|
2763
|
+
scanned.push({
|
|
2764
|
+
block,
|
|
2765
|
+
opened: block.level === 1,
|
|
2766
|
+
selected: void 0
|
|
2767
|
+
});
|
|
2313
2768
|
continue;
|
|
2314
2769
|
}
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2770
|
+
const selected = opened && isBlockquoteNode(block) ? block : void 0;
|
|
2771
|
+
scanned.push({
|
|
2772
|
+
block,
|
|
2773
|
+
opened,
|
|
2774
|
+
selected
|
|
2775
|
+
});
|
|
2776
|
+
if (selected !== void 0) break;
|
|
2318
2777
|
}
|
|
2778
|
+
const selected = scanned.find((entry) => entry.selected !== void 0)?.selected;
|
|
2779
|
+
if (selected === void 0) return void 0;
|
|
2780
|
+
const text = normalizeSummary(selected.children.filter(isParagraphNode).map((paragraph) => extractCellText(paragraph.children)).join(" "));
|
|
2781
|
+
return text.length === 0 ? void 0 : text;
|
|
2319
2782
|
}
|
|
2320
2783
|
/**
|
|
2321
2784
|
* Computes the drift between one compared key's guide text and source text. A pair agrees
|
|
@@ -2426,8 +2889,9 @@ function formatDrift(drift) {
|
|
|
2426
2889
|
}
|
|
2427
2890
|
/**
|
|
2428
2891
|
* Finds every disagreement between a guide and the source it documents, naming both sites:
|
|
2429
|
-
* each `## Surface` row against its declaration's description paragraph, each
|
|
2430
|
-
*
|
|
2892
|
+
* each `## Surface` row against its declaration's description paragraph, each present
|
|
2893
|
+
* `Signature` cell against the declaration's computed signature written as a code span, each
|
|
2894
|
+
* `## Methods` row against its member's, and the first titled guide fence of a heading against the
|
|
2431
2895
|
* `@example` block of the same title. An example's compared text is its language on the first
|
|
2432
2896
|
* line and its body beneath, so a fence that names another language drifts on its own.
|
|
2433
2897
|
*
|
|
@@ -2438,11 +2902,14 @@ function formatDrift(drift) {
|
|
|
2438
2902
|
* pair where one side carries none, and a pair where neither side carries text are all drift.
|
|
2439
2903
|
* The pairing is per title across the whole document, not per heading: the first fence a title
|
|
2440
2904
|
* reaches is the compared one, and every later fence of that title is outside the comparison,
|
|
2441
|
-
* whether it sits under the same heading or under a second heading of the same text.
|
|
2905
|
+
* whether it sits under the same heading or under a second heading of the same text. A signature
|
|
2906
|
+
* is compared only when both sides carry one, so an H3 entity heading, which carries no cell, and
|
|
2907
|
+
* a source reflected without emitted declarations stay outside that comparison.
|
|
2442
2908
|
*
|
|
2443
2909
|
* @param guide - The parsed guide
|
|
2444
2910
|
* @param source - The reflected source the guide documents
|
|
2445
|
-
* @returns One entry per disagreement: Surface
|
|
2911
|
+
* @returns One entry per disagreement: each Surface row's summary then signature, then Methods
|
|
2912
|
+
* rows, then examples
|
|
2446
2913
|
*
|
|
2447
2914
|
* @example
|
|
2448
2915
|
* ```ts
|
|
@@ -2458,6 +2925,13 @@ function findDrift(guide, source) {
|
|
|
2458
2925
|
if (match === void 0) continue;
|
|
2459
2926
|
const drift = computeDrift(key, "summary", symbol.summary, match.summary);
|
|
2460
2927
|
if (drift !== void 0) drifts.push(drift);
|
|
2928
|
+
if (symbol.signature === void 0 || match.signature === void 0) continue;
|
|
2929
|
+
const computed = normalizeSummary(extractCellText([{
|
|
2930
|
+
element: "codeSpan",
|
|
2931
|
+
value: match.signature
|
|
2932
|
+
}]));
|
|
2933
|
+
const signed = computeDrift(key, "signature", symbol.signature, computed);
|
|
2934
|
+
if (signed !== void 0) drifts.push(signed);
|
|
2461
2935
|
}
|
|
2462
2936
|
for (const group of guide.methods()) {
|
|
2463
2937
|
const members = new Map(source.methods(group.interface).map((entry) => [entry.name, entry]));
|
|
@@ -2505,26 +2979,26 @@ function collectTitles(guide, source) {
|
|
|
2505
2979
|
return titled;
|
|
2506
2980
|
}
|
|
2507
2981
|
/**
|
|
2508
|
-
* Builds a copy of `table` with one cell's inline content
|
|
2509
|
-
*
|
|
2510
|
-
*
|
|
2982
|
+
* Builds a copy of `table` with one cell's inline content replaced by `cell`. Every other cell
|
|
2983
|
+
* keeps its own nodes, so a rewrite touches the one cell it names and the header and the
|
|
2984
|
+
* alignment row travel unchanged.
|
|
2511
2985
|
*
|
|
2512
2986
|
* @param table - The table to copy
|
|
2513
2987
|
* @param row - The index of the row to rewrite within {@link TableNode.rows}
|
|
2514
2988
|
* @param column - The index of the cell to rewrite within that row
|
|
2515
|
-
* @param
|
|
2989
|
+
* @param cell - The cell's new inline content, such as {@link buildCell} returns
|
|
2516
2990
|
* @returns The rewritten table
|
|
2517
2991
|
*
|
|
2518
2992
|
* @example
|
|
2519
2993
|
* ```ts
|
|
2520
|
-
* buildTable(table, 0,
|
|
2994
|
+
* buildTable(table, 0, 3, buildCell('Walks the tree.')).rows[0]?.[3] // [{ element: 'text', value: 'Walks the tree.' }]
|
|
2521
2995
|
* ```
|
|
2522
2996
|
*/
|
|
2523
|
-
function buildTable(table, row, column,
|
|
2997
|
+
function buildTable(table, row, column, cell) {
|
|
2524
2998
|
return {
|
|
2525
2999
|
element: "table",
|
|
2526
3000
|
header: table.header,
|
|
2527
|
-
rows: table.rows.map((cells, index) => index === row ? cells.map((
|
|
3001
|
+
rows: table.rows.map((cells, index) => index === row ? cells.map((current, position) => position === column ? cell : current) : cells),
|
|
2528
3002
|
align: table.align
|
|
2529
3003
|
};
|
|
2530
3004
|
}
|
|
@@ -2567,10 +3041,10 @@ function spliceSpan(source, span, replacement) {
|
|
|
2567
3041
|
return source.slice(0, span.start) + replacement + source.slice(span.end);
|
|
2568
3042
|
}
|
|
2569
3043
|
/**
|
|
2570
|
-
* Renders a
|
|
2571
|
-
*
|
|
2572
|
-
*
|
|
2573
|
-
*
|
|
3044
|
+
* Renders a uniform `Name | Kind | Signature | Summary` table with one row per symbol, the name
|
|
3045
|
+
* as a code span, the keyword as text, and the signature and summary through {@link buildCell}.
|
|
3046
|
+
* An absent signature or summary renders an empty cell, which {@link extractSurface} reads back
|
|
3047
|
+
* as absent. Guide construction refuses an empty signature cell.
|
|
2574
3048
|
*
|
|
2575
3049
|
* @remarks
|
|
2576
3050
|
* The render carries no `## Surface` heading, because a guide documents its surface in several
|
|
@@ -2585,7 +3059,7 @@ function spliceSpan(source, span, replacement) {
|
|
|
2585
3059
|
* @example
|
|
2586
3060
|
* ```ts
|
|
2587
3061
|
* renderSurface([{ name: 'walk', keyword: 'function', summary: 'Walks the tree.' }])
|
|
2588
|
-
* // '| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks the tree. |'
|
|
3062
|
+
* // '| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | | Walks the tree. |'
|
|
2589
3063
|
* ```
|
|
2590
3064
|
*/
|
|
2591
3065
|
function renderSurface(symbols) {
|
|
@@ -2594,12 +3068,16 @@ function renderSurface(symbols) {
|
|
|
2594
3068
|
header: [
|
|
2595
3069
|
[{
|
|
2596
3070
|
element: "text",
|
|
2597
|
-
value:
|
|
3071
|
+
value: NAME
|
|
2598
3072
|
}],
|
|
2599
3073
|
[{
|
|
2600
3074
|
element: "text",
|
|
2601
3075
|
value: KIND
|
|
2602
3076
|
}],
|
|
3077
|
+
[{
|
|
3078
|
+
element: "text",
|
|
3079
|
+
value: SIGNATURE
|
|
3080
|
+
}],
|
|
2603
3081
|
[{
|
|
2604
3082
|
element: "text",
|
|
2605
3083
|
value: SUMMARY
|
|
@@ -2614,9 +3092,11 @@ function renderSurface(symbols) {
|
|
|
2614
3092
|
element: "text",
|
|
2615
3093
|
value: symbol.keyword
|
|
2616
3094
|
}],
|
|
3095
|
+
buildCell(symbol.signature ?? ""),
|
|
2617
3096
|
buildCell(symbol.summary ?? "")
|
|
2618
3097
|
]),
|
|
2619
3098
|
align: [
|
|
3099
|
+
null,
|
|
2620
3100
|
null,
|
|
2621
3101
|
null,
|
|
2622
3102
|
null
|
|
@@ -2655,7 +3135,7 @@ function renderMethods(group) {
|
|
|
2655
3135
|
element: "table",
|
|
2656
3136
|
header: [[{
|
|
2657
3137
|
element: "text",
|
|
2658
|
-
value:
|
|
3138
|
+
value: NAME
|
|
2659
3139
|
}], [{
|
|
2660
3140
|
element: "text",
|
|
2661
3141
|
value: SUMMARY
|
|
@@ -2707,62 +3187,58 @@ function renderExample(example) {
|
|
|
2707
3187
|
/**
|
|
2708
3188
|
* Replaces one compared cell in a guide's text and returns the whole guide back. `key` names the
|
|
2709
3189
|
* row the way {@link findDrift} names it — a {@link computeSymbolKey} key for a `## Surface` row,
|
|
2710
|
-
* an `Owner.member` key for a `## Methods` row — and the row's
|
|
2711
|
-
* `
|
|
2712
|
-
* unchanged; a key reaching no cell returns `undefined`, and a row already carrying
|
|
2713
|
-
* returns the guide byte for byte.
|
|
3190
|
+
* an `Owner.member` key for a `## Methods` row — and the row's cell under the `column` header
|
|
3191
|
+
* becomes `cell`. Only the table's own source region is rewritten, so every byte outside it
|
|
3192
|
+
* travels unchanged; a key reaching no cell returns `undefined`, and a row already carrying that
|
|
3193
|
+
* cell returns the guide byte for byte.
|
|
2714
3194
|
*
|
|
2715
3195
|
* @remarks
|
|
2716
|
-
* A row the key does not reach, a table carrying no
|
|
2717
|
-
*
|
|
2718
|
-
*
|
|
2719
|
-
*
|
|
2720
|
-
*
|
|
2721
|
-
*
|
|
2722
|
-
* is a fixed point on the second run rather than a row rewritten forever. The
|
|
2723
|
-
* renders one-space padded whatever padding it carried, so the checkout's
|
|
3196
|
+
* A row the key does not reach, a table carrying no `column` header, and a document whose parse
|
|
3197
|
+
* recorded no region for the table are each a miss, and a miss returns `undefined` rather than
|
|
3198
|
+
* throwing, so a caller reports the key it could not place — the one meaning `undefined` carries
|
|
3199
|
+
* in every replacer here. A row already carrying `cell` returns the guide byte for byte, because
|
|
3200
|
+
* a rewrite would re-pad the whole table for no change; that identity reads both cells through
|
|
3201
|
+
* {@link extractCellText} and {@link normalizeSummary}, so a caller passing text the compared form
|
|
3202
|
+
* still moves is a fixed point on the second run rather than a row rewritten forever. The
|
|
3203
|
+
* rewritten table renders one-space padded whatever padding it carried, so the checkout's
|
|
3204
|
+
* formatter re-aligns it, and a code span renders with every `|` written `\|` and a longer
|
|
3205
|
+
* backtick fence when its text holds a backtick.
|
|
2724
3206
|
*
|
|
2725
3207
|
* @param guide - The guide's markdown source
|
|
2726
3208
|
* @param key - The compared key naming the row
|
|
2727
|
-
* @param
|
|
3209
|
+
* @param column - The header text of the column to write, {@link SUMMARY} or {@link SIGNATURE}
|
|
3210
|
+
* @param cell - The cell's new inline content, such as {@link buildCell} returns
|
|
2728
3211
|
* @returns The guide's text with that cell replaced, or `undefined` when the key reaches no cell
|
|
2729
3212
|
*
|
|
2730
3213
|
* @example
|
|
2731
3214
|
* ```ts
|
|
2732
|
-
* replaceCell('## Surface\n\n| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks. |', 'function walk', 'Walks a tree.')
|
|
2733
|
-
* // '## Surface\n\n| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks a tree. |'
|
|
3215
|
+
* replaceCell('## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | `() => void` | Walks. |', 'function walk', SUMMARY, buildCell('Walks a tree.'))
|
|
3216
|
+
* // '## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | `() => void` | Walks a tree. |'
|
|
2734
3217
|
* ```
|
|
2735
3218
|
*/
|
|
2736
|
-
function replaceCell(guide, key,
|
|
3219
|
+
function replaceCell(guide, key, column, cell) {
|
|
2737
3220
|
const markdown = createMarkdown(guide);
|
|
2738
3221
|
const document = markdown.document;
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
}
|
|
2758
|
-
}
|
|
2759
|
-
if (located === void 0) return void 0;
|
|
2760
|
-
const column = findColumnIndex(located, SUMMARY);
|
|
2761
|
-
if (column === void 0) return void 0;
|
|
2762
|
-
if ((extractRowSummary(located, index) ?? "") === normalizeSummary(summary)) return guide;
|
|
2763
|
-
const span = markdown.span(located);
|
|
3222
|
+
const surface = Iterator.from(selectSectionBlocks(document, SURFACE)).filter(isTableNode).flatMap((table) => table.rows.keys().map((index) => ({
|
|
3223
|
+
table,
|
|
3224
|
+
index,
|
|
3225
|
+
symbol: extractRowSymbol(table, index)
|
|
3226
|
+
}))).find((row) => row.symbol !== void 0 && computeSymbolKey(row.symbol) === key);
|
|
3227
|
+
const groups = collectGroups(document);
|
|
3228
|
+
const selected = surface ?? Iterator.from(groups).flatMap(([table, owner]) => table.rows.keys().map((index) => ({
|
|
3229
|
+
table,
|
|
3230
|
+
index,
|
|
3231
|
+
owner,
|
|
3232
|
+
entry: extractRowEntry(table, index)
|
|
3233
|
+
}))).find((row) => row.entry !== void 0 && `${row.owner}.${row.entry.name}` === key);
|
|
3234
|
+
if (selected === void 0) return void 0;
|
|
3235
|
+
const { table, index } = selected;
|
|
3236
|
+
const position = findColumnIndex(table, column);
|
|
3237
|
+
if (position === void 0) return void 0;
|
|
3238
|
+
if (normalizeSummary(extractCellText(table.rows[index]?.[position] ?? [])) === normalizeSummary(extractCellText(cell))) return guide;
|
|
3239
|
+
const span = markdown.span(table);
|
|
2764
3240
|
if (span === void 0) return void 0;
|
|
2765
|
-
return spliceSpan(guide, span, renderMarkdown(buildTable(
|
|
3241
|
+
return spliceSpan(guide, span, renderMarkdown(buildTable(table, index, position, cell)));
|
|
2766
3242
|
}
|
|
2767
3243
|
/**
|
|
2768
3244
|
* Replaces one titled fence in a guide's text and returns the whole guide back. The first fence
|
|
@@ -2791,14 +3267,9 @@ function replaceCell(guide, key, summary) {
|
|
|
2791
3267
|
*/
|
|
2792
3268
|
function replaceFence(guide, title, example) {
|
|
2793
3269
|
const markdown = createMarkdown(guide);
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
if (located !== void 0 || fence.title !== title) continue;
|
|
2798
|
-
located = node;
|
|
2799
|
-
current = fence;
|
|
2800
|
-
}
|
|
2801
|
-
if (located === void 0 || current === void 0) return void 0;
|
|
3270
|
+
const selected = Iterator.from(collectFences(markdown.document)).find(([, fence]) => fence.title === title);
|
|
3271
|
+
if (selected === void 0) return void 0;
|
|
3272
|
+
const [located, current] = selected;
|
|
2802
3273
|
if (current.code === example.code && current.language === example.language) return guide;
|
|
2803
3274
|
const span = markdown.span(located);
|
|
2804
3275
|
if (span === void 0) return void 0;
|
|
@@ -2848,9 +3319,7 @@ function replaceSummary(comment, summary, width = 100) {
|
|
|
2848
3319
|
const indent = /^[ \t]*/.exec(comment)?.[0] ?? "";
|
|
2849
3320
|
const wrapped = wrapText(summary, width - indent.length - 3);
|
|
2850
3321
|
if (wrapped.length === 0) return void 0;
|
|
2851
|
-
const
|
|
2852
|
-
let tag = -1;
|
|
2853
|
-
for (let index = 0; index < masked.length && tag < 0; index += 1) if (/^[ \t]*@\w/.test(masked[index] ?? "")) tag = index;
|
|
3322
|
+
const tag = maskFences(content.join("\n")).split("\n").findIndex((line) => /^[ \t]*@\w/.test(line));
|
|
2854
3323
|
if (normalizeSummary(content.slice(0, tag < 0 ? content.length : tag).join("\n")) === normalizeSummary(summary)) return comment;
|
|
2855
3324
|
const tail = tag < 0 ? [] : content.slice(tag);
|
|
2856
3325
|
if (tail.length === 0 && wrapped.length === 1 && content.length === 1) {
|
|
@@ -2906,17 +3375,17 @@ function replaceExample(comment, example) {
|
|
|
2906
3375
|
const content = unwrapComment(comment);
|
|
2907
3376
|
const masked = maskFences(content.join("\n")).split("\n");
|
|
2908
3377
|
const title = example.title ?? "";
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
}
|
|
3378
|
+
const start = masked.findIndex((line) => {
|
|
3379
|
+
const tag = /^[ \t]*@example(?=[ \t]|$)[ \t]*(.*)$/.exec(line);
|
|
3380
|
+
return tag !== null && (tag[1] ?? "").trim() === title;
|
|
3381
|
+
});
|
|
2914
3382
|
if (start < 0) return void 0;
|
|
2915
3383
|
const current = collectExamples(content.join("\n"), example.name).find((entry) => (entry.title ?? "") === title);
|
|
2916
3384
|
if (current !== void 0 && current.code === example.code && current.language === example.language) return comment;
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
3385
|
+
const next = masked.findIndex((line, index) => index > start && /^[ \t]*@\w/.test(line));
|
|
3386
|
+
const boundary = next < 0 ? content.length : next;
|
|
3387
|
+
const last = content.findLastIndex((line, index) => index > start && index < boundary && line.length > 0);
|
|
3388
|
+
const end = last < 0 ? start + 1 : last + 1;
|
|
2920
3389
|
const indent = /^[ \t]*/.exec(comment)?.[0] ?? "";
|
|
2921
3390
|
const body = [
|
|
2922
3391
|
`\`\`\`${example.language ?? ""}`,
|
|
@@ -2974,52 +3443,56 @@ function replaceExample(comment, example) {
|
|
|
2974
3443
|
function locateComment(text, key) {
|
|
2975
3444
|
const lines = extractSourceLines(text);
|
|
2976
3445
|
const keys = collectKeys(lines);
|
|
2977
|
-
const
|
|
2978
|
-
const
|
|
2979
|
-
|
|
2980
|
-
for (let index = 0; index < lines.length; index += 1) {
|
|
2981
|
-
const line = lines[index];
|
|
2982
|
-
if (line === void 0) continue;
|
|
2983
|
-
offsets.push(offset);
|
|
2984
|
-
positions.set(line, index);
|
|
3446
|
+
const records = [];
|
|
3447
|
+
for (const [index, line] of lines.entries()) {
|
|
3448
|
+
const offset = records.at(-1)?.next ?? 0;
|
|
2985
3449
|
const after = offset + line.source.length;
|
|
2986
|
-
|
|
3450
|
+
records.push({
|
|
3451
|
+
line,
|
|
3452
|
+
index,
|
|
3453
|
+
offset,
|
|
3454
|
+
next: after + (text.startsWith("\r\n", after) ? 2 : 1)
|
|
3455
|
+
});
|
|
2987
3456
|
}
|
|
3457
|
+
const offsets = records.map((record) => record.offset);
|
|
3458
|
+
const positions = new Map(records.map((record) => [record.line, record.index]));
|
|
2988
3459
|
for (const comment of extractSourceComments(lines)) {
|
|
2989
3460
|
if (keys.get(comment.line) !== key) continue;
|
|
2990
3461
|
const close = (positions.get(comment.line) ?? 0) - 1;
|
|
2991
3462
|
const closing = lines[close]?.jsdoc;
|
|
2992
3463
|
const end = closing === void 0 ? -1 : closing.lastIndexOf("*/");
|
|
2993
3464
|
if (end < 0) continue;
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
let inside = false;
|
|
2997
|
-
let line = -1;
|
|
2998
|
-
let column = -1;
|
|
2999
|
-
for (let index = first; index <= close; index += 1) {
|
|
3465
|
+
const first = lines.keys().take(close).map((index) => close - index).find((index) => lines[index - 1]?.jsdoc === void 0) ?? 0;
|
|
3466
|
+
const found = Array.prototype.keys.call({ length: close - first + 1 }).map((distance) => first + distance).reduce((state, index) => {
|
|
3000
3467
|
const projection = lines[index]?.jsdoc ?? "";
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
line
|
|
3007
|
-
column
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3468
|
+
return Iterator.from(projection.matchAll(/(?=\/\*\*|\*\/)/g)).reduce((current, match) => {
|
|
3469
|
+
const at = match.index;
|
|
3470
|
+
if (at < current.cursor || !projection.startsWith(current.inside ? "*/" : "/**", at)) return current;
|
|
3471
|
+
return {
|
|
3472
|
+
inside: !current.inside,
|
|
3473
|
+
line: current.inside ? current.line : index,
|
|
3474
|
+
column: current.inside ? current.column : at,
|
|
3475
|
+
cursor: at + (current.inside ? 2 : 3)
|
|
3476
|
+
};
|
|
3477
|
+
}, {
|
|
3478
|
+
...state,
|
|
3479
|
+
cursor: 0
|
|
3480
|
+
});
|
|
3481
|
+
}, {
|
|
3482
|
+
inside: false,
|
|
3483
|
+
line: -1,
|
|
3484
|
+
column: -1,
|
|
3485
|
+
cursor: 0
|
|
3486
|
+
});
|
|
3487
|
+
if (found.line < 0) continue;
|
|
3488
|
+
const start = (lines[found.line]?.source ?? "").slice(0, found.column).trim() === "" ? 0 : found.column;
|
|
3015
3489
|
return {
|
|
3016
|
-
start: (offsets[line] ?? 0) + start,
|
|
3490
|
+
start: (offsets[found.line] ?? 0) + start,
|
|
3017
3491
|
end: (offsets[close] ?? 0) + end + 2
|
|
3018
3492
|
};
|
|
3019
3493
|
}
|
|
3020
3494
|
}
|
|
3021
|
-
|
|
3022
|
-
//#region src/core/parsers.ts
|
|
3495
|
+
// src/core/parsers.ts
|
|
3023
3496
|
/**
|
|
3024
3497
|
* Parses a `## By concept` manifest table into its {@link ManifestEntry} rows —
|
|
3025
3498
|
* each row's Concept cell (flattened text), Spec / Tests cells (a single link
|
|
@@ -3071,11 +3544,10 @@ function parseManifest(markdown, directory) {
|
|
|
3071
3544
|
}
|
|
3072
3545
|
return entries;
|
|
3073
3546
|
}
|
|
3074
|
-
|
|
3075
|
-
//#region src/core/shapers.ts
|
|
3547
|
+
// src/core/shapers.ts
|
|
3076
3548
|
/**
|
|
3077
3549
|
* Shapes a {@link SurfaceSymbol} — a documented / exported symbol's `name`
|
|
3078
|
-
* paired with its {@link ExportKeyword} and
|
|
3550
|
+
* paired with its {@link ExportKeyword}, optional `signature`, and optional compared `summary`.
|
|
3079
3551
|
*
|
|
3080
3552
|
* @example
|
|
3081
3553
|
* ```ts
|
|
@@ -3089,6 +3561,7 @@ function parseManifest(markdown, directory) {
|
|
|
3089
3561
|
var surfaceSymbolShape = objectShape({
|
|
3090
3562
|
name: stringShape(),
|
|
3091
3563
|
keyword: literalShape(EXPORT_KEYWORDS),
|
|
3564
|
+
signature: optionalShape(stringShape()),
|
|
3092
3565
|
summary: optionalShape(stringShape())
|
|
3093
3566
|
});
|
|
3094
3567
|
/**
|
|
@@ -3182,8 +3655,7 @@ var manifestEntryShape = objectShape({
|
|
|
3182
3655
|
source: unionShape(stringShape(), arrayShape(stringShape())),
|
|
3183
3656
|
tests: stringShape()
|
|
3184
3657
|
});
|
|
3185
|
-
|
|
3186
|
-
//#region src/core/Guide.ts
|
|
3658
|
+
// src/core/Guide.ts
|
|
3187
3659
|
/**
|
|
3188
3660
|
* Presents a pure, structured view over one parsed guide — the documented
|
|
3189
3661
|
* projections (`sections` / `tagline` / `surface` / `methods` / `unnamed` / `links` /
|
|
@@ -3193,14 +3665,16 @@ var manifestEntryShape = objectShape({
|
|
|
3193
3665
|
* Parses `source` once through `@orkestrel/markdown` and never touches the
|
|
3194
3666
|
* filesystem — `Guide` reads only the markdown text it is given and records
|
|
3195
3667
|
* nothing about where the guide came from. Every accessor returns the same
|
|
3196
|
-
* cached, readonly array on every call.
|
|
3668
|
+
* cached, readonly array on every call. Before caching, refuses the first Surface table with
|
|
3669
|
+
* a header other than `Name | Kind | Signature | Summary` or a keyed empty Signature cell,
|
|
3670
|
+
* through {@link validateSurface}.
|
|
3197
3671
|
*
|
|
3198
3672
|
* @example
|
|
3199
3673
|
* ```ts
|
|
3200
3674
|
* import { Guide } from '@orkestrel/guide'
|
|
3201
3675
|
*
|
|
3202
|
-
* const guide = new Guide('## Surface\n\n| Name | Kind |\n| --- | --- |\n| `X` | class |')
|
|
3203
|
-
* guide.surface() // [{ name: 'X', keyword: 'class' }]
|
|
3676
|
+
* const guide = new Guide('## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `X` | class | `new () => X` | |')
|
|
3677
|
+
* guide.surface() // [{ name: 'X', keyword: 'class', signature: '`new () => X`' }]
|
|
3204
3678
|
* ```
|
|
3205
3679
|
*/
|
|
3206
3680
|
var Guide = class {
|
|
@@ -3214,6 +3688,7 @@ var Guide = class {
|
|
|
3214
3688
|
#fences;
|
|
3215
3689
|
constructor(source) {
|
|
3216
3690
|
const document = createMarkdown(source).document;
|
|
3691
|
+
validateSurface(document);
|
|
3217
3692
|
this.#sections = document.children.filter(isHeadingNode).filter((heading) => heading.level === 2).map((heading) => flattenText(heading).trim());
|
|
3218
3693
|
this.#tagline = extractTagline(document);
|
|
3219
3694
|
this.#surface = extractSurface(document);
|
|
@@ -3248,8 +3723,7 @@ var Guide = class {
|
|
|
3248
3723
|
return this.#fences;
|
|
3249
3724
|
}
|
|
3250
3725
|
};
|
|
3251
|
-
|
|
3252
|
-
//#region src/core/sources/Source.ts
|
|
3726
|
+
// src/core/sources/Source.ts
|
|
3253
3727
|
/**
|
|
3254
3728
|
* Reflects, as a pure `SourceInterface`, a module scope's intentional direct declarations,
|
|
3255
3729
|
* conventional barrel-reachable surface, and member methods over a consumer-supplied file
|
|
@@ -3315,12 +3789,15 @@ var Source = class {
|
|
|
3315
3789
|
#hidden;
|
|
3316
3790
|
#declarations;
|
|
3317
3791
|
#origins = /* @__PURE__ */ new Map();
|
|
3792
|
+
#emitted;
|
|
3793
|
+
#signed = /* @__PURE__ */ new Map();
|
|
3318
3794
|
constructor(options) {
|
|
3319
3795
|
this.#files = options.files;
|
|
3320
3796
|
this.#directories = normalizeDirectories(options.module);
|
|
3797
|
+
this.#emitted = options.declarations;
|
|
3321
3798
|
}
|
|
3322
3799
|
exports() {
|
|
3323
|
-
if (this.#exports === void 0) this.#exports = this.#scanSymbols(
|
|
3800
|
+
if (this.#exports === void 0) this.#exports = this.#scanSymbols((key, text) => this.#scanExports(key, text));
|
|
3324
3801
|
return this.#exports;
|
|
3325
3802
|
}
|
|
3326
3803
|
surface() {
|
|
@@ -3338,7 +3815,7 @@ var Source = class {
|
|
|
3338
3815
|
return Object.keys(this.#files).some((key) => key === relative || key.startsWith(`${relative}/`));
|
|
3339
3816
|
}
|
|
3340
3817
|
hidden() {
|
|
3341
|
-
if (this.#hidden === void 0) this.#hidden = this.#scanSymbols(extractHidden);
|
|
3818
|
+
if (this.#hidden === void 0) this.#hidden = this.#scanSymbols((_key, text) => extractHidden(text));
|
|
3342
3819
|
return this.#hidden;
|
|
3343
3820
|
}
|
|
3344
3821
|
examples(name) {
|
|
@@ -3404,7 +3881,7 @@ var Source = class {
|
|
|
3404
3881
|
visited.add(path);
|
|
3405
3882
|
const text = this.#files[path];
|
|
3406
3883
|
if (text === void 0) continue;
|
|
3407
|
-
for (const symbol of
|
|
3884
|
+
for (const symbol of this.#scanExports(path, text)) {
|
|
3408
3885
|
const identity = computeSymbolKey(symbol);
|
|
3409
3886
|
if (seen.has(identity)) continue;
|
|
3410
3887
|
seen.add(identity);
|
|
@@ -3427,7 +3904,7 @@ var Source = class {
|
|
|
3427
3904
|
for (const key of selectModuleKeys(this.#files, this.#directories)) {
|
|
3428
3905
|
const text = this.#files[key];
|
|
3429
3906
|
if (text === void 0) continue;
|
|
3430
|
-
for (const symbol of scan(text)) {
|
|
3907
|
+
for (const symbol of scan(key, text)) {
|
|
3431
3908
|
const identity = computeSymbolKey(symbol);
|
|
3432
3909
|
if (seen.has(identity)) continue;
|
|
3433
3910
|
seen.add(identity);
|
|
@@ -3436,6 +3913,23 @@ var Source = class {
|
|
|
3436
3913
|
}
|
|
3437
3914
|
return symbols.sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
|
|
3438
3915
|
}
|
|
3916
|
+
#scanExports(key, text) {
|
|
3917
|
+
const cached = this.#signed.get(key);
|
|
3918
|
+
if (cached !== void 0) return cached;
|
|
3919
|
+
const declaration = this.#emitted?.[`${key.slice(0, -3)}.d.ts`];
|
|
3920
|
+
const signatures = new Map((declaration === void 0 ? [] : extractSignatures(declaration)).map((symbol) => [computeSymbolKey(symbol), symbol.signature]));
|
|
3921
|
+
const symbols = extractExports(text).map((symbol) => {
|
|
3922
|
+
const signature = signatures.get(computeSymbolKey(symbol));
|
|
3923
|
+
return signature === void 0 ? symbol : {
|
|
3924
|
+
name: symbol.name,
|
|
3925
|
+
keyword: symbol.keyword,
|
|
3926
|
+
signature,
|
|
3927
|
+
...symbol.summary === void 0 ? {} : { summary: symbol.summary }
|
|
3928
|
+
};
|
|
3929
|
+
});
|
|
3930
|
+
this.#signed.set(key, symbols);
|
|
3931
|
+
return symbols;
|
|
3932
|
+
}
|
|
3439
3933
|
#members(keyword, name, visited) {
|
|
3440
3934
|
if (visited.has(name)) return [];
|
|
3441
3935
|
visited.add(name);
|
|
@@ -3468,8 +3962,7 @@ var Source = class {
|
|
|
3468
3962
|
return declarations;
|
|
3469
3963
|
}
|
|
3470
3964
|
};
|
|
3471
|
-
|
|
3472
|
-
//#region src/core/sources/SourceManager.ts
|
|
3965
|
+
// src/core/sources/SourceManager.ts
|
|
3473
3966
|
/**
|
|
3474
3967
|
* Resolves a consumer-owned import-specifier policy into pure source views and
|
|
3475
3968
|
* caches those views by module, so aliases for one module share one entity.
|
|
@@ -3523,8 +4016,7 @@ var SourceManager = class {
|
|
|
3523
4016
|
return views;
|
|
3524
4017
|
}
|
|
3525
4018
|
};
|
|
3526
|
-
|
|
3527
|
-
//#region src/core/Parity.ts
|
|
4019
|
+
// src/core/Parity.ts
|
|
3528
4020
|
/**
|
|
3529
4021
|
* Composes generic guide-parity inspection and explicit in-memory rewrites over a caller inventory.
|
|
3530
4022
|
*/
|
|
@@ -3538,7 +4030,8 @@ var Parity = class Parity {
|
|
|
3538
4030
|
modules: { ...options.modules },
|
|
3539
4031
|
languages: [...options.languages],
|
|
3540
4032
|
language: options.language,
|
|
3541
|
-
...options.pitch === void 0 ? {} : { pitch: { ...options.pitch } }
|
|
4033
|
+
...options.pitch === void 0 ? {} : { pitch: { ...options.pitch } },
|
|
4034
|
+
...options.declarations === void 0 ? {} : { declarations: { ...options.declarations } }
|
|
3542
4035
|
};
|
|
3543
4036
|
this.#rows = this.#createRows(this.#options.files);
|
|
3544
4037
|
}
|
|
@@ -3639,17 +4132,31 @@ var Parity = class Parity {
|
|
|
3639
4132
|
for (const entry of this.#options.entries) {
|
|
3640
4133
|
const text = files[entry.spec];
|
|
3641
4134
|
if (text === void 0) continue;
|
|
4135
|
+
const guide = this.#attribute(entry.spec, () => new Guide(text));
|
|
4136
|
+
this.#attribute(entry.spec, () => validateModules(files, entry.source));
|
|
3642
4137
|
rows.push({
|
|
3643
4138
|
entry,
|
|
3644
|
-
guide
|
|
4139
|
+
guide,
|
|
3645
4140
|
source: new Source({
|
|
3646
4141
|
files,
|
|
3647
|
-
module: entry.source
|
|
4142
|
+
module: entry.source,
|
|
4143
|
+
...this.#options.declarations === void 0 ? {} : { declarations: this.#options.declarations }
|
|
3648
4144
|
})
|
|
3649
4145
|
});
|
|
3650
4146
|
}
|
|
3651
4147
|
return rows;
|
|
3652
4148
|
}
|
|
4149
|
+
#attribute(spec, step) {
|
|
4150
|
+
try {
|
|
4151
|
+
return step();
|
|
4152
|
+
} catch (error) {
|
|
4153
|
+
if (!isGuideError(error)) throw error;
|
|
4154
|
+
throw new GuideError(`${JSON.stringify(spec.slice(0, 200))}: ${error.message}`, error.code, {
|
|
4155
|
+
cause: error,
|
|
4156
|
+
...error.context === void 0 ? {} : { context: error.context }
|
|
4157
|
+
});
|
|
4158
|
+
}
|
|
4159
|
+
}
|
|
3653
4160
|
#inspectInput(findings) {
|
|
3654
4161
|
if (this.#options.entries.length === 0) findings.push({ text: "The manifest has no guide entries." });
|
|
3655
4162
|
for (const entry of this.#options.entries) {
|
|
@@ -3824,21 +4331,19 @@ var Parity = class Parity {
|
|
|
3824
4331
|
files: this.#options.files,
|
|
3825
4332
|
modules: this.#options.modules
|
|
3826
4333
|
});
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
for (const imported of extractFenceImports(fence.code)) {
|
|
4334
|
+
if (!Iterator.from(row.guide.fences()).reduce((previous, fence) => {
|
|
4335
|
+
if (fence.language !== this.#options.language) return previous;
|
|
4336
|
+
return Iterator.from(extractFenceImports(fence.code)).reduce((matched, imported) => {
|
|
3831
4337
|
const source = sources.source(imported.specifier);
|
|
3832
|
-
if (source === void 0)
|
|
3833
|
-
compared = true;
|
|
4338
|
+
if (source === void 0) return matched;
|
|
3834
4339
|
const surface = source.surface().map((symbol) => symbol.name);
|
|
3835
4340
|
for (const name of findMissing(imported.names, surface)) findings.push({
|
|
3836
4341
|
spec: row.entry.spec,
|
|
3837
4342
|
text: `${row.entry.spec} imports missing ${name} from ${imported.specifier}.`
|
|
3838
4343
|
});
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
4344
|
+
return true;
|
|
4345
|
+
}, previous);
|
|
4346
|
+
}, false)) findings.push({
|
|
3842
4347
|
spec: row.entry.spec,
|
|
3843
4348
|
text: `${row.entry.spec} has no mapped self import.`
|
|
3844
4349
|
});
|
|
@@ -3868,8 +4373,8 @@ var Parity = class Parity {
|
|
|
3868
4373
|
});
|
|
3869
4374
|
return;
|
|
3870
4375
|
}
|
|
3871
|
-
const left = new Guide(readme).tagline();
|
|
3872
|
-
const right = new Guide(spec).tagline();
|
|
4376
|
+
const left = this.#attribute(pitch.readme, () => new Guide(readme)).tagline();
|
|
4377
|
+
const right = this.#attribute(pitch.spec, () => new Guide(spec)).tagline();
|
|
3873
4378
|
if (left !== void 0 && left === right) return;
|
|
3874
4379
|
findings.push({
|
|
3875
4380
|
spec: pitch.spec,
|
|
@@ -3881,11 +4386,22 @@ var Parity = class Parity {
|
|
|
3881
4386
|
const current = files.get(row.entry.spec);
|
|
3882
4387
|
if (current === void 0) return "the guide inventory text is absent";
|
|
3883
4388
|
if (drift.category === "summary") {
|
|
3884
|
-
const replacement = replaceCell(current, drift.key, drift.source);
|
|
4389
|
+
const replacement = replaceCell(current, drift.key, SUMMARY, buildCell(drift.source));
|
|
3885
4390
|
if (replacement === void 0) return "the guide summary cell or its provenance is unavailable";
|
|
3886
4391
|
files.set(row.entry.spec, replacement);
|
|
3887
4392
|
return;
|
|
3888
4393
|
}
|
|
4394
|
+
if (drift.category === "signature") {
|
|
4395
|
+
const signature = row.source.surface().find((symbol) => computeSymbolKey(symbol) === drift.key)?.signature;
|
|
4396
|
+
if (signature === void 0) return "the computed signature is unavailable";
|
|
4397
|
+
const replacement = replaceCell(current, drift.key, SIGNATURE, [{
|
|
4398
|
+
element: "codeSpan",
|
|
4399
|
+
value: signature
|
|
4400
|
+
}]);
|
|
4401
|
+
if (replacement === void 0) return "the guide signature cell or its provenance is unavailable";
|
|
4402
|
+
files.set(row.entry.spec, replacement);
|
|
4403
|
+
return;
|
|
4404
|
+
}
|
|
3889
4405
|
const example = collectTitles(row.guide, row.source).get(drift.key);
|
|
3890
4406
|
if (example === void 0) return "the paired source example is unavailable";
|
|
3891
4407
|
const replacement = replaceFence(current, drift.key, example);
|
|
@@ -3893,6 +4409,7 @@ var Parity = class Parity {
|
|
|
3893
4409
|
files.set(row.entry.spec, replacement);
|
|
3894
4410
|
}
|
|
3895
4411
|
#rewriteSource(row, drift, files) {
|
|
4412
|
+
if (drift.category === "signature") return "a signature is computed from the source declaration";
|
|
3896
4413
|
if (drift.guide === void 0) return "guide authority is absent";
|
|
3897
4414
|
if (drift.category === "summary") {
|
|
3898
4415
|
const located = this.#locateSource(row.entry, drift.key, files);
|
|
@@ -3940,17 +4457,16 @@ var Parity = class Parity {
|
|
|
3940
4457
|
for (const path of selectModuleKeys(inventory, normalizeDirectories(row.entry.source))) {
|
|
3941
4458
|
const text = files.get(path);
|
|
3942
4459
|
if (text === void 0) continue;
|
|
3943
|
-
|
|
3944
|
-
for (const key of keys) {
|
|
4460
|
+
const selected = keys.reduce((previous, key) => {
|
|
3945
4461
|
const span = locateComment(text, key);
|
|
3946
|
-
if (span === void 0)
|
|
4462
|
+
if (span === void 0) return previous;
|
|
3947
4463
|
const example = collectExamples(normalizeComment(text.slice(span.start, span.end)), target.name).find((entry) => entry.title === title);
|
|
3948
|
-
if (example === void 0)
|
|
3949
|
-
|
|
4464
|
+
if (example === void 0) return previous;
|
|
4465
|
+
return previous === void 0 || span.start < previous.span.start ? {
|
|
3950
4466
|
span,
|
|
3951
4467
|
example
|
|
3952
|
-
};
|
|
3953
|
-
}
|
|
4468
|
+
} : previous;
|
|
4469
|
+
}, void 0);
|
|
3954
4470
|
if (selected !== void 0) return {
|
|
3955
4471
|
path,
|
|
3956
4472
|
text,
|
|
@@ -3959,8 +4475,7 @@ var Parity = class Parity {
|
|
|
3959
4475
|
}
|
|
3960
4476
|
}
|
|
3961
4477
|
};
|
|
3962
|
-
|
|
3963
|
-
//#region src/core/factories.ts
|
|
4478
|
+
// src/core/factories.ts
|
|
3964
4479
|
/**
|
|
3965
4480
|
* Creates a structured {@link GuideInterface} view over one guide's markdown
|
|
3966
4481
|
* source — parses once and caches its `sections` / `surface` / `methods` /
|
|
@@ -3968,13 +4483,16 @@ var Parity = class Parity {
|
|
|
3968
4483
|
*
|
|
3969
4484
|
* @param source - The guide's markdown source text
|
|
3970
4485
|
* @returns A working {@link GuideInterface}
|
|
4486
|
+
* @throws {@link GuideError} when a Surface header is nonuniform or a keyed Signature cell is empty.
|
|
3971
4487
|
*
|
|
3972
4488
|
* @example Construct a Guide from markdown text
|
|
3973
4489
|
* ```ts
|
|
3974
4490
|
* import { createGuide } from '@orkestrel/guide'
|
|
3975
4491
|
*
|
|
3976
|
-
* const guide = createGuide(
|
|
3977
|
-
*
|
|
4492
|
+
* const guide = createGuide(
|
|
4493
|
+
* '## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `X` | class | `new () => X` | |',
|
|
4494
|
+
* )
|
|
4495
|
+
* guide.surface() // [{ name: 'X', keyword: 'class', signature: '`new () => X`' }]
|
|
3978
4496
|
* guide.sections() // ['Surface']
|
|
3979
4497
|
* ```
|
|
3980
4498
|
*/
|
|
@@ -4146,7 +4664,6 @@ function createMethodGroupContract() {
|
|
|
4146
4664
|
function createManifestEntryContract() {
|
|
4147
4665
|
return createContract(manifestEntryShape);
|
|
4148
4666
|
}
|
|
4149
|
-
|
|
4150
|
-
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, hasBehaviouralSurface, 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 };
|
|
4667
|
+
export { DRIFT_CATEGORIES, EXPORT_KEYWORDS, EXTERNAL_SCHEMES, GUIDE_CODES, GUIDE_ERROR_BRAND, Guide, GuideError, KIND, MANIFEST, METHODS, NAME, Parity, SIGNATURE, SUMMARY, SURFACE, SURFACE_HEADER, Source, SourceManager, TESTS, WRAP_WIDTH, buildCell, buildComment, buildFence, buildTable, collectDeclarations, collectExamples, collectFences, collectGroups, collectKeys, collectSummaries, collectTitles, compareMembership, computeDepths, 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, extractSignature, extractSignatures, extractSourceComments, extractSourceLines, extractSurface, extractTagline, extractTests, extractUnnamed, findClosing, findColumnIndex, findDrift, findFirstCode, findMissing, findMissingSymbols, findSeparators, findUnexampled, findUnlisted, formatDrift, formatSide, hasBehaviouralSurface, hasCanonicalSegments, identifyDrift, isDrift, isDriftCategory, isExportKeyword, isExternalLink, isGuideError, isManifestEntry, isMethodEntry, isMethodGroup, isSourceExample, isSurfaceSymbol, joinHead, locateComment, manifestEntryShape, maskFences, methodEntryShape, methodGroupShape, normalizeComment, normalizeDirectories, normalizeIdentifier, normalizeSummary, parseManifest, renderExample, renderMember, renderMethods, renderSurface, replaceCell, replaceExample, replaceFence, replaceSummary, resolveLink, resolvePath, selectModuleKeys, selectSectionBlocks, sourceExampleShape, spliceSpan, surfaceSymbolShape, unwrapComment, validateModules, validateSurface, wrapText };
|
|
4151
4668
|
|
|
4152
4669
|
//# sourceMappingURL=index.js.map
|