flashtrace 0.9.1 → 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 +0 -1
- package/dist/flashtrace.mjs +54 -45
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/flashtrace.mjs
CHANGED
|
@@ -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
|
|
237
|
-
var
|
|
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
|
|
275
|
+
function parseNeedEntry(raw, ownerId) {
|
|
272
276
|
const cleaned = raw.replaceAll("`", "").trim();
|
|
273
|
-
const m = cleaned.match(
|
|
274
|
-
return m ?
|
|
277
|
+
const m = cleaned.match(REF_RE);
|
|
278
|
+
return m ? resolveRef(m[1], m[2], m[3], ownerId) : null;
|
|
275
279
|
}
|
|
276
|
-
function
|
|
280
|
+
function parseCoverEntry(raw, ownerId) {
|
|
277
281
|
const cleaned = raw.replaceAll("`", "").trim();
|
|
278
|
-
const m = cleaned.match(
|
|
279
|
-
return m ?
|
|
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 {
|
|
@@ -317,13 +321,22 @@ function isParagraphLine(line) {
|
|
|
317
321
|
}
|
|
318
322
|
var isParagraphAt = (lines, inTable, j) => !inTable[j] && isParagraphLine(lines[j]);
|
|
319
323
|
var isSetextHeading = (lines, inTable, titleIndex) => titleIndex + 1 < lines.length && SETEXT_UNDERLINE_RE.test(lines[titleIndex + 1]) && isParagraphAt(lines, inTable, titleIndex);
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
let
|
|
323
|
-
while (
|
|
324
|
-
|
|
324
|
+
function scanSetextHeadings(lines, inTable) {
|
|
325
|
+
const opensHeading = new Array(lines.length).fill(false);
|
|
326
|
+
let j = 0;
|
|
327
|
+
while (j < lines.length) {
|
|
328
|
+
if (!isParagraphAt(lines, inTable, j)) {
|
|
329
|
+
j++;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const start = j;
|
|
333
|
+
while (j + 1 < lines.length && isParagraphAt(lines, inTable, j + 1)) j++;
|
|
334
|
+
if (isSetextHeading(lines, inTable, j)) opensHeading.fill(true, start, j + 1);
|
|
335
|
+
j++;
|
|
336
|
+
}
|
|
337
|
+
return opensHeading;
|
|
325
338
|
}
|
|
326
|
-
var isBoundary = (lines, inTable, j) => !inTable[j] && DEFINITION_RE.test(lines[j]) || HEADING_RE.test(lines[j]) ||
|
|
339
|
+
var isBoundary = (lines, inTable, opensHeading, j) => !inTable[j] && DEFINITION_RE.test(lines[j]) || HEADING_RE.test(lines[j]) || opensHeading[j];
|
|
327
340
|
function foldSetextTitle(lines, inTable, lastIndex) {
|
|
328
341
|
let first = lastIndex;
|
|
329
342
|
while (first > 0 && isParagraphAt(lines, inTable, first - 1)) first--;
|
|
@@ -432,9 +445,9 @@ function applyKeyword(item, keyword, entries, file, keywordLine, problems, sourc
|
|
|
432
445
|
return;
|
|
433
446
|
}
|
|
434
447
|
const target = keyword === "Needs" ? "needs" : "covers";
|
|
435
|
-
const parse = keyword === "Needs" ? parseNeedEntry :
|
|
448
|
+
const parse = keyword === "Needs" ? parseNeedEntry : parseCoverEntry;
|
|
436
449
|
for (const entry of entries) {
|
|
437
|
-
const id = parse(entry);
|
|
450
|
+
const id = parse(entry, item.id);
|
|
438
451
|
if (id) item[target].push(id);
|
|
439
452
|
else
|
|
440
453
|
problems.push({
|
|
@@ -444,10 +457,11 @@ function applyKeyword(item, keyword, entries, file, keywordLine, problems, sourc
|
|
|
444
457
|
});
|
|
445
458
|
}
|
|
446
459
|
}
|
|
447
|
-
function parseItemBody(lines,
|
|
460
|
+
function parseItemBody(lines, boundary, start, item, file, problems, forwards) {
|
|
461
|
+
const { inTable, opensHeading } = boundary;
|
|
448
462
|
let j = start;
|
|
449
463
|
let descriptionDone = false;
|
|
450
|
-
while (j < lines.length && !isBoundary(lines, inTable, j)) {
|
|
464
|
+
while (j < lines.length && !isBoundary(lines, inTable, opensHeading, j)) {
|
|
451
465
|
const line = lines[j];
|
|
452
466
|
if (takeForward(line, file, j, forwards)) {
|
|
453
467
|
j++;
|
|
@@ -483,10 +497,12 @@ function parseItemBody(lines, inTable, start, item, file, problems, forwards) {
|
|
|
483
497
|
function parseMarkdown(file, text, problems, forwards = []) {
|
|
484
498
|
const lines = text.split(/\r?\n/);
|
|
485
499
|
const inTable = scanTables(lines, file, problems);
|
|
500
|
+
const opensHeading = scanSetextHeadings(lines, inTable);
|
|
501
|
+
const boundary = { inTable, opensHeading };
|
|
486
502
|
const items = [];
|
|
487
503
|
let i = 0;
|
|
488
504
|
while (i < lines.length) {
|
|
489
|
-
const startsHeading =
|
|
505
|
+
const startsHeading = opensHeading[i];
|
|
490
506
|
if (!startsHeading && takeForward(lines[i], file, i, forwards)) {
|
|
491
507
|
i++;
|
|
492
508
|
continue;
|
|
@@ -507,7 +523,7 @@ function parseMarkdown(file, text, problems, forwards = []) {
|
|
|
507
523
|
}
|
|
508
524
|
const item = newItem(makeId(definition[1], definition[2], definition[3], definition[4]), "markdown", file, i + 1);
|
|
509
525
|
item.title = titleAbove(lines, inTable, i);
|
|
510
|
-
i = parseItemBody(lines,
|
|
526
|
+
i = parseItemBody(lines, boundary, i + 1, item, file, problems, forwards);
|
|
511
527
|
items.push(item);
|
|
512
528
|
}
|
|
513
529
|
return items;
|
|
@@ -516,7 +532,7 @@ function parseMarkdown(file, text, problems, forwards = []) {
|
|
|
516
532
|
// src/parse-code.mjs
|
|
517
533
|
import path2 from "node:path";
|
|
518
534
|
var TAG_RE = new RegExp(
|
|
519
|
-
String.raw`\[(?:\s*${ID_SRC}\s*)?>>\s*${
|
|
535
|
+
String.raw`\[(?:\s*${ID_SRC}\s*)?>>\s*${REF_SRC}\s*\]|\[\s*${ID_SRC}\s*\]`,
|
|
520
536
|
"g"
|
|
521
537
|
);
|
|
522
538
|
var FORWARD_RE = new RegExp(FORWARD_SRC, "g");
|
|
@@ -653,36 +669,29 @@ function commentText(line, state, grammar) {
|
|
|
653
669
|
}
|
|
654
670
|
return comment;
|
|
655
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
|
+
}
|
|
656
686
|
function collectTags(comment, file, line, state, items, problems) {
|
|
657
687
|
for (const m of comment.matchAll(TAG_RE)) {
|
|
658
|
-
if (m[
|
|
659
|
-
const item = newItem(makeId(m[
|
|
688
|
+
if (m[8]) {
|
|
689
|
+
const item = newItem(makeId(m[8], m[9], m[10], m[11]), "code", file, line);
|
|
660
690
|
state.lastItem = item;
|
|
661
691
|
state.byId.set(item.id, item);
|
|
662
692
|
items.push(item);
|
|
663
|
-
continue;
|
|
664
|
-
}
|
|
665
|
-
const id = makeId(m[5], m[6], m[7], m[8]);
|
|
666
|
-
if (m[1]) {
|
|
667
|
-
const source = makeId(m[1], m[2], m[3], m[4]);
|
|
668
|
-
const anchor = state.byId.get(source);
|
|
669
|
-
if (anchor) {
|
|
670
|
-
anchor.needs.push(id);
|
|
671
|
-
} else {
|
|
672
|
-
problems.push({
|
|
673
|
-
file,
|
|
674
|
-
line,
|
|
675
|
-
message: `need tag [${source} >> ${id}] has no preceding item tag [${source}] in this file`
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
} else if (state.lastItem) {
|
|
679
|
-
state.lastItem.needs.push(id);
|
|
680
693
|
} else {
|
|
681
|
-
problems
|
|
682
|
-
file,
|
|
683
|
-
line,
|
|
684
|
-
message: `need tag [>>${id}] has no preceding item tag in this file`
|
|
685
|
-
});
|
|
694
|
+
attachNeed(m, file, line, state, problems);
|
|
686
695
|
}
|
|
687
696
|
}
|
|
688
697
|
}
|