@driftsys/markspec 0.12.1 → 0.13.0

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.
Files changed (279) hide show
  1. package/esm/ast/build.d.ts.map +1 -1
  2. package/esm/ast/build.js +19 -5
  3. package/esm/ast/equivalence.js +14 -2
  4. package/esm/ast/nodes.d.ts +15 -3
  5. package/esm/ast/nodes.d.ts.map +1 -1
  6. package/esm/compiler/inverses.d.ts.map +1 -1
  7. package/esm/compiler/inverses.js +18 -3
  8. package/esm/compiler/mod.d.ts +34 -1
  9. package/esm/compiler/mod.d.ts.map +1 -1
  10. package/esm/compiler/mod.js +112 -48
  11. package/esm/compiler/schema.d.ts +3 -2
  12. package/esm/compiler/schema.d.ts.map +1 -1
  13. package/esm/compiler/schema.js +6 -3
  14. package/esm/criteria/scenarios.d.ts +55 -0
  15. package/esm/criteria/scenarios.d.ts.map +1 -0
  16. package/esm/criteria/scenarios.js +133 -0
  17. package/esm/discovery/mod.d.ts +20 -1
  18. package/esm/discovery/mod.d.ts.map +1 -1
  19. package/esm/discovery/mod.js +105 -17
  20. package/esm/formatter/entry_body.d.ts +8 -5
  21. package/esm/formatter/entry_body.d.ts.map +1 -1
  22. package/esm/formatter/entry_body.js +12 -8
  23. package/esm/formatter/feature_file.d.ts +40 -0
  24. package/esm/formatter/feature_file.d.ts.map +1 -0
  25. package/esm/formatter/feature_file.js +88 -0
  26. package/esm/formatter/mod.d.ts +21 -2
  27. package/esm/formatter/mod.d.ts.map +1 -1
  28. package/esm/formatter/mod.js +64 -22
  29. package/esm/gates/mod.d.ts +2 -2
  30. package/esm/gates/mod.d.ts.map +1 -1
  31. package/esm/gates/mod.js +17 -2
  32. package/esm/gherkin/load.d.ts +35 -0
  33. package/esm/gherkin/load.d.ts.map +1 -0
  34. package/esm/gherkin/load.js +39 -0
  35. package/esm/gherkin/parse.d.ts +11 -0
  36. package/esm/gherkin/parse.d.ts.map +1 -0
  37. package/esm/gherkin/parse.js +311 -0
  38. package/esm/gherkin/position.d.ts +23 -0
  39. package/esm/gherkin/position.d.ts.map +1 -0
  40. package/esm/gherkin/position.js +21 -0
  41. package/esm/gherkin/procedure.d.ts +76 -0
  42. package/esm/gherkin/procedure.d.ts.map +1 -0
  43. package/esm/gherkin/procedure.js +164 -0
  44. package/esm/gherkin/project.d.ts +35 -0
  45. package/esm/gherkin/project.d.ts.map +1 -0
  46. package/esm/gherkin/project.js +64 -0
  47. package/esm/gherkin/role.d.ts +23 -0
  48. package/esm/gherkin/role.d.ts.map +1 -0
  49. package/esm/gherkin/role.js +28 -0
  50. package/esm/gherkin/types.d.ts +118 -0
  51. package/esm/gherkin/types.d.ts.map +1 -0
  52. package/esm/gherkin/types.js +12 -0
  53. package/esm/lock/acquire_compile.d.ts +12 -4
  54. package/esm/lock/acquire_compile.d.ts.map +1 -1
  55. package/esm/lock/acquire_compile.js +15 -5
  56. package/esm/lock/canonical_edges.d.ts +6 -2
  57. package/esm/lock/canonical_edges.d.ts.map +1 -1
  58. package/esm/lock/canonical_edges.js +10 -3
  59. package/esm/lock/model.d.ts +5 -0
  60. package/esm/lock/model.d.ts.map +1 -1
  61. package/esm/lock/parser.d.ts.map +1 -1
  62. package/esm/lock/parser.js +2 -0
  63. package/esm/lock/resolve.d.ts +6 -2
  64. package/esm/lock/resolve.d.ts.map +1 -1
  65. package/esm/lock/resolve.js +36 -4
  66. package/esm/lock/serializer.d.ts.map +1 -1
  67. package/esm/lock/serializer.js +7 -1
  68. package/esm/mod.d.ts +23 -6
  69. package/esm/mod.d.ts.map +1 -1
  70. package/esm/mod.js +18 -5
  71. package/esm/model/mod.d.ts +42 -1
  72. package/esm/model/mod.d.ts.map +1 -1
  73. package/esm/model/mod.js +1 -1
  74. package/esm/model/relations.d.ts +9 -0
  75. package/esm/model/relations.d.ts.map +1 -1
  76. package/esm/model/relations.js +16 -1
  77. package/esm/parser/attributes.d.ts +82 -3
  78. package/esm/parser/attributes.d.ts.map +1 -1
  79. package/esm/parser/attributes.js +199 -32
  80. package/esm/parser/body_tokens.d.ts +1 -1
  81. package/esm/parser/body_tokens.d.ts.map +1 -1
  82. package/esm/parser/body_tokens.js +49 -35
  83. package/esm/parser/feature_file.d.ts +116 -0
  84. package/esm/parser/feature_file.d.ts.map +1 -0
  85. package/esm/parser/feature_file.js +540 -0
  86. package/esm/parser/markdown.d.ts +7 -0
  87. package/esm/parser/markdown.d.ts.map +1 -1
  88. package/esm/parser/markdown.js +129 -40
  89. package/esm/parser/mod.d.ts +18 -0
  90. package/esm/parser/mod.d.ts.map +1 -1
  91. package/esm/parser/mod.js +51 -0
  92. package/esm/parser/translate.d.ts.map +1 -1
  93. package/esm/parser/translate.js +5 -0
  94. package/esm/refs/mod.d.ts +2 -1
  95. package/esm/refs/mod.d.ts.map +1 -1
  96. package/esm/refs/mod.js +12 -4
  97. package/esm/refs/split.d.ts +58 -0
  98. package/esm/refs/split.d.ts.map +1 -0
  99. package/esm/refs/split.js +137 -0
  100. package/esm/reporter/mod.d.ts +7 -0
  101. package/esm/reporter/mod.d.ts.map +1 -1
  102. package/esm/reporter/mod.js +113 -3
  103. package/esm/validator/attributes.d.ts.map +1 -1
  104. package/esm/validator/attributes.js +4 -1
  105. package/esm/validator/block_role.d.ts +40 -0
  106. package/esm/validator/block_role.d.ts.map +1 -0
  107. package/esm/validator/block_role.js +109 -0
  108. package/esm/validator/feature_ac.d.ts.map +1 -1
  109. package/esm/validator/feature_ac.js +6 -1
  110. package/esm/validator/feature_parse.d.ts +35 -0
  111. package/esm/validator/feature_parse.d.ts.map +1 -0
  112. package/esm/validator/feature_parse.js +69 -0
  113. package/esm/validator/locators.d.ts +36 -0
  114. package/esm/validator/locators.d.ts.map +1 -0
  115. package/esm/validator/locators.js +184 -0
  116. package/esm/validator/mod.d.ts +10 -1
  117. package/esm/validator/mod.d.ts.map +1 -1
  118. package/esm/validator/mod.js +38 -14
  119. package/esm/validator/normalize.d.ts.map +1 -1
  120. package/esm/validator/normalize.js +8 -3
  121. package/esm/validator/per_type_attrs.d.ts +3 -3
  122. package/esm/validator/per_type_attrs.js +3 -3
  123. package/esm/validator/pipeline.d.ts +4 -12
  124. package/esm/validator/pipeline.d.ts.map +1 -1
  125. package/esm/validator/pipeline.js +24 -5
  126. package/esm/validator/procedure.d.ts +22 -0
  127. package/esm/validator/procedure.d.ts.map +1 -0
  128. package/esm/validator/procedure.js +58 -0
  129. package/esm/validator/trace_types.d.ts.map +1 -1
  130. package/esm/validator/trace_types.js +4 -3
  131. package/esm/validator/traceability.d.ts.map +1 -1
  132. package/esm/validator/traceability.js +4 -1
  133. package/esm/validator/type_resolution.d.ts +5 -3
  134. package/esm/validator/type_resolution.d.ts.map +1 -1
  135. package/esm/validator/type_resolution.js +14 -2
  136. package/esm/validator/types.d.ts +11 -0
  137. package/esm/validator/types.d.ts.map +1 -1
  138. package/esm/validator/types.js +26 -4
  139. package/esm/validator/uxil_family.d.ts +1 -1
  140. package/package.json +3 -1
  141. package/script/ast/build.d.ts.map +1 -1
  142. package/script/ast/build.js +19 -5
  143. package/script/ast/equivalence.js +14 -2
  144. package/script/ast/nodes.d.ts +15 -3
  145. package/script/ast/nodes.d.ts.map +1 -1
  146. package/script/compiler/inverses.d.ts.map +1 -1
  147. package/script/compiler/inverses.js +18 -3
  148. package/script/compiler/mod.d.ts +34 -1
  149. package/script/compiler/mod.d.ts.map +1 -1
  150. package/script/compiler/mod.js +110 -46
  151. package/script/compiler/schema.d.ts +3 -2
  152. package/script/compiler/schema.d.ts.map +1 -1
  153. package/script/compiler/schema.js +6 -3
  154. package/script/criteria/scenarios.d.ts +55 -0
  155. package/script/criteria/scenarios.d.ts.map +1 -0
  156. package/script/criteria/scenarios.js +139 -0
  157. package/script/discovery/mod.d.ts +20 -1
  158. package/script/discovery/mod.d.ts.map +1 -1
  159. package/script/discovery/mod.js +106 -17
  160. package/script/formatter/entry_body.d.ts +8 -5
  161. package/script/formatter/entry_body.d.ts.map +1 -1
  162. package/script/formatter/entry_body.js +12 -8
  163. package/script/formatter/feature_file.d.ts +40 -0
  164. package/script/formatter/feature_file.d.ts.map +1 -0
  165. package/script/formatter/feature_file.js +92 -0
  166. package/script/formatter/mod.d.ts +21 -2
  167. package/script/formatter/mod.d.ts.map +1 -1
  168. package/script/formatter/mod.js +63 -21
  169. package/script/gates/mod.d.ts +2 -2
  170. package/script/gates/mod.d.ts.map +1 -1
  171. package/script/gates/mod.js +17 -2
  172. package/script/gherkin/load.d.ts +35 -0
  173. package/script/gherkin/load.d.ts.map +1 -0
  174. package/script/gherkin/load.js +76 -0
  175. package/script/gherkin/parse.d.ts +11 -0
  176. package/script/gherkin/parse.d.ts.map +1 -0
  177. package/script/gherkin/parse.js +314 -0
  178. package/script/gherkin/position.d.ts +23 -0
  179. package/script/gherkin/position.d.ts.map +1 -0
  180. package/script/gherkin/position.js +24 -0
  181. package/script/gherkin/procedure.d.ts +76 -0
  182. package/script/gherkin/procedure.d.ts.map +1 -0
  183. package/script/gherkin/procedure.js +169 -0
  184. package/script/gherkin/project.d.ts +35 -0
  185. package/script/gherkin/project.d.ts.map +1 -0
  186. package/script/gherkin/project.js +67 -0
  187. package/script/gherkin/role.d.ts +23 -0
  188. package/script/gherkin/role.d.ts.map +1 -0
  189. package/script/gherkin/role.js +31 -0
  190. package/script/gherkin/types.d.ts +118 -0
  191. package/script/gherkin/types.d.ts.map +1 -0
  192. package/script/gherkin/types.js +13 -0
  193. package/script/lock/acquire_compile.d.ts +12 -4
  194. package/script/lock/acquire_compile.d.ts.map +1 -1
  195. package/script/lock/acquire_compile.js +15 -5
  196. package/script/lock/canonical_edges.d.ts +6 -2
  197. package/script/lock/canonical_edges.d.ts.map +1 -1
  198. package/script/lock/canonical_edges.js +10 -3
  199. package/script/lock/model.d.ts +5 -0
  200. package/script/lock/model.d.ts.map +1 -1
  201. package/script/lock/parser.d.ts.map +1 -1
  202. package/script/lock/parser.js +2 -0
  203. package/script/lock/resolve.d.ts +6 -2
  204. package/script/lock/resolve.d.ts.map +1 -1
  205. package/script/lock/resolve.js +36 -4
  206. package/script/lock/serializer.d.ts.map +1 -1
  207. package/script/lock/serializer.js +7 -1
  208. package/script/mod.d.ts +23 -6
  209. package/script/mod.d.ts.map +1 -1
  210. package/script/mod.js +45 -6
  211. package/script/model/mod.d.ts +42 -1
  212. package/script/model/mod.d.ts.map +1 -1
  213. package/script/model/mod.js +2 -1
  214. package/script/model/relations.d.ts +9 -0
  215. package/script/model/relations.d.ts.map +1 -1
  216. package/script/model/relations.js +17 -1
  217. package/script/parser/attributes.d.ts +82 -3
  218. package/script/parser/attributes.d.ts.map +1 -1
  219. package/script/parser/attributes.js +205 -33
  220. package/script/parser/body_tokens.d.ts +1 -1
  221. package/script/parser/body_tokens.d.ts.map +1 -1
  222. package/script/parser/body_tokens.js +49 -35
  223. package/script/parser/feature_file.d.ts +116 -0
  224. package/script/parser/feature_file.d.ts.map +1 -0
  225. package/script/parser/feature_file.js +548 -0
  226. package/script/parser/markdown.d.ts +7 -0
  227. package/script/parser/markdown.d.ts.map +1 -1
  228. package/script/parser/markdown.js +128 -39
  229. package/script/parser/mod.d.ts +18 -0
  230. package/script/parser/mod.d.ts.map +1 -1
  231. package/script/parser/mod.js +52 -1
  232. package/script/parser/translate.d.ts.map +1 -1
  233. package/script/parser/translate.js +5 -0
  234. package/script/refs/mod.d.ts +2 -1
  235. package/script/refs/mod.d.ts.map +1 -1
  236. package/script/refs/mod.js +12 -4
  237. package/script/refs/split.d.ts +58 -0
  238. package/script/refs/split.d.ts.map +1 -0
  239. package/script/refs/split.js +145 -0
  240. package/script/reporter/mod.d.ts +7 -0
  241. package/script/reporter/mod.d.ts.map +1 -1
  242. package/script/reporter/mod.js +113 -3
  243. package/script/validator/attributes.d.ts.map +1 -1
  244. package/script/validator/attributes.js +4 -1
  245. package/script/validator/block_role.d.ts +40 -0
  246. package/script/validator/block_role.d.ts.map +1 -0
  247. package/script/validator/block_role.js +112 -0
  248. package/script/validator/feature_ac.d.ts.map +1 -1
  249. package/script/validator/feature_ac.js +6 -1
  250. package/script/validator/feature_parse.d.ts +35 -0
  251. package/script/validator/feature_parse.d.ts.map +1 -0
  252. package/script/validator/feature_parse.js +73 -0
  253. package/script/validator/locators.d.ts +36 -0
  254. package/script/validator/locators.d.ts.map +1 -0
  255. package/script/validator/locators.js +188 -0
  256. package/script/validator/mod.d.ts +10 -1
  257. package/script/validator/mod.d.ts.map +1 -1
  258. package/script/validator/mod.js +38 -14
  259. package/script/validator/normalize.d.ts.map +1 -1
  260. package/script/validator/normalize.js +8 -3
  261. package/script/validator/per_type_attrs.d.ts +3 -3
  262. package/script/validator/per_type_attrs.js +3 -3
  263. package/script/validator/pipeline.d.ts +4 -12
  264. package/script/validator/pipeline.d.ts.map +1 -1
  265. package/script/validator/pipeline.js +23 -5
  266. package/script/validator/procedure.d.ts +22 -0
  267. package/script/validator/procedure.d.ts.map +1 -0
  268. package/script/validator/procedure.js +61 -0
  269. package/script/validator/trace_types.d.ts.map +1 -1
  270. package/script/validator/trace_types.js +4 -3
  271. package/script/validator/traceability.d.ts.map +1 -1
  272. package/script/validator/traceability.js +4 -1
  273. package/script/validator/type_resolution.d.ts +5 -3
  274. package/script/validator/type_resolution.d.ts.map +1 -1
  275. package/script/validator/type_resolution.js +14 -2
  276. package/script/validator/types.d.ts +11 -0
  277. package/script/validator/types.d.ts.map +1 -1
  278. package/script/validator/types.js +27 -4
  279. package/script/validator/uxil_family.d.ts +1 -1
@@ -10,10 +10,11 @@ import { ulid as defaultUlid } from "@std/ulid";
10
10
  import { stringify as stringifyYaml } from "@std/yaml";
11
11
  import { attributeSpec, CSV_SPLITTABLE_TYPES, IDENTITY_KEY, } from "../model/mod.js";
12
12
  import { MARKDOWN_EXTENSIONS } from "../discovery/mod.js";
13
- import { ATTR_LINE_RE, parseAttributes } from "../parser/attributes.js";
13
+ import { ATTR_LINE_RE, findTrailerStart, parseAttributes, } from "../parser/attributes.js";
14
14
  import { extractFrontMatter } from "../parser/frontmatter.js";
15
15
  import { parseMarkdown } from "../parser/markdown.js";
16
16
  import { fencedCodeLines } from "../util/fence.js";
17
+ import { splitTraceValues } from "../refs/split.js";
17
18
  import { applyLineEnding, detectLineEnding, normalizeLineEndings, } from "../util/line_endings.js";
18
19
  import { isSentenceInitial as _isSentenceInitial, normalizeProseModals, } from "../util/modals.js";
19
20
  import { synthesizedUlid } from "./synth_ulid.js";
@@ -505,6 +506,11 @@ function normalizeTabMarkers(markdown, options, diagnostics) {
505
506
  * @returns Format result with output text and diagnostics
506
507
  */
507
508
  export function format(markdown, options) {
509
+ // A `.feature` file is Gherkin, not Markdown: neither the entry formatter
510
+ // nor the prose pass may touch it. Its Id stamping is `formatFeatureText`.
511
+ if (extname(options?.file ?? "").toLowerCase() === ".feature") {
512
+ return { output: markdown, diagnostics: [], changed: false };
513
+ }
508
514
  const diagnostics = [];
509
515
  const ending = detectLineEnding(markdown);
510
516
  const prepared = normalizeTabMarkers(normalizeLineEndings(markdown), options, diagnostics);
@@ -636,6 +642,14 @@ function formatEntries(markdown, options) {
636
642
  // input reproduces the same identity. Falls back to fresh random
637
643
  // when `Source:` is missing — synthesizing without a source pointer
638
644
  // makes no sense, but the formatter never fails a stamp.
645
+ // A trailer holding a line the attribute parser cannot read (a
646
+ // continuation of a value) is left exactly as it is: rewriting it
647
+ // would drop that line, and stamping an Id would replace the
648
+ // identity the author wrote. The parser reports the line as MSL-P021.
649
+ const trailerRange = findAttributeBlockRange(lines, entry.location.line, indent, itemEndFloor(), protectedRanges);
650
+ if (trailerRange &&
651
+ lines.slice(trailerRange.start, trailerRange.end).some((l) => l.trim() !== "" && !ATTR_LINE_RE.test(l.trim())))
652
+ continue;
639
653
  const hasIdentity = attrs.some((a) => a.key === IDENTITY_KEY);
640
654
  if (!hasIdentity && entry.shape === "Authored") {
641
655
  const origin = attrs.find((a) => a.key === "Origin")?.value.trim();
@@ -684,8 +698,17 @@ function formatEntries(markdown, options) {
684
698
  // Replace existing attribute block.
685
699
  const newBlock = renderAttributeBlock(normalized, indent);
686
700
  const oldBlock = lines.slice(range.start, range.end).join("\n");
687
- if (newBlock !== oldBlock) {
688
- lines.splice(range.start, range.end - range.start, ...newBlock.split("\n"));
701
+ // A block directly under body prose (no blank line), indented or
702
+ // not, is not a code block in CommonMark: it continues the
703
+ // paragraph. The canonical layout separates it (#916). A line above
704
+ // that belongs to a preserved range (a refused child entry) is left
705
+ // as it is.
706
+ const above = range.start - 1;
707
+ const needsBlank = above > titleLineIdx &&
708
+ lines[above].trim() !== "" &&
709
+ !protectedRanges.some((r) => above >= r.start && above < r.end);
710
+ if (newBlock !== oldBlock || needsBlank) {
711
+ lines.splice(range.start, range.end - range.start, ...(needsBlank ? [""] : []), ...newBlock.split("\n"));
689
712
  changed = true;
690
713
  }
691
714
  }
@@ -842,17 +865,23 @@ function collapseBlankLines(lines) {
842
865
  * Expand CSV values on repeatable-type attributes into one entry per value
843
866
  * per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
844
867
  * but must round-trip as multi-line output; `citation` is left alone
845
- * because locators may contain commas.
868
+ * because locators may contain commas. `id-list` values split with
869
+ * {@linkcode splitTraceValues}, so a comma inside a scenario locator does
870
+ * not split.
846
871
  */
847
872
  export function expandCsvValues(attrs) {
848
873
  const result = [];
849
874
  for (const attr of attrs) {
850
875
  const spec = attributeSpec(attr.key);
851
876
  if (spec && CSV_SPLITTABLE_TYPES.has(spec.type) && attr.value.includes(",")) {
852
- const values = attr.value
853
- .split(",")
854
- .map((s) => s.trim())
855
- .filter((s) => s.length > 0);
877
+ // An id-list value keeps commas inside a bracket locator
878
+ // (`A [x, y], B`, #915); the locator text is kept as authored.
879
+ const values = spec.type === "id-list"
880
+ ? splitTraceValues(attr.value)
881
+ : attr.value
882
+ .split(",")
883
+ .map((s) => s.trim())
884
+ .filter((s) => s.length > 0);
856
885
  for (const value of values) {
857
886
  result.push({ key: attr.key, value });
858
887
  }
@@ -1040,7 +1069,24 @@ function removeEmptyTrailerLines(body, entries, diagnostics) {
1040
1069
  * for an entry starting at the given line.
1041
1070
  *
1042
1071
  * Scans forward from the entry start to find the list item boundary,
1043
- * then walks backwards to find the contiguous trailing attribute block.
1072
+ * then passes the entry content below the last preserved range, with the
1073
+ * list-item indent removed, to the parser's {@linkcode findTrailerStart}.
1074
+ * The formatter and the parser therefore agree on which lines are the
1075
+ * trailer, so `markspec fmt` never rewrites a line that the parser read as
1076
+ * body, and never drops an attribute line that the parser read (#916).
1077
+ * The LSP MSL-P023 quick fix uses it too.
1078
+ *
1079
+ * @param lines - Raw lines of the whole file.
1080
+ * @param entryStartLine - 1-based line of the entry's title (`- [ID] ...`).
1081
+ * @param indent - Content column of the list item: the 0-based column of
1082
+ * the `[` that opens the display ID.
1083
+ * @param itemEndFloor - Pass the parser's `Entry.endLine` (0 when unknown):
1084
+ * the item end scan starts no earlier than this line index, so a lazy
1085
+ * continuation line does not end the item early (see `findItemEnd`).
1086
+ * @param preservedRanges - Ranges inside the entry that are kept verbatim
1087
+ * (nested entries); the trailer is searched below the last one.
1088
+ * @returns The 0-based, half-open line range `[start, end)` of the trailer
1089
+ * over `lines`, or `undefined` when the entry has no trailer.
1044
1090
  */
1045
1091
  export function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFloor = 0, preservedRanges = []) {
1046
1092
  const startIdx = entryStartLine - 1;
@@ -1052,22 +1098,18 @@ export function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFl
1052
1098
  }
1053
1099
  if (scanEnd <= startIdx)
1054
1100
  return undefined;
1055
- // Walk backwards collecting attribute lines.
1056
- let attrStart = scanEnd;
1057
- for (let i = scanEnd - 1; i > startIdx; i--) {
1101
+ // Content lines of the entry body, below the last preserved range, with
1102
+ // the list-item indent removed as the parser does. The shared trailer
1103
+ // detection decides where the attribute block starts (#916).
1104
+ let floor = startIdx + 1;
1105
+ for (let i = startIdx + 1; i < scanEnd; i++) {
1058
1106
  if (preservedRanges.some((range) => i >= range.start && i < range.end)) {
1059
- break;
1060
- }
1061
- const trimmed = lines[i].trim();
1062
- if (trimmed === "")
1063
- break;
1064
- if (ATTR_LINE_RE.test(trimmed)) {
1065
- attrStart = i;
1066
- }
1067
- else {
1068
- break;
1107
+ floor = i + 1;
1069
1108
  }
1070
1109
  }
1110
+ const indentStr = " ".repeat(indent);
1111
+ const content = lines.slice(floor, scanEnd).map((l) => l.startsWith(indentStr) ? l.slice(indent) : l);
1112
+ const attrStart = floor + findTrailerStart(content);
1071
1113
  if (attrStart >= scanEnd)
1072
1114
  return undefined;
1073
1115
  return { start: attrStart, end: scanEnd };
@@ -29,8 +29,8 @@ import { type LockEdge, type ParseLockfileResult, type ReadFile as LockReadFile
29
29
  * `fmt --check` never disagree on what "formatted" means. `MSL-F010` is pure
30
30
  * formatter drift; `MSL-F011` is reference-canonicalization drift (a ULID or
31
31
  * stale display ID `fmt` would rewrite) — kept distinct so the author knows
32
- * which fmt concern fired. Markdown only — `markspec fmt` never rewrites source
33
- * files, so the caller passes only Markdown file contents.
32
+ * which fmt concern fired. Markdown and `.feature` files only — `markspec fmt`
33
+ * never rewrites source files, so the caller passes only those file contents.
34
34
  *
35
35
  * @param mdContents Markdown file path → current on-disk content.
36
36
  * @param entries The full parsed entry set (project + corpus). Only
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/gates/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,QAAQ,IAAI,YAAY,EAE9B,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,mBAAmB,EAAE,cAAc,GAAG,SAAS,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CAyCvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,GACtE,OAAO,CAAC,UAAU,EAAE,CAAC,CAuCvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,OAAO,CAAC,UAAU,EAAE,CAAC,CAQvB"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/gates/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAK3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,QAAQ,IAAI,YAAY,EAE9B,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,mBAAmB,EAAE,cAAc,GAAG,SAAS,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CAsDvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,GACtE,OAAO,CAAC,UAAU,EAAE,CAAC,CAuCvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,OAAO,CAAC,UAAU,EAAE,CAAC,CAQvB"}
package/esm/gates/mod.js CHANGED
@@ -18,7 +18,9 @@
18
18
  * it — no cycle.
19
19
  */
20
20
  import { isCorpusEntry } from "../model/mod.js";
21
+ import { extname } from "@std/path";
21
22
  import { format } from "../formatter/mod.js";
23
+ import { formatFeatureText } from "../formatter/feature_file.js";
22
24
  import { parseFile } from "../parser/mod.js";
23
25
  import { buildRefIndex, canonicalizeRefs } from "../refs/mod.js";
24
26
  import { detectOfflineEdgeDrift, formatEdgeDriftMessage, verifyUpstreamCache, } from "../lock/mod.js";
@@ -32,8 +34,8 @@ import { runLint } from "../lint/mod.js";
32
34
  * `fmt --check` never disagree on what "formatted" means. `MSL-F010` is pure
33
35
  * formatter drift; `MSL-F011` is reference-canonicalization drift (a ULID or
34
36
  * stale display ID `fmt` would rewrite) — kept distinct so the author knows
35
- * which fmt concern fired. Markdown only — `markspec fmt` never rewrites source
36
- * files, so the caller passes only Markdown file contents.
37
+ * which fmt concern fired. Markdown and `.feature` files only — `markspec fmt`
38
+ * never rewrites source files, so the caller passes only those file contents.
37
39
  *
38
40
  * @param mdContents Markdown file path → current on-disk content.
39
41
  * @param entries The full parsed entry set (project + corpus). Only
@@ -55,6 +57,19 @@ export async function fmtDriftGate(mdContents, entries, ledger, formatMarkdownPr
55
57
  // `emittableEntries` (upstream-only, #771); do not "unify" it.
56
58
  const refIndex = buildRefIndex(entries.filter((e) => !isCorpusEntry(e)));
57
59
  for (const [filePath, content] of mdContents) {
60
+ // A `.feature` file only drifts when a headed entry lacks its Id. It has
61
+ // no prose pass and no reference canonicalisation.
62
+ if (extname(filePath).toLowerCase() === ".feature") {
63
+ if ((await formatFeatureText(content, filePath)).changed) {
64
+ diagnostics.push({
65
+ code: "MSL-F010",
66
+ severity: "error",
67
+ message: "file is not formatted (run `markspec fmt`)",
68
+ location: { file: filePath, line: 1, column: 1 },
69
+ });
70
+ }
71
+ continue;
72
+ }
58
73
  const formatted = format(content, {
59
74
  file: filePath,
60
75
  formatMarkdownProse,
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @module core/gherkin/load
3
+ *
4
+ * Lazy loader for the `@cucumber/gherkin` parser. The parser is imported
5
+ * dynamically, so commands that never read Gherkin blocks do not load it.
6
+ */
7
+ import type { Dialect } from "@cucumber/gherkin";
8
+ import type { GherkinDocument } from "@cucumber/messages";
9
+ /** The parts of the Gherkin parser that MarkSpec uses. */
10
+ export interface GherkinApi {
11
+ /**
12
+ * Parse Gherkin source text. Builds a new parser for each call, because
13
+ * the parser keeps state. Throws the library's composite error when the
14
+ * text is not valid Gherkin.
15
+ */
16
+ parse(text: string): GherkinDocument;
17
+ /** Language dialects, keyed by language code (for example `fr`). */
18
+ readonly dialects: Record<string, Dialect>;
19
+ }
20
+ /** The two parser modules, as the importer returns them. */
21
+ type ParserModules = [
22
+ typeof import("@cucumber/gherkin"),
23
+ typeof import("@cucumber/messages")
24
+ ];
25
+ /**
26
+ * Load the Gherkin parser. The result is cached; a failed load is not
27
+ * cached, so a later call tries again.
28
+ *
29
+ * @param importer - Replaces the module import. Internal, for tests.
30
+ */
31
+ export declare function loadGherkin(importer?: () => Promise<ParserModules>): Promise<GherkinApi>;
32
+ /** The parser when it is already loaded, otherwise `undefined`. */
33
+ export declare function loadedGherkin(): GherkinApi | undefined;
34
+ export {};
35
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/gherkin/load.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,0DAA0D;AAC1D,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IACrC,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAKD,4DAA4D;AAC5D,KAAK,aAAa,GAAG;IACnB,cAAc,mBAAmB,CAAC;IAClC,cAAc,oBAAoB,CAAC;CACpC,CAAC;AASF;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,QAAQ,GAAE,MAAM,OAAO,CAAC,aAAa,CAAiB,GACrD,OAAO,CAAC,UAAU,CAAC,CAuBrB;AAED,mEAAmE;AACnE,wBAAgB,aAAa,IAAI,UAAU,GAAG,SAAS,CAEtD"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @module core/gherkin/load
3
+ *
4
+ * Lazy loader for the `@cucumber/gherkin` parser. The parser is imported
5
+ * dynamically, so commands that never read Gherkin blocks do not load it.
6
+ */
7
+ let loaded;
8
+ let pending;
9
+ /** Imports the two parser modules. */
10
+ const importModules = () => Promise.all([
11
+ import("@cucumber/gherkin"),
12
+ import("@cucumber/messages"),
13
+ ]);
14
+ /**
15
+ * Load the Gherkin parser. The result is cached; a failed load is not
16
+ * cached, so a later call tries again.
17
+ *
18
+ * @param importer - Replaces the module import. Internal, for tests.
19
+ */
20
+ export function loadGherkin(importer = importModules) {
21
+ if (loaded)
22
+ return Promise.resolve(loaded);
23
+ pending ??= importer().then(([{ AstBuilder, GherkinClassicTokenMatcher, Parser, dialects }, { IdGenerator },]) => {
24
+ const api = {
25
+ parse: (text) => new Parser(new AstBuilder(IdGenerator.incrementing()), new GherkinClassicTokenMatcher()).parse(text),
26
+ dialects,
27
+ };
28
+ loaded = api;
29
+ return api;
30
+ }).catch((err) => {
31
+ pending = undefined;
32
+ throw err;
33
+ });
34
+ return pending;
35
+ }
36
+ /** The parser when it is already loaded, otherwise `undefined`. */
37
+ export function loadedGherkin() {
38
+ return loaded;
39
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module core/gherkin/parse
3
+ *
4
+ * Wraps, parses and normalizes one Gherkin block into a {@linkcode FeatureAst}.
5
+ * The function is pure: it takes the loaded parser as an argument.
6
+ */
7
+ import type { GherkinApi } from "./load.js";
8
+ import type { FeatureParse } from "./types.js";
9
+ /** Parse and normalize one Gherkin block. */
10
+ export declare function parseFeature(api: GherkinApi, source: string): FeatureParse;
11
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/gherkin/parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAEV,YAAY,EAMb,MAAM,YAAY,CAAC;AA4DpB,6CAA6C;AAC7C,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAoQ1E"}
@@ -0,0 +1,311 @@
1
+ /**
2
+ * @module core/gherkin/parse
3
+ *
4
+ * Wraps, parses and normalizes one Gherkin block into a {@linkcode FeatureAst}.
5
+ * The function is pure: it takes the loaded parser as an argument.
6
+ */
7
+ const LANGUAGE_RE = /^\s*#\s*language\s*:\s*([A-Za-z-]+)\s*$/;
8
+ // `keywordType` values of `StepKeywordType` in `@cucumber/messages`.
9
+ const KEYWORD_BY_TYPE = {
10
+ Context: "given",
11
+ Action: "when",
12
+ Outcome: "then",
13
+ Unknown: "step",
14
+ };
15
+ function wrapSource(api, source) {
16
+ const lines = source.split("\n");
17
+ // The language comment may follow blank or comment lines, as in the parser.
18
+ let start = 0;
19
+ let language = "en";
20
+ let languageLine = 0;
21
+ for (let i = 0; i < lines.length; i++) {
22
+ const trimmed = lines[i].trim();
23
+ if (trimmed !== "" && !trimmed.startsWith("#"))
24
+ break;
25
+ const match = LANGUAGE_RE.exec(lines[i].replace(/\r$/, ""));
26
+ if (match) {
27
+ language = match[1];
28
+ start = i + 1;
29
+ languageLine = i + 1;
30
+ break;
31
+ }
32
+ }
33
+ const featureWords = api.dialects[language]?.feature ?? ["Feature"];
34
+ for (let i = start; i < lines.length; i++) {
35
+ const trimmed = lines[i].trim();
36
+ if (trimmed === "" || trimmed.startsWith("#") || trimmed.startsWith("@"))
37
+ continue;
38
+ if (featureWords.some((word) => trimmed.startsWith(`${word}:`))) {
39
+ return { text: source, language, syntheticLine: 0, languageLine };
40
+ }
41
+ break;
42
+ }
43
+ const synthetic = `${featureWords[0]}:`;
44
+ const wrapped = [...lines.slice(0, start), synthetic, ...lines.slice(start)];
45
+ return {
46
+ text: wrapped.join("\n"),
47
+ language,
48
+ syntheticLine: start + 1,
49
+ languageLine,
50
+ };
51
+ }
52
+ /** Parse and normalize one Gherkin block. */
53
+ export function parseFeature(api, source) {
54
+ const wrap = wrapSource(api, source);
55
+ const shift = (line) => wrap.syntheticLine > 0 && line > wrap.syntheticLine ? line - 1 : line;
56
+ let document;
57
+ try {
58
+ document = api.parse(wrap.text);
59
+ }
60
+ catch (err) {
61
+ const first = err
62
+ .errors?.[0];
63
+ const location = first?.location;
64
+ return {
65
+ ok: false,
66
+ line: location ? Math.max(1, shift(location.line)) : 1,
67
+ column: location?.column ?? 1,
68
+ message: first?.message ??
69
+ (err instanceof Error ? err.message : String(err)),
70
+ };
71
+ }
72
+ const parsed = document.feature;
73
+ if (!parsed) {
74
+ return {
75
+ ok: false,
76
+ line: 1,
77
+ column: 1,
78
+ message: "no Feature found in the Gherkin block",
79
+ };
80
+ }
81
+ const sourceLines = source.split("\n");
82
+ // Exclusive end column of a source line, after trailing whitespace.
83
+ const lineEnd = (line) => (sourceLines[line - 1] ?? "").trimEnd().length + 1;
84
+ const sections = [];
85
+ const synthetic = wrap.syntheticLine > 0;
86
+ const section = (keyword, at) => {
87
+ const line = shift(at.line);
88
+ const column = at.column ?? 1;
89
+ sections.push({
90
+ keyword,
91
+ range: {
92
+ start: { line, column },
93
+ end: { line, column: column + keyword.length + 1 },
94
+ },
95
+ });
96
+ };
97
+ if (!synthetic)
98
+ section(parsed.keyword, parsed.location);
99
+ const step = (s) => {
100
+ const keyword = s.keyword.trimEnd();
101
+ const startLine = shift(s.location.line);
102
+ const column = s.location.column ?? 1;
103
+ let endLine = startLine;
104
+ let endColumn = column + s.keyword.length + s.text.length;
105
+ if (s.docString) {
106
+ // The content cannot give the closing line: an empty doc string and
107
+ // one that holds a single blank line both have content "". Find the
108
+ // first line after the opening one that starts with the delimiter.
109
+ const open = shift(s.docString.location.line);
110
+ const delimiter = s.docString.delimiter;
111
+ let close = open + 1;
112
+ while (close < sourceLines.length &&
113
+ !(sourceLines[close - 1] ?? "").trimStart().startsWith(delimiter))
114
+ close++;
115
+ endLine = close;
116
+ endColumn = lineEnd(endLine);
117
+ }
118
+ if (s.dataTable) {
119
+ const last = s.dataTable.rows[s.dataTable.rows.length - 1];
120
+ if (last) {
121
+ endLine = shift(last.location.line);
122
+ endColumn = lineEnd(endLine);
123
+ }
124
+ }
125
+ return {
126
+ keyword,
127
+ normalized: normalizeStep(api, wrap.language, s),
128
+ text: s.text,
129
+ ...(s.docString
130
+ ? {
131
+ docString: {
132
+ ...(s.docString.mediaType
133
+ ? { mediaType: s.docString.mediaType }
134
+ : {}),
135
+ content: s.docString.content,
136
+ },
137
+ }
138
+ : {}),
139
+ ...(s.dataTable
140
+ ? {
141
+ dataTable: s.dataTable.rows.map((r) => r.cells.map((c) => c.value)),
142
+ }
143
+ : {}),
144
+ range: {
145
+ start: { line: startLine, column },
146
+ end: { line: endLine, column: endColumn },
147
+ },
148
+ };
149
+ };
150
+ const examples = (e) => {
151
+ section(e.keyword, e.location);
152
+ const rows = e.tableBody;
153
+ const lastRow = rows[rows.length - 1] ?? e.tableHeader;
154
+ const start = shift(e.location.line);
155
+ return {
156
+ name: e.name.trim(),
157
+ keyword: e.keyword,
158
+ tags: e.tags.map((t) => t.name),
159
+ header: e.tableHeader?.cells.map((c) => c.value) ?? [],
160
+ rows: rows.map((r) => r.cells.map((c) => c.value)),
161
+ range: {
162
+ start: { line: start, column: e.location.column ?? 1 },
163
+ end: lastRow
164
+ ? {
165
+ line: shift(lastRow.location.line),
166
+ column: lineEnd(shift(lastRow.location.line)),
167
+ }
168
+ : {
169
+ line: start,
170
+ column: (e.location.column ?? 1) + e.keyword.length + 1,
171
+ },
172
+ },
173
+ };
174
+ };
175
+ const scenarios = [];
176
+ const scenario = (s, background, ruleName) => {
177
+ section(s.keyword, s.location);
178
+ const steps = s.steps.map(step);
179
+ const exs = s.examples.map(examples);
180
+ const start = shift(s.location.line);
181
+ const column = s.location.column ?? 1;
182
+ const tail = [...steps, ...exs].map((x) => x.range.end);
183
+ const end = tail.length > 0
184
+ ? tail.reduce((a, b) => b.line > a.line || (b.line === a.line && b.column > a.column) ? b : a)
185
+ : { line: start, column: column + s.keyword.length + 1 };
186
+ // Last description line: the last text line of the scenario's own head,
187
+ // ignoring blank and comment lines.
188
+ let descriptionEndLine;
189
+ if (s.description.trim() !== "") {
190
+ // The description ends before the first step, the next tag line or the
191
+ // next structural keyword, whichever comes first.
192
+ let bound = steps[0]?.range.start.line ?? sourceLines.length + 1;
193
+ const dialect = api.dialects[wrap.language];
194
+ const words = dialect
195
+ ? [
196
+ ...dialect.feature,
197
+ ...dialect.background,
198
+ ...dialect.rule,
199
+ ...dialect.scenario,
200
+ ...dialect.scenarioOutline,
201
+ ...dialect.examples,
202
+ ]
203
+ : ["Feature", "Background", "Rule", "Scenario", "Examples"];
204
+ for (let line = start + 1; line < bound; line++) {
205
+ const text = (sourceLines[line - 1] ?? "").trim();
206
+ if (text.startsWith("@") || words.some((w) => text.startsWith(`${w}:`))) {
207
+ bound = line;
208
+ break;
209
+ }
210
+ }
211
+ for (let line = bound - 1; line > start; line--) {
212
+ const text = (sourceLines[line - 1] ?? "").trim();
213
+ if (text !== "" && !text.startsWith("#")) {
214
+ descriptionEndLine = line;
215
+ break;
216
+ }
217
+ }
218
+ }
219
+ scenarios.push({
220
+ name: s.name.trim(),
221
+ keyword: s.keyword,
222
+ tags: s.tags.map((t) => t.name),
223
+ ...(ruleName !== undefined ? { ruleName } : {}),
224
+ description: s.description,
225
+ ...(descriptionEndLine !== undefined ? { descriptionEndLine } : {}),
226
+ isOutline: s.examples.length > 0 ||
227
+ isOutlineKeyword(api, wrap.language, s.keyword),
228
+ background,
229
+ steps,
230
+ examples: exs,
231
+ range: { start: { line: start, column }, end },
232
+ });
233
+ };
234
+ const backgrounds = [];
235
+ const backgroundSteps = (b) => {
236
+ section(b.keyword, b.location);
237
+ const steps = b.steps.map(step);
238
+ backgrounds.push(...steps);
239
+ return steps;
240
+ };
241
+ let featureBackground = [];
242
+ for (const child of parsed.children) {
243
+ if (child.background) {
244
+ featureBackground = [
245
+ ...featureBackground,
246
+ ...backgroundSteps(child.background),
247
+ ];
248
+ }
249
+ else if (child.scenario) {
250
+ scenario(child.scenario, featureBackground, undefined);
251
+ }
252
+ else if (child.rule) {
253
+ const rule = child.rule;
254
+ section(rule.keyword, rule.location);
255
+ let ruleBackground = featureBackground;
256
+ for (const inner of rule.children) {
257
+ if (inner.background) {
258
+ ruleBackground = [
259
+ ...ruleBackground,
260
+ ...backgroundSteps(inner.background),
261
+ ];
262
+ }
263
+ else if (inner.scenario) {
264
+ scenario(inner.scenario, ruleBackground, rule.name.trim());
265
+ }
266
+ }
267
+ }
268
+ }
269
+ // The parser consumes a `# language:` header and does not list it as a
270
+ // comment, so it is added back at its own line.
271
+ const comments = document.comments.map((c) => ({
272
+ line: shift(c.location.line),
273
+ text: c.text.trim(),
274
+ }));
275
+ if (wrap.languageLine > 0 && !comments.some((c) => c.line === wrap.languageLine)) {
276
+ comments.push({
277
+ line: wrap.languageLine,
278
+ text: (sourceLines[wrap.languageLine - 1] ?? "").trim(),
279
+ });
280
+ comments.sort((a, b) => a.line - b.line);
281
+ }
282
+ return {
283
+ ok: true,
284
+ feature: {
285
+ name: parsed.name.trim(),
286
+ keyword: parsed.keyword,
287
+ synthetic,
288
+ language: parsed.language || wrap.language,
289
+ description: parsed.description,
290
+ tags: parsed.tags.map((t) => t.name),
291
+ scenarios,
292
+ backgrounds,
293
+ sections,
294
+ comments,
295
+ },
296
+ };
297
+ }
298
+ function normalizeStep(api, language, s) {
299
+ const type = s.keywordType ?? "Unknown";
300
+ // The parser reports And and But alike as Conjunction. A dialect may use
301
+ // one word for both; such a word counts as `but` only when it is in the
302
+ // `but` table, so a shared word is normalized as `but`.
303
+ if (type !== "Conjunction")
304
+ return KEYWORD_BY_TYPE[type] ?? "step";
305
+ const but = api.dialects[language]?.but ?? ["But "];
306
+ return but.some((word) => word.trim() === s.keyword.trim()) ? "but" : "and";
307
+ }
308
+ function isOutlineKeyword(api, language, keyword) {
309
+ const outline = api.dialects[language]?.scenarioOutline ?? [];
310
+ return outline.includes(keyword);
311
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @module core/gherkin/position
3
+ *
4
+ * Maps a position inside a Gherkin block to a line of the file.
5
+ */
6
+ import type { GherkinRange } from "./types.js";
7
+ import type { Entry } from "../model/mod.js";
8
+ /**
9
+ * Return the 1-based file line of `sourceLine`, a 1-based line of the
10
+ * authored block text of `node` (the same lines `FeatureAst` ranges use).
11
+ * The result matches the lines `buildCriteria` reports and needs no further
12
+ * translation. In Markdown, `bodyStartLine` is a file line and `node.range`
13
+ * is relative to the body. In a source doc comment, `bodyStartLine` stays
14
+ * relative to the extracted comment text, and `translateEntryLocations`
15
+ * (`parser/translate.ts`) shifts `node.range` by the comment's file offset
16
+ * instead; the sum is the file line in both cases.
17
+ */
18
+ export declare function featureFileLine(entry: Entry,
19
+ /** The feature block: a body-AST `FeatureNode`. */
20
+ node: {
21
+ readonly range: GherkinRange;
22
+ }, sourceLine: number): number;
23
+ //# sourceMappingURL=position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/gherkin/position.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK;AACZ,mDAAmD;AACnD,IAAI,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAAE,EACtC,UAAU,EAAE,MAAM,GACjB,MAAM,CAGR"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module core/gherkin/position
3
+ *
4
+ * Maps a position inside a Gherkin block to a line of the file.
5
+ */
6
+ /**
7
+ * Return the 1-based file line of `sourceLine`, a 1-based line of the
8
+ * authored block text of `node` (the same lines `FeatureAst` ranges use).
9
+ * The result matches the lines `buildCriteria` reports and needs no further
10
+ * translation. In Markdown, `bodyStartLine` is a file line and `node.range`
11
+ * is relative to the body. In a source doc comment, `bodyStartLine` stays
12
+ * relative to the extracted comment text, and `translateEntryLocations`
13
+ * (`parser/translate.ts`) shifts `node.range` by the comment's file offset
14
+ * instead; the sum is the file line in both cases.
15
+ */
16
+ export function featureFileLine(entry,
17
+ /** The feature block: a body-AST `FeatureNode`. */
18
+ node, sourceLine) {
19
+ const bodyStart = entry.bodyStartLine ?? (entry.location.line + 1);
20
+ return bodyStart + node.range.start.line + sourceLine - 1;
21
+ }