@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.
@@ -1246,7 +1246,14 @@ function extractHidden(source) {
1246
1246
  }
1247
1247
  /**
1248
1248
  * Joins the declaration head starting at `start` into one space-separated
1249
- * 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.
1250
1257
  *
1251
1258
  * @param lines - The file's source lines
1252
1259
  * @param start - The index of the head's first line
@@ -1255,6 +1262,7 @@ function extractHidden(source) {
1255
1262
  * @example
1256
1263
  * ```ts
1257
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 }
1258
1266
  * ```
1259
1267
  */
1260
1268
  function joinHead(lines, start) {
@@ -1262,8 +1270,15 @@ function joinHead(lines, start) {
1262
1270
  for (let index = start; index < lines.length; index += 1) {
1263
1271
  const line = lines[index];
1264
1272
  if (line === void 0) break;
1265
- parts.push(index === start ? line.trimEnd() : line.trim());
1266
- if (line.trimEnd().endsWith("{")) return {
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 {
1267
1282
  text: parts.join(" "),
1268
1283
  end: index
1269
1284
  };
@@ -1304,12 +1319,14 @@ function escapeRegExp(value) {
1304
1319
  * optional heritage clause between the identifier and the opening `{`; the identifier is the head's
1305
1320
  * own run up to that list or clause, so it enters the key as literal text and no name reaches a
1306
1321
  * `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
1307
- * keeping JSDoc evidence intact. Every balanced `<...>` span is removed from the head before its
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
1308
1324
  * `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
1309
1325
  * reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
1310
1326
  * qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
1311
1327
  * a column-zero close answers for that key: a head that opens none records nothing, and a later
1312
- * 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.
1313
1330
  *
1314
1331
  * @param source - The file's source text to read
1315
1332
  * @returns One entry per collected declaration, keyed `${keyword} ${name}`
@@ -1323,7 +1340,7 @@ function escapeRegExp(value) {
1323
1340
  function collectDeclarations(source) {
1324
1341
  const declarations = /* @__PURE__ */ new Map();
1325
1342
  const opener = /^export (?:class|interface) /;
1326
- const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{$/;
1343
+ const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{(?:\s*\})?$/;
1327
1344
  const lines = extractSourceLines(source);
1328
1345
  const projected = lines.map((line) => line.code);
1329
1346
  for (let index = 0; index < projected.length; index += 1) {
@@ -1336,14 +1353,22 @@ function collectDeclarations(source) {
1336
1353
  const name = declared?.[2];
1337
1354
  if (keyword === void 0 || name === void 0) continue;
1338
1355
  const key = `${keyword} ${name}`;
1339
- if (declarations.has(key)) continue;
1356
+ const known = declarations.get(key);
1357
+ if (known !== void 0 && (known.body.length > 0 || known.bases.length > 0)) continue;
1340
1358
  let depth = 0;
1341
1359
  let flat = "";
1342
- for (const character of head.text.slice(`export ${key}`.length, -1)) if (character === "<") depth += 1;
1360
+ for (const character of head.text.slice(`export ${key}`.length, head.text.lastIndexOf("{"))) if (character === "<") depth += 1;
1343
1361
  else if (character === ">") depth = Math.max(0, depth - 1);
1344
1362
  else if (depth === 0) flat += character;
1345
1363
  const clause = flat.replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
1346
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
+ }
1347
1372
  for (let close = head.end + 1; close < projected.length; close += 1) {
1348
1373
  if (projected[close] !== "}") continue;
1349
1374
  declarations.set(key, {
@@ -3245,9 +3270,12 @@ var Guide = class {
3245
3270
  * remain valid. `methods` resolves a declaration's members through its
3246
3271
  * `extends` chain within the same module scope, keeping the keyword it started
3247
3272
  * from; a base the scope does not declare contributes nothing. One declaration
3248
- * answers for a name: the first file in sorted key order that declares the head
3249
- * supplies its members and its bases, and a second file declaring the same name
3250
- * adds nothing. Every reading derives once per instance from the immutable
3273
+ * answers under each keyword: the first file in sorted key order that declares
3274
+ * the head supplies its members and its bases, and a second file declaring the
3275
+ * same name under that keyword adds nothing. The interface answers for a name,
3276
+ * and the class when no interface declares it; one file declaring the name as
3277
+ * both shapes, a TypeScript declaration merge, answers with both, own members
3278
+ * ahead of inherited ones and the interface's own first. Every reading derives once per instance from the immutable
3251
3279
  * inventory and is reused — the scope's declaration map on the first `methods`
3252
3280
  * or `examples` lookup, then each name's members and each example collection
3253
3281
  * under the name asked for — so a reader asking twice reads the files once and
@@ -3287,6 +3315,7 @@ var Source = class {
3287
3315
  #surface;
3288
3316
  #hidden;
3289
3317
  #declarations;
3318
+ #origins = /* @__PURE__ */ new Map();
3290
3319
  constructor(options) {
3291
3320
  this.#files = options.files;
3292
3321
  this.#directories = normalizeDirectories(options.module);
@@ -3321,10 +3350,18 @@ var Source = class {
3321
3350
  return examples;
3322
3351
  }
3323
3352
  #scanMethods(name) {
3324
- const declared = this.#members("interface", name, /* @__PURE__ */ new Set());
3325
- if (declared !== void 0) return declared;
3326
- const inherited = this.#members("class", name, /* @__PURE__ */ new Set());
3327
- return inherited === void 0 ? [] : inherited.filter((entry) => entry.name !== "constructor");
3353
+ const fromInterface = this.#members("interface", name, /* @__PURE__ */ new Set());
3354
+ const fromClass = this.#members("class", name, /* @__PURE__ */ new Set())?.filter((entry) => entry.name !== "constructor");
3355
+ const origin = this.#origin("interface", name);
3356
+ if (origin === void 0 || origin !== this.#origin("class", name)) return fromInterface ?? fromClass ?? [];
3357
+ const methods = /* @__PURE__ */ new Map();
3358
+ for (const entry of [
3359
+ ...extractMemberMethods(this.#locate("interface", name)?.body ?? []),
3360
+ ...extractMemberMethods(this.#locate("class", name)?.body ?? []),
3361
+ ...fromInterface ?? [],
3362
+ ...fromClass ?? []
3363
+ ]) if (entry.name !== "constructor" && !methods.has(entry.name)) methods.set(entry.name, entry);
3364
+ return Array.from(methods.values()).sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
3328
3365
  }
3329
3366
  #scanExamples() {
3330
3367
  const examples = [];
@@ -3414,6 +3451,9 @@ var Source = class {
3414
3451
  if (this.#declarations === void 0) this.#declarations = this.#scanDeclarations();
3415
3452
  return this.#declarations.get(`${keyword} ${name}`);
3416
3453
  }
3454
+ #origin(keyword, name) {
3455
+ return this.#locate(keyword, name) === void 0 ? void 0 : this.#origins.get(`${keyword} ${name}`);
3456
+ }
3417
3457
  #scanDeclarations() {
3418
3458
  const declarations = /* @__PURE__ */ new Map();
3419
3459
  for (const key of selectModuleKeys(this.#files, this.#directories)) {
@@ -3423,6 +3463,7 @@ var Source = class {
3423
3463
  if (declarations.has(identity)) continue;
3424
3464
  if (declaration.body.length === 0 && declaration.bases.length === 0) continue;
3425
3465
  declarations.set(identity, declaration);
3466
+ this.#origins.set(identity, key);
3426
3467
  }
3427
3468
  }
3428
3469
  return declarations;
@@ -3696,12 +3737,14 @@ var Parity = class Parity {
3696
3737
  const groups = row.guide.methods();
3697
3738
  const documented = groups.map((group) => group.interface);
3698
3739
  const declared = new Set(row.source.surface().map((symbol) => symbol.name));
3740
+ const classes = new Set(row.source.surface().filter((symbol) => symbol.keyword === "class").map((symbol) => symbol.name));
3699
3741
  for (const group of groups) {
3700
3742
  const finding = compareMembership(row.entry.spec, group.interface, group.methods.map((entry) => entry.name), row.source.methods(group.interface).map((entry) => entry.name));
3701
3743
  if (finding !== void 0) findings.push(finding);
3702
3744
  }
3703
3745
  for (const symbol of row.source.surface()) {
3704
3746
  if (symbol.keyword !== "interface" && symbol.keyword !== "class") continue;
3747
+ if (symbol.keyword === "interface" && classes.has(symbol.name)) continue;
3705
3748
  const members = row.source.methods(symbol.name).map((entry) => entry.name);
3706
3749
  if (members.length === 0) continue;
3707
3750
  const contract = `${symbol.name}Interface`;