flashtrace 0.9.2 → 0.10.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.
package/README.md CHANGED
@@ -27,7 +27,6 @@
27
27
  </table>
28
28
  </div>
29
29
 
30
- ---
31
30
  ---
32
31
 
33
32
  <h4 align="center">Quality Summary</h4>
@@ -233,8 +233,10 @@ var WILDCARD_SRC = String.raw`(?:\d+\.\d+\.x|\d+\.x\.y|x\.y\.z|\d+\.x|x\.y|x)`;
233
233
  var REV_REF_SRC = `(?:${WILDCARD_SRC}|${REV_SRC})`;
234
234
  var ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEGMENT_SRC}\/)*${SEGMENT_SRC})\/)?(${SEGMENT_SRC})#(${REV_SRC})`;
235
235
  var ID_RE = new RegExp(`^${ID_SRC}$`);
236
- var NEED_ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEGMENT_SRC}\/)*${SEGMENT_SRC})\/)?(${SEGMENT_SRC})#(${REV_REF_SRC})`;
237
- var NEED_ID_RE = new RegExp(`^${NEED_ID_SRC}$`);
236
+ var PATH_SRC = String.raw`(?:${SEGMENT_SRC}\/)*${SEGMENT_SRC}`;
237
+ var REF_SRC = `([A-Za-z]+)(?::(${PATH_SRC}))?(?:#(${REV_REF_SRC}))?`;
238
+ var REF_RE = new RegExp(`^${REF_SRC}$`);
239
+ var COVER_REF_RE = new RegExp(`^([A-Za-z]+)(?::(${PATH_SRC}))?(?:#(${REV_SRC}))?$`);
238
240
  var FORWARD_SRC = String.raw`\[\s*${ID_SRC}\s*-->\s*${ID_SRC}\s*\]`;
239
241
  var makeId = (type, group, name, rev) => `${type}:${group ? group + "/" : ""}${name}#${rev}`;
240
242
  var makeForward = (m, base, file, line) => ({
@@ -245,6 +247,8 @@ var makeForward = (m, base, file, line) => ({
245
247
  });
246
248
  var keyOf = (id) => id.slice(0, id.lastIndexOf("#"));
247
249
  var revOf = (id) => id.slice(id.lastIndexOf("#") + 1);
250
+ var pathOf = (id) => id.slice(id.indexOf(":") + 1, id.lastIndexOf("#"));
251
+ var resolveRef = (type, path5, rev, ownerId) => `${type}:${path5 ?? pathOf(ownerId)}#${rev ?? revOf(ownerId)}`;
248
252
  function compareRev(a, b) {
249
253
  const partsA = a.split(".");
250
254
  const partsB = b.split(".");
@@ -268,15 +272,15 @@ function revMatches(pattern, concrete) {
268
272
  return true;
269
273
  }
270
274
  var idMatches = (need, id) => keyOf(need) === keyOf(id) && revMatches(revOf(need), revOf(id));
271
- function parseIdEntry(raw) {
275
+ function parseNeedEntry(raw, ownerId) {
272
276
  const cleaned = raw.replaceAll("`", "").trim();
273
- const m = cleaned.match(ID_RE);
274
- return m ? makeId(m[1], m[2], m[3], m[4]) : null;
277
+ const m = cleaned.match(REF_RE);
278
+ return m ? resolveRef(m[1], m[2], m[3], ownerId) : null;
275
279
  }
276
- function parseNeedEntry(raw) {
280
+ function parseCoverEntry(raw, ownerId) {
277
281
  const cleaned = raw.replaceAll("`", "").trim();
278
- const m = cleaned.match(NEED_ID_RE);
279
- return m ? makeId(m[1], m[2], m[3], m[4]) : null;
282
+ const m = cleaned.match(COVER_REF_RE);
283
+ return m ? resolveRef(m[1], m[2], m[3], ownerId) : null;
280
284
  }
281
285
  function newItem(id, origin, file, line) {
282
286
  return {
@@ -441,9 +445,9 @@ function applyKeyword(item, keyword, entries, file, keywordLine, problems, sourc
441
445
  return;
442
446
  }
443
447
  const target = keyword === "Needs" ? "needs" : "covers";
444
- const parse = keyword === "Needs" ? parseNeedEntry : parseIdEntry;
448
+ const parse = keyword === "Needs" ? parseNeedEntry : parseCoverEntry;
445
449
  for (const entry of entries) {
446
- const id = parse(entry);
450
+ const id = parse(entry, item.id);
447
451
  if (id) item[target].push(id);
448
452
  else
449
453
  problems.push({
@@ -528,7 +532,7 @@ function parseMarkdown(file, text, problems, forwards = []) {
528
532
  // src/parse-code.mjs
529
533
  import path2 from "node:path";
530
534
  var TAG_RE = new RegExp(
531
- String.raw`\[(?:\s*${ID_SRC}\s*)?>>\s*${NEED_ID_SRC}\s*\]|\[\s*${ID_SRC}\s*\]`,
535
+ String.raw`\[(?:\s*${ID_SRC}\s*)?>>\s*${REF_SRC}\s*\]|\[\s*${ID_SRC}\s*\]`,
532
536
  "g"
533
537
  );
534
538
  var FORWARD_RE = new RegExp(FORWARD_SRC, "g");
@@ -665,36 +669,29 @@ function commentText(line, state, grammar) {
665
669
  }
666
670
  return comment;
667
671
  }
672
+ function attachNeed(m, file, line, state, problems) {
673
+ const source = m[1] ? makeId(m[1], m[2], m[3], m[4]) : null;
674
+ const anchor = source ? state.byId.get(source) : state.lastItem;
675
+ if (!anchor) {
676
+ const written = m[5] + (m[6] ? `:${m[6]}` : "") + (m[7] ? `#${m[7]}` : "");
677
+ problems.push({
678
+ file,
679
+ line,
680
+ message: source ? `need tag [${source} >> ${written}] has no preceding item tag [${source}] in this file` : `need tag [>>${written}] has no preceding item tag in this file`
681
+ });
682
+ return;
683
+ }
684
+ anchor.needs.push(resolveRef(m[5], m[6], m[7], anchor.id));
685
+ }
668
686
  function collectTags(comment, file, line, state, items, problems) {
669
687
  for (const m of comment.matchAll(TAG_RE)) {
670
- if (m[9]) {
671
- const item = newItem(makeId(m[9], m[10], m[11], m[12]), "code", file, line);
688
+ if (m[8]) {
689
+ const item = newItem(makeId(m[8], m[9], m[10], m[11]), "code", file, line);
672
690
  state.lastItem = item;
673
691
  state.byId.set(item.id, item);
674
692
  items.push(item);
675
- continue;
676
- }
677
- const id = makeId(m[5], m[6], m[7], m[8]);
678
- if (m[1]) {
679
- const source = makeId(m[1], m[2], m[3], m[4]);
680
- const anchor = state.byId.get(source);
681
- if (anchor) {
682
- anchor.needs.push(id);
683
- } else {
684
- problems.push({
685
- file,
686
- line,
687
- message: `need tag [${source} >> ${id}] has no preceding item tag [${source}] in this file`
688
- });
689
- }
690
- } else if (state.lastItem) {
691
- state.lastItem.needs.push(id);
692
693
  } else {
693
- problems.push({
694
- file,
695
- line,
696
- message: `need tag [>>${id}] has no preceding item tag in this file`
697
- });
694
+ attachNeed(m, file, line, state, problems);
698
695
  }
699
696
  }
700
697
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flashtrace",
3
- "version": "0.9.2",
3
+ "version": "0.10.0",
4
4
  "description": "Lightning-fast, reference-based requirement tracing that works anywhere.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {