@orkestrel/guide 0.0.22 → 0.0.24

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.
@@ -102,12 +102,14 @@ export declare function buildTable(table: TableNode, row: number, column: number
102
102
  * optional heritage clause between the identifier and the opening `{`; the identifier is the head's
103
103
  * own run up to that list or clause, so it enters the key as literal text and no name reaches a
104
104
  * `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
105
- * keeping JSDoc evidence intact. Every balanced `<...>` span is removed from the head before its
105
+ * keeping JSDoc evidence intact; a head whose last line closes its own body with `{}` or `{ }`
106
+ * records an empty body. Every balanced `<...>` span is removed from the head before its
106
107
  * `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
107
108
  * reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
108
109
  * qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
109
110
  * a column-zero close answers for that key: a head that opens none records nothing, and a later
110
- * head of a key already collected adds nothing.
111
+ * head of a key already collected adds nothing unless the earlier head recorded neither a body
112
+ * nor bases, which declares nothing as {@link Source} reads it, so the later head replaces it.
111
113
  *
112
114
  * @param source - The file's source text to read
113
115
  * @returns One entry per collected declaration, keyed `${keyword} ${name}`
@@ -490,7 +492,7 @@ export declare function createSurfaceSymbolContract(): ContractInterface<Surface
490
492
  * {@link collectDeclarations}).
491
493
  */
492
494
  export declare interface Declaration {
493
- /** Holds the declaration's raw body lines, between the head and the column-zero closing `}`. */
495
+ /** Holds the declaration's raw body lines, between the head and the column-zero closing `}`; empty when the head's last line closes its own body. */
494
496
  readonly body: readonly string[];
495
497
  /** Lists the base identifiers its head extends, in head order. */
496
498
  readonly bases: readonly string[];
@@ -504,7 +506,7 @@ export declare interface Declaration {
504
506
  export declare interface DeclarationHead {
505
507
  /** Holds the joined, space-separated head text. */
506
508
  readonly text: string;
507
- /** Holds the index (within the source `lines`) of the line ending in `{`. */
509
+ /** Holds the index (within the source `lines`) of the line that carries the opening `{`. */
508
510
  readonly end: number;
509
511
  }
510
512
 
@@ -1565,7 +1567,14 @@ export declare const isSurfaceSymbol: Guard<SurfaceSymbol>;
1565
1567
 
1566
1568
  /**
1567
1569
  * Joins the declaration head starting at `start` into one space-separated
1568
- * line, consuming lines until the first that ends with `{`.
1570
+ * line, consuming lines until the first that opens a body: one that ends with
1571
+ * `{`, or one that closes an empty body with `{}` or `{ }`.
1572
+ *
1573
+ * @remarks
1574
+ * A line ending with `{}` closes an empty body only when every angle, round,
1575
+ * and square bracket the head opened outside quoted text has closed; inside
1576
+ * one, `{}` is a type or an argument, and an arrow's `=>` closes nothing. A
1577
+ * head that reaches the next column-zero `export` line opens no body.
1569
1578
  *
1570
1579
  * @param lines - The file's source lines
1571
1580
  * @param start - The index of the head's first line
@@ -1574,6 +1583,7 @@ export declare const isSurfaceSymbol: Guard<SurfaceSymbol>;
1574
1583
  * @example
1575
1584
  * ```ts
1576
1585
  * joinHead(['export class X {'], 0) // { text: 'export class X {', end: 0 }
1586
+ * joinHead(['export interface Y extends X {}'], 0) // { text: 'export interface Y extends X {}', end: 0 }
1577
1587
  * ```
1578
1588
  */
1579
1589
  export declare function joinHead(lines: readonly string[], start: number): DeclarationHead | undefined;
@@ -2330,9 +2340,12 @@ export declare function selectSectionBlocks(document: MarkdownDocument, heading:
2330
2340
  * remain valid. `methods` resolves a declaration's members through its
2331
2341
  * `extends` chain within the same module scope, keeping the keyword it started
2332
2342
  * from; a base the scope does not declare contributes nothing. One declaration
2333
- * answers for a name: the first file in sorted key order that declares the head
2334
- * supplies its members and its bases, and a second file declaring the same name
2335
- * adds nothing. Every reading derives once per instance from the immutable
2343
+ * answers under each keyword: the first file in sorted key order that declares
2344
+ * the head supplies its members and its bases, and a second file declaring the
2345
+ * same name under that keyword adds nothing. The interface answers for a name,
2346
+ * and the class when no interface declares it; one file declaring the name as
2347
+ * both shapes, a TypeScript declaration merge, answers with both, own members
2348
+ * ahead of inherited ones and the interface's own first. Every reading derives once per instance from the immutable
2336
2349
  * inventory and is reused — the scope's declaration map on the first `methods`
2337
2350
  * or `examples` lookup, then each name's members and each example collection
2338
2351
  * under the name asked for — so a reader asking twice reads the files once and
@@ -2492,13 +2505,17 @@ export declare interface SourceInterface {
2492
2505
  * block's description paragraph. The first file declaring the name answers for it.
2493
2506
  *
2494
2507
  * @remarks
2495
- * One declaration answers for `name`: the module scope's files are read in
2496
- * sorted key order and the first one whose located head has a body or has
2497
- * bases supplies both the members and the bases, so a second file
2498
- * declaring the same name adds nothing; a head with neither a body nor
2499
- * bases does not count as declared, so an empty `export interface X {}`
2500
- * is skipped and resolution continues to a later file or falls through to
2501
- * a same-named class. Resolution reads that head's `extends` clause and follows it
2508
+ * One declaration answers under each keyword: the module scope's files are
2509
+ * read in sorted key order and the first one whose located head has a body
2510
+ * or has bases supplies both the members and the bases, so a second file
2511
+ * declaring the same name under that keyword adds nothing; a head with
2512
+ * neither a body nor bases does not count as declared, so an empty
2513
+ * `export interface X {}` is skipped and resolution continues to a later
2514
+ * file. The interface answers for `name`, and the class answers when no
2515
+ * interface declares it. Where one file declares `name` as both an
2516
+ * interface and a class, which TypeScript merges into one type, both
2517
+ * answer: each shape's own members come ahead of inherited ones, the
2518
+ * interface's own first. Resolution reads each head's `extends` clause and follows it
2502
2519
  * through this same module scope, keeping the keyword it started from: an
2503
2520
  * `interface` chain resolves through interfaces and a `class` chain through
2504
2521
  * classes, so a class's `implements` clause is outside the walk. A base the
@@ -102,12 +102,14 @@ export declare function buildTable(table: TableNode, row: number, column: number
102
102
  * optional heritage clause between the identifier and the opening `{`; the identifier is the head's
103
103
  * own run up to that list or clause, so it enters the key as literal text and no name reaches a
104
104
  * `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
105
- * keeping JSDoc evidence intact. Every balanced `<...>` span is removed from the head before its
105
+ * keeping JSDoc evidence intact; a head whose last line closes its own body with `{}` or `{ }`
106
+ * records an empty body. Every balanced `<...>` span is removed from the head before its
106
107
  * `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
107
108
  * reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
108
109
  * qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
109
110
  * a column-zero close answers for that key: a head that opens none records nothing, and a later
110
- * head of a key already collected adds nothing.
111
+ * head of a key already collected adds nothing unless the earlier head recorded neither a body
112
+ * nor bases, which declares nothing as {@link Source} reads it, so the later head replaces it.
111
113
  *
112
114
  * @param source - The file's source text to read
113
115
  * @returns One entry per collected declaration, keyed `${keyword} ${name}`
@@ -490,7 +492,7 @@ export declare function createSurfaceSymbolContract(): ContractInterface<Surface
490
492
  * {@link collectDeclarations}).
491
493
  */
492
494
  export declare interface Declaration {
493
- /** Holds the declaration's raw body lines, between the head and the column-zero closing `}`. */
495
+ /** Holds the declaration's raw body lines, between the head and the column-zero closing `}`; empty when the head's last line closes its own body. */
494
496
  readonly body: readonly string[];
495
497
  /** Lists the base identifiers its head extends, in head order. */
496
498
  readonly bases: readonly string[];
@@ -504,7 +506,7 @@ export declare interface Declaration {
504
506
  export declare interface DeclarationHead {
505
507
  /** Holds the joined, space-separated head text. */
506
508
  readonly text: string;
507
- /** Holds the index (within the source `lines`) of the line ending in `{`. */
509
+ /** Holds the index (within the source `lines`) of the line that carries the opening `{`. */
508
510
  readonly end: number;
509
511
  }
510
512
 
@@ -1565,7 +1567,14 @@ export declare const isSurfaceSymbol: Guard<SurfaceSymbol>;
1565
1567
 
1566
1568
  /**
1567
1569
  * Joins the declaration head starting at `start` into one space-separated
1568
- * line, consuming lines until the first that ends with `{`.
1570
+ * line, consuming lines until the first that opens a body: one that ends with
1571
+ * `{`, or one that closes an empty body with `{}` or `{ }`.
1572
+ *
1573
+ * @remarks
1574
+ * A line ending with `{}` closes an empty body only when every angle, round,
1575
+ * and square bracket the head opened outside quoted text has closed; inside
1576
+ * one, `{}` is a type or an argument, and an arrow's `=>` closes nothing. A
1577
+ * head that reaches the next column-zero `export` line opens no body.
1569
1578
  *
1570
1579
  * @param lines - The file's source lines
1571
1580
  * @param start - The index of the head's first line
@@ -1574,6 +1583,7 @@ export declare const isSurfaceSymbol: Guard<SurfaceSymbol>;
1574
1583
  * @example
1575
1584
  * ```ts
1576
1585
  * joinHead(['export class X {'], 0) // { text: 'export class X {', end: 0 }
1586
+ * joinHead(['export interface Y extends X {}'], 0) // { text: 'export interface Y extends X {}', end: 0 }
1577
1587
  * ```
1578
1588
  */
1579
1589
  export declare function joinHead(lines: readonly string[], start: number): DeclarationHead | undefined;
@@ -2330,9 +2340,12 @@ export declare function selectSectionBlocks(document: MarkdownDocument, heading:
2330
2340
  * remain valid. `methods` resolves a declaration's members through its
2331
2341
  * `extends` chain within the same module scope, keeping the keyword it started
2332
2342
  * from; a base the scope does not declare contributes nothing. One declaration
2333
- * answers for a name: the first file in sorted key order that declares the head
2334
- * supplies its members and its bases, and a second file declaring the same name
2335
- * adds nothing. Every reading derives once per instance from the immutable
2343
+ * answers under each keyword: the first file in sorted key order that declares
2344
+ * the head supplies its members and its bases, and a second file declaring the
2345
+ * same name under that keyword adds nothing. The interface answers for a name,
2346
+ * and the class when no interface declares it; one file declaring the name as
2347
+ * both shapes, a TypeScript declaration merge, answers with both, own members
2348
+ * ahead of inherited ones and the interface's own first. Every reading derives once per instance from the immutable
2336
2349
  * inventory and is reused — the scope's declaration map on the first `methods`
2337
2350
  * or `examples` lookup, then each name's members and each example collection
2338
2351
  * under the name asked for — so a reader asking twice reads the files once and
@@ -2492,13 +2505,17 @@ export declare interface SourceInterface {
2492
2505
  * block's description paragraph. The first file declaring the name answers for it.
2493
2506
  *
2494
2507
  * @remarks
2495
- * One declaration answers for `name`: the module scope's files are read in
2496
- * sorted key order and the first one whose located head has a body or has
2497
- * bases supplies both the members and the bases, so a second file
2498
- * declaring the same name adds nothing; a head with neither a body nor
2499
- * bases does not count as declared, so an empty `export interface X {}`
2500
- * is skipped and resolution continues to a later file or falls through to
2501
- * a same-named class. Resolution reads that head's `extends` clause and follows it
2508
+ * One declaration answers under each keyword: the module scope's files are
2509
+ * read in sorted key order and the first one whose located head has a body
2510
+ * or has bases supplies both the members and the bases, so a second file
2511
+ * declaring the same name under that keyword adds nothing; a head with
2512
+ * neither a body nor bases does not count as declared, so an empty
2513
+ * `export interface X {}` is skipped and resolution continues to a later
2514
+ * file. The interface answers for `name`, and the class answers when no
2515
+ * interface declares it. Where one file declares `name` as both an
2516
+ * interface and a class, which TypeScript merges into one type, both
2517
+ * answer: each shape's own members come ahead of inherited ones, the
2518
+ * interface's own first. Resolution reads each head's `extends` clause and follows it
2502
2519
  * through this same module scope, keeping the keyword it started from: an
2503
2520
  * `interface` chain resolves through interfaces and a `class` chain through
2504
2521
  * classes, so a class's `implements` clause is outside the walk. A base the
@@ -1245,7 +1245,14 @@ function extractHidden(source) {
1245
1245
  }
1246
1246
  /**
1247
1247
  * Joins the declaration head starting at `start` into one space-separated
1248
- * line, consuming lines until the first that ends with `{`.
1248
+ * line, consuming lines until the first that opens a body: one that ends with
1249
+ * `{`, or one that closes an empty body with `{}` or `{ }`.
1250
+ *
1251
+ * @remarks
1252
+ * A line ending with `{}` closes an empty body only when every angle, round,
1253
+ * and square bracket the head opened outside quoted text has closed; inside
1254
+ * one, `{}` is a type or an argument, and an arrow's `=>` closes nothing. A
1255
+ * head that reaches the next column-zero `export` line opens no body.
1249
1256
  *
1250
1257
  * @param lines - The file's source lines
1251
1258
  * @param start - The index of the head's first line
@@ -1254,6 +1261,7 @@ function extractHidden(source) {
1254
1261
  * @example
1255
1262
  * ```ts
1256
1263
  * joinHead(['export class X {'], 0) // { text: 'export class X {', end: 0 }
1264
+ * joinHead(['export interface Y extends X {}'], 0) // { text: 'export interface Y extends X {}', end: 0 }
1257
1265
  * ```
1258
1266
  */
1259
1267
  function joinHead(lines, start) {
@@ -1261,8 +1269,15 @@ function joinHead(lines, start) {
1261
1269
  for (let index = start; index < lines.length; index += 1) {
1262
1270
  const line = lines[index];
1263
1271
  if (line === void 0) break;
1264
- parts.push(index === start ? line.trimEnd() : line.trim());
1265
- if (line.trimEnd().endsWith("{")) return {
1272
+ const text = line.trimEnd();
1273
+ if (index > start && text.startsWith("export ")) return void 0;
1274
+ parts.push(index === start ? text : text.trimStart());
1275
+ if (text.endsWith("{")) return {
1276
+ text: parts.join(" "),
1277
+ end: index
1278
+ };
1279
+ const bare = parts.join(" ").replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g, "");
1280
+ 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 {
1266
1281
  text: parts.join(" "),
1267
1282
  end: index
1268
1283
  };
@@ -1303,12 +1318,14 @@ function escapeRegExp(value) {
1303
1318
  * optional heritage clause between the identifier and the opening `{`; the identifier is the head's
1304
1319
  * own run up to that list or clause, so it enters the key as literal text and no name reaches a
1305
1320
  * `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
1306
- * keeping JSDoc evidence intact. Every balanced `<...>` span is removed from the head before its
1321
+ * keeping JSDoc evidence intact; a head whose last line closes its own body with `{}` or `{ }`
1322
+ * records an empty body. Every balanced `<...>` span is removed from the head before its
1307
1323
  * `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
1308
1324
  * reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
1309
1325
  * qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
1310
1326
  * a column-zero close answers for that key: a head that opens none records nothing, and a later
1311
- * head of a key already collected adds nothing.
1327
+ * head of a key already collected adds nothing unless the earlier head recorded neither a body
1328
+ * nor bases, which declares nothing as {@link Source} reads it, so the later head replaces it.
1312
1329
  *
1313
1330
  * @param source - The file's source text to read
1314
1331
  * @returns One entry per collected declaration, keyed `${keyword} ${name}`
@@ -1322,7 +1339,7 @@ function escapeRegExp(value) {
1322
1339
  function collectDeclarations(source) {
1323
1340
  const declarations = /* @__PURE__ */ new Map();
1324
1341
  const opener = /^export (?:class|interface) /;
1325
- const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{$/;
1342
+ const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{(?:\s*\})?$/;
1326
1343
  const lines = extractSourceLines(source);
1327
1344
  const projected = lines.map((line) => line.code);
1328
1345
  for (let index = 0; index < projected.length; index += 1) {
@@ -1335,14 +1352,22 @@ function collectDeclarations(source) {
1335
1352
  const name = declared?.[2];
1336
1353
  if (keyword === void 0 || name === void 0) continue;
1337
1354
  const key = `${keyword} ${name}`;
1338
- if (declarations.has(key)) continue;
1355
+ const known = declarations.get(key);
1356
+ if (known !== void 0 && (known.body.length > 0 || known.bases.length > 0)) continue;
1339
1357
  let depth = 0;
1340
1358
  let flat = "";
1341
- for (const character of head.text.slice(`export ${key}`.length, -1)) if (character === "<") depth += 1;
1359
+ for (const character of head.text.slice(`export ${key}`.length, head.text.lastIndexOf("{"))) if (character === "<") depth += 1;
1342
1360
  else if (character === ">") depth = Math.max(0, depth - 1);
1343
1361
  else if (depth === 0) flat += character;
1344
1362
  const clause = flat.replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
1345
1363
  const bases = clause === void 0 ? [] : clause.split(",").map((base) => base.trim()).filter(isNonEmptyString);
1364
+ if (head.text.endsWith("}")) {
1365
+ declarations.set(key, {
1366
+ body: [],
1367
+ bases
1368
+ });
1369
+ continue;
1370
+ }
1346
1371
  for (let close = head.end + 1; close < projected.length; close += 1) {
1347
1372
  if (projected[close] !== "}") continue;
1348
1373
  declarations.set(key, {
@@ -3244,9 +3269,12 @@ var Guide = class {
3244
3269
  * remain valid. `methods` resolves a declaration's members through its
3245
3270
  * `extends` chain within the same module scope, keeping the keyword it started
3246
3271
  * from; a base the scope does not declare contributes nothing. One declaration
3247
- * answers for a name: the first file in sorted key order that declares the head
3248
- * supplies its members and its bases, and a second file declaring the same name
3249
- * adds nothing. Every reading derives once per instance from the immutable
3272
+ * answers under each keyword: the first file in sorted key order that declares
3273
+ * the head supplies its members and its bases, and a second file declaring the
3274
+ * same name under that keyword adds nothing. The interface answers for a name,
3275
+ * and the class when no interface declares it; one file declaring the name as
3276
+ * both shapes, a TypeScript declaration merge, answers with both, own members
3277
+ * ahead of inherited ones and the interface's own first. Every reading derives once per instance from the immutable
3250
3278
  * inventory and is reused — the scope's declaration map on the first `methods`
3251
3279
  * or `examples` lookup, then each name's members and each example collection
3252
3280
  * under the name asked for — so a reader asking twice reads the files once and
@@ -3286,6 +3314,7 @@ var Source = class {
3286
3314
  #surface;
3287
3315
  #hidden;
3288
3316
  #declarations;
3317
+ #origins = /* @__PURE__ */ new Map();
3289
3318
  constructor(options) {
3290
3319
  this.#files = options.files;
3291
3320
  this.#directories = normalizeDirectories(options.module);
@@ -3320,10 +3349,18 @@ var Source = class {
3320
3349
  return examples;
3321
3350
  }
3322
3351
  #scanMethods(name) {
3323
- const declared = this.#members("interface", name, /* @__PURE__ */ new Set());
3324
- if (declared !== void 0) return declared;
3325
- const inherited = this.#members("class", name, /* @__PURE__ */ new Set());
3326
- return inherited === void 0 ? [] : inherited.filter((entry) => entry.name !== "constructor");
3352
+ const fromInterface = this.#members("interface", name, /* @__PURE__ */ new Set());
3353
+ const fromClass = this.#members("class", name, /* @__PURE__ */ new Set())?.filter((entry) => entry.name !== "constructor");
3354
+ const origin = this.#origin("interface", name);
3355
+ if (origin === void 0 || origin !== this.#origin("class", name)) return fromInterface ?? fromClass ?? [];
3356
+ const methods = /* @__PURE__ */ new Map();
3357
+ for (const entry of [
3358
+ ...extractMemberMethods(this.#locate("interface", name)?.body ?? []),
3359
+ ...extractMemberMethods(this.#locate("class", name)?.body ?? []),
3360
+ ...fromInterface ?? [],
3361
+ ...fromClass ?? []
3362
+ ]) if (entry.name !== "constructor" && !methods.has(entry.name)) methods.set(entry.name, entry);
3363
+ return Array.from(methods.values()).sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
3327
3364
  }
3328
3365
  #scanExamples() {
3329
3366
  const examples = [];
@@ -3413,6 +3450,9 @@ var Source = class {
3413
3450
  if (this.#declarations === void 0) this.#declarations = this.#scanDeclarations();
3414
3451
  return this.#declarations.get(`${keyword} ${name}`);
3415
3452
  }
3453
+ #origin(keyword, name) {
3454
+ return this.#locate(keyword, name) === void 0 ? void 0 : this.#origins.get(`${keyword} ${name}`);
3455
+ }
3416
3456
  #scanDeclarations() {
3417
3457
  const declarations = /* @__PURE__ */ new Map();
3418
3458
  for (const key of selectModuleKeys(this.#files, this.#directories)) {
@@ -3422,6 +3462,7 @@ var Source = class {
3422
3462
  if (declarations.has(identity)) continue;
3423
3463
  if (declaration.body.length === 0 && declaration.bases.length === 0) continue;
3424
3464
  declarations.set(identity, declaration);
3465
+ this.#origins.set(identity, key);
3425
3466
  }
3426
3467
  }
3427
3468
  return declarations;
@@ -3695,12 +3736,14 @@ var Parity = class Parity {
3695
3736
  const groups = row.guide.methods();
3696
3737
  const documented = groups.map((group) => group.interface);
3697
3738
  const declared = new Set(row.source.surface().map((symbol) => symbol.name));
3739
+ const classes = new Set(row.source.surface().filter((symbol) => symbol.keyword === "class").map((symbol) => symbol.name));
3698
3740
  for (const group of groups) {
3699
3741
  const finding = compareMembership(row.entry.spec, group.interface, group.methods.map((entry) => entry.name), row.source.methods(group.interface).map((entry) => entry.name));
3700
3742
  if (finding !== void 0) findings.push(finding);
3701
3743
  }
3702
3744
  for (const symbol of row.source.surface()) {
3703
3745
  if (symbol.keyword !== "interface" && symbol.keyword !== "class") continue;
3746
+ if (symbol.keyword === "interface" && classes.has(symbol.name)) continue;
3704
3747
  const members = row.source.methods(symbol.name).map((entry) => entry.name);
3705
3748
  if (members.length === 0) continue;
3706
3749
  const contract = `${symbol.name}Interface`;