@optique/core 1.0.0-dev.487 → 1.0.0-dev.488

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/doc.cjs CHANGED
@@ -27,9 +27,10 @@ function scoreSection(section) {
27
27
  /**
28
28
  * The default section comparator: command-only sections come first, then
29
29
  * mixed sections, then option/argument-only sections. Untitled sections
30
- * receive a slight priority boost so the main (untitled) section appears
31
- * before titled sections of a similar classification. Sections with the
32
- * same score preserve their original relative order (stable sort).
30
+ * receive a score bonus of -1 via {@link scoreSection} so that untitled
31
+ * command-only sections naturally sort before titled command-only sections.
32
+ * Sections with the same score preserve their original relative order
33
+ * (stable sort).
33
34
  */
34
35
  function defaultSectionOrder(a, b) {
35
36
  return scoreSection(a) - scoreSection(b);
@@ -103,8 +104,7 @@ function formatDocPage(programName, page, options = {}) {
103
104
  })).toSorted((a, b) => {
104
105
  const cmp = comparator(a.section, b.section);
105
106
  if (cmp !== 0) return cmp;
106
- const titleCmp = (a.section.title == null ? 0 : 1) - (b.section.title == null ? 0 : 1);
107
- return titleCmp !== 0 ? titleCmp : a.index - b.index;
107
+ return a.index - b.index;
108
108
  }).map(({ section }) => section);
109
109
  for (const section of sections) {
110
110
  if (section.entries.length < 1) continue;
package/dist/doc.js CHANGED
@@ -27,9 +27,10 @@ function scoreSection(section) {
27
27
  /**
28
28
  * The default section comparator: command-only sections come first, then
29
29
  * mixed sections, then option/argument-only sections. Untitled sections
30
- * receive a slight priority boost so the main (untitled) section appears
31
- * before titled sections of a similar classification. Sections with the
32
- * same score preserve their original relative order (stable sort).
30
+ * receive a score bonus of -1 via {@link scoreSection} so that untitled
31
+ * command-only sections naturally sort before titled command-only sections.
32
+ * Sections with the same score preserve their original relative order
33
+ * (stable sort).
33
34
  */
34
35
  function defaultSectionOrder(a, b) {
35
36
  return scoreSection(a) - scoreSection(b);
@@ -103,8 +104,7 @@ function formatDocPage(programName, page, options = {}) {
103
104
  })).toSorted((a, b) => {
104
105
  const cmp = comparator(a.section, b.section);
105
106
  if (cmp !== 0) return cmp;
106
- const titleCmp = (a.section.title == null ? 0 : 1) - (b.section.title == null ? 0 : 1);
107
- return titleCmp !== 0 ? titleCmp : a.index - b.index;
107
+ return a.index - b.index;
108
108
  }).map(({ section }) => section);
109
109
  for (const section of sections) {
110
110
  if (section.entries.length < 1) continue;
package/dist/parser.cjs CHANGED
@@ -387,14 +387,34 @@ function buildDocPage(parser, context, args) {
387
387
  kind: "available",
388
388
  state: context.state
389
389
  }, void 0);
390
- const entries = fragments.filter((f) => f.type === "entry");
391
- const sections = [];
392
- for (const fragment of fragments) {
393
- if (fragment.type !== "section") continue;
394
- if (fragment.title == null) entries.push(...fragment.entries);
395
- else sections.push(fragment);
390
+ const buildingSections = [];
391
+ let untitledSection = null;
392
+ const titledSectionMap = /* @__PURE__ */ new Map();
393
+ for (const fragment of fragments) if (fragment.type === "entry") {
394
+ if (untitledSection == null) {
395
+ untitledSection = { entries: [] };
396
+ buildingSections.push(untitledSection);
397
+ }
398
+ untitledSection.entries.push(fragment);
399
+ } else if (fragment.type === "section") if (fragment.title == null) {
400
+ if (untitledSection == null) {
401
+ untitledSection = { entries: [] };
402
+ buildingSections.push(untitledSection);
403
+ }
404
+ untitledSection.entries.push(...fragment.entries);
405
+ } else {
406
+ let section = titledSectionMap.get(fragment.title);
407
+ if (section == null) {
408
+ section = {
409
+ title: fragment.title,
410
+ entries: []
411
+ };
412
+ titledSectionMap.set(fragment.title, section);
413
+ buildingSections.push(section);
414
+ }
415
+ section.entries.push(...fragment.entries);
396
416
  }
397
- if (entries.length > 0) sections.push({ entries });
417
+ const sections = buildingSections;
398
418
  const usage = [...require_usage.normalizeUsage(parser.usage)];
399
419
  let i = 0;
400
420
  for (const arg of args) {
package/dist/parser.js CHANGED
@@ -387,14 +387,34 @@ function buildDocPage(parser, context, args) {
387
387
  kind: "available",
388
388
  state: context.state
389
389
  }, void 0);
390
- const entries = fragments.filter((f) => f.type === "entry");
391
- const sections = [];
392
- for (const fragment of fragments) {
393
- if (fragment.type !== "section") continue;
394
- if (fragment.title == null) entries.push(...fragment.entries);
395
- else sections.push(fragment);
390
+ const buildingSections = [];
391
+ let untitledSection = null;
392
+ const titledSectionMap = /* @__PURE__ */ new Map();
393
+ for (const fragment of fragments) if (fragment.type === "entry") {
394
+ if (untitledSection == null) {
395
+ untitledSection = { entries: [] };
396
+ buildingSections.push(untitledSection);
397
+ }
398
+ untitledSection.entries.push(fragment);
399
+ } else if (fragment.type === "section") if (fragment.title == null) {
400
+ if (untitledSection == null) {
401
+ untitledSection = { entries: [] };
402
+ buildingSections.push(untitledSection);
403
+ }
404
+ untitledSection.entries.push(...fragment.entries);
405
+ } else {
406
+ let section = titledSectionMap.get(fragment.title);
407
+ if (section == null) {
408
+ section = {
409
+ title: fragment.title,
410
+ entries: []
411
+ };
412
+ titledSectionMap.set(fragment.title, section);
413
+ buildingSections.push(section);
414
+ }
415
+ section.entries.push(...fragment.entries);
396
416
  }
397
- if (entries.length > 0) sections.push({ entries });
417
+ const sections = buildingSections;
398
418
  const usage = [...normalizeUsage(parser.usage)];
399
419
  let i = 0;
400
420
  for (const arg of args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.487+3c38bb65",
3
+ "version": "1.0.0-dev.488+690cf201",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",