@orkestrel/guide 0.0.21 → 0.0.23
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 +52 -9
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +31 -5
- package/dist/src/core/index.d.ts +31 -5
- package/dist/src/core/index.js +52 -10
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +51 -9
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.js +51 -9
- package/dist/src/server/index.js.map +1 -1
- package/package.json +7 -7
package/dist/src/core/index.cjs
CHANGED
|
@@ -852,6 +852,23 @@ function findMissingSymbols(symbols, source) {
|
|
|
852
852
|
return findMissing(symbols.map(computeSymbolKey), source.map(computeSymbolKey));
|
|
853
853
|
}
|
|
854
854
|
/**
|
|
855
|
+
* Checks whether a source declares at least one behavioural member — a `class` or `interface`
|
|
856
|
+
* in its surface that carries a call-signature member — so a guide owes a `## Methods` group only
|
|
857
|
+
* where the source has one to document.
|
|
858
|
+
*
|
|
859
|
+
* @param source - The reflected source under parity
|
|
860
|
+
* @returns True if a surface `class` or `interface` declares a member; false otherwise
|
|
861
|
+
*
|
|
862
|
+
* @example
|
|
863
|
+
* ```ts
|
|
864
|
+
* hasBehaviouralSurface(createSource({ files: { 'src/types.ts': 'export interface Widget { render(): void }' }, module: 'src' })) // true
|
|
865
|
+
* hasBehaviouralSurface(createSource({ files: { 'src/constants.ts': 'export const NAMES = Object.freeze({})' }, module: 'src' })) // false
|
|
866
|
+
* ```
|
|
867
|
+
*/
|
|
868
|
+
function hasBehaviouralSurface(source) {
|
|
869
|
+
return source.surface().some((symbol) => (symbol.keyword === "class" || symbol.keyword === "interface") && source.methods(symbol.name).length > 0);
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
855
872
|
* Finds the names in `names` that have no example — a fence containing the name at a
|
|
856
873
|
* word boundary in `fences`, or a membership in `examples`, both count as
|
|
857
874
|
* "has an example"; presence-only, fence and JSDoc content are never checked.
|
|
@@ -1229,7 +1246,14 @@ function extractHidden(source) {
|
|
|
1229
1246
|
}
|
|
1230
1247
|
/**
|
|
1231
1248
|
* Joins the declaration head starting at `start` into one space-separated
|
|
1232
|
-
* line, consuming lines until the first that ends with
|
|
1249
|
+
* line, consuming lines until the first that opens a body: one that ends with
|
|
1250
|
+
* `{`, or one that closes an empty body with `{}` or `{ }`.
|
|
1251
|
+
*
|
|
1252
|
+
* @remarks
|
|
1253
|
+
* A line ending with `{}` closes an empty body only when every angle, round,
|
|
1254
|
+
* and square bracket the head opened outside quoted text has closed; inside
|
|
1255
|
+
* one, `{}` is a type or an argument, and an arrow's `=>` closes nothing. A
|
|
1256
|
+
* head that reaches the next column-zero `export` line opens no body.
|
|
1233
1257
|
*
|
|
1234
1258
|
* @param lines - The file's source lines
|
|
1235
1259
|
* @param start - The index of the head's first line
|
|
@@ -1238,6 +1262,7 @@ function extractHidden(source) {
|
|
|
1238
1262
|
* @example
|
|
1239
1263
|
* ```ts
|
|
1240
1264
|
* joinHead(['export class X {'], 0) // { text: 'export class X {', end: 0 }
|
|
1265
|
+
* joinHead(['export interface Y extends X {}'], 0) // { text: 'export interface Y extends X {}', end: 0 }
|
|
1241
1266
|
* ```
|
|
1242
1267
|
*/
|
|
1243
1268
|
function joinHead(lines, start) {
|
|
@@ -1245,8 +1270,15 @@ function joinHead(lines, start) {
|
|
|
1245
1270
|
for (let index = start; index < lines.length; index += 1) {
|
|
1246
1271
|
const line = lines[index];
|
|
1247
1272
|
if (line === void 0) break;
|
|
1248
|
-
|
|
1249
|
-
if (
|
|
1273
|
+
const text = line.trimEnd();
|
|
1274
|
+
if (index > start && text.startsWith("export ")) return void 0;
|
|
1275
|
+
parts.push(index === start ? text : text.trimStart());
|
|
1276
|
+
if (text.endsWith("{")) return {
|
|
1277
|
+
text: parts.join(" "),
|
|
1278
|
+
end: index
|
|
1279
|
+
};
|
|
1280
|
+
const bare = parts.join(" ").replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g, "");
|
|
1281
|
+
if ((bare.match(/</g)?.length ?? 0) <= (bare.match(/(?<!=)>/g)?.length ?? 0) && (bare.match(/\(/g)?.length ?? 0) <= (bare.match(/\)/g)?.length ?? 0) && (bare.match(/\[/g)?.length ?? 0) <= (bare.match(/\]/g)?.length ?? 0) && /\{\s*\}$/.test(text)) return {
|
|
1250
1282
|
text: parts.join(" "),
|
|
1251
1283
|
end: index
|
|
1252
1284
|
};
|
|
@@ -1287,12 +1319,14 @@ function escapeRegExp(value) {
|
|
|
1287
1319
|
* optional heritage clause between the identifier and the opening `{`; the identifier is the head's
|
|
1288
1320
|
* own run up to that list or clause, so it enters the key as literal text and no name reaches a
|
|
1289
1321
|
* `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
|
|
1290
|
-
* keeping JSDoc evidence intact
|
|
1322
|
+
* keeping JSDoc evidence intact; a head whose last line closes its own body with `{}` or `{ }`
|
|
1323
|
+
* records an empty body. Every balanced `<...>` span is removed from the head before its
|
|
1291
1324
|
* `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
|
|
1292
1325
|
* reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
|
|
1293
1326
|
* qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
|
|
1294
1327
|
* a column-zero close answers for that key: a head that opens none records nothing, and a later
|
|
1295
|
-
* head of a key already collected adds nothing
|
|
1328
|
+
* head of a key already collected adds nothing unless the earlier head recorded neither a body
|
|
1329
|
+
* nor bases, which declares nothing as {@link Source} reads it, so the later head replaces it.
|
|
1296
1330
|
*
|
|
1297
1331
|
* @param source - The file's source text to read
|
|
1298
1332
|
* @returns One entry per collected declaration, keyed `${keyword} ${name}`
|
|
@@ -1306,7 +1340,7 @@ function escapeRegExp(value) {
|
|
|
1306
1340
|
function collectDeclarations(source) {
|
|
1307
1341
|
const declarations = /* @__PURE__ */ new Map();
|
|
1308
1342
|
const opener = /^export (?:class|interface) /;
|
|
1309
|
-
const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{
|
|
1343
|
+
const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{(?:\s*\})?$/;
|
|
1310
1344
|
const lines = extractSourceLines(source);
|
|
1311
1345
|
const projected = lines.map((line) => line.code);
|
|
1312
1346
|
for (let index = 0; index < projected.length; index += 1) {
|
|
@@ -1319,14 +1353,22 @@ function collectDeclarations(source) {
|
|
|
1319
1353
|
const name = declared?.[2];
|
|
1320
1354
|
if (keyword === void 0 || name === void 0) continue;
|
|
1321
1355
|
const key = `${keyword} ${name}`;
|
|
1322
|
-
|
|
1356
|
+
const known = declarations.get(key);
|
|
1357
|
+
if (known !== void 0 && (known.body.length > 0 || known.bases.length > 0)) continue;
|
|
1323
1358
|
let depth = 0;
|
|
1324
1359
|
let flat = "";
|
|
1325
|
-
for (const character of head.text.slice(`export ${key}`.length,
|
|
1360
|
+
for (const character of head.text.slice(`export ${key}`.length, head.text.lastIndexOf("{"))) if (character === "<") depth += 1;
|
|
1326
1361
|
else if (character === ">") depth = Math.max(0, depth - 1);
|
|
1327
1362
|
else if (depth === 0) flat += character;
|
|
1328
1363
|
const clause = flat.replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
|
|
1329
1364
|
const bases = clause === void 0 ? [] : clause.split(",").map((base) => base.trim()).filter(_orkestrel_contract.isNonEmptyString);
|
|
1365
|
+
if (head.text.endsWith("}")) {
|
|
1366
|
+
declarations.set(key, {
|
|
1367
|
+
body: [],
|
|
1368
|
+
bases
|
|
1369
|
+
});
|
|
1370
|
+
continue;
|
|
1371
|
+
}
|
|
1330
1372
|
for (let close = head.end + 1; close < projected.length; close += 1) {
|
|
1331
1373
|
if (projected[close] !== "}") continue;
|
|
1332
1374
|
declarations.set(key, {
|
|
@@ -3616,7 +3658,7 @@ var Parity = class Parity {
|
|
|
3616
3658
|
text: `${row.entry.spec} has no ## ${heading} section.`
|
|
3617
3659
|
});
|
|
3618
3660
|
}
|
|
3619
|
-
if (row.guide.methods().length === 0) findings.push({
|
|
3661
|
+
if (row.guide.methods().length === 0 && hasBehaviouralSurface(row.source)) findings.push({
|
|
3620
3662
|
spec: row.entry.spec,
|
|
3621
3663
|
text: `${row.entry.spec} has no documented method groups.`
|
|
3622
3664
|
});
|
|
@@ -4160,6 +4202,7 @@ exports.findUnexampled = findUnexampled;
|
|
|
4160
4202
|
exports.findUnlisted = findUnlisted;
|
|
4161
4203
|
exports.formatDrift = formatDrift;
|
|
4162
4204
|
exports.formatSide = formatSide;
|
|
4205
|
+
exports.hasBehaviouralSurface = hasBehaviouralSurface;
|
|
4163
4206
|
exports.hasCanonicalSegments = hasCanonicalSegments;
|
|
4164
4207
|
exports.identifyDrift = identifyDrift;
|
|
4165
4208
|
exports.isDrift = isDrift;
|