prettier-plugin-mmd 0.1.0 → 0.3.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.ja.md +17 -7
- package/README.md +21 -8
- package/lib/index.mjs +1054 -461
- package/package.json +9 -4
package/lib/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { parse, visitorKeys } from "@mmd-toolkit/parser";
|
|
2
2
|
import { builders, printer, utils } from "prettier/doc";
|
|
3
|
+
import { Marked } from "marked";
|
|
4
|
+
import { util } from "prettier";
|
|
3
5
|
//#region src/printers/collections.ts
|
|
4
6
|
/**
|
|
5
7
|
* Append the items in order to the existing array, as `target.push(...items)`
|
|
@@ -445,7 +447,7 @@ function semicolonRulesOf(source) {
|
|
|
445
447
|
const terminators = new Set(body.body.filter((item) => item.type === "RailroadRule").map((item) => item.range[1] - 1));
|
|
446
448
|
rules = {
|
|
447
449
|
kind: "required",
|
|
448
|
-
verbatimStyleLines:
|
|
450
|
+
verbatimStyleLines: "word",
|
|
449
451
|
grammatical: /* @__PURE__ */ new Set([...terminators, ...source.root.comments.filter((comment) => comment.mark === ";").map((comment) => comment.range[0])])
|
|
450
452
|
};
|
|
451
453
|
break;
|
|
@@ -460,7 +462,7 @@ function semicolonRulesOf(source) {
|
|
|
460
462
|
rules = {
|
|
461
463
|
kind: "text",
|
|
462
464
|
grammatical,
|
|
463
|
-
verbatimStyleLines:
|
|
465
|
+
verbatimStyleLines: "semicolon"
|
|
464
466
|
};
|
|
465
467
|
break;
|
|
466
468
|
}
|
|
@@ -806,16 +808,16 @@ function findStyleWord(text) {
|
|
|
806
808
|
}
|
|
807
809
|
/** Diagrams whose grammatical punctuation needs complete word-line protection. */
|
|
808
810
|
function usesVerbatimStyleLines(source) {
|
|
809
|
-
return semicolonRulesOf(source).verbatimStyleLines;
|
|
811
|
+
return semicolonRulesOf(source).verbatimStyleLines !== false;
|
|
810
812
|
}
|
|
811
813
|
/** Verbatim word lines, computed once for protected grammatical punctuation. */
|
|
812
814
|
const verbatimStyleLinesBySource = /* @__PURE__ */ new WeakMap();
|
|
813
815
|
/**
|
|
814
|
-
* Railroad
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
* can join a word across physical lines; all those lines stay together
|
|
816
|
+
* Railroad keeps word lines before joining can select a required terminator;
|
|
817
|
+
* Wardley keeps only lines already containing a semicolon. Both read the line
|
|
818
|
+
* after global directives are omitted. Keeping complete statements and comments
|
|
819
|
+
* protects native punctuation without predicting which semicolon is selected.
|
|
820
|
+
* A removed directive can join a word across physical lines; all those lines stay together
|
|
819
821
|
* (common.md, Where a directive is; docs/railroad.md and docs/wardley.md,
|
|
820
822
|
* Semicolons).
|
|
821
823
|
*/
|
|
@@ -824,13 +826,15 @@ function findVerbatimStyleLines(source) {
|
|
|
824
826
|
if (cached !== void 0) return cached;
|
|
825
827
|
const lines = /* @__PURE__ */ new Set();
|
|
826
828
|
verbatimStyleLinesBySource.set(source, lines);
|
|
827
|
-
|
|
829
|
+
const rule = semicolonRulesOf(source).verbatimStyleLines;
|
|
830
|
+
if (rule === false) return lines;
|
|
828
831
|
let lineStart = source.root.body.range[0];
|
|
829
832
|
let position = lineStart;
|
|
830
833
|
const parts = [];
|
|
831
834
|
/** Retains every source line contributing to this directive-free line. */
|
|
832
835
|
function finishLine(end) {
|
|
833
|
-
|
|
836
|
+
const line = parts.join("");
|
|
837
|
+
if ((rule === "word" || line.includes(";")) && findStyleWord(line) !== -1) {
|
|
834
838
|
let start = lineStartOf(source, lineStart);
|
|
835
839
|
while (start <= end) {
|
|
836
840
|
lines.add(start);
|
|
@@ -951,13 +955,13 @@ const { replaceEndOfLine: replaceEndOfLine$1 } = utils;
|
|
|
951
955
|
* real comments, while still keeping them before directives.
|
|
952
956
|
*
|
|
953
957
|
* Throws when the gap holds any other text than whitespace, line
|
|
954
|
-
* terminators, comments, directives,
|
|
955
|
-
* other token in a node, so such text means that the
|
|
956
|
-
* wrong bounds.
|
|
958
|
+
* terminators, comments, directives, `;` tokens, and supplied opaque nodes:
|
|
959
|
+
* the tree places every other token in a node, so such text means that the
|
|
960
|
+
* printer was given wrong bounds.
|
|
957
961
|
*/
|
|
958
962
|
function readGap(source, start, end, keepsSeparators, options = {}) {
|
|
959
963
|
const { endsText = false, keepsInlineDirectivesWithPrevious = false, dropsSeparatorsBeforeComments = false } = options;
|
|
960
|
-
const lines = scanLines(source, start, end, keepsSeparators, options.relocatedWhitespace ?? [], options.omitted ?? []);
|
|
964
|
+
const lines = scanLines(source, start, end, keepsSeparators, options.relocatedWhitespace ?? [], options.omitted ?? [], options.opaqueNodes ?? []);
|
|
961
965
|
if (lines.length === 1) return readSingleLine(source, lines[0], endsText, keepsInlineDirectivesWithPrevious, dropsSeparatorsBeforeComments);
|
|
962
966
|
const [first, ...rest] = lines;
|
|
963
967
|
const last = rest.pop();
|
|
@@ -1040,8 +1044,20 @@ function readSingleLine(source, line, endsText, keepsInlineDirectivesWithPreviou
|
|
|
1040
1044
|
whitespaceLineAfter: false
|
|
1041
1045
|
};
|
|
1042
1046
|
}
|
|
1043
|
-
/**
|
|
1044
|
-
|
|
1047
|
+
/**
|
|
1048
|
+
* Reads the element that starts at `offset`, and where it ends. Opaque nodes
|
|
1049
|
+
* are complete, disjoint and source-ordered; their internal trivia belongs
|
|
1050
|
+
* to their retained source instead of becoming separate gap items.
|
|
1051
|
+
*/
|
|
1052
|
+
function readGapElement(source, offset, opaqueNodes = []) {
|
|
1053
|
+
const opaque = opaqueNodes[findFirstIndex(opaqueNodes, (node) => node.range[0] >= offset)];
|
|
1054
|
+
if (opaque?.range[0] === offset) return {
|
|
1055
|
+
element: {
|
|
1056
|
+
kind: "item",
|
|
1057
|
+
item: opaque
|
|
1058
|
+
},
|
|
1059
|
+
end: opaque.range[1]
|
|
1060
|
+
};
|
|
1045
1061
|
const trivia = findTriviaBetween(source, offset, offset + 1).at(0);
|
|
1046
1062
|
if (trivia !== void 0) return {
|
|
1047
1063
|
element: {
|
|
@@ -1117,7 +1133,7 @@ function isLineSeparator(character) {
|
|
|
1117
1133
|
/**
|
|
1118
1134
|
* Splits the gap into lines, keeping the items of each line.
|
|
1119
1135
|
*/
|
|
1120
|
-
function scanLines(source, start, end, keepsSeparators, relocatedWhitespace, omittedRanges) {
|
|
1136
|
+
function scanLines(source, start, end, keepsSeparators, relocatedWhitespace, omittedRanges, opaqueNodes) {
|
|
1121
1137
|
const lines = [newLine()];
|
|
1122
1138
|
let current = lines[0];
|
|
1123
1139
|
let spacePending = false;
|
|
@@ -1147,7 +1163,7 @@ function scanLines(source, start, end, keepsSeparators, relocatedWhitespace, omi
|
|
|
1147
1163
|
offset = Math.min(end, omitted[1]);
|
|
1148
1164
|
continue;
|
|
1149
1165
|
}
|
|
1150
|
-
const { element, end: elementEnd } = readGapElement(source, offset);
|
|
1166
|
+
const { element, end: elementEnd } = readGapElement(source, offset, opaqueNodes);
|
|
1151
1167
|
switch (element.kind) {
|
|
1152
1168
|
case "item":
|
|
1153
1169
|
if (!keepsSeparators && isDroppedSemicolon(source, element.item.range[0])) {
|
|
@@ -1381,12 +1397,14 @@ function toAtom(token) {
|
|
|
1381
1397
|
* `-> "b" e - satisfies -> f;g` has the target `f;g`, and the joined line has
|
|
1382
1398
|
* the target `fg`. Such a statement is kept as written (docs/sequence.md and
|
|
1383
1399
|
* docs/class.md, Multi-line statements). This is the one decision about
|
|
1384
|
-
* joining lines that every layout takes.
|
|
1400
|
+
* joining lines that every layout takes. A caller that keeps line breaks
|
|
1401
|
+
* between its structural tokens can ignore trivia in this check; semicolon
|
|
1402
|
+
* line protections still apply.
|
|
1385
1403
|
*/
|
|
1386
|
-
function spansLinesThatCannotJoin(source, start, end) {
|
|
1404
|
+
function spansLinesThatCannotJoin(source, start, end, options = {}) {
|
|
1387
1405
|
const text = source.text.slice(start, end);
|
|
1388
1406
|
if (!text.includes("\n")) return false;
|
|
1389
|
-
if (text.includes(";") || findTriviaBetween(source, start, end).length > 0) return true;
|
|
1407
|
+
if (text.includes(";") || !options.ignoresTrivia && findTriviaBetween(source, start, end).length > 0) return true;
|
|
1390
1408
|
return findSemicolonLines(source).has(lineStartOf(source, end - 1));
|
|
1391
1409
|
}
|
|
1392
1410
|
/**
|
|
@@ -1412,6 +1430,41 @@ function keptAsWritten(start, end) {
|
|
|
1412
1430
|
};
|
|
1413
1431
|
}
|
|
1414
1432
|
/**
|
|
1433
|
+
* The physical line that completes a block header aligns with its statement,
|
|
1434
|
+
* so the body remains one level deeper. A value spanning that line stays whole
|
|
1435
|
+
* (docs/state.md, Composite states; docs/requirement.md, Bodies).
|
|
1436
|
+
*/
|
|
1437
|
+
function alignBlockOpeningLine(source, layout, opening) {
|
|
1438
|
+
const start = lineStartOf(source, opening);
|
|
1439
|
+
if (layout.atoms.some((atom) => atom.start < start && start < atom.end)) return layout;
|
|
1440
|
+
const first = layout.atoms.find((atom) => start <= atom.start && atom.start <= opening);
|
|
1441
|
+
return first === void 0 ? layout : {
|
|
1442
|
+
...layout,
|
|
1443
|
+
outdented: /* @__PURE__ */ new Set([...layout.outdented, first.start])
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Some grammars require a non-LF whitespace run to start before a retained LF.
|
|
1448
|
+
* Keep each first gap-line tail, including complete trivia, while later lines
|
|
1449
|
+
* use ordinary continuation columns (diagrams/requirement.md, Whitespace;
|
|
1450
|
+
* docs/xychart.md, Multi-line statements).
|
|
1451
|
+
*/
|
|
1452
|
+
function keepFirstGapLineTails(source, atoms) {
|
|
1453
|
+
return atoms.map((atom, index) => {
|
|
1454
|
+
const next = atoms[index + 1];
|
|
1455
|
+
if (next === void 0) return atom;
|
|
1456
|
+
for (let end = atom.end; end < next.start;) {
|
|
1457
|
+
const part = readGapElement(source, end);
|
|
1458
|
+
if (part.element.kind === "lineTerminator") return {
|
|
1459
|
+
...atom,
|
|
1460
|
+
end
|
|
1461
|
+
};
|
|
1462
|
+
end = part.end;
|
|
1463
|
+
}
|
|
1464
|
+
return atom;
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1415
1468
|
* Where a layout ends: the end of its last atom. The statements of the body
|
|
1416
1469
|
* start after the header, which holds more than the keyword where the header
|
|
1417
1470
|
* has a direction or an orientation.
|
|
@@ -1438,11 +1491,11 @@ function layoutKeywordHeader(source, keyword) {
|
|
|
1438
1491
|
* `formatsTriviaLines` instead keeps the line breaks while formatting the
|
|
1439
1492
|
* tokens and trivia with the caller's statement and continuation indentation.
|
|
1440
1493
|
*/
|
|
1441
|
-
function layoutEmptyDescriptionBlock(source, start, end, formatsTriviaLines = false) {
|
|
1442
|
-
if (!formatsTriviaLines && spansLinesThatCannotJoin(source, start, end)) return keptAsWritten(start, end);
|
|
1494
|
+
function layoutEmptyDescriptionBlock(source, start, end, formatsTriviaLines = false, opening) {
|
|
1495
|
+
if (!formatsTriviaLines && spansLinesThatCannotJoin(source, start, end)) return spaceDescriptionOpening(source, start, keptAsWritten(start, end), opening);
|
|
1443
1496
|
return {
|
|
1444
1497
|
atoms: collectAtoms(source, start, end, [], []).filter((atom) => source.text.slice(atom.start, atom.end).trim() !== ""),
|
|
1445
|
-
rules:
|
|
1498
|
+
rules: descriptionOpeningRules(source, start, opening),
|
|
1446
1499
|
outdented: /* @__PURE__ */ new Set(),
|
|
1447
1500
|
lineBreaks: formatsTriviaLines ? "kept" : "joined"
|
|
1448
1501
|
};
|
|
@@ -1456,13 +1509,14 @@ function layoutEmptyDescriptionBlock(source, start, end, formatsTriviaLines = fa
|
|
|
1456
1509
|
* whose ranges are exactly those of the brace tokens. Their intervening gap
|
|
1457
1510
|
* is the compacted interior, also used by state-kept-lines.ts.
|
|
1458
1511
|
*/
|
|
1459
|
-
function layoutCompactEmptyDescriptionBlock(source, start, end) {
|
|
1512
|
+
function layoutCompactEmptyDescriptionBlock(source, start, end, opening) {
|
|
1460
1513
|
if (findTriviaBetween(source, start, end).length > 0 || spansLinesThatCannotJoin(source, start, end)) return null;
|
|
1461
1514
|
const closing = expectToken(findTokenEndingBefore(source, end), "the closing empty description brace");
|
|
1462
1515
|
expectValue(closing, "}");
|
|
1516
|
+
const layout = layoutEmptyDescriptionBlock(source, start, end, false, opening);
|
|
1463
1517
|
return {
|
|
1464
|
-
...
|
|
1465
|
-
rules:
|
|
1518
|
+
...layout,
|
|
1519
|
+
rules: new Map([...layout.rules, [closing.range[0], "none"]]),
|
|
1466
1520
|
joinedBefore: /* @__PURE__ */ new Set([closing.range[0]])
|
|
1467
1521
|
};
|
|
1468
1522
|
}
|
|
@@ -1471,13 +1525,15 @@ function layoutCompactEmptyDescriptionBlock(source, start, end) {
|
|
|
1471
1525
|
* its original layout. Keeping the fallback lazy preserves the caller's
|
|
1472
1526
|
* trivia and continuation layout without building it for a compact block.
|
|
1473
1527
|
*/
|
|
1474
|
-
function layoutCompactEmptyDescriptionBlockWithFallback(source, start, end, originalLayout) {
|
|
1475
|
-
return layoutCompactEmptyDescriptionBlock(source, start, end) ?? originalLayout();
|
|
1528
|
+
function layoutCompactEmptyDescriptionBlockWithFallback(source, start, end, originalLayout, opening) {
|
|
1529
|
+
return layoutCompactEmptyDescriptionBlock(source, start, end, opening) ?? originalLayout();
|
|
1476
1530
|
}
|
|
1477
1531
|
/**
|
|
1478
|
-
* The layout of an `accDescr { ... }` statement:
|
|
1479
|
-
*
|
|
1480
|
-
* rules document of the diagram type, Accessibility statements).
|
|
1532
|
+
* The layout of an `accDescr { ... }` statement: its text stands one level
|
|
1533
|
+
* inside the statement and its `}` stands at the statement's level (the
|
|
1534
|
+
* rules document of the diagram type, Accessibility statements). Callers set
|
|
1535
|
+
* `preservesBodyColumns` where raw text also controls membership or box reading.
|
|
1536
|
+
* A closed block
|
|
1481
1537
|
* without text prints `{}` unless trivia requires its existing layout. The
|
|
1482
1538
|
* text is a value of `valueTypes`. The block is closed unless the statement
|
|
1483
1539
|
* says that it is not, as in an XY chart, where a block that is not closed
|
|
@@ -1503,30 +1559,75 @@ function layoutDescriptionBlock(source, statement, end, valueTypes, options = {}
|
|
|
1503
1559
|
}
|
|
1504
1560
|
valueRange = hasText ? [from, to] : null;
|
|
1505
1561
|
}
|
|
1506
|
-
if (valueRange === null) {
|
|
1507
|
-
/** Keeps the existing empty-block trivia and continuation layout. */
|
|
1508
|
-
function originalLayout() {
|
|
1509
|
-
return layoutEmptyDescriptionBlock(source, start, end, options.formatsEmptyTrivia);
|
|
1510
|
-
}
|
|
1511
|
-
return statement.closed !== false ? layoutCompactEmptyDescriptionBlockWithFallback(source, start, end, originalLayout) : originalLayout();
|
|
1512
|
-
}
|
|
1513
1562
|
const block = {
|
|
1514
1563
|
range: statement.range,
|
|
1515
1564
|
value: statement.value,
|
|
1516
1565
|
closed: statement.closed ?? true,
|
|
1517
1566
|
...options.opening === void 0 ? {} : { opening: options.opening }
|
|
1518
1567
|
};
|
|
1519
|
-
|
|
1568
|
+
let layout;
|
|
1569
|
+
if (valueRange === null) {
|
|
1570
|
+
/** Keeps the existing empty-block trivia and continuation layout. */
|
|
1571
|
+
function originalLayout() {
|
|
1572
|
+
return layoutEmptyDescriptionBlock(source, start, end, options.formatsEmptyTrivia, options.opening);
|
|
1573
|
+
}
|
|
1574
|
+
layout = statement.closed !== false ? layoutCompactEmptyDescriptionBlockWithFallback(source, start, end, originalLayout, options.opening) : originalLayout();
|
|
1575
|
+
} else {
|
|
1576
|
+
const closing = findAccDescrBlockClosing(source, block);
|
|
1577
|
+
layout = {
|
|
1578
|
+
atoms: collectAtoms(source, start, end, collectValueNodes(statement, valueTypes).map((value) => value === statement.value ? {
|
|
1579
|
+
...value,
|
|
1580
|
+
range: valueRange
|
|
1581
|
+
} : value), findAccDescrBlockStretches(source, block, valueRange, options.keepsTrailingTrivia)),
|
|
1582
|
+
rules: descriptionOpeningRules(source, start, options.opening),
|
|
1583
|
+
outdented: closing === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([closing]),
|
|
1584
|
+
lineBreaks: "kept"
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1587
|
+
return options.preservesBodyColumns ? layout : indentDescriptionLines(source, block, layout);
|
|
1588
|
+
}
|
|
1589
|
+
/**
|
|
1590
|
+
* Separate the description keyword from its brace in ordinary whitespace;
|
|
1591
|
+
* interior contacts remain authored (docs/info.md, Description blocks).
|
|
1592
|
+
*/
|
|
1593
|
+
function descriptionOpeningRules(source, start, opening) {
|
|
1594
|
+
const brace = expectToken(findDescriptionOpening(source, expectToken(findTokenStartingAt(source, start), "the description keyword"), opening), "the description opener");
|
|
1595
|
+
expectValue(brace, "{");
|
|
1596
|
+
return /* @__PURE__ */ new Map([[brace.range[0], "space"]]);
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Expose only a plain same-line keyword/brace gap inside a retained header.
|
|
1600
|
+
* The rest of its atom stays whole, including empty-body trivia. Protected
|
|
1601
|
+
* line readings take precedence (docs/c4.md, Empty description blocks).
|
|
1602
|
+
*/
|
|
1603
|
+
function spaceDescriptionOpening(source, start, layout, opening) {
|
|
1604
|
+
const keyword = expectToken(findTokenStartingAt(source, start), "accDescr");
|
|
1605
|
+
const brace = expectToken(findDescriptionOpening(source, keyword, opening), "the description opener");
|
|
1606
|
+
if (brace.value !== "{" || ![...source.text.slice(keyword.range[1], brace.range[0])].every((character) => character === " " || character === " ")) return layout;
|
|
1607
|
+
const atoms = [];
|
|
1608
|
+
for (const atom of layout.atoms) {
|
|
1609
|
+
if (atom.doc !== void 0 || atom.start > keyword.range[0] || atom.end < brace.range[1] || spansLinesThatCannotJoin(source, atom.start, atom.end, { ignoresTrivia: true })) {
|
|
1610
|
+
atoms.push(atom);
|
|
1611
|
+
continue;
|
|
1612
|
+
}
|
|
1613
|
+
atoms.push({
|
|
1614
|
+
...atom,
|
|
1615
|
+
end: keyword.range[1]
|
|
1616
|
+
}, {
|
|
1617
|
+
...atom,
|
|
1618
|
+
start: brace.range[0]
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1520
1621
|
return {
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
} : value), findAccDescrBlockStretches(source, block, valueRange, options.keepsTrailingTrivia)),
|
|
1525
|
-
rules: /* @__PURE__ */ new Map(),
|
|
1526
|
-
outdented: closing === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([closing]),
|
|
1527
|
-
lineBreaks: "kept"
|
|
1622
|
+
...layout,
|
|
1623
|
+
atoms,
|
|
1624
|
+
rules: new Map([...layout.rules, [brace.range[0], "space"]])
|
|
1528
1625
|
};
|
|
1529
1626
|
}
|
|
1627
|
+
/** The authored opener, or the next structural token after the keyword. */
|
|
1628
|
+
function findDescriptionOpening(source, keyword, opening) {
|
|
1629
|
+
return opening === void 0 ? findStructuralToken(source, keyword.range[1]) : findTokenStartingAt(source, opening);
|
|
1630
|
+
}
|
|
1530
1631
|
/** Fails when a token that the tree implies is missing. */
|
|
1531
1632
|
function expectToken(token, what) {
|
|
1532
1633
|
if (token === void 0) throw new Error(`prettier-plugin-mmd: no token for ${what}`);
|
|
@@ -1537,19 +1638,66 @@ function expectValue(token, value) {
|
|
|
1537
1638
|
if (token.value !== value) throw new Error(`prettier-plugin-mmd: expected the token ${JSON.stringify(value)}, found ${JSON.stringify(token.value)} at offset ${token.range[0]}`);
|
|
1538
1639
|
}
|
|
1539
1640
|
/**
|
|
1540
|
-
*
|
|
1541
|
-
*
|
|
1542
|
-
*
|
|
1543
|
-
*
|
|
1544
|
-
*
|
|
1545
|
-
*
|
|
1641
|
+
* Align ordinary description text after LF without changing its contents or
|
|
1642
|
+
* line breaks. The Db setter drops this indentation. Directives and removed
|
|
1643
|
+
* line feeds keep their source, and atoms outside the body stay untouched
|
|
1644
|
+
* (docs/timeline.md, Multi-line values; docs/pie.md, Description blocks).
|
|
1645
|
+
* Callers whose Db also stores the raw description as a member keep their
|
|
1646
|
+
* original layout instead (docs/flowchart.md, Multi-line values).
|
|
1647
|
+
*/
|
|
1648
|
+
function indentDescriptionLines(source, block, layout) {
|
|
1649
|
+
const opening = expectToken(findDescriptionOpening(source, expectToken(findTokenStartingAt(source, block.range[0]), "the description keyword"), block.opening), "the description opener");
|
|
1650
|
+
const closing = findAccDescrBlockClosing(source, block);
|
|
1651
|
+
const bodyEnd = closing ?? block.range[1];
|
|
1652
|
+
const atoms = [];
|
|
1653
|
+
const keptBreaksBefore = new Set(layout.keptBreaksBefore);
|
|
1654
|
+
const outdented = new Set(layout.outdented);
|
|
1655
|
+
if (closing !== null) outdented.add(closing);
|
|
1656
|
+
for (const atom of layout.atoms) {
|
|
1657
|
+
if (atom.end <= opening.range[1] || atom.start >= bodyEnd) {
|
|
1658
|
+
atoms.push(atom);
|
|
1659
|
+
continue;
|
|
1660
|
+
}
|
|
1661
|
+
const trivia = findTriviaBetween(source, atom.start, atom.end);
|
|
1662
|
+
let start = atom.start;
|
|
1663
|
+
for (let offset = Math.max(start, opening.range[1]); offset < Math.min(atom.end, bodyEnd); offset++) {
|
|
1664
|
+
if (source.text[offset] !== "\n") continue;
|
|
1665
|
+
if (trivia.some((item) => item.range[0] <= offset && offset < item.range[1]) || source.removedLineFeeds.has(offset)) continue;
|
|
1666
|
+
if (start < offset) atoms.push({
|
|
1667
|
+
start,
|
|
1668
|
+
end: offset
|
|
1669
|
+
});
|
|
1670
|
+
start = offset + 1;
|
|
1671
|
+
while (start < atom.end && (source.text[start] === " " || source.text[start] === " ")) start++;
|
|
1672
|
+
if (start < atom.end && source.text[start] !== "\n") keptBreaksBefore.add(start);
|
|
1673
|
+
offset = start - 1;
|
|
1674
|
+
}
|
|
1675
|
+
if (start < atom.end) atoms.push({
|
|
1676
|
+
...atom,
|
|
1677
|
+
start
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
return {
|
|
1681
|
+
...layout,
|
|
1682
|
+
atoms,
|
|
1683
|
+
keptBreaksBefore,
|
|
1684
|
+
outdented
|
|
1685
|
+
};
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* The retained stretch of an `accDescr { ... }` block: from the `{` to the
|
|
1689
|
+
* end of its text and following trivia when text starts on a later line.
|
|
1690
|
+
* Initially retain the complete interior, including margins and comment lines.
|
|
1691
|
+
* `indentDescriptionLines` then aligns safe lines; container descriptions keep
|
|
1692
|
+
* the raw columns that also supply membership (docs/flowchart.md, Multi-line
|
|
1693
|
+
* values). The whitespace after `{` is read with `{`, so text on
|
|
1546
1694
|
* the line of the `{` is spaced as any other token. `valueRange` supplies the
|
|
1547
1695
|
* printed bounds when a Literal's AST range includes exterior whitespace.
|
|
1548
1696
|
* `keepsTrailingTrivia` also keeps trivia lines after an opener-line value,
|
|
1549
1697
|
* without absorbing the closing brace (docs/c4.md, Description blocks).
|
|
1550
1698
|
*/
|
|
1551
1699
|
function findAccDescrBlockStretches(source, statement, valueRange = statement.value?.range ?? null, keepsTrailingTrivia = false) {
|
|
1552
|
-
const brace = expectToken(statement.opening === void 0 ?
|
|
1700
|
+
const brace = expectToken(statement.opening === void 0 ? findDescriptionOpening(source, expectToken(findTokenStartingAt(source, statement.range[0]), "`accDescr`")) : findTokenStartingAt(source, statement.opening), "the `{` of an accDescr block");
|
|
1553
1701
|
expectValue(brace, "{");
|
|
1554
1702
|
if (valueRange === null) return [];
|
|
1555
1703
|
const lastTrivia = findTriviaBetween(source, valueRange[1], statement.range[1]).at(-1);
|
|
@@ -1563,7 +1711,7 @@ function findAccDescrBlockStretches(source, statement, valueRange = statement.va
|
|
|
1563
1711
|
/**
|
|
1564
1712
|
* The start of the `}` that closes an `accDescr` block, whose line starts
|
|
1565
1713
|
* at the statement's indentation, or null when the block is not closed. The
|
|
1566
|
-
*
|
|
1714
|
+
* text range keeps its written limits (see `findAccDescrBlockStretches`),
|
|
1567
1715
|
* and the whitespace before the `}` is neither in the text nor in the Db,
|
|
1568
1716
|
* so the `}` lines up with the `accDescr` that it closes.
|
|
1569
1717
|
*/
|
|
@@ -1625,7 +1773,7 @@ function protectSemicolonPrefixes(source, start, end, atoms, structuralSemicolon
|
|
|
1625
1773
|
}
|
|
1626
1774
|
//#endregion
|
|
1627
1775
|
//#region src/printers/lines.ts
|
|
1628
|
-
const { align, hardline, literalline: literalline$
|
|
1776
|
+
const { align, hardline: hardline$1, literalline: literalline$2 } = builders;
|
|
1629
1777
|
const { mapDoc, replaceEndOfLine } = utils;
|
|
1630
1778
|
/**
|
|
1631
1779
|
* Joins lines with line breaks, with one empty line where a line has
|
|
@@ -1649,22 +1797,22 @@ function lineBreakBetween(previous, next, indentation) {
|
|
|
1649
1797
|
const deeper = next.extraIndentation ?? "";
|
|
1650
1798
|
if (next.writtenBreakBefore !== void 0) return [next.writtenBreakBefore, next.writtenIndentation ?? indentation + deeper];
|
|
1651
1799
|
if (next.spaceLineBefore === true) return [
|
|
1652
|
-
literalline$
|
|
1800
|
+
literalline$2,
|
|
1653
1801
|
" ",
|
|
1654
|
-
literalline$
|
|
1802
|
+
literalline$2,
|
|
1655
1803
|
next.writtenIndentation ?? indentation + deeper
|
|
1656
1804
|
];
|
|
1657
|
-
if (next.writtenIndentation !== void 0) return [next.blankBefore ? [literalline$
|
|
1805
|
+
if (next.writtenIndentation !== void 0) return [next.blankBefore ? [literalline$2, literalline$2] : literalline$2, next.writtenIndentation];
|
|
1658
1806
|
if (!previous.endsWithWhitespace) return next.blankBefore ? [
|
|
1659
|
-
hardline,
|
|
1660
|
-
hardline,
|
|
1807
|
+
hardline$1,
|
|
1808
|
+
hardline$1,
|
|
1661
1809
|
deeper
|
|
1662
|
-
] : [hardline, deeper];
|
|
1810
|
+
] : [hardline$1, deeper];
|
|
1663
1811
|
return next.blankBefore ? [
|
|
1664
|
-
literalline$
|
|
1665
|
-
hardline,
|
|
1812
|
+
literalline$2,
|
|
1813
|
+
hardline$1,
|
|
1666
1814
|
deeper
|
|
1667
|
-
] : [literalline$
|
|
1815
|
+
] : [literalline$2, indentation + deeper];
|
|
1668
1816
|
}
|
|
1669
1817
|
/**
|
|
1670
1818
|
* Breaks the line after `last` and starts the next line at `indentation`,
|
|
@@ -1784,7 +1932,7 @@ function endsInsideOpenDirective(source) {
|
|
|
1784
1932
|
}
|
|
1785
1933
|
//#endregion
|
|
1786
1934
|
//#region src/printers/atoms.ts
|
|
1787
|
-
const { indent: indent$
|
|
1935
|
+
const { indent: indent$3 } = builders;
|
|
1788
1936
|
/**
|
|
1789
1937
|
* Prints atoms with the gaps between them.
|
|
1790
1938
|
*
|
|
@@ -1794,7 +1942,8 @@ const { indent: indent$2 } = builders;
|
|
|
1794
1942
|
* inside the statement, the line stays broken, and every later line of the
|
|
1795
1943
|
* statement starts one level deeper, except the lines of the layout's
|
|
1796
1944
|
* outdented atoms; runs of empty lines become one. An atom's written
|
|
1797
|
-
* indentation overrides that level. When the
|
|
1945
|
+
* indentation or statement-relative padding overrides that level. When the
|
|
1946
|
+
* layout joins line breaks, or joins
|
|
1798
1947
|
* the one before an atom (`joinedBefore`), such a line break is printed as
|
|
1799
1948
|
* whitespace on one line is.
|
|
1800
1949
|
*/
|
|
@@ -1824,12 +1973,13 @@ function printAtoms(source, layout, indentation) {
|
|
|
1824
1973
|
}
|
|
1825
1974
|
for (const atom of layout.atoms) {
|
|
1826
1975
|
const text = source.text.slice(atom.start, atom.end);
|
|
1976
|
+
const alignedIndentation = atom.statementPadding === void 0 ? void 0 : indentation.statement + atom.statementPadding;
|
|
1827
1977
|
if (previous !== void 0) {
|
|
1828
1978
|
if (layout.writtenGapsBefore?.has(atom.start) === true) {
|
|
1829
1979
|
const lastBreak = source.text.lastIndexOf("\n", atom.start - 1);
|
|
1830
1980
|
if (layout.alignedGapsBefore?.has(atom.start) === true && lastBreak >= previous.end && [...source.text.slice(lastBreak + 1, atom.start)].every((character) => character === " " || character === " ")) current.push(printAsWritten(source, previous.end, lastBreak + 1), indentation.statement);
|
|
1831
1981
|
else current.push(printAsWritten(source, previous.end, atom.start));
|
|
1832
|
-
current.push(printAsWritten(source, atom.start, atom.end));
|
|
1982
|
+
current.push(atom.doc ?? printAsWritten(source, atom.start, atom.end));
|
|
1833
1983
|
currentEndsWithWhitespace = endsWithSpaceOrTab(text);
|
|
1834
1984
|
previous = atom;
|
|
1835
1985
|
continue;
|
|
@@ -1847,13 +1997,13 @@ function printAtoms(source, layout, indentation) {
|
|
|
1847
1997
|
gapOffset = gap.trailing.range[1];
|
|
1848
1998
|
}
|
|
1849
1999
|
for (const line of gap.lines) {
|
|
1850
|
-
breakCurrentLine(line.blankBefore, false, indentation.trivia);
|
|
2000
|
+
breakCurrentLine(line.blankBefore, false, alignedIndentation ?? indentation.trivia);
|
|
1851
2001
|
currentWrittenBreak = keepsBreaks ? literalBreaksBetween(source, gapOffset, line.run.range[0]) : void 0;
|
|
1852
2002
|
current = [line.run.doc];
|
|
1853
2003
|
currentEndsWithWhitespace = line.run.endsWithWhitespace;
|
|
1854
2004
|
gapOffset = line.run.range[1];
|
|
1855
2005
|
}
|
|
1856
|
-
breakCurrentLine(gap.blankAfter, layout.outdented.has(atom.start), atom.writtenIndentation);
|
|
2006
|
+
breakCurrentLine(gap.blankAfter, layout.outdented.has(atom.start), atom.writtenIndentation ?? alignedIndentation);
|
|
1857
2007
|
currentWrittenBreak = keepsBreaks ? literalBreaksBetween(source, gapOffset, gap.leading?.range[0] ?? atom.start) : void 0;
|
|
1858
2008
|
if (gap.leading !== null) current = [withLeading(gap.leading, "")];
|
|
1859
2009
|
} else if (gap.trailing !== null || gap.leading !== null) {
|
|
@@ -1872,7 +2022,7 @@ function printAtoms(source, layout, indentation) {
|
|
|
1872
2022
|
current.push((written.includes("\u2028") || written.includes("\u2029")) && layout.joinedBefore?.has(atom.start) !== true ? written : inStyleRuleStretch ? written === "" ? "" : " " : spaceFor(layout.rules.get(atom.start), previous, atom));
|
|
1873
2023
|
}
|
|
1874
2024
|
}
|
|
1875
|
-
current.push(printAsWritten(source, atom.start, atom.end));
|
|
2025
|
+
current.push(atom.doc ?? printAsWritten(source, atom.start, atom.end));
|
|
1876
2026
|
currentEndsWithWhitespace = endsWithSpaceOrTab(text);
|
|
1877
2027
|
previous = atom;
|
|
1878
2028
|
}
|
|
@@ -1882,7 +2032,7 @@ function printAtoms(source, layout, indentation) {
|
|
|
1882
2032
|
if (index === 0) return line.doc;
|
|
1883
2033
|
const previousLine = lines[index - 1];
|
|
1884
2034
|
if (line.outdented) return [lineBreakBetween(previousLine, line, indentation.statement), line.doc];
|
|
1885
|
-
return indent$
|
|
2035
|
+
return indent$3([lineBreakBetween(previousLine, line, indentation.continuation), line.doc]);
|
|
1886
2036
|
}),
|
|
1887
2037
|
endsWithWhitespace: lines[lines.length - 1].endsWithWhitespace
|
|
1888
2038
|
};
|
|
@@ -1903,7 +2053,7 @@ function literalBreaksBetween(source, start, end) {
|
|
|
1903
2053
|
}
|
|
1904
2054
|
//#endregion
|
|
1905
2055
|
//#region src/printers/blocks.ts
|
|
1906
|
-
const { indent: indent$
|
|
2056
|
+
const { indent: indent$2 } = builders;
|
|
1907
2057
|
/**
|
|
1908
2058
|
* The indentation of a line with a comment that starts with `%%{`, which has
|
|
1909
2059
|
* `gaps` gaps of whitespace before the comment after its first item (see
|
|
@@ -2291,10 +2441,10 @@ function openingLine(doc, block, endsWithWhitespace) {
|
|
|
2291
2441
|
}
|
|
2292
2442
|
/**
|
|
2293
2443
|
* Prints a diagram from its header line: its statements one level deeper,
|
|
2294
|
-
* or at the level of the header with `bodyDepth` 0 (
|
|
2295
|
-
*
|
|
2296
|
-
* the
|
|
2297
|
-
*
|
|
2444
|
+
* or at the level of the header with `bodyDepth` 0 (eventmodeling and sankey).
|
|
2445
|
+
* The statements run to the end of the text, so comments and directives after
|
|
2446
|
+
* the last one stand at its level, and what stands on the last line is a line
|
|
2447
|
+
* of its own.
|
|
2298
2448
|
*/
|
|
2299
2449
|
function printDiagramBlock(source, header, block, options, bodyDepth = 1) {
|
|
2300
2450
|
const indentation = indentationOf(options, bodyDepth);
|
|
@@ -2310,7 +2460,7 @@ function printDiagramBlock(source, header, block, options, bodyDepth = 1) {
|
|
|
2310
2460
|
const body = [block.continuesOpeningLine ? "" : lineBreakBetween(header, lines[0], indentation), joinLines(lines, indentation)];
|
|
2311
2461
|
return [
|
|
2312
2462
|
header.doc,
|
|
2313
|
-
bodyDepth === 0 ? body : indent$
|
|
2463
|
+
bodyDepth === 0 ? body : indent$2(body),
|
|
2314
2464
|
endOfText
|
|
2315
2465
|
];
|
|
2316
2466
|
}
|
|
@@ -2324,7 +2474,7 @@ function printClosedBlock(header, block, closing, depth, options) {
|
|
|
2324
2474
|
const bodyIndentation = indentationOf(options, depth + 1);
|
|
2325
2475
|
const last = block.lines.at(-1) ?? header;
|
|
2326
2476
|
const [first] = block.lines;
|
|
2327
|
-
const body = first === void 0 ? "" : indent$
|
|
2477
|
+
const body = first === void 0 ? "" : indent$2([block.continuesOpeningLine ? "" : lineBreakBetween(header, first, bodyIndentation), joinLines(block.lines, bodyIndentation)]);
|
|
2328
2478
|
return [
|
|
2329
2479
|
header.doc,
|
|
2330
2480
|
body,
|
|
@@ -2337,7 +2487,7 @@ function printOpenBlock(header, block, depth, options) {
|
|
|
2337
2487
|
const first = block.lines.at(0);
|
|
2338
2488
|
return [
|
|
2339
2489
|
header.doc,
|
|
2340
|
-
first === void 0 ? "" : indent$
|
|
2490
|
+
first === void 0 ? "" : indent$2([block.continuesOpeningLine ? "" : lineBreakBetween(header, first, indentationOf(options, depth + 1)), joinLines(block.lines, indentationOf(options, depth + 1))]),
|
|
2341
2491
|
block.writtenEnd ?? ""
|
|
2342
2492
|
];
|
|
2343
2493
|
}
|
|
@@ -2505,9 +2655,11 @@ function layoutBlockRow(source, statements) {
|
|
|
2505
2655
|
if (statements.some((statement, index) => index > 0 && readGap(source, statements[index - 1].range[1], statement.range[0], true).breaksLine)) return keptAsWritten(statements[0].range[0], statements.at(-1).range[1]);
|
|
2506
2656
|
const rules = /* @__PURE__ */ new Map();
|
|
2507
2657
|
const atoms = [];
|
|
2658
|
+
let lineBreaks = "joined";
|
|
2508
2659
|
for (const [index, statement] of statements.entries()) {
|
|
2509
2660
|
const layout = layoutBlockStatement(source, statement);
|
|
2510
2661
|
appendItems(atoms, layout.atoms);
|
|
2662
|
+
if (layout.lineBreaks === "kept") lineBreaks = "kept";
|
|
2511
2663
|
for (const [offset, rule] of layout.rules) rules.set(offset, rule);
|
|
2512
2664
|
if (index > 0) rules.set(statement.range[0], "space");
|
|
2513
2665
|
}
|
|
@@ -2515,7 +2667,7 @@ function layoutBlockRow(source, statements) {
|
|
|
2515
2667
|
atoms,
|
|
2516
2668
|
rules,
|
|
2517
2669
|
outdented: /* @__PURE__ */ new Set(),
|
|
2518
|
-
lineBreaks
|
|
2670
|
+
lineBreaks
|
|
2519
2671
|
};
|
|
2520
2672
|
}
|
|
2521
2673
|
/**
|
|
@@ -2534,16 +2686,20 @@ function layoutCompositeHead(source, composite) {
|
|
|
2534
2686
|
outdented: /* @__PURE__ */ new Set(),
|
|
2535
2687
|
lineBreaks: "joined"
|
|
2536
2688
|
};
|
|
2537
|
-
|
|
2689
|
+
const start = keyword.range[0];
|
|
2690
|
+
const end = head.range[1];
|
|
2691
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
2692
|
+
if (keepsLineBreaks && (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
2538
2693
|
const layout = layoutBlockStatement(source, head);
|
|
2694
|
+
const atoms = [{
|
|
2695
|
+
start: keyword.range[0],
|
|
2696
|
+
end: keyword.range[1]
|
|
2697
|
+
}, ...layout.atoms];
|
|
2539
2698
|
return {
|
|
2540
|
-
atoms:
|
|
2541
|
-
start: keyword.range[0],
|
|
2542
|
-
end: keyword.range[1]
|
|
2543
|
-
}, ...layout.atoms],
|
|
2699
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
2544
2700
|
rules: new Map([...layout.rules, [head.range[0], "none"]]),
|
|
2545
2701
|
outdented: /* @__PURE__ */ new Set(),
|
|
2546
|
-
lineBreaks: "joined"
|
|
2702
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
2547
2703
|
};
|
|
2548
2704
|
}
|
|
2549
2705
|
/** Where the line that opens a composite ends, and the `end` that closes it. */
|
|
@@ -2560,17 +2716,21 @@ function findCompositeBounds(source, composite) {
|
|
|
2560
2716
|
* The layout of a statement, from its start to the end of its range.
|
|
2561
2717
|
*
|
|
2562
2718
|
* - A statement written over several lines stands on one line where the
|
|
2563
|
-
* lexer reads the line break as whitespace
|
|
2564
|
-
*
|
|
2565
|
-
*
|
|
2719
|
+
* lexer reads the line break as whitespace. Trivia keeps structural gaps
|
|
2720
|
+
* broken with ordinary continuation columns; semicolon lines and joining
|
|
2721
|
+
* regions retain their layout (docs/block.md, Multi-line statements).
|
|
2566
2722
|
* - The rules of the gaps are those of docs/block.md: Columns and space,
|
|
2567
2723
|
* Shapes, Edges, and Styles.
|
|
2568
2724
|
*/
|
|
2569
2725
|
function layoutBlockStatement(source, statement) {
|
|
2570
2726
|
const start = statement.range[0];
|
|
2571
2727
|
const end = statement.range[1];
|
|
2572
|
-
if (statement.type === "BlockAccDescrBlockStatement") return
|
|
2573
|
-
|
|
2728
|
+
if (statement.type === "BlockAccDescrBlockStatement") return layoutDescriptionBlock(source, {
|
|
2729
|
+
...statement,
|
|
2730
|
+
value: null
|
|
2731
|
+
}, end, blockValueNodeTypes, { formatsEmptyTrivia: true });
|
|
2732
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
2733
|
+
if (keepsLineBreaks && (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
2574
2734
|
const rules = /* @__PURE__ */ new Map();
|
|
2575
2735
|
const kept = [];
|
|
2576
2736
|
switch (statement.type) {
|
|
@@ -2592,11 +2752,12 @@ function layoutBlockStatement(source, statement) {
|
|
|
2592
2752
|
break;
|
|
2593
2753
|
default: throw new Error(`prettier-plugin-mmd: unknown statement ${JSON.stringify(statement)}`);
|
|
2594
2754
|
}
|
|
2755
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, blockValueNodeTypes), kept);
|
|
2595
2756
|
return {
|
|
2596
|
-
atoms:
|
|
2757
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
2597
2758
|
rules,
|
|
2598
2759
|
outdented: /* @__PURE__ */ new Set(),
|
|
2599
|
-
lineBreaks: "joined"
|
|
2760
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
2600
2761
|
};
|
|
2601
2762
|
}
|
|
2602
2763
|
/**
|
|
@@ -3093,7 +3254,7 @@ function layoutBlockOpening$2(source, statement, opening) {
|
|
|
3093
3254
|
* break inside a statement is whitespace to the lexer only after
|
|
3094
3255
|
* `direction` and after the `:` of `accTitle` and `accDescr`
|
|
3095
3256
|
* (diagrams/class.md, The statement context); one with a comment or a
|
|
3096
|
-
* directive
|
|
3257
|
+
* directive keeps its line breaks and aligns structural continuations. The
|
|
3097
3258
|
* lines of an `accDescr { ... }` block are lines of its text, and are
|
|
3098
3259
|
* kept (docs/class.md, Multi-line values).
|
|
3099
3260
|
* - A relation has one space on each side of its arrow and of its
|
|
@@ -3107,49 +3268,59 @@ function layoutBlockOpening$2(source, statement, opening) {
|
|
|
3107
3268
|
*/
|
|
3108
3269
|
function layoutClassStatement(source, statement, end) {
|
|
3109
3270
|
const start = statement.range[0];
|
|
3110
|
-
if (statement.type !== "ClassAccDescrBlockStatement" && spansLinesThatCannotJoin(source, start, end)) return {
|
|
3111
|
-
atoms: [{
|
|
3112
|
-
start,
|
|
3113
|
-
end
|
|
3114
|
-
}],
|
|
3115
|
-
rules: /* @__PURE__ */ new Map(),
|
|
3116
|
-
outdented: /* @__PURE__ */ new Set(),
|
|
3117
|
-
lineBreaks: "kept"
|
|
3118
|
-
};
|
|
3119
|
-
const values = collectValueNodes(statement, classValueNodeTypes);
|
|
3120
3271
|
if (statement.type === "ClassAccDescrBlockStatement") {
|
|
3121
3272
|
const block = {
|
|
3122
3273
|
range: statement.range,
|
|
3123
3274
|
value: statement.value,
|
|
3124
3275
|
closed: true
|
|
3125
3276
|
};
|
|
3126
|
-
/**
|
|
3127
|
-
function
|
|
3277
|
+
/** Keeps the block's line breaks, including those around empty trivia. */
|
|
3278
|
+
function layoutExpandedBlock() {
|
|
3128
3279
|
const closing = findAccDescrBlockClosing(source, block);
|
|
3129
|
-
return {
|
|
3130
|
-
atoms: collectAtoms(source, start, end,
|
|
3131
|
-
rules:
|
|
3280
|
+
return indentDescriptionLines(source, block, {
|
|
3281
|
+
atoms: collectAtoms(source, start, end, collectValueNodes(statement, classValueNodeTypes), findAccDescrBlockStretches(source, block)),
|
|
3282
|
+
rules: descriptionOpeningRules(source, start),
|
|
3132
3283
|
outdented: closing === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([closing]),
|
|
3133
3284
|
lineBreaks: "kept"
|
|
3134
|
-
};
|
|
3285
|
+
});
|
|
3135
3286
|
}
|
|
3136
|
-
return statement.value === null ? layoutCompactEmptyDescriptionBlockWithFallback(source, start, end,
|
|
3287
|
+
return statement.value === null ? layoutCompactEmptyDescriptionBlockWithFallback(source, start, end, layoutExpandedBlock) : layoutExpandedBlock();
|
|
3137
3288
|
}
|
|
3289
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
3290
|
+
if (keepsLineBreaks && (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return {
|
|
3291
|
+
atoms: [{
|
|
3292
|
+
start,
|
|
3293
|
+
end
|
|
3294
|
+
}],
|
|
3295
|
+
rules: /* @__PURE__ */ new Map(),
|
|
3296
|
+
outdented: /* @__PURE__ */ new Set(),
|
|
3297
|
+
lineBreaks: "kept"
|
|
3298
|
+
};
|
|
3299
|
+
const values = collectValueNodes(statement, classValueNodeTypes);
|
|
3138
3300
|
const kept = [
|
|
3139
3301
|
...findGenericStretches(source, statement, end),
|
|
3140
|
-
...findMemberStretches(statement),
|
|
3302
|
+
...findMemberStretches(source, statement),
|
|
3141
3303
|
...findBlankLabelStretches(source, statement),
|
|
3142
3304
|
...findOpenNameStretches(source, statement)
|
|
3143
3305
|
];
|
|
3306
|
+
if (statement.type === "ClassCallbackStatement" && statement.callback.type === "ClassLiteral") {
|
|
3307
|
+
const opening = expectToken(findStructuralToken(source, statement.callback.range[1]), "the `(` after a callback name");
|
|
3308
|
+
expectValue(opening, "(");
|
|
3309
|
+
kept.push({
|
|
3310
|
+
start: statement.callback.range[0],
|
|
3311
|
+
end: opening.range[1]
|
|
3312
|
+
});
|
|
3313
|
+
}
|
|
3144
3314
|
const keepsDirectionValue = (statement.type === "ClassAccTitleStatement" || statement.type === "ClassAccDescrStatement") && source.text.slice(start, statement.value.range[0]).includes("\n") && holdsDirection(source, {
|
|
3145
3315
|
range: statement.range,
|
|
3146
3316
|
text: statement.value.value
|
|
3147
3317
|
}, { caseSensitive: true });
|
|
3318
|
+
const atoms = collectAtoms(source, start, end, values.filter((value) => !kept.some((stretch) => containsRange(stretch, value))), kept);
|
|
3148
3319
|
return {
|
|
3149
|
-
atoms:
|
|
3320
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
3150
3321
|
rules: statementRules$8(source, statement),
|
|
3151
3322
|
outdented: /* @__PURE__ */ new Set(),
|
|
3152
|
-
lineBreaks: keepsDirectionValue ? "kept" : "joined"
|
|
3323
|
+
lineBreaks: keepsLineBreaks || keepsDirectionValue ? "kept" : "joined"
|
|
3153
3324
|
};
|
|
3154
3325
|
}
|
|
3155
3326
|
/**
|
|
@@ -3226,20 +3397,43 @@ function findBlankLabelStretches(source, statement) {
|
|
|
3226
3397
|
}];
|
|
3227
3398
|
}
|
|
3228
3399
|
/**
|
|
3229
|
-
* The member
|
|
3230
|
-
*
|
|
3400
|
+
* The member of a member statement, retaining its values while ordinary
|
|
3401
|
+
* method padding uses its planned layout. Whitespace after a visibility mark is part of
|
|
3231
3402
|
* the member's name in the Db (diagrams/class.md, Building the summary):
|
|
3232
3403
|
* `+ foo()` has the name ` foo`, and `+foo()` the name `foo`.
|
|
3233
3404
|
*/
|
|
3234
|
-
function findMemberStretches(statement) {
|
|
3405
|
+
function findMemberStretches(source, statement) {
|
|
3235
3406
|
if (statement.type !== "ClassMemberStatement" || statement.member === null) return [];
|
|
3236
3407
|
const { range } = statement.member;
|
|
3237
3408
|
return [{
|
|
3238
3409
|
start: range[0],
|
|
3239
|
-
end: range[1]
|
|
3410
|
+
end: range[1],
|
|
3411
|
+
doc: statement.member.type === "ClassMethod" ? printClassMethod(source, statement.member) : void 0
|
|
3240
3412
|
}];
|
|
3241
3413
|
}
|
|
3242
3414
|
/**
|
|
3415
|
+
* Method fields already exclude harmless exterior padding. Keep their contents
|
|
3416
|
+
* and classifier tails, formatting only the gaps around the AST fields
|
|
3417
|
+
* (diagrams/class.md, Member lines; docs/class.md, Member lines).
|
|
3418
|
+
*/
|
|
3419
|
+
function printClassMethod(source, method) {
|
|
3420
|
+
const [start, end] = method.range;
|
|
3421
|
+
const text = source.text.slice(start, end);
|
|
3422
|
+
if (method.textBefore !== null || method.textAfter !== null || text.includes("\n") || text.includes("\u2028") || text.includes("\u2029") || text.includes(";") || findClassSemicolonLines(source).has(lineStartOf(source, start)) || findTriviaBetween(source, start, end).length > 0) return void 0;
|
|
3423
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(method, classValueNodeTypes), []);
|
|
3424
|
+
const rules = /* @__PURE__ */ new Map();
|
|
3425
|
+
for (const atom of atoms.slice(1)) rules.set(atom.start, atom.start === method.returnType?.range[0] ? "space" : "none");
|
|
3426
|
+
return printAtoms(source, {
|
|
3427
|
+
atoms,
|
|
3428
|
+
rules,
|
|
3429
|
+
outdented: /* @__PURE__ */ new Set(),
|
|
3430
|
+
lineBreaks: "joined"
|
|
3431
|
+
}, {
|
|
3432
|
+
statement: "",
|
|
3433
|
+
continuation: ""
|
|
3434
|
+
}).doc;
|
|
3435
|
+
}
|
|
3436
|
+
/**
|
|
3243
3437
|
* The generic types of the class names of a node before `end`, each from
|
|
3244
3438
|
* its first `~` to its second, as written: the whitespace between the two
|
|
3245
3439
|
* `~` is part of the type in the Db (diagrams/class.md, Building the
|
|
@@ -3407,7 +3601,7 @@ function printClass(path, options, print, source) {
|
|
|
3407
3601
|
const node = path.node;
|
|
3408
3602
|
switch (node.type) {
|
|
3409
3603
|
case "ClassDiagram": return withSignificantIndentation(printDiagram$6(path, bodyOptions, print, source, node), options);
|
|
3410
|
-
case "ClassMethod":
|
|
3604
|
+
case "ClassMethod": return printClassMethod(source, node) ?? printAsWritten(source, node.range[0], node.range[1]);
|
|
3411
3605
|
case "ClassAttribute":
|
|
3412
3606
|
case "ClassAnnotation": return printAsWritten(source, node.range[0], node.range[1]);
|
|
3413
3607
|
}
|
|
@@ -3461,7 +3655,7 @@ function printNamespace(path, options, print, source, statement, depth) {
|
|
|
3461
3655
|
}
|
|
3462
3656
|
/**
|
|
3463
3657
|
* Prints a class statement with its member body: the line of the class with
|
|
3464
|
-
* its `{`, the member lines one level deeper
|
|
3658
|
+
* its `{`, the member lines one level deeper using their own layouts, and the `}`
|
|
3465
3659
|
* (docs/class.md, Member bodies).
|
|
3466
3660
|
*/
|
|
3467
3661
|
function printMemberBlock(path, options, print, source, statement, depth) {
|
|
@@ -3737,7 +3931,7 @@ function findC4KeptLines(source) {
|
|
|
3737
3931
|
const line = lineStartOf(source, directive.range[0]);
|
|
3738
3932
|
const end = lineEndOf(source, directive.range[1]);
|
|
3739
3933
|
const next = nonDirectiveTokens[findFirstIndex(nonDirectiveTokens, (token) => token.range[0] >= line)];
|
|
3740
|
-
if (next !== void 0 && next.range[0] < end)
|
|
3934
|
+
if (next !== void 0 && next.range[0] < end) joined.add(line);
|
|
3741
3935
|
}
|
|
3742
3936
|
const kept = {
|
|
3743
3937
|
joined,
|
|
@@ -3803,15 +3997,47 @@ function addNameListRules(source, names, rules) {
|
|
|
3803
3997
|
/**
|
|
3804
3998
|
* The rules of a `classDef` or `style` statement: its names are separated by
|
|
3805
3999
|
* `,` without whitespace, and the first style stands after one space. The
|
|
3806
|
-
*
|
|
3807
|
-
*
|
|
4000
|
+
* default style/comma gaps follow the source. Safe ER and requirement units
|
|
4001
|
+
* instead use no space before a comma and one after it (docs/er.md and
|
|
4002
|
+
* docs/requirement.md, Styles and classes).
|
|
3808
4003
|
*/
|
|
3809
|
-
function styleStatementRules(source, names, styles) {
|
|
4004
|
+
function styleStatementRules(source, names, styles, compactStyles = false) {
|
|
3810
4005
|
const rules = /* @__PURE__ */ new Map();
|
|
3811
4006
|
addNameListRules(source, names, rules);
|
|
3812
4007
|
rules.set(styles[0].range[0], "space");
|
|
4008
|
+
if (compactStyles) for (let index = 1; index < styles.length; index++) {
|
|
4009
|
+
const comma = expectToken(findStructuralToken(source, styles[index - 1].range[1]), "the comma between styles");
|
|
4010
|
+
rules.set(comma.range[0], "none");
|
|
4011
|
+
rules.set(styles[index].range[0], "space");
|
|
4012
|
+
}
|
|
3813
4013
|
return rules;
|
|
3814
4014
|
}
|
|
4015
|
+
/** Keep property and value text, changing only the first colon's padding. */
|
|
4016
|
+
function printStyleUnitSpacing(source, style) {
|
|
4017
|
+
const colon = source.text.indexOf(":", style.range[0]);
|
|
4018
|
+
if (colon <= style.range[0] || colon >= style.range[1]) return printAsWritten(source, ...style.range);
|
|
4019
|
+
let propertyEnd = colon;
|
|
4020
|
+
while (source.text[propertyEnd - 1] === " " || source.text[propertyEnd - 1] === " ") propertyEnd--;
|
|
4021
|
+
if (propertyEnd === style.range[0]) return printAsWritten(source, ...style.range);
|
|
4022
|
+
let valueStart = colon + 1;
|
|
4023
|
+
while (source.text[valueStart] === " " || source.text[valueStart] === " ") valueStart++;
|
|
4024
|
+
return [
|
|
4025
|
+
printAsWritten(source, style.range[0], propertyEnd),
|
|
4026
|
+
":",
|
|
4027
|
+
valueStart < style.range[1] ? [" ", printAsWritten(source, valueStart, style.range[1])] : ""
|
|
4028
|
+
];
|
|
4029
|
+
}
|
|
4030
|
+
/**
|
|
4031
|
+
* ER and requirement discard simple same-line style-unit padding. Keep trivia,
|
|
4032
|
+
* physical/Unicode line boundaries and complete semicolon-sensitive lines on
|
|
4033
|
+
* their original path (diagrams/er.md and diagrams/requirement.md, Style context).
|
|
4034
|
+
*/
|
|
4035
|
+
function styleUnitsCanCompact(source, start, end, styles) {
|
|
4036
|
+
return styles.every((style) => {
|
|
4037
|
+
const text = source.text.slice(...style.range);
|
|
4038
|
+
return !text.includes("\n") && !text.includes("\u2028") && !text.includes("\u2029");
|
|
4039
|
+
}) && !source.text.slice(lineStartOf(source, start), lineEndOf(source, end)).includes(";") && findTriviaBetween(source, start, end).length === 0;
|
|
4040
|
+
}
|
|
3815
4041
|
/**
|
|
3816
4042
|
* The rules of a `class` statement: the names of the entities and the
|
|
3817
4043
|
* classes are lists separated by `,` without whitespace, and the first class
|
|
@@ -3901,13 +4127,33 @@ function layoutC4Header(source, diagram) {
|
|
|
3901
4127
|
const start = diagram.range[0];
|
|
3902
4128
|
const keyword = expectToken(findTokenStartingAt(source, start), "the C4 header");
|
|
3903
4129
|
const end = diagram.beforeBody.at(-1)?.range[1] ?? keyword.range[1];
|
|
3904
|
-
|
|
3905
|
-
return {
|
|
4130
|
+
const layout = findTriviaBetween(source, start, end).length > 0 ? keptAsWritten(start, end) : {
|
|
3906
4131
|
atoms: collectAtoms(source, start, end, [], []),
|
|
3907
4132
|
rules: /* @__PURE__ */ new Map(),
|
|
3908
4133
|
outdented: /* @__PURE__ */ new Set(),
|
|
3909
4134
|
lineBreaks: "joined"
|
|
3910
4135
|
};
|
|
4136
|
+
return indentC4BeforeBody(source, diagram.beforeBody, layout);
|
|
4137
|
+
}
|
|
4138
|
+
/**
|
|
4139
|
+
* Null blocks before a body use ordinary description columns without changing
|
|
4140
|
+
* their adjacency or line breaks. Protected source stays written (ast/c4.md,
|
|
4141
|
+
* C4Diagram and C4BoundaryStatement; docs/c4.md, Empty description blocks).
|
|
4142
|
+
*/
|
|
4143
|
+
function indentC4BeforeBody(source, blocks, layout) {
|
|
4144
|
+
let aligned = layout;
|
|
4145
|
+
for (const block of blocks) {
|
|
4146
|
+
const text = source.text.slice(...block.range);
|
|
4147
|
+
if (text.includes(";") || holdsJoiningRegion(source, ...block.range)) continue;
|
|
4148
|
+
aligned = spaceDescriptionOpening(source, block.range[0], aligned);
|
|
4149
|
+
if (!text.includes("\n")) continue;
|
|
4150
|
+
aligned = indentDescriptionLines(source, {
|
|
4151
|
+
range: block.range,
|
|
4152
|
+
value: block.value,
|
|
4153
|
+
closed: true
|
|
4154
|
+
}, aligned);
|
|
4155
|
+
}
|
|
4156
|
+
return aligned;
|
|
3911
4157
|
}
|
|
3912
4158
|
/** The boundary braces, outside arguments and beforeBody blocks. */
|
|
3913
4159
|
function c4BoundaryBraces(source, statement) {
|
|
@@ -3929,11 +4175,11 @@ function layoutC4Call(source, statement, end) {
|
|
|
3929
4175
|
const start = statement.range[0];
|
|
3930
4176
|
const opening = findTokenEndingBefore(source, end);
|
|
3931
4177
|
if (statement.type === "C4BoundaryStatement" && opening?.value === "{") {
|
|
3932
|
-
const previous = expectToken(
|
|
4178
|
+
const previous = expectToken(findTokensBetween(source, start, opening.range[0]).findLast((token) => token.type !== "Directive"), "the end of a C4 boundary call");
|
|
3933
4179
|
const gap = source.text.slice(previous.range[1], opening.range[0]);
|
|
3934
|
-
if (gap.includes("\n") && gap.trim() === "" && !gap.includes("\u2028") && !gap.includes("\u2029") && findTriviaBetween(source,
|
|
4180
|
+
if (gap.includes("\n") && gap.trim() === "" && !gap.includes("\u2028") && !gap.includes("\u2029") && findTriviaBetween(source, previous.range[1], opening.range[0]).length === 0) {
|
|
3935
4181
|
const head = layoutC4Call(source, statement, previous.range[1]);
|
|
3936
|
-
return {
|
|
4182
|
+
return alignBlockOpeningLine(source, {
|
|
3937
4183
|
...head,
|
|
3938
4184
|
atoms: [...head.atoms, {
|
|
3939
4185
|
start: opening.range[0],
|
|
@@ -3941,11 +4187,72 @@ function layoutC4Call(source, statement, end) {
|
|
|
3941
4187
|
}],
|
|
3942
4188
|
rules: new Map([...head.rules, [opening.range[0], "space"]]),
|
|
3943
4189
|
joinedBefore: /* @__PURE__ */ new Set([...head.joinedBefore ?? [], opening.range[0]])
|
|
3944
|
-
};
|
|
4190
|
+
}, previous.range[0]);
|
|
3945
4191
|
}
|
|
3946
4192
|
}
|
|
3947
|
-
if (
|
|
4193
|
+
if (spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true })) return keptAsWritten(start, end);
|
|
3948
4194
|
const values = collectValueNodes(statement, c4ValueNodeTypes).filter((value) => value.range[1] <= end);
|
|
4195
|
+
const namedAttributes = statement.arguments.filter((argument) => argument?.type === "C4NamedAttribute");
|
|
4196
|
+
const atoms = splitC4EmptyEntryTokens(source, collectAtoms(source, start, end, values, findC4CallStretches(source, statement, end, values)));
|
|
4197
|
+
const rules = /* @__PURE__ */ new Map();
|
|
4198
|
+
const outdented = /* @__PURE__ */ new Set();
|
|
4199
|
+
const joinedBefore = /* @__PURE__ */ new Set();
|
|
4200
|
+
const keptBreaksBefore = /* @__PURE__ */ new Set();
|
|
4201
|
+
const bareStarts = /* @__PURE__ */ new Set();
|
|
4202
|
+
const bareEnds = /* @__PURE__ */ new Set();
|
|
4203
|
+
for (const argument of statement.arguments) {
|
|
4204
|
+
if (argument?.type !== "C4Literal") continue;
|
|
4205
|
+
bareStarts.add(argument.range[0]);
|
|
4206
|
+
bareEnds.add(argument.range[1]);
|
|
4207
|
+
}
|
|
4208
|
+
for (let index = 1; index < atoms.length; index++) {
|
|
4209
|
+
const previous = atoms[index - 1];
|
|
4210
|
+
const atom = atoms[index];
|
|
4211
|
+
const before = source.text.slice(previous.start, previous.end);
|
|
4212
|
+
const text = source.text.slice(atom.start, atom.end);
|
|
4213
|
+
const gap = source.text.slice(previous.end, atom.start);
|
|
4214
|
+
const sensitivePrefix = bareStarts.has(atom.start) && (text.startsWith("\"") || text.startsWith("$"));
|
|
4215
|
+
const afterDelimiter = before === "(" || before.endsWith(",");
|
|
4216
|
+
const beforeComma = text.startsWith(",");
|
|
4217
|
+
const inBeforeBody = statement.type === "C4BoundaryStatement" && statement.beforeBody.some((block) => block.range[0] <= atom.start && atom.end <= block.range[1]);
|
|
4218
|
+
const afterCall = statement.type === "C4BoundaryStatement" && atom.start >= (statement.beforeBody[0]?.range[0] ?? end - 1);
|
|
4219
|
+
const namedGap = namedAttributes.some((argument) => argument.range[0] <= previous.start && atom.end <= argument.range[1]);
|
|
4220
|
+
if (namedGap && gap.includes("\n")) keptBreaksBefore.add(atom.start);
|
|
4221
|
+
const keepsPhysicalLine = gap.includes("\n") && !afterCall && !namedGap;
|
|
4222
|
+
const keepsCommaGap = beforeComma && !bareEnds.has(previous.end) && before !== "(";
|
|
4223
|
+
if (keepsPhysicalLine || sensitivePrefix || keepsCommaGap || !inBeforeBody && !afterCall && !afterDelimiter && !beforeComma && before !== "$" && text !== "=" && before !== "=" && text !== "{") {
|
|
4224
|
+
if (gap !== "") atoms[index] = {
|
|
4225
|
+
start: previous.end,
|
|
4226
|
+
end: atom.end
|
|
4227
|
+
};
|
|
4228
|
+
rules.set(previous.end, "none");
|
|
4229
|
+
continue;
|
|
4230
|
+
}
|
|
4231
|
+
if (afterCall && findTriviaBetween(source, previous.end, atom.start).length === 0) joinedBefore.add(atom.start);
|
|
4232
|
+
if (text === "{" && atom.end === end) {
|
|
4233
|
+
outdented.add(atom.start);
|
|
4234
|
+
rules.set(atom.start, "space");
|
|
4235
|
+
} else if (afterDelimiter) rules.set(atom.start, before !== "(" && text !== ")" && !beforeComma ? "space" : "none");
|
|
4236
|
+
else if (namedGap && (text === "=" || before === "=")) rules.set(atom.start, "space");
|
|
4237
|
+
else if (beforeComma || text === ")" || before === "$" || text === "=" || before === "=") rules.set(atom.start, "none");
|
|
4238
|
+
}
|
|
4239
|
+
const layout = indentC4BeforeBody(source, statement.type === "C4BoundaryStatement" ? statement.beforeBody : [], {
|
|
4240
|
+
atoms,
|
|
4241
|
+
rules,
|
|
4242
|
+
outdented,
|
|
4243
|
+
lineBreaks: "kept",
|
|
4244
|
+
joinedBefore,
|
|
4245
|
+
keptBreaksBefore
|
|
4246
|
+
});
|
|
4247
|
+
return statement.type === "C4BoundaryStatement" && opening?.value === "{" ? alignBlockOpeningLine(source, layout, opening.range[0]) : layout;
|
|
4248
|
+
}
|
|
4249
|
+
/**
|
|
4250
|
+
* Preserve semicolon-bearing null blocks and textual line prefixes through
|
|
4251
|
+
* their last semicolon. A prefix can cross a value, which must stay whole
|
|
4252
|
+
* (common.md, Style and classDef lines; docs/c4.md, Line rule and semicolons).
|
|
4253
|
+
*/
|
|
4254
|
+
function findC4CallStretches(source, statement, end, values) {
|
|
4255
|
+
const start = statement.range[0];
|
|
3949
4256
|
const kept = [];
|
|
3950
4257
|
if (statement.type === "C4BoundaryStatement") {
|
|
3951
4258
|
for (const block of statement.beforeBody) if (source.text.slice(...block.range).includes(";")) kept.push({
|
|
@@ -3953,10 +4260,6 @@ function layoutC4Call(source, statement, end) {
|
|
|
3953
4260
|
end: block.range[1]
|
|
3954
4261
|
});
|
|
3955
4262
|
}
|
|
3956
|
-
for (const argument of statement.arguments) if (argument?.type === "C4NamedAttribute" && source.text.slice(...argument.range).includes("\n")) kept.push({
|
|
3957
|
-
start: argument.range[0],
|
|
3958
|
-
end: argument.range[1]
|
|
3959
|
-
});
|
|
3960
4263
|
for (let line = lineStartOf(source, start); line < end;) {
|
|
3961
4264
|
const lineEnd = semicolonSegmentEnd(source, line);
|
|
3962
4265
|
const last = source.text.lastIndexOf(";", Math.min(end, lineEnd) - 1);
|
|
@@ -3984,51 +4287,25 @@ function layoutC4Call(source, statement, end) {
|
|
|
3984
4287
|
};
|
|
3985
4288
|
else stretches.push(stretch);
|
|
3986
4289
|
}
|
|
3987
|
-
|
|
4290
|
+
return stretches;
|
|
4291
|
+
}
|
|
4292
|
+
/** Expose the padding in an opening empty-entry token (tokens/c4.md). */
|
|
4293
|
+
function splitC4EmptyEntryTokens(source, atoms) {
|
|
4294
|
+
const split = [];
|
|
4295
|
+
for (const atom of atoms) {
|
|
3988
4296
|
const token = findTokenStartingAt(source, atom.start);
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
});
|
|
3997
|
-
const rules = /* @__PURE__ */ new Map();
|
|
3998
|
-
const joinedBefore = /* @__PURE__ */ new Set();
|
|
3999
|
-
const bareStarts = new Set(statement.arguments.filter((argument) => argument?.type === "C4Literal").map((argument) => argument.range[0]));
|
|
4000
|
-
const bareEnds = new Set(statement.arguments.filter((argument) => argument?.type === "C4Literal").map((argument) => argument.range[1]));
|
|
4001
|
-
for (let index = 1; index < atoms.length; index++) {
|
|
4002
|
-
const previous = atoms[index - 1];
|
|
4003
|
-
const atom = atoms[index];
|
|
4004
|
-
const before = source.text.slice(previous.start, previous.end);
|
|
4005
|
-
const text = source.text.slice(atom.start, atom.end);
|
|
4006
|
-
const gap = source.text.slice(previous.end, atom.start);
|
|
4007
|
-
const sensitivePrefix = bareStarts.has(atom.start) && (text.startsWith("\"") || text.startsWith("$"));
|
|
4008
|
-
const afterDelimiter = before === "(" || before.endsWith(",");
|
|
4009
|
-
const beforeComma = text.startsWith(",");
|
|
4010
|
-
const inBeforeBody = statement.type === "C4BoundaryStatement" && statement.beforeBody.some((block) => block.range[0] <= atom.start && atom.end <= block.range[1]);
|
|
4011
|
-
const afterCall = statement.type === "C4BoundaryStatement" && atom.start >= (statement.beforeBody[0]?.range[0] ?? end - 1);
|
|
4012
|
-
if (gap.includes("\n") && !afterCall || sensitivePrefix || beforeComma && !bareEnds.has(previous.end) && before !== "(" || !inBeforeBody && !afterCall && !afterDelimiter && !beforeComma && before !== "$" && text !== "=" && before !== "=" && text !== "{") {
|
|
4013
|
-
if (gap !== "") atoms[index] = {
|
|
4014
|
-
start: previous.end,
|
|
4297
|
+
if (token?.type === "Punctuator" && token.value.startsWith("(") && token.value.endsWith(",")) {
|
|
4298
|
+
split.push({
|
|
4299
|
+
start: atom.start,
|
|
4300
|
+
end: atom.start + 1
|
|
4301
|
+
});
|
|
4302
|
+
split.push({
|
|
4303
|
+
start: atom.end - 1,
|
|
4015
4304
|
end: atom.end
|
|
4016
|
-
};
|
|
4017
|
-
|
|
4018
|
-
continue;
|
|
4019
|
-
}
|
|
4020
|
-
if (afterCall) joinedBefore.add(atom.start);
|
|
4021
|
-
if (text === "{" && atom.end === end) rules.set(atom.start, "space");
|
|
4022
|
-
else if (afterDelimiter) rules.set(atom.start, before !== "(" && text !== ")" && !beforeComma ? "space" : "none");
|
|
4023
|
-
else if (beforeComma || text === ")" || before === "$" || text === "=" || before === "=") rules.set(atom.start, "none");
|
|
4305
|
+
});
|
|
4306
|
+
} else split.push(atom);
|
|
4024
4307
|
}
|
|
4025
|
-
return
|
|
4026
|
-
atoms,
|
|
4027
|
-
rules,
|
|
4028
|
-
outdented: /* @__PURE__ */ new Set(),
|
|
4029
|
-
lineBreaks: "kept",
|
|
4030
|
-
joinedBefore
|
|
4031
|
-
};
|
|
4308
|
+
return split;
|
|
4032
4309
|
}
|
|
4033
4310
|
/**
|
|
4034
4311
|
* Title separators consume one character, unlike colon text. A multiline
|
|
@@ -4040,32 +4317,36 @@ function layoutC4Text(source, statement) {
|
|
|
4040
4317
|
const [start, end] = statement.range;
|
|
4041
4318
|
if (keptSemicolonPrefixEnd(source, start) > start) return keptAsWritten(start, end);
|
|
4042
4319
|
if (statement.type === "C4AccDescrBlockStatement") {
|
|
4043
|
-
if (
|
|
4320
|
+
if (source.text.slice(start, end).includes(";")) return keptAsWritten(start, end);
|
|
4044
4321
|
return layoutDescriptionBlock(source, statement, end, c4ValueNodeTypes, { keepsTrailingTrivia: true });
|
|
4045
4322
|
}
|
|
4046
|
-
if (
|
|
4047
|
-
if (statement.type === "
|
|
4048
|
-
const
|
|
4049
|
-
if (source
|
|
4323
|
+
if (source.text.slice(start, end).includes("\n") && c4DirectionIn(statement.value?.value ?? "")) return keptAsWritten(start, end);
|
|
4324
|
+
if (statement.type === "C4AccTitleStatement" || statement.type === "C4AccDescrStatement") {
|
|
4325
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
4326
|
+
if (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true })) return keptAsWritten(start, end);
|
|
4327
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, c4ValueNodeTypes), []);
|
|
4050
4328
|
return {
|
|
4051
|
-
atoms:
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
end
|
|
4057
|
-
}],
|
|
4058
|
-
rules: /* @__PURE__ */ new Map([[separator + 1, "space"]]),
|
|
4329
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
4330
|
+
rules: statement.value === null ? /* @__PURE__ */ new Map() : accessibilityRules(source, {
|
|
4331
|
+
range: statement.range,
|
|
4332
|
+
value: statement.value
|
|
4333
|
+
}),
|
|
4059
4334
|
outdented: /* @__PURE__ */ new Set(),
|
|
4060
|
-
lineBreaks: "joined"
|
|
4335
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
4061
4336
|
};
|
|
4062
4337
|
}
|
|
4338
|
+
if (findTriviaBetween(source, start, end).length > 0 || spansLinesThatCannotJoin(source, start, end)) return keptAsWritten(start, end);
|
|
4339
|
+
const separator = expectToken(findTokenStartingAt(source, start), "a C4 title keyword").range[1];
|
|
4340
|
+
if (source.text[separator] === "\u2028" || source.text[separator] === "\u2029") return keptAsWritten(start, end);
|
|
4063
4341
|
return {
|
|
4064
|
-
atoms:
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4342
|
+
atoms: [{
|
|
4343
|
+
start,
|
|
4344
|
+
end: separator
|
|
4345
|
+
}, {
|
|
4346
|
+
start: separator + 1,
|
|
4347
|
+
end
|
|
4348
|
+
}],
|
|
4349
|
+
rules: /* @__PURE__ */ new Map([[separator + 1, "space"]]),
|
|
4069
4350
|
outdented: /* @__PURE__ */ new Set(),
|
|
4070
4351
|
lineBreaks: "joined"
|
|
4071
4352
|
};
|
|
@@ -4330,73 +4611,44 @@ function layoutUsecaseStatement(source, statement, end) {
|
|
|
4330
4611
|
*/
|
|
4331
4612
|
function layoutUsecaseAccessibility(source, statement, end) {
|
|
4332
4613
|
const start = statement.range[0];
|
|
4614
|
+
if (statement.type === "UsecaseAccDescrBlockStatement") {
|
|
4615
|
+
const layout = layoutDescriptionBlock(source, statement, end, usecaseValueNodeTypes, {
|
|
4616
|
+
trimValueEdges: true,
|
|
4617
|
+
formatsEmptyTrivia: true,
|
|
4618
|
+
keepsTrailingTrivia: true
|
|
4619
|
+
});
|
|
4620
|
+
return {
|
|
4621
|
+
...layout,
|
|
4622
|
+
atoms: protectSemicolonPrefixes(source, start, end, layout.atoms)
|
|
4623
|
+
};
|
|
4624
|
+
}
|
|
4333
4625
|
const keyword = expectToken(findStructuralToken(source, start), "the accessibility keyword");
|
|
4334
|
-
const separator = expectToken(findStructuralToken(source, keyword.range[1]), "the accessibility colon
|
|
4626
|
+
const separator = expectToken(findStructuralToken(source, keyword.range[1]), "the accessibility colon");
|
|
4335
4627
|
const valueRange = trimmedLiteralRange(source, statement.value);
|
|
4336
4628
|
const rules = /* @__PURE__ */ new Map();
|
|
4337
|
-
const outdented = /* @__PURE__ */ new Set();
|
|
4338
4629
|
const joinedBefore = /* @__PURE__ */ new Set();
|
|
4339
|
-
|
|
4630
|
+
const atoms = [{
|
|
4340
4631
|
start: keyword.range[0],
|
|
4341
4632
|
end: keyword.range[1]
|
|
4633
|
+
}, {
|
|
4634
|
+
start: separator.range[0],
|
|
4635
|
+
end: separator.range[1]
|
|
4342
4636
|
}];
|
|
4343
|
-
|
|
4344
|
-
if (
|
|
4637
|
+
rules.set(separator.range[0], "none");
|
|
4638
|
+
if (valueRange !== null) {
|
|
4345
4639
|
atoms.push({
|
|
4346
|
-
start:
|
|
4347
|
-
end:
|
|
4640
|
+
start: valueRange[0],
|
|
4641
|
+
end: valueRange[1]
|
|
4348
4642
|
});
|
|
4349
|
-
rules.set(
|
|
4350
|
-
|
|
4351
|
-
atoms.push({
|
|
4352
|
-
start: valueRange[0],
|
|
4353
|
-
end: valueRange[1]
|
|
4354
|
-
});
|
|
4355
|
-
rules.set(valueRange[0], "space");
|
|
4356
|
-
joinedBefore.add(valueRange[0]);
|
|
4357
|
-
}
|
|
4358
|
-
} else {
|
|
4359
|
-
if (valueRange === null && spansLinesThatCannotJoin(source, start, end)) return keptAsWritten(start, end);
|
|
4360
|
-
const block = {
|
|
4361
|
-
range: statement.range,
|
|
4362
|
-
value: statement.value,
|
|
4363
|
-
closed: true
|
|
4364
|
-
};
|
|
4365
|
-
const closing = findAccDescrBlockClosing(source, block);
|
|
4366
|
-
if (closing === null) throw new Error("prettier-plugin-mmd: an unclosed usecase description block");
|
|
4367
|
-
const stretches = findAccDescrBlockStretches(source, block, valueRange);
|
|
4368
|
-
if (stretches.length > 0) appendItems(atoms, stretches);
|
|
4369
|
-
else {
|
|
4370
|
-
atoms.push({
|
|
4371
|
-
start: separator.range[0],
|
|
4372
|
-
end: separator.range[1]
|
|
4373
|
-
});
|
|
4374
|
-
if (valueRange !== null) {
|
|
4375
|
-
atoms.push({
|
|
4376
|
-
start: valueRange[0],
|
|
4377
|
-
end: valueRange[1]
|
|
4378
|
-
});
|
|
4379
|
-
joinedBefore.add(valueRange[0]);
|
|
4380
|
-
}
|
|
4381
|
-
}
|
|
4382
|
-
atoms.push({
|
|
4383
|
-
start: closing,
|
|
4384
|
-
end
|
|
4385
|
-
});
|
|
4386
|
-
outdented.add(closing);
|
|
4387
|
-
if (valueRange === null) {
|
|
4388
|
-
rules.set(closing, "none");
|
|
4389
|
-
joinedBefore.add(closing);
|
|
4390
|
-
lineBreaks = "joined";
|
|
4391
|
-
}
|
|
4643
|
+
rules.set(valueRange[0], "space");
|
|
4644
|
+
joinedBefore.add(valueRange[0]);
|
|
4392
4645
|
}
|
|
4393
|
-
atoms = protectSemicolonPrefixes(source, start, end, atoms);
|
|
4394
4646
|
return {
|
|
4395
|
-
atoms,
|
|
4647
|
+
atoms: protectSemicolonPrefixes(source, start, end, atoms),
|
|
4396
4648
|
rules,
|
|
4397
|
-
outdented,
|
|
4649
|
+
outdented: /* @__PURE__ */ new Set(),
|
|
4398
4650
|
joinedBefore,
|
|
4399
|
-
lineBreaks
|
|
4651
|
+
lineBreaks: "kept"
|
|
4400
4652
|
};
|
|
4401
4653
|
}
|
|
4402
4654
|
/** Trims exterior common whitespace while keeping complete embedded trivia. */
|
|
@@ -4774,26 +5026,35 @@ function layoutBlockOpening$1(source, statement, opening) {
|
|
|
4774
5026
|
* lexer reads the line break as whitespace, which it does only after the
|
|
4775
5027
|
* `:` of `accTitle` and `accDescr`, between `direction` and its value, and
|
|
4776
5028
|
* inside the statements of the style context (diagrams/er.md, The
|
|
4777
|
-
* statement context);
|
|
4778
|
-
*
|
|
4779
|
-
* block
|
|
4780
|
-
*
|
|
5029
|
+
* statement context); comments and directives keep line breaks while
|
|
5030
|
+
* structural continuations align. The lines of an `accDescr`
|
|
5031
|
+
* block keep their line breaks and align one level inside the statement,
|
|
5032
|
+
* except inside subgraphs, where raw text also supplies membership
|
|
5033
|
+
* (docs/er.md, Multi-line values).
|
|
4781
5034
|
* - A relationship has one space around its three units and its `:`
|
|
4782
5035
|
* (docs/er.md, Relationship spacing).
|
|
4783
5036
|
* - The classes after `:::` and in the lists of `class`, `classDef`, and
|
|
4784
5037
|
* `style` statements are separated by `,` without whitespace
|
|
4785
5038
|
* (docs/er.md, Entities and Styles and classes).
|
|
4786
5039
|
*/
|
|
4787
|
-
function layoutErStatement(source, statement, end) {
|
|
5040
|
+
function layoutErStatement(source, statement, end, preservesDescriptionColumns) {
|
|
4788
5041
|
const start = statement.range[0];
|
|
4789
|
-
if (statement.type === "ErAccDescrBlockStatement") return layoutDescriptionBlock(source, statement, end, erValueNodeTypes);
|
|
4790
|
-
|
|
5042
|
+
if (statement.type === "ErAccDescrBlockStatement") return layoutDescriptionBlock(source, statement, end, erValueNodeTypes, { preservesBodyColumns: preservesDescriptionColumns });
|
|
5043
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
5044
|
+
if (keepsLineBreaks && (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
4791
5045
|
const kept = findKeptStretches$1(source, statement);
|
|
5046
|
+
const styles = (statement.type === "ErStyleStatement" || statement.type === "ErClassDefStatement") && styleUnitsCanCompact(source, start, end, statement.styles) ? statement.styles : [];
|
|
5047
|
+
for (const style of styles) kept.push({
|
|
5048
|
+
start: style.range[0],
|
|
5049
|
+
end: style.range[1],
|
|
5050
|
+
doc: printStyleUnitSpacing(source, style)
|
|
5051
|
+
});
|
|
5052
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, erValueNodeTypes), kept);
|
|
4792
5053
|
return {
|
|
4793
|
-
atoms:
|
|
4794
|
-
rules: statementRules$7(source, statement),
|
|
5054
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
5055
|
+
rules: statementRules$7(source, statement, styles.length > 0),
|
|
4795
5056
|
outdented: /* @__PURE__ */ new Set(),
|
|
4796
|
-
lineBreaks: "joined"
|
|
5057
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
4797
5058
|
};
|
|
4798
5059
|
}
|
|
4799
5060
|
/**
|
|
@@ -4825,12 +5086,14 @@ function findEndingSemicolonStretches(source, statement) {
|
|
|
4825
5086
|
}
|
|
4826
5087
|
/**
|
|
4827
5088
|
* The layout of an attribute: its type, `?`, name, keys, and comment on one
|
|
4828
|
-
* line (docs/er.md, Attribute spacing).
|
|
4829
|
-
*
|
|
5089
|
+
* line (docs/er.md, Attribute spacing). Comments and directives keep the line
|
|
5090
|
+
* breaks, while structural gaps still take continuation indentation. Joining
|
|
5091
|
+
* regions and textual semicolon boundaries retain their complete source.
|
|
4830
5092
|
*/
|
|
4831
5093
|
function layoutAttribute(source, attribute) {
|
|
4832
5094
|
const [start, end] = attribute.range;
|
|
4833
|
-
|
|
5095
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
5096
|
+
if (keepsLineBreaks && (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
4834
5097
|
const rules = /* @__PURE__ */ new Map([[attribute.name.range[0], "space"]]);
|
|
4835
5098
|
for (const token of findTokensBetween(source, start, end)) if (isStructural(source, token) && token.value === "?") rules.set(token.range[0], "none");
|
|
4836
5099
|
for (const [index, key] of attribute.keys.entries()) {
|
|
@@ -4843,7 +5106,7 @@ function layoutAttribute(source, attribute) {
|
|
|
4843
5106
|
atoms: collectAtoms(source, start, end, collectValueNodes(attribute, erValueNodeTypes), []),
|
|
4844
5107
|
rules,
|
|
4845
5108
|
outdented: /* @__PURE__ */ new Set(),
|
|
4846
|
-
lineBreaks: "joined"
|
|
5109
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
4847
5110
|
};
|
|
4848
5111
|
}
|
|
4849
5112
|
/**
|
|
@@ -4854,7 +5117,7 @@ function findStructuralTokenBefore(source, offset, lowerBound) {
|
|
|
4854
5117
|
return findTokensBetween(source, lowerBound, offset).filter((token) => isStructural(source, token)).at(-1);
|
|
4855
5118
|
}
|
|
4856
5119
|
/** The gap rules of a statement. */
|
|
4857
|
-
function statementRules$7(source, statement) {
|
|
5120
|
+
function statementRules$7(source, statement, compactStyles = false) {
|
|
4858
5121
|
switch (statement.type) {
|
|
4859
5122
|
case "ErEntityStatement": {
|
|
4860
5123
|
const rules = entityHeaderRules(source, statement);
|
|
@@ -4867,8 +5130,8 @@ function statementRules$7(source, statement) {
|
|
|
4867
5130
|
}
|
|
4868
5131
|
case "ErRelationshipStatement": return relationshipRules$1(source, statement);
|
|
4869
5132
|
case "ErDirectionStatement": return directionRules(source, statement);
|
|
4870
|
-
case "ErClassDefStatement": return styleStatementRules(source, statement.cssClasses, statement.styles);
|
|
4871
|
-
case "ErStyleStatement": return styleStatementRules(source, statement.entities, statement.styles);
|
|
5133
|
+
case "ErClassDefStatement": return styleStatementRules(source, statement.cssClasses, statement.styles, compactStyles);
|
|
5134
|
+
case "ErStyleStatement": return styleStatementRules(source, statement.entities, statement.styles, compactStyles);
|
|
4872
5135
|
case "ErClassStatement": return classStatementRules(source, statement.entities, statement.cssClasses);
|
|
4873
5136
|
case "ErAccTitleStatement":
|
|
4874
5137
|
case "ErAccDescrStatement": return accessibilityRules(source, statement);
|
|
@@ -5023,10 +5286,11 @@ function printEr(path, options, print, source) {
|
|
|
5023
5286
|
case "subgraph": return printSubgraph$1(path, options, print, source, classified.statement, depth);
|
|
5024
5287
|
case "entity":
|
|
5025
5288
|
if (hasAttributeBlock(source, classified.statement)) return printAttributeBlock(path, options, print, source, classified.statement, depth);
|
|
5026
|
-
|
|
5027
|
-
case "simple":
|
|
5289
|
+
break;
|
|
5290
|
+
case "simple": break;
|
|
5028
5291
|
default: throw new Error(`prettier-plugin-mmd: unknown kind of statement ${JSON.stringify(classified)}`);
|
|
5029
5292
|
}
|
|
5293
|
+
return printLine$6(source, options, layoutErStatement(source, classified.statement, node.range[1], depth > 1), depth);
|
|
5030
5294
|
}
|
|
5031
5295
|
/** Prints a statement laid out on its lines at `depth`. */
|
|
5032
5296
|
function printLine$6(source, options, layout, depth) {
|
|
@@ -5721,7 +5985,7 @@ function classifyAgentflowStatement(statement) {
|
|
|
5721
5985
|
}
|
|
5722
5986
|
}
|
|
5723
5987
|
/** Agentflow statements use flowchart's shared graph spacing and atom printer. */
|
|
5724
|
-
function layoutStatement$1(source, statement, end) {
|
|
5988
|
+
function layoutStatement$1(source, statement, end, preservesDescriptionColumns) {
|
|
5725
5989
|
const start = statement.range[0];
|
|
5726
5990
|
if (statement.type === "AgentflowConnectorStatement") return layoutContainerHeader(source, statement, end);
|
|
5727
5991
|
const accessibility = layoutGraphAccessibility(source, statement, end, findAgentflowKeptLines(source));
|
|
@@ -5746,6 +6010,7 @@ function layoutStatement$1(source, statement, end) {
|
|
|
5746
6010
|
case "AgentflowAccDescrBlockStatement":
|
|
5747
6011
|
appendItems(kept, findAccDescrBlockStretches(source, statement));
|
|
5748
6012
|
if (!statement.closed) return keptAsWritten(start, end);
|
|
6013
|
+
for (const [position, rule] of descriptionOpeningRules(source, start)) rules.set(position, rule);
|
|
5749
6014
|
break;
|
|
5750
6015
|
case "AgentflowVertexStatement": walk(statement, (node) => {
|
|
5751
6016
|
if (node.type === "AgentflowShape") addShapeRules(source, node, rules);
|
|
@@ -5755,10 +6020,11 @@ function layoutStatement$1(source, statement, end) {
|
|
|
5755
6020
|
const layout = layoutRange(source, start, end, collectValueNodes(statement, agentflowValueNodeTypes), kept, rules);
|
|
5756
6021
|
if (statement.type === "AgentflowAccDescrBlockStatement") {
|
|
5757
6022
|
const closing = findAccDescrBlockClosing(source, statement);
|
|
5758
|
-
|
|
6023
|
+
const descriptionLayout = {
|
|
5759
6024
|
...layout,
|
|
5760
6025
|
outdented: closing === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([closing])
|
|
5761
6026
|
};
|
|
6027
|
+
return preservesDescriptionColumns ? descriptionLayout : indentDescriptionLines(source, statement, descriptionLayout);
|
|
5762
6028
|
}
|
|
5763
6029
|
return layout;
|
|
5764
6030
|
}
|
|
@@ -5789,9 +6055,8 @@ function printAgentflow(path, options, print, source) {
|
|
|
5789
6055
|
if (classified === null) throw new Error("prettier-plugin-mmd: an unexpected Agentflow node");
|
|
5790
6056
|
if (classified.kind === "container") return printContainer(path, bodyOptions, print, source, classified.statement);
|
|
5791
6057
|
const statement = classified.statement;
|
|
5792
|
-
const layout = layoutStatement$1(source, statement, findPrintedEnd$1(source, statement));
|
|
5793
6058
|
const depth = depthOf$3(path);
|
|
5794
|
-
return printAtoms(source,
|
|
6059
|
+
return printAtoms(source, layoutStatement$1(source, statement, findPrintedEnd$1(source, statement), depth > 1), {
|
|
5795
6060
|
statement: indentationOf(bodyOptions, depth),
|
|
5796
6061
|
continuation: indentationOf(bodyOptions, depth + 1)
|
|
5797
6062
|
}).doc;
|
|
@@ -6072,20 +6337,21 @@ function layoutSubgraphHeader(source, subgraph, headerEnd) {
|
|
|
6072
6337
|
* The layout of a statement other than a subgraph, from its start to
|
|
6073
6338
|
* `end` (see `findPrintedEnd`).
|
|
6074
6339
|
*/
|
|
6075
|
-
function layoutStatement(source, statement, end) {
|
|
6340
|
+
function layoutStatement(source, statement, end, preservesDescriptionColumns) {
|
|
6076
6341
|
const start = statement.range[0];
|
|
6077
6342
|
const accessibility = layoutGraphAccessibility(source, statement, end, findFlowchartKeptLines(source));
|
|
6078
6343
|
if (accessibility !== null) return accessibility;
|
|
6079
6344
|
if (holdsJoiningRegion(source, start, end)) return keptAsWritten(start, end);
|
|
6080
6345
|
const kept = findKeptStretches(source, statement, end);
|
|
6081
6346
|
const values = collectValueNodes(statement, valueNodeTypes);
|
|
6082
|
-
const rules = statement.type === "FlowchartVertexStatement" ? vertexStatementRules(source, statement) : /* @__PURE__ */ new Map();
|
|
6083
|
-
|
|
6347
|
+
const rules = statement.type === "FlowchartVertexStatement" ? vertexStatementRules(source, statement) : statement.type === "FlowchartAccDescrBlockStatement" ? descriptionOpeningRules(source, start) : /* @__PURE__ */ new Map();
|
|
6348
|
+
const layout = {
|
|
6084
6349
|
atoms: collectAtoms(source, start, end, values, kept),
|
|
6085
6350
|
rules,
|
|
6086
6351
|
outdented: findOutdentedAtoms(source, statement),
|
|
6087
6352
|
lineBreaks: "kept"
|
|
6088
6353
|
};
|
|
6354
|
+
return statement.type === "FlowchartAccDescrBlockStatement" && !preservesDescriptionColumns ? indentDescriptionLines(source, statement, layout) : layout;
|
|
6089
6355
|
}
|
|
6090
6356
|
/**
|
|
6091
6357
|
* The atoms of a statement whose line starts at the statement's
|
|
@@ -6222,9 +6488,8 @@ function printFlowchart(path, options, print, source) {
|
|
|
6222
6488
|
case "FlowchartSubgraphStatement": return printSubgraph(path, bodyOptions, print, source, node);
|
|
6223
6489
|
default: {
|
|
6224
6490
|
const statement = node;
|
|
6225
|
-
const layout = layoutStatement(source, statement, findPrintedEnd(source, statement));
|
|
6226
6491
|
const depth = depthOf$2(path);
|
|
6227
|
-
return printAtoms(source,
|
|
6492
|
+
return printAtoms(source, layoutStatement(source, statement, findPrintedEnd(source, statement), depth > 1), {
|
|
6228
6493
|
statement: indentationOf(bodyOptions, depth),
|
|
6229
6494
|
continuation: indentationOf(bodyOptions, depth + 1)
|
|
6230
6495
|
}).doc;
|
|
@@ -6412,25 +6677,27 @@ function isAtLineEnd$1(source, offset) {
|
|
|
6412
6677
|
* - A statement written over several lines stands on one line where the
|
|
6413
6678
|
* lexer reads the line break as whitespace, which it does only right after
|
|
6414
6679
|
* a keyword and before a part of a statement (diagrams/gantt.md, The
|
|
6415
|
-
* statement context)
|
|
6416
|
-
*
|
|
6417
|
-
*
|
|
6418
|
-
* statements).
|
|
6680
|
+
* statement context). Trivia keeps structural click/day/list/accessibility
|
|
6681
|
+
* gaps broken, with ordinary continuation columns; raw line values,
|
|
6682
|
+
* semicolon lines and joining regions keep their original layout
|
|
6683
|
+
* (docs/gantt.md, Multi-line statements).
|
|
6419
6684
|
* - The rules of the gaps are those of docs/gantt.md: Task data, Settings,
|
|
6420
6685
|
* Lists, Click statements, and Accessibility statements.
|
|
6421
6686
|
*/
|
|
6422
6687
|
function layoutGanttStatement(source, statement, end) {
|
|
6423
6688
|
const start = statement.range[0];
|
|
6424
6689
|
if (statement.type === "GanttAccDescrBlockStatement") return layoutDescriptionBlock(source, statement, end, ganttValueNodeTypes);
|
|
6425
|
-
|
|
6690
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
6691
|
+
const formatsTriviaLines = statement.type === "GanttClickStatement" || statement.type === "GanttWeekdayStatement" || statement.type === "GanttWeekendStatement" || statement.type === "GanttIncludesStatement" || statement.type === "GanttExcludesStatement" || statement.type === "GanttAccTitleStatement" || statement.type === "GanttAccDescrStatement";
|
|
6692
|
+
if (keepsLineBreaks && (!formatsTriviaLines || holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true })) || holdsCaseIgnoredSeparator(source, statement, end)) return keptAsWritten(start, end);
|
|
6426
6693
|
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, ganttValueNodeTypes), []);
|
|
6427
6694
|
const remainder = findBlankRemainder$1(source, statement);
|
|
6428
6695
|
if (remainder !== null) atoms.push(remainder);
|
|
6429
6696
|
return {
|
|
6430
|
-
atoms,
|
|
6697
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
6431
6698
|
rules: statementRules$6(source, statement, atoms, remainder),
|
|
6432
6699
|
outdented: /* @__PURE__ */ new Set(),
|
|
6433
|
-
lineBreaks: "joined"
|
|
6700
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
6434
6701
|
};
|
|
6435
6702
|
}
|
|
6436
6703
|
/**
|
|
@@ -6578,7 +6845,7 @@ function findLinesReadByTheirWhitespace$1(source) {
|
|
|
6578
6845
|
}
|
|
6579
6846
|
//#endregion
|
|
6580
6847
|
//#region src/printers/sectioned.ts
|
|
6581
|
-
const { indent } = builders;
|
|
6848
|
+
const { indent: indent$1 } = builders;
|
|
6582
6849
|
/**
|
|
6583
6850
|
* Prints the body of a diagram whose statements a `section` groups, and the
|
|
6584
6851
|
* nodes below it, to the end of the text (docs/gantt.md and docs/journey.md).
|
|
@@ -6623,7 +6890,7 @@ function findStatementsAfterSection(statements, isSection) {
|
|
|
6623
6890
|
/** Prints a statement on its lines, at the level that the section decides. */
|
|
6624
6891
|
function printStatement(diagram, source, options, statement, isDeeper) {
|
|
6625
6892
|
const printed = printLine$5(source, options, diagram.layoutStatement(source, statement, statement.range[1]), isDeeper ? 2 : 1);
|
|
6626
|
-
return isDeeper ? indent(printed) : printed;
|
|
6893
|
+
return isDeeper ? indent$1(printed) : printed;
|
|
6627
6894
|
}
|
|
6628
6895
|
/** Prints a statement laid out on its lines at `depth`. */
|
|
6629
6896
|
function printLine$5(source, options, layout, depth) {
|
|
@@ -6731,25 +6998,27 @@ function isAtLineEnd(source, offset) {
|
|
|
6731
6998
|
*
|
|
6732
6999
|
* - A statement written over several lines stands on one line where the
|
|
6733
7000
|
* lexer reads the line break as whitespace, which it does only right after
|
|
6734
|
-
* a keyword (diagrams/journey.md, The statement context)
|
|
6735
|
-
*
|
|
6736
|
-
*
|
|
6737
|
-
*
|
|
7001
|
+
* a keyword (diagrams/journey.md, The statement context). Accessibility
|
|
7002
|
+
* line trivia keeps its breaks with ordinary continuation columns; titles,
|
|
7003
|
+
* sections and protected regions keep their original layout
|
|
7004
|
+
* (docs/journey.md, Multi-line statements).
|
|
6738
7005
|
* - The rules of the gaps are those of docs/journey.md: Task data, Titles and
|
|
6739
7006
|
* sections, and Accessibility statements.
|
|
6740
7007
|
*/
|
|
6741
7008
|
function layoutJourneyStatement(source, statement, end) {
|
|
6742
7009
|
const start = statement.range[0];
|
|
6743
7010
|
if (statement.type === "JourneyAccDescrBlockStatement") return layoutDescriptionBlock(source, statement, end, journeyValueNodeTypes);
|
|
6744
|
-
|
|
7011
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
7012
|
+
const formatsTriviaLines = statement.type === "JourneyAccTitleStatement" || statement.type === "JourneyAccDescrStatement";
|
|
7013
|
+
if (keepsLineBreaks && (!formatsTriviaLines || holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
6745
7014
|
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, journeyValueNodeTypes), []);
|
|
6746
7015
|
const remainder = findBlankRemainder(source, statement);
|
|
6747
7016
|
if (remainder !== null) atoms.push(remainder);
|
|
6748
7017
|
return {
|
|
6749
|
-
atoms,
|
|
7018
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
6750
7019
|
rules: statementRules$5(source, statement, atoms, remainder),
|
|
6751
7020
|
outdented: /* @__PURE__ */ new Set(),
|
|
6752
|
-
lineBreaks: "joined"
|
|
7021
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
6753
7022
|
};
|
|
6754
7023
|
}
|
|
6755
7024
|
/** The gap rules of a statement, by the start of the atom after the gap. */
|
|
@@ -7571,7 +7840,8 @@ function findQuadrantKeptLines(source) {
|
|
|
7571
7840
|
/**
|
|
7572
7841
|
* The node types of a quadrant chart whose text is a value, printed as
|
|
7573
7842
|
* written: a title, a text of an accessibility statement, a coordinate, and a
|
|
7574
|
-
* style (QuadrantLiteral)
|
|
7843
|
+
* style (QuadrantLiteral), with ordinary style-colon padding normalized below;
|
|
7844
|
+
* the text of an axis or of a quadrant and the name
|
|
7575
7845
|
* of a point (QuadrantLabel), whose whitespace is in the Db; the name of a
|
|
7576
7846
|
* class of `classDef` (QuadrantIdentifier); and the class name of a point
|
|
7577
7847
|
* (Identifier). They have no child fields; `tests/value-nodes.test.ts` checks
|
|
@@ -7588,22 +7858,49 @@ const quadrantValueNodeTypes = /* @__PURE__ */ new Set([
|
|
|
7588
7858
|
*
|
|
7589
7859
|
* - A statement written over several lines stands on one line where the
|
|
7590
7860
|
* lexer reads the line break as whitespace (diagrams/quadrant.md, Lexical
|
|
7591
|
-
* structure, Line breaks)
|
|
7592
|
-
*
|
|
7593
|
-
*
|
|
7594
|
-
*
|
|
7861
|
+
* structure, Line breaks). Point and accessibility line trivia keeps its
|
|
7862
|
+
* breaks with ordinary continuation columns; semicolon lines, joining
|
|
7863
|
+
* regions and other statements retain their layout (docs/quadrant.md,
|
|
7864
|
+
* Multi-line statements).
|
|
7595
7865
|
* - The rules of the gaps are those of docs/quadrant.md: Keywords and texts,
|
|
7596
7866
|
* Axes, Points, Styles, and Titles and accessibility statements.
|
|
7597
7867
|
*/
|
|
7598
7868
|
function layoutQuadrantStatement(source, statement, end) {
|
|
7599
7869
|
const start = statement.range[0];
|
|
7600
7870
|
if (statement.type === "QuadrantAccDescrBlockStatement") return layoutDescriptionBlock(source, statement, end, quadrantValueNodeTypes);
|
|
7601
|
-
|
|
7871
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
7872
|
+
const formatsTriviaLines = statement.type === "QuadrantPointStatement" || statement.type === "QuadrantAccTitleStatement" || statement.type === "QuadrantAccDescrStatement";
|
|
7873
|
+
if (keepsLineBreaks && (!formatsTriviaLines || holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
7874
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, quadrantValueNodeTypes), []);
|
|
7875
|
+
const styleStarts = new Set(statement.type === "QuadrantPointStatement" || statement.type === "QuadrantClassDefStatement" ? statement.styles.map((style) => style.range[0]) : []);
|
|
7876
|
+
const styledAtoms = atoms.map((atom) => styleStarts.has(atom.start) ? formatStyleAtom(source, atom) : atom);
|
|
7602
7877
|
return {
|
|
7603
|
-
atoms:
|
|
7878
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, styledAtoms) : styledAtoms,
|
|
7604
7879
|
rules: statementRules$4(source, statement),
|
|
7605
7880
|
outdented: /* @__PURE__ */ new Set(),
|
|
7606
|
-
lineBreaks: "joined"
|
|
7881
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
7882
|
+
};
|
|
7883
|
+
}
|
|
7884
|
+
/**
|
|
7885
|
+
* Ordinary style name/colon/value boundaries have one form. Keep the source
|
|
7886
|
+
* range and value bytes; trivia, line rules and suffix forms stay opaque
|
|
7887
|
+
* (docs/quadrant.md, Styles).
|
|
7888
|
+
*/
|
|
7889
|
+
function formatStyleAtom(source, atom) {
|
|
7890
|
+
const text = source.text.slice(atom.start, atom.end);
|
|
7891
|
+
const colon = text.indexOf(":");
|
|
7892
|
+
if (colon < 0 || text.includes(":", colon + 1) || text.includes(";") || findTriviaBetween(source, atom.start, atom.end).length > 0 || holdsJoiningRegion(source, atom.start, atom.end) || findSemicolonLines(source).has(lineStartOf(source, atom.start)) || [...text].some((character) => character !== " " && character !== " " && isWhitespace(character))) return atom;
|
|
7893
|
+
let nameEnd = colon;
|
|
7894
|
+
while (text[nameEnd - 1] === " " || text[nameEnd - 1] === " ") nameEnd--;
|
|
7895
|
+
let valueStart = colon + 1;
|
|
7896
|
+
while (text[valueStart] === " " || text[valueStart] === " ") valueStart++;
|
|
7897
|
+
return {
|
|
7898
|
+
...atom,
|
|
7899
|
+
doc: [
|
|
7900
|
+
text.slice(0, nameEnd),
|
|
7901
|
+
": ",
|
|
7902
|
+
text.slice(valueStart)
|
|
7903
|
+
]
|
|
7607
7904
|
};
|
|
7608
7905
|
}
|
|
7609
7906
|
/** The gap rules of a statement, by the start of the atom after the gap. */
|
|
@@ -7887,42 +8184,51 @@ function findBlockBraces(source, statement) {
|
|
|
7887
8184
|
* `:::` and the `,` between them (docs/requirement.md, Bodies and Class
|
|
7888
8185
|
* lists). A statement written over lines, where the lexer reads the line
|
|
7889
8186
|
* break as whitespace, stands on one line; one with a comment or a directive
|
|
7890
|
-
* in it
|
|
8187
|
+
* in it keeps its line breaks and aligns structural continuations.
|
|
7891
8188
|
*/
|
|
7892
8189
|
function layoutBlockOpening(source, statement, opening) {
|
|
7893
8190
|
const start = statement.range[0];
|
|
7894
8191
|
const end = opening.range[1];
|
|
7895
|
-
|
|
8192
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
8193
|
+
if (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true })) return keptAsWritten(start, end);
|
|
7896
8194
|
const rules = /* @__PURE__ */ new Map([[statement.name.range[0], "space"], [opening.range[0], "space"]]);
|
|
7897
8195
|
addClassListRules(source, statement.cssClasses, statement.name.range[1], rules);
|
|
7898
|
-
|
|
7899
|
-
|
|
8196
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, requirementValueNodeTypes).filter((value) => value.range[1] <= opening.range[0]), []);
|
|
8197
|
+
return alignBlockOpeningLine(source, {
|
|
8198
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
7900
8199
|
rules,
|
|
7901
8200
|
outdented: /* @__PURE__ */ new Set(),
|
|
7902
|
-
lineBreaks: "joined"
|
|
7903
|
-
};
|
|
8201
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
8202
|
+
}, opening.range[0]);
|
|
7904
8203
|
}
|
|
7905
8204
|
/**
|
|
7906
8205
|
* The layout of an item of a body. A field is printed on one line: its
|
|
7907
8206
|
* keyword, the `:` touching it, and its value after one space; a field
|
|
7908
8207
|
* written over lines, where the lexer reads the line break as whitespace,
|
|
7909
|
-
* stands on one line too
|
|
7910
|
-
*
|
|
8208
|
+
* stands on one line too. Comments and directives retain line breaks while
|
|
8209
|
+
* structural continuations align. An empty description block, which mermaid.js
|
|
8210
|
+
* does not read, is
|
|
7911
8211
|
* compacted with the shared empty-block layout (docs/requirement.md, Fields
|
|
7912
8212
|
* and Empty description blocks).
|
|
7913
8213
|
*/
|
|
7914
8214
|
function layoutBodyItem(source, item) {
|
|
7915
8215
|
const [start, end] = item.range;
|
|
7916
|
-
if (item.type === "RequirementIgnoredText") return layoutCompactEmptyDescriptionBlockWithFallback(source, start, end, () =>
|
|
7917
|
-
|
|
8216
|
+
if (item.type === "RequirementIgnoredText") return layoutCompactEmptyDescriptionBlockWithFallback(source, start, end, () => indentDescriptionLines(source, {
|
|
8217
|
+
range: item.range,
|
|
8218
|
+
value: null,
|
|
8219
|
+
closed: true
|
|
8220
|
+
}, layoutEmptyDescriptionBlock(source, start, end, true)));
|
|
8221
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
8222
|
+
if (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true })) return keptAsWritten(start, end);
|
|
7918
8223
|
const colon = expectToken(findStructuralToken(source, expectToken(findStructuralToken(source, start), "a field").range[1]), "the `:` of a field");
|
|
7919
8224
|
expectValue(colon, ":");
|
|
7920
8225
|
const value = expectToken(findStructuralToken(source, colon.range[1]), "the value of a field");
|
|
8226
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(item, requirementValueNodeTypes), []);
|
|
7921
8227
|
return {
|
|
7922
|
-
atoms:
|
|
8228
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
7923
8229
|
rules: /* @__PURE__ */ new Map([[colon.range[0], "none"], [value.range[0], "space"]]),
|
|
7924
8230
|
outdented: /* @__PURE__ */ new Set(),
|
|
7925
|
-
lineBreaks: "joined"
|
|
8231
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
7926
8232
|
};
|
|
7927
8233
|
}
|
|
7928
8234
|
/**
|
|
@@ -7931,25 +8237,35 @@ function layoutBodyItem(source, item) {
|
|
|
7931
8237
|
*
|
|
7932
8238
|
* - A statement written over several lines stands on one line where the
|
|
7933
8239
|
* lexer reads the line break as whitespace (diagrams/requirement.md, The
|
|
7934
|
-
* statement context);
|
|
7935
|
-
*
|
|
8240
|
+
* statement context); comments and directives keep line breaks while
|
|
8241
|
+
* structural continuations align. Semicolon boundaries and joining regions
|
|
8242
|
+
* keep their source. The lines of an
|
|
7936
8243
|
* `accDescr` block are lines of its text, and are kept (docs/requirement.md,
|
|
7937
8244
|
* Accessibility statements). A `class` statement is laid out as
|
|
7938
8245
|
* `joinsClassStatement` says.
|
|
7939
|
-
* - A relationship has one space between its units
|
|
7940
|
-
*
|
|
8246
|
+
* - A relationship has one space between its units. Comments and directives
|
|
8247
|
+
* prevent joining its lines, while the existing atoms still align structural
|
|
8248
|
+
* gaps. Joining regions and textual semicolon boundaries keep their source
|
|
8249
|
+
* (docs/requirement.md, Relationship spacing).
|
|
7941
8250
|
* - The other statements follow the rules shared with an ER diagram (see
|
|
7942
8251
|
* `statement-rules.ts`).
|
|
7943
8252
|
*/
|
|
7944
8253
|
function layoutRequirementStatement(source, statement, end) {
|
|
7945
8254
|
const start = statement.range[0];
|
|
7946
8255
|
if (statement.type === "RequirementAccDescrBlockStatement") return layoutDescriptionBlock(source, statement, end, requirementValueNodeTypes);
|
|
7947
|
-
|
|
8256
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
8257
|
+
if (keepsLineBreaks && (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
8258
|
+
const styles = (statement.type === "RequirementStyleStatement" || statement.type === "RequirementClassDefStatement") && styleUnitsCanCompact(source, start, end, statement.styles) ? statement.styles : [];
|
|
8259
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, requirementValueNodeTypes), styles.map((style) => ({
|
|
8260
|
+
start: style.range[0],
|
|
8261
|
+
end: style.range[1],
|
|
8262
|
+
doc: printStyleUnitSpacing(source, style)
|
|
8263
|
+
})));
|
|
7948
8264
|
return {
|
|
7949
|
-
atoms:
|
|
7950
|
-
rules: statementRules$3(source, statement),
|
|
8265
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
8266
|
+
rules: statementRules$3(source, statement, styles.length > 0),
|
|
7951
8267
|
outdented: /* @__PURE__ */ new Set(),
|
|
7952
|
-
lineBreaks: statement.type === "RequirementClassStatement" && !joinsClassStatement(source, statement) ? "kept" : "joined"
|
|
8268
|
+
lineBreaks: keepsLineBreaks || statement.type === "RequirementClassStatement" && !joinsClassStatement(source, statement) ? "kept" : "joined"
|
|
7953
8269
|
};
|
|
7954
8270
|
}
|
|
7955
8271
|
/**
|
|
@@ -7973,12 +8289,12 @@ function isStyleWord(name) {
|
|
|
7973
8289
|
return name.name !== "" && [...name.name].every((character) => character >= "a" && character <= "z" || character >= "A" && character <= "Z" || character >= "0" && character <= "9" || character === "_");
|
|
7974
8290
|
}
|
|
7975
8291
|
/** The gap rules of a statement that holds no body. */
|
|
7976
|
-
function statementRules$3(source, statement) {
|
|
8292
|
+
function statementRules$3(source, statement, compactStyles = false) {
|
|
7977
8293
|
switch (statement.type) {
|
|
7978
8294
|
case "RequirementRelationshipStatement": return relationshipRules(source, statement);
|
|
7979
8295
|
case "RequirementDirectionStatement": return directionRules(source, statement);
|
|
7980
|
-
case "RequirementStyleStatement": return styleStatementRules(source, statement.names, statement.styles);
|
|
7981
|
-
case "RequirementClassDefStatement": return styleStatementRules(source, statement.cssClasses, statement.styles);
|
|
8296
|
+
case "RequirementStyleStatement": return styleStatementRules(source, statement.names, statement.styles, compactStyles);
|
|
8297
|
+
case "RequirementClassDefStatement": return styleStatementRules(source, statement.cssClasses, statement.styles, compactStyles);
|
|
7982
8298
|
case "RequirementClassStatement": return classStatementRules(source, statement.names, statement.cssClasses);
|
|
7983
8299
|
case "RequirementClassShorthandStatement": {
|
|
7984
8300
|
const rules = /* @__PURE__ */ new Map();
|
|
@@ -8332,22 +8648,23 @@ function layoutBlockHeader(source, start, end, text) {
|
|
|
8332
8648
|
* - A statement written over several lines stands on one line: a line
|
|
8333
8649
|
* break inside a statement comes after whitespace, and the lexer reads
|
|
8334
8650
|
* the two as whitespace (diagrams/sequence.md, The statement context,
|
|
8335
|
-
* rule 2).
|
|
8336
|
-
*
|
|
8337
|
-
* lines of its text
|
|
8338
|
-
* statements).
|
|
8651
|
+
* rule 2). Comments and directives keep line breaks while structural
|
|
8652
|
+
* continuations align; the lines of an `accDescr { ... }` block are
|
|
8653
|
+
* lines of its text: keep their breaks and align their safe indentation
|
|
8654
|
+
* (docs/sequence.md, Multi-line statements).
|
|
8339
8655
|
* - A title is laid out by `layoutTitle`.
|
|
8340
8656
|
* - A message has one space before and after its arrow (docs/sequence.md,
|
|
8341
8657
|
* Arrow spacing).
|
|
8342
8658
|
* - A `:` before a text touches what comes before it and has one space
|
|
8343
8659
|
* after it when a text follows (docs/sequence.md, Colons).
|
|
8344
|
-
* -
|
|
8345
|
-
*
|
|
8346
|
-
*
|
|
8660
|
+
* - Later lines of an `accDescr { ... }` block align one level inside the
|
|
8661
|
+
* statement without joining their text. Its `}` stands at the level of
|
|
8662
|
+
* the statement (docs/sequence.md, Multi-line values).
|
|
8347
8663
|
*/
|
|
8348
8664
|
function layoutSequenceStatement(source, statement, end) {
|
|
8349
8665
|
const start = statement.range[0];
|
|
8350
|
-
|
|
8666
|
+
const keepsLineBreaks = statement.type !== "SequenceAccDescrBlockStatement" && spansLinesThatCannotJoin(source, start, end);
|
|
8667
|
+
if (keepsLineBreaks && (statement.type === "SequenceTitleStatement" || holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return {
|
|
8351
8668
|
atoms: [{
|
|
8352
8669
|
start,
|
|
8353
8670
|
end
|
|
@@ -8368,39 +8685,24 @@ function layoutSequenceStatement(source, statement, end) {
|
|
|
8368
8685
|
/** Builds the existing value, trivia and closing-brace layout. */
|
|
8369
8686
|
function originalLayout() {
|
|
8370
8687
|
const closing = findAccDescrBlockClosing(source, block);
|
|
8371
|
-
return {
|
|
8688
|
+
return indentDescriptionLines(source, block, {
|
|
8372
8689
|
atoms: collectAtoms(source, start, end, values, findAccDescrBlockStretches(source, block)),
|
|
8373
|
-
rules:
|
|
8690
|
+
rules: descriptionOpeningRules(source, start),
|
|
8374
8691
|
outdented: closing === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([closing]),
|
|
8375
8692
|
lineBreaks: "kept"
|
|
8376
|
-
};
|
|
8693
|
+
});
|
|
8377
8694
|
}
|
|
8378
8695
|
return statement.value === null && statement.closed ? layoutCompactEmptyDescriptionBlockWithFallback(source, start, end, originalLayout) : originalLayout();
|
|
8379
8696
|
}
|
|
8697
|
+
const atoms = collectAtoms(source, start, end, values, tail);
|
|
8380
8698
|
return {
|
|
8381
|
-
atoms:
|
|
8699
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
8382
8700
|
rules: statementRules$2(source, statement),
|
|
8383
8701
|
outdented: /* @__PURE__ */ new Set(),
|
|
8384
|
-
lineBreaks: "joined"
|
|
8702
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
8385
8703
|
};
|
|
8386
8704
|
}
|
|
8387
8705
|
/**
|
|
8388
|
-
* Whether a statement is kept as written, from its start to `end`: it is
|
|
8389
|
-
* written over several lines, and a comment or a directive lies in it
|
|
8390
|
-
* (docs/sequence.md, Multi-line statements). Such a statement cannot stand
|
|
8391
|
-
* on one line, and its lines are part of it only through the whitespace at
|
|
8392
|
-
* their ends (diagrams/sequence.md, The statement context, rule 2), which
|
|
8393
|
-
* the formatter does not write. A title with a comment line between its
|
|
8394
|
-
* keyword and its text is one: the comment line is removed before the
|
|
8395
|
-
* lexer reads the text (common.md, Comment lines), so the line after it is
|
|
8396
|
-
* the title. The lines of an `accDescr { ... }` block are lines of its
|
|
8397
|
-
* text, kept by its own layout.
|
|
8398
|
-
*/
|
|
8399
|
-
function isKeptAsWritten(source, statement, end) {
|
|
8400
|
-
if (statement.type === "SequenceAccDescrBlockStatement") return false;
|
|
8401
|
-
return spansLinesThatCannotJoin(source, statement.range[0], end);
|
|
8402
|
-
}
|
|
8403
|
-
/**
|
|
8404
8706
|
* The layout of a title: its keyword with the directives right after it,
|
|
8405
8707
|
* one space for the one whitespace character that follows them, and the
|
|
8406
8708
|
* rest as written (docs/sequence.md, Title). The title of the Db keeps the
|
|
@@ -9040,8 +9342,9 @@ function layoutStateHeader(source, keyword) {
|
|
|
9040
9342
|
* The layout of the line that opens a body, from the start of a statement
|
|
9041
9343
|
* to the end of its `{`. The `{` stands on the line of the name, after one
|
|
9042
9344
|
* space; a `{` written on the next line is moved there (docs/state.md,
|
|
9043
|
-
* Composite states).
|
|
9044
|
-
*
|
|
9345
|
+
* Composite states). Comments and directives keep line breaks while structural
|
|
9346
|
+
* continuations align. Such a line is kept as written when joining regions or
|
|
9347
|
+
* semicolons protect it, when text that
|
|
9045
9348
|
* mermaid.js does not read stands before its `{` and is read by its place
|
|
9046
9349
|
* (see `hasReadOtherwiseTextBeforeBody`), or when it follows a state name
|
|
9047
9350
|
* (see `isStateNameStatement`).
|
|
@@ -9049,15 +9352,17 @@ function layoutStateHeader(source, keyword) {
|
|
|
9049
9352
|
function layoutBodyOpening(source, statement, opening, followsStateName) {
|
|
9050
9353
|
const start = statement.range[0];
|
|
9051
9354
|
const end = opening.range[1];
|
|
9052
|
-
|
|
9355
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
9356
|
+
if (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }) || hasReadOtherwiseTextBeforeBody(statement) || followsStateName) return keptAsWritten(start, end);
|
|
9053
9357
|
const rules = /* @__PURE__ */ new Map([[opening.range[0], "space"]]);
|
|
9054
9358
|
if (statement.type === "StateAliasDefinitionStatement") addAliasHeaderRules(source, statement, rules);
|
|
9055
|
-
|
|
9056
|
-
|
|
9359
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, stateValueNodeTypes).filter((value) => value.range[1] <= opening.range[0]), []);
|
|
9360
|
+
return alignBlockOpeningLine(source, {
|
|
9361
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
9057
9362
|
rules,
|
|
9058
|
-
outdented: /* @__PURE__ */ new Set(),
|
|
9059
|
-
lineBreaks: "joined"
|
|
9060
|
-
};
|
|
9363
|
+
outdented: /* @__PURE__ */ new Set([opening.range[0]]),
|
|
9364
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
9365
|
+
}, opening.range[0]);
|
|
9061
9366
|
}
|
|
9062
9367
|
/**
|
|
9063
9368
|
* Whether a `{` stands in the text between `start` and `end`, outside its
|
|
@@ -9084,9 +9389,10 @@ function holdsBrace(source, start, end) {
|
|
|
9084
9389
|
* `as`, the position of a note, `classDef` and `style` and their names,
|
|
9085
9390
|
* `scale`, `direction`, and the `:` of `accTitle` and `accDescr`
|
|
9086
9391
|
* (diagrams/state.md, Lexical structure); one with a comment or a
|
|
9087
|
-
* directive
|
|
9088
|
-
* lines of an `accDescr { ... }` block and of a note
|
|
9089
|
-
*
|
|
9392
|
+
* directive keeps its line breaks and aligns structural continuations. The
|
|
9393
|
+
* lines of an `accDescr { ... }` block and of a note remain separate;
|
|
9394
|
+
* ordinary note paragraph margins follow their own layout (docs/state.md,
|
|
9395
|
+
* Multi-line values and Notes).
|
|
9090
9396
|
* - A transition has one space on each side of its arrow (docs/state.md,
|
|
9091
9397
|
* Arrow spacing).
|
|
9092
9398
|
* - The `:` of a description or a label has one space on each side
|
|
@@ -9094,7 +9400,7 @@ function holdsBrace(source, start, end) {
|
|
|
9094
9400
|
* - What follows the id of a note, and the second description of an alias
|
|
9095
9401
|
* definition, are kept as written (docs/state.md, Notes and Aliases).
|
|
9096
9402
|
*/
|
|
9097
|
-
function layoutStateStatement(source, statement, end, followsStateName) {
|
|
9403
|
+
function layoutStateStatement(source, statement, end, followsStateName, noteIndentation) {
|
|
9098
9404
|
const start = statement.range[0];
|
|
9099
9405
|
if (followsStateName && holdsBrace(source, start, end)) return keptAsWritten(start, end);
|
|
9100
9406
|
if (statement.type === "StateAccDescrBlockStatement") {
|
|
@@ -9102,17 +9408,18 @@ function layoutStateStatement(source, statement, end, followsStateName) {
|
|
|
9102
9408
|
/** Builds the existing value, trivia and closing-brace layout. */
|
|
9103
9409
|
function originalLayout() {
|
|
9104
9410
|
const closing = findAccDescrBlockClosing(source, block);
|
|
9105
|
-
return {
|
|
9411
|
+
return indentDescriptionLines(source, block, {
|
|
9106
9412
|
atoms: collectAtoms(source, start, end, collectValueNodes(block, stateValueNodeTypes), findAccDescrBlockStretches(source, block)),
|
|
9107
|
-
rules:
|
|
9413
|
+
rules: descriptionOpeningRules(source, start),
|
|
9108
9414
|
outdented: closing === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([closing]),
|
|
9109
9415
|
lineBreaks: "kept"
|
|
9110
|
-
};
|
|
9416
|
+
});
|
|
9111
9417
|
}
|
|
9112
9418
|
return statement.value === null && statement.closed ? layoutCompactEmptyDescriptionBlockWithFallback(source, start, end, originalLayout) : originalLayout();
|
|
9113
9419
|
}
|
|
9114
|
-
if (statement.type === "StateNoteStatement" && isNoteOverLines(source, statement)) return layoutNoteOverLines(source, statement, end);
|
|
9115
|
-
|
|
9420
|
+
if (statement.type === "StateNoteStatement" && isNoteOverLines(source, statement)) return layoutNoteOverLines(source, statement, end, noteIndentation);
|
|
9421
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
9422
|
+
if (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }) || (statement.type === "StateCompositeStatement" || statement.type === "StateAliasDefinitionStatement") && hasReadOtherwiseTextBeforeBody(statement)) return keptAsWritten(start, end);
|
|
9116
9423
|
const kept = [
|
|
9117
9424
|
...findNoteStretches(statement, end),
|
|
9118
9425
|
...findSecondDescriptionStretches(source, statement, end),
|
|
@@ -9122,11 +9429,12 @@ function layoutStateStatement(source, statement, end, followsStateName) {
|
|
|
9122
9429
|
range: statement.range,
|
|
9123
9430
|
text: statement.value.value
|
|
9124
9431
|
});
|
|
9432
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, stateValueNodeTypes).filter((value) => !kept.some((stretch) => stretch.start <= value.range[0] && value.range[1] <= stretch.end)), kept);
|
|
9125
9433
|
return {
|
|
9126
|
-
atoms:
|
|
9434
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
9127
9435
|
rules: statementRules$1(source, statement),
|
|
9128
9436
|
outdented: /* @__PURE__ */ new Set(),
|
|
9129
|
-
lineBreaks: keepsDirectionValue ? "kept" : "joined"
|
|
9437
|
+
lineBreaks: keepsLineBreaks || keepsDirectionValue ? "kept" : "joined"
|
|
9130
9438
|
};
|
|
9131
9439
|
}
|
|
9132
9440
|
/**
|
|
@@ -9320,28 +9628,121 @@ function findNoteStretches(statement, end) {
|
|
|
9320
9628
|
}];
|
|
9321
9629
|
}
|
|
9322
9630
|
/**
|
|
9323
|
-
*
|
|
9324
|
-
*
|
|
9325
|
-
* note (docs/state.md,
|
|
9326
|
-
*
|
|
9327
|
-
*
|
|
9328
|
-
* note is dropped. A note whose `end note` does not start its line, or
|
|
9329
|
-
* whose text starts on the line of the id, is printed from its id by the
|
|
9330
|
-
* gap rules, with its line breaks kept.
|
|
9631
|
+
* A multiline note keeps its lines and aligns eligible paragraph margins one
|
|
9632
|
+
* level inside its header. Protected text retains its complete written span;
|
|
9633
|
+
* `end note` aligns with the header (docs/state.md, Notes). A note whose
|
|
9634
|
+
* `end note` does not start its line, or whose text starts on the line of
|
|
9635
|
+
* the id, is printed from its id by the gap rules, with line breaks kept.
|
|
9331
9636
|
*/
|
|
9332
|
-
function layoutNoteOverLines(source, statement, end) {
|
|
9637
|
+
function layoutNoteOverLines(source, statement, end, indentation) {
|
|
9333
9638
|
const endKeyword = expectToken(findStructuralTokenEndingBefore(source, expectToken(findTokenEndingBefore(source, statement.range[1]), "the `note` of an `end note`").range[0]), "the `end` of an `end note`");
|
|
9334
9639
|
const text = findNoteTextStretch(source, statement, endKeyword);
|
|
9640
|
+
const lines = text === null ? null : noteTextLines(source, statement, text, indentation);
|
|
9335
9641
|
return {
|
|
9336
|
-
atoms: collectAtoms(source, statement.range[0], end, collectValueNodes(statement, stateValueNodeTypes), text === null ? [] : [text]),
|
|
9642
|
+
atoms: collectAtoms(source, statement.range[0], end, collectValueNodes(statement, stateValueNodeTypes), text === null ? [] : [text]).flatMap((atom) => lines !== null && atom.start === text?.start && atom.end === text.end ? lines : [atom]),
|
|
9337
9643
|
rules: text === null ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map([[text.start, "none"]]),
|
|
9338
9644
|
outdented: /* @__PURE__ */ new Set([endKeyword.range[0]]),
|
|
9339
9645
|
lineBreaks: "kept"
|
|
9340
9646
|
};
|
|
9341
9647
|
}
|
|
9342
9648
|
/**
|
|
9343
|
-
*
|
|
9344
|
-
*
|
|
9649
|
+
* Align eligible paragraph bodies, or only the first physical body line whose
|
|
9650
|
+
* ASCII margin Mermaid trims. Embedded forms keep their full source. Explicit
|
|
9651
|
+
* ASCII columns avoid introducing Markdown-significant tabs with useTabs
|
|
9652
|
+
* (docs/state.md, Notes).
|
|
9653
|
+
*/
|
|
9654
|
+
function noteTextLines(source, statement, text, indentation) {
|
|
9655
|
+
if (source.text[text.start] !== "\n" || source.text.slice(statement.range[0], text.start).includes("\n") || source.text.slice(...statement.range).includes(";") || findTriviaBetween(source, ...statement.range).length > 0 || holdsJoiningRegion(source, ...statement.range)) return null;
|
|
9656
|
+
return paragraphNoteTextLines(source, text, indentation) ?? firstNoteTextLine(source, text, indentation);
|
|
9657
|
+
}
|
|
9658
|
+
/**
|
|
9659
|
+
* A single paragraph aligns its content rows, including inline emphasis,
|
|
9660
|
+
* same-line code and inline `<br/>`. Outer blank rows retain their exact text;
|
|
9661
|
+
* block syntax and markup that can own later margins remain protected.
|
|
9662
|
+
*/
|
|
9663
|
+
function paragraphNoteTextLines(source, text, indentation) {
|
|
9664
|
+
const lines = [];
|
|
9665
|
+
const contentRows = [];
|
|
9666
|
+
let sawContent = false;
|
|
9667
|
+
let endedParagraph = false;
|
|
9668
|
+
let contentEnd = text.end;
|
|
9669
|
+
while (contentEnd > text.start + 1 && " \n".includes(source.text[contentEnd - 1])) contentEnd--;
|
|
9670
|
+
for (let offset = text.start + 1; offset <= text.end;) {
|
|
9671
|
+
const nextBreak = source.text.indexOf("\n", offset);
|
|
9672
|
+
const end = nextBreak < 0 ? text.end : Math.min(nextBreak, text.end);
|
|
9673
|
+
let start = offset;
|
|
9674
|
+
while (source.text[start] === " " || source.text[start] === " ") start++;
|
|
9675
|
+
if (start >= end) {
|
|
9676
|
+
lines.push({
|
|
9677
|
+
start: offset,
|
|
9678
|
+
end,
|
|
9679
|
+
writtenIndentation: ""
|
|
9680
|
+
});
|
|
9681
|
+
endedParagraph ||= sawContent;
|
|
9682
|
+
offset = end + 1;
|
|
9683
|
+
continue;
|
|
9684
|
+
}
|
|
9685
|
+
const margin = source.text.slice(offset, start);
|
|
9686
|
+
const content = source.text.slice(start, end);
|
|
9687
|
+
if (endedParagraph || sawContent && margin.includes(" ") || content.startsWith("<br/>") || [...content.split("<br/>").join("")].some((character) => "~[]<>\\".includes(character) || character !== " " && isWhitespace(character)) || end < contentEnd && source.text.slice(end - 2, end) === " ") return null;
|
|
9688
|
+
sawContent = true;
|
|
9689
|
+
contentRows.push(content);
|
|
9690
|
+
lines.push({
|
|
9691
|
+
start,
|
|
9692
|
+
end,
|
|
9693
|
+
writtenIndentation: indentation
|
|
9694
|
+
});
|
|
9695
|
+
offset = end + 1;
|
|
9696
|
+
}
|
|
9697
|
+
if (!sawContent) return null;
|
|
9698
|
+
return isParagraphNoteText(indentation.length < 4 ? contentRows.join("\n") : source.text.slice(text.start + 1, text.end)) ? lines : null;
|
|
9699
|
+
}
|
|
9700
|
+
/**
|
|
9701
|
+
* Use Mermaid's Markdown lexer in an isolated instance. Other consumers of
|
|
9702
|
+
* Marked cannot change these defaults through marked.use (docs/state.md, Notes).
|
|
9703
|
+
*/
|
|
9704
|
+
const noteMarkdown = new Marked({
|
|
9705
|
+
gfm: true,
|
|
9706
|
+
breaks: false,
|
|
9707
|
+
pedantic: false
|
|
9708
|
+
});
|
|
9709
|
+
/** Only supported paragraph tokens permit changing physical line margins. */
|
|
9710
|
+
function isParagraphNoteText(text) {
|
|
9711
|
+
const tokens = noteMarkdown.lexer(text.trim());
|
|
9712
|
+
const paragraph = tokens[0];
|
|
9713
|
+
return tokens.length === 1 && paragraph.type === "paragraph" && paragraph.tokens !== void 0 && paragraph.tokens.every(isMarginIndependentNoteToken);
|
|
9714
|
+
}
|
|
9715
|
+
/** Token forms that permit changing surrounding paragraph line margins. */
|
|
9716
|
+
function isMarginIndependentNoteToken(token) {
|
|
9717
|
+
switch (token.type) {
|
|
9718
|
+
case "text": return !token.raw.includes("`");
|
|
9719
|
+
case "em":
|
|
9720
|
+
case "strong": return token.tokens !== void 0 && token.tokens.every(isMarginIndependentNoteToken);
|
|
9721
|
+
case "codespan":
|
|
9722
|
+
case "link": return !token.raw.includes("\n");
|
|
9723
|
+
case "html": return token.raw === "<br/>" && token.block === false;
|
|
9724
|
+
default: return false;
|
|
9725
|
+
}
|
|
9726
|
+
}
|
|
9727
|
+
/** A nonblank first physical row loses its leading space/tab padding in the Db. */
|
|
9728
|
+
function firstNoteTextLine(source, text, indentation) {
|
|
9729
|
+
let start = text.start + 1;
|
|
9730
|
+
while (source.text[start] === " " || source.text[start] === " ") start++;
|
|
9731
|
+
const lineEnd = lineEndOf(source, text.start + 1);
|
|
9732
|
+
if (start >= text.end || start >= lineEnd || isWhitespace(source.text[start])) return null;
|
|
9733
|
+
const end = Math.min(lineEnd, text.end);
|
|
9734
|
+
return [{
|
|
9735
|
+
start,
|
|
9736
|
+
end,
|
|
9737
|
+
writtenIndentation: indentation
|
|
9738
|
+
}, ...end < text.end ? [{
|
|
9739
|
+
start: end,
|
|
9740
|
+
end: text.end
|
|
9741
|
+
}] : []];
|
|
9742
|
+
}
|
|
9743
|
+
/**
|
|
9744
|
+
* The body stretch initially collected as one atom: from the line break after
|
|
9745
|
+
* its id to the line break before the line of `end note`,
|
|
9345
9746
|
* or null where text other than comments and directives follows the id on
|
|
9346
9747
|
* its line or `end note` does not start its line.
|
|
9347
9748
|
*/
|
|
@@ -9505,13 +9906,8 @@ function printState(path, options, print, source) {
|
|
|
9505
9906
|
if (classified === null) throw new Error(`prettier-plugin-mmd: ${node.type} is no node of a state diagram that is printed`);
|
|
9506
9907
|
const depth = depthOf(path);
|
|
9507
9908
|
const followsStateName = isStateNameStatement(path.previous);
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
if (hasBodyBlock(source, classified.statement)) return printBodyBlock(path, options, print, source, classified.statement, depth, followsStateName);
|
|
9511
|
-
return printLine$1(source, options, layoutStateStatement(source, classified.statement, findStatePrintedEnd(source, classified.statement), followsStateName), depth);
|
|
9512
|
-
case "simple": return printLine$1(source, options, layoutStateStatement(source, classified.statement, findStatePrintedEnd(source, classified.statement), followsStateName), depth);
|
|
9513
|
-
default: throw new Error(`prettier-plugin-mmd: unknown kind of statement ${JSON.stringify(classified)}`);
|
|
9514
|
-
}
|
|
9909
|
+
if (classified.kind === "body" && hasBodyBlock(source, classified.statement)) return printBodyBlock(path, options, print, source, classified.statement, depth, followsStateName);
|
|
9910
|
+
return printLine$1(source, options, layoutStateStatement(source, classified.statement, findStatePrintedEnd(source, classified.statement), followsStateName, " ".repeat(options.tabWidth * (depth + 1))), depth);
|
|
9515
9911
|
}
|
|
9516
9912
|
/** Prints a statement laid out on its lines at `depth`. */
|
|
9517
9913
|
function printLine$1(source, options, layout, depth) {
|
|
@@ -9636,7 +10032,7 @@ function layoutCommonLine(source, statement, isTitle) {
|
|
|
9636
10032
|
* Shared block edges and aligned closer, followed by retained hidden suffixes
|
|
9637
10033
|
* (docs/pie.md, Description blocks; docs/gitgraph.md, Title and common values).
|
|
9638
10034
|
*/
|
|
9639
|
-
function layoutCommonDescription(source, statement, valueTypes) {
|
|
10035
|
+
function layoutCommonDescription(source, statement, valueTypes, options = {}) {
|
|
9640
10036
|
const [start, end] = statement.range;
|
|
9641
10037
|
const closing = findTokensBetween(source, start, statement.textAfter?.at(0)?.range[0] ?? end).findLast((token) => isStructural(source, token) && token.value === "}");
|
|
9642
10038
|
const blockEnd = expectToken(closing, "the description closer").range[1];
|
|
@@ -9648,6 +10044,7 @@ function layoutCommonDescription(source, statement, valueTypes) {
|
|
|
9648
10044
|
const opener = expectToken(findStructuralToken(source, start), "accDescr");
|
|
9649
10045
|
const brace = expectToken(findStructuralToken(source, statement.textBeforeOpen?.at(-1)?.range[1] ?? opener.range[1]), "the description opener");
|
|
9650
10046
|
let layout = layoutDescriptionBlock(source, block, blockEnd, valueTypes, {
|
|
10047
|
+
...options,
|
|
9651
10048
|
keepsTrailingTrivia: true,
|
|
9652
10049
|
formatsEmptyTrivia: true,
|
|
9653
10050
|
trimValueEdges: true,
|
|
@@ -9889,7 +10286,7 @@ function layoutTreeviewStatement(source, item, column, boxMode, drawing) {
|
|
|
9889
10286
|
lineBreaks: "kept",
|
|
9890
10287
|
joinedBefore: findTriviaBetween(source, keyword.range[1], brace.range[0]).length === 0 ? /* @__PURE__ */ new Set([brace.range[0]]) : /* @__PURE__ */ new Set()
|
|
9891
10288
|
};
|
|
9892
|
-
} else layout = layoutCommonDescription(source, content, treeviewValueNodeTypes);
|
|
10289
|
+
} else layout = layoutCommonDescription(source, content, treeviewValueNodeTypes, { preservesBodyColumns: boxMode });
|
|
9893
10290
|
const gap = drawing?.keptOpenerGaps.get(item);
|
|
9894
10291
|
if (gap !== void 0) layout = {
|
|
9895
10292
|
...layout,
|
|
@@ -10162,13 +10559,14 @@ function printTreeview(path, options, _print, source) {
|
|
|
10162
10559
|
if (line.item.type === "TreeviewIgnoredText" && drawing !== void 0) return drawing.decorations.get(line.item);
|
|
10163
10560
|
const head = line.item.type === "TreeviewNode" ? drawing?.heads.get(line.item) ?? "" : "";
|
|
10164
10561
|
const after = line.item.type === "TreeviewNode" ? drawing?.trailingDecorations.get(line.item) ?? [] : [];
|
|
10562
|
+
const descriptionIndentation = line.item.type === "TreeviewAccDescrBlockStatement" ? significantIndentationOf(options, boxMode ? 1 : line.depth + 1) : "";
|
|
10165
10563
|
return [
|
|
10166
10564
|
placements.get(line).head,
|
|
10167
10565
|
head,
|
|
10168
10566
|
printAtoms(source, layouts.get(line), {
|
|
10169
10567
|
statement: boxMode ? "" : significantIndentationOf(options, line.depth),
|
|
10170
|
-
continuation:
|
|
10171
|
-
trivia:
|
|
10568
|
+
continuation: descriptionIndentation,
|
|
10569
|
+
trivia: descriptionIndentation
|
|
10172
10570
|
}).doc,
|
|
10173
10571
|
...after.flatMap((decoration) => {
|
|
10174
10572
|
const guide = drawing.decorations.get(decoration);
|
|
@@ -10306,7 +10704,7 @@ function hasTrailingIndentation(source, start, end) {
|
|
|
10306
10704
|
return false;
|
|
10307
10705
|
}
|
|
10308
10706
|
/** Ordinary row components join; trivia and protected segments keep their lines. */
|
|
10309
|
-
function layoutTreemapStatement(source, statement, column) {
|
|
10707
|
+
function layoutTreemapStatement(source, statement, column, continuationPadding) {
|
|
10310
10708
|
const [start, end] = treemapStatementRange(statement);
|
|
10311
10709
|
let layout;
|
|
10312
10710
|
switch (statement.type) {
|
|
@@ -10337,9 +10735,18 @@ function layoutTreemapStatement(source, statement, column) {
|
|
|
10337
10735
|
atoms: atoms.map((atom, index) => {
|
|
10338
10736
|
const previous = atoms[index - 1];
|
|
10339
10737
|
const hasEarlierIndentation = previous !== void 0 && hasTrailingIndentation(source, previous.end, atom.start);
|
|
10738
|
+
const styleContinuation = statement.type === "TreemapClassDefStatement" && statement.style?.range[0] === atom.start && !hasEarlierIndentation;
|
|
10739
|
+
let writtenIndentation = column;
|
|
10740
|
+
if (hasEarlierIndentation || findTokenStartingAt(source, atom.start)?.value === ":::" || statement.type !== "TreemapClassDefStatement" && statement.classSelector?.range[0] === atom.start) writtenIndentation = "";
|
|
10741
|
+
else if (styleContinuation) writtenIndentation += continuationPadding;
|
|
10742
|
+
if (styleContinuation) return {
|
|
10743
|
+
...atom,
|
|
10744
|
+
statementPadding: continuationPadding,
|
|
10745
|
+
writtenIndentation
|
|
10746
|
+
};
|
|
10340
10747
|
return {
|
|
10341
10748
|
...atom,
|
|
10342
|
-
writtenIndentation
|
|
10749
|
+
writtenIndentation
|
|
10343
10750
|
};
|
|
10344
10751
|
}),
|
|
10345
10752
|
rules,
|
|
@@ -10379,11 +10786,17 @@ function printTreemap(path, options, _print, source) {
|
|
|
10379
10786
|
} : placeLeadingDirectives(source, line.leading, column.length, options.useTabs ? " " : " ")];
|
|
10380
10787
|
}));
|
|
10381
10788
|
const relocatedWhitespace = lines.map((line, index) => [lines[index - 1]?.range[1] ?? keyword.range[1], line.range[0]]);
|
|
10382
|
-
const block = printBlock(lines.map((line) =>
|
|
10383
|
-
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10789
|
+
const block = printBlock(lines.map((line) => {
|
|
10790
|
+
const column = significantIndentationOf(options, line.depth);
|
|
10791
|
+
return [placements.get(line).head, ...line.statements.flatMap((statement, index) => {
|
|
10792
|
+
const descriptionIndentation = statement.type === "TreemapAccDescrBlockStatement" ? significantIndentationOf(options, line.depth + 1) : "";
|
|
10793
|
+
return [index === 0 ? "" : printAsWritten(source, treemapStatementRange(line.statements[index - 1])[1], treemapStatementRange(statement)[0]), printAtoms(source, layoutTreemapStatement(source, statement, column, significantIndentationOf(options, 1)), {
|
|
10794
|
+
statement: column,
|
|
10795
|
+
continuation: descriptionIndentation,
|
|
10796
|
+
trivia: descriptionIndentation
|
|
10797
|
+
}).doc];
|
|
10798
|
+
})];
|
|
10799
|
+
}), source, {
|
|
10387
10800
|
statements: lines,
|
|
10388
10801
|
start: keyword.range[1],
|
|
10389
10802
|
end: source.text.length,
|
|
@@ -10516,15 +10929,16 @@ function layoutTimelineHeader(source, keyword) {
|
|
|
10516
10929
|
* - A period with its events, and the events after another statement, keep
|
|
10517
10930
|
* the line breaks between the units: a period and an event keep their
|
|
10518
10931
|
* whitespace as their text, so no event moves from line to line. The later
|
|
10519
|
-
*
|
|
10520
|
-
* Periods and events). The line
|
|
10521
|
-
* after the `:` of an event is
|
|
10932
|
+
* event colons align under the period's colon when it immediately follows
|
|
10933
|
+
* the period on its line (docs/timeline.md, Periods and events). The line
|
|
10934
|
+
* break that is the one whitespace character after the `:` of an event is
|
|
10935
|
+
* not one of them (see `layoutEvents`).
|
|
10522
10936
|
* - A title, a section, and an accessibility statement written over several
|
|
10523
10937
|
* lines stand on one line where the lexer reads the line break as
|
|
10524
|
-
* whitespace, which it does only right after a keyword
|
|
10525
|
-
*
|
|
10526
|
-
*
|
|
10527
|
-
*
|
|
10938
|
+
* whitespace, which it does only right after a keyword. Accessibility line
|
|
10939
|
+
* trivia keeps its breaks with ordinary continuation columns; titles,
|
|
10940
|
+
* sections, events and protected regions retain their original layout
|
|
10941
|
+
* (docs/timeline.md, Multi-line statements).
|
|
10528
10942
|
*/
|
|
10529
10943
|
function layoutTimelineStatement(source, statement, end) {
|
|
10530
10944
|
const start = statement.range[0];
|
|
@@ -10533,12 +10947,15 @@ function layoutTimelineStatement(source, statement, end) {
|
|
|
10533
10947
|
case "TimelinePeriodStatement":
|
|
10534
10948
|
case "TimelineEventStatement": return layoutEvents(source, statement, end);
|
|
10535
10949
|
}
|
|
10536
|
-
|
|
10950
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
10951
|
+
const formatsTriviaLines = statement.type === "TimelineAccTitleStatement" || statement.type === "TimelineAccDescrStatement";
|
|
10952
|
+
if (keepsLineBreaks && (!formatsTriviaLines || holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
10953
|
+
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, timelineValueNodeTypes), []);
|
|
10537
10954
|
return {
|
|
10538
|
-
atoms:
|
|
10955
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
10539
10956
|
rules: textStatementRules(source, statement),
|
|
10540
10957
|
outdented: /* @__PURE__ */ new Set(),
|
|
10541
|
-
lineBreaks: "joined"
|
|
10958
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
10542
10959
|
};
|
|
10543
10960
|
}
|
|
10544
10961
|
/** The gap rules of a title, a section, or an accessibility statement. */
|
|
@@ -10569,16 +10986,25 @@ function layoutEvents(source, statement, end) {
|
|
|
10569
10986
|
const atoms = collectAtoms(source, start, end, collectValueNodes(statement, timelineValueNodeTypes), []);
|
|
10570
10987
|
const rules = /* @__PURE__ */ new Map();
|
|
10571
10988
|
const joinedBefore = /* @__PURE__ */ new Set();
|
|
10989
|
+
const alignedColons = /* @__PURE__ */ new Set();
|
|
10990
|
+
let statementPadding = statement.type === "TimelineEventStatement" ? "" : void 0;
|
|
10572
10991
|
for (const event of statement.events) {
|
|
10573
10992
|
const eventIndex = atoms.findIndex((atom) => atom.start === event.range[0]);
|
|
10574
10993
|
const colon = eventIndex < 1 ? void 0 : atoms[eventIndex - 1];
|
|
10575
10994
|
if (colon === void 0) throw new Error(`prettier-plugin-mmd: no colon before the event at offset ${event.range[0]}`);
|
|
10995
|
+
if (event === statement.events[0] && statement.type === "TimelinePeriodStatement") {
|
|
10996
|
+
const writtenPeriod = source.text.slice(...statement.period.range);
|
|
10997
|
+
if (colon.start === statement.period.range[1] && !writtenPeriod.includes("\n") && !writtenPeriod.includes("\u2028") && !writtenPeriod.includes("\u2029")) statementPadding = writtenPeriod.split(" ").map((part) => " ".repeat(util.getStringWidth(part))).join(" ");
|
|
10998
|
+
} else if (statementPadding !== void 0) alignedColons.add(colon.start);
|
|
10576
10999
|
if (readGap(source, colon.end, event.range[0], true).breaksLine) joinedBefore.add(event.range[0]);
|
|
10577
11000
|
rules.set(event.range[0], "space");
|
|
10578
11001
|
}
|
|
10579
11002
|
if (joinedBefore.size > 0 && spansLinesThatCannotJoin(source, start, end)) return keptAsWritten(start, end);
|
|
10580
11003
|
return {
|
|
10581
|
-
atoms
|
|
11004
|
+
atoms: atoms.map((atom) => alignedColons.has(atom.start) ? {
|
|
11005
|
+
...atom,
|
|
11006
|
+
statementPadding
|
|
11007
|
+
} : atom),
|
|
10582
11008
|
rules,
|
|
10583
11009
|
outdented: /* @__PURE__ */ new Set(),
|
|
10584
11010
|
lineBreaks: "kept",
|
|
@@ -10663,23 +11089,26 @@ function valueNodesOf(statement) {
|
|
|
10663
11089
|
* The layout of a header (docs/xychart.md, Header and orientation): the
|
|
10664
11090
|
* keyword and the orientation after it, which stands after one space, also
|
|
10665
11091
|
* where it was written on a later line after whitespace. A header with a
|
|
10666
|
-
* comment or
|
|
10667
|
-
*
|
|
11092
|
+
* comment or directive keeps its trivia breaks with continuation columns;
|
|
11093
|
+
* semicolon lines and joining regions retain their layout (docs/xychart.md,
|
|
11094
|
+
* Multi-line statements).
|
|
10668
11095
|
*/
|
|
10669
11096
|
function layoutXychartHeader(source, header) {
|
|
10670
11097
|
const [start, end] = header.range;
|
|
10671
|
-
|
|
11098
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
11099
|
+
if (keepsLineBreaks && (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
10672
11100
|
const keyword = expectToken(findStructuralToken(source, start), "the header");
|
|
10673
11101
|
const rules = /* @__PURE__ */ new Map();
|
|
10674
11102
|
if (header.orientation !== null) {
|
|
10675
11103
|
const orientation = expectToken(findStructuralToken(source, keyword.range[1]), "the orientation");
|
|
10676
11104
|
rules.set(orientation.range[0], "space");
|
|
10677
11105
|
}
|
|
11106
|
+
const atoms = collectAtoms(source, start, end, [], []);
|
|
10678
11107
|
return {
|
|
10679
|
-
atoms:
|
|
11108
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
10680
11109
|
rules,
|
|
10681
11110
|
outdented: /* @__PURE__ */ new Set(),
|
|
10682
|
-
lineBreaks: "joined"
|
|
11111
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
10683
11112
|
};
|
|
10684
11113
|
}
|
|
10685
11114
|
/**
|
|
@@ -10688,21 +11117,25 @@ function layoutXychartHeader(source, header) {
|
|
|
10688
11117
|
* - A statement written over several lines stands on one line where the
|
|
10689
11118
|
* lexer reads the line break as whitespace (diagrams/xychart.md, Lexical
|
|
10690
11119
|
* structure, Line breaks); one with a comment or a directive in it, or a
|
|
10691
|
-
* `;`,
|
|
10692
|
-
*
|
|
10693
|
-
*
|
|
11120
|
+
* `;`, keeps its required line breaks. Ordinary exterior gaps take
|
|
11121
|
+
* continuation indentation; required line tails and protected regions stay
|
|
11122
|
+
* written.
|
|
11123
|
+
* Description-body lines align inside their block (docs/xychart.md,
|
|
11124
|
+
* Accessibility statements and Multi-line statements).
|
|
10694
11125
|
* - The rules of the gaps are those of docs/xychart.md: Text units, Brackets
|
|
10695
11126
|
* and commas, Ranges, Values and labels, and Accessibility statements.
|
|
10696
11127
|
*/
|
|
10697
11128
|
function layoutXychartStatement(source, statement, end) {
|
|
10698
11129
|
const start = statement.range[0];
|
|
10699
11130
|
if (statement.type === "XychartAccDescrBlockStatement") return layoutDescriptionBlock(source, statement, end, descriptionBlockTextTypes);
|
|
10700
|
-
|
|
11131
|
+
const keepsLineBreaks = spansLinesThatCannotJoin(source, start, end);
|
|
11132
|
+
if (keepsLineBreaks && (holdsJoiningRegion(source, start, end) || spansLinesThatCannotJoin(source, start, end, { ignoresTrivia: true }))) return keptAsWritten(start, end);
|
|
11133
|
+
const atoms = collectAtoms(source, start, end, valueNodesOf(statement), []);
|
|
10701
11134
|
return {
|
|
10702
|
-
atoms:
|
|
11135
|
+
atoms: keepsLineBreaks ? keepFirstGapLineTails(source, atoms) : atoms,
|
|
10703
11136
|
rules: statementRules(source, statement),
|
|
10704
11137
|
outdented: /* @__PURE__ */ new Set(),
|
|
10705
|
-
lineBreaks: "joined"
|
|
11138
|
+
lineBreaks: keepsLineBreaks ? "kept" : "joined"
|
|
10706
11139
|
};
|
|
10707
11140
|
}
|
|
10708
11141
|
/** The gap rules of a statement, by the start of the atom after the gap. */
|
|
@@ -10870,7 +11303,7 @@ function statementBlockRules(source) {
|
|
|
10870
11303
|
}
|
|
10871
11304
|
//#endregion
|
|
10872
11305
|
//#region src/printers/hidden-forms.ts
|
|
10873
|
-
const { literalline } = builders;
|
|
11306
|
+
const { literalline: literalline$1 } = builders;
|
|
10874
11307
|
/**
|
|
10875
11308
|
* Hidden body openers and closers share a line with their written neighbors
|
|
10876
11309
|
* (docs/pie.md and docs/gitgraph.md, Hidden yaml and Hidden directives).
|
|
@@ -10932,7 +11365,7 @@ function hiddenBlockRules(source, hiddenEnds, kept, printedEnd, headerHiddenEnds
|
|
|
10932
11365
|
if (!hasOrdinaryHiddenBreak(start, stop)) return printAsWritten(source, start, stop);
|
|
10933
11366
|
const gap = readGap(source, start, stop, false);
|
|
10934
11367
|
const firstBreak = source.text.indexOf("\n", start);
|
|
10935
|
-
const breaks = !terminal && !headerHiddenEnds.has(start) && gap.blankAfter ? [literalline, literalline] : [literalline];
|
|
11368
|
+
const breaks = !terminal && !headerHiddenEnds.has(start) && gap.blankAfter ? [literalline$1, literalline$1] : [literalline$1];
|
|
10936
11369
|
if (terminal && !source.text.endsWith("\n")) breaks.pop();
|
|
10937
11370
|
return [printAsWritten(source, start, firstBreak), ...breaks];
|
|
10938
11371
|
}
|
|
@@ -10992,19 +11425,20 @@ function createFlatHiddenDiagramPrinter(layouts) {
|
|
|
10992
11425
|
headerHiddenEnds.add(item.range[1]);
|
|
10993
11426
|
headerEnd = item.range[1];
|
|
10994
11427
|
}
|
|
10995
|
-
const
|
|
11428
|
+
const bodyDepth = layouts.bodyDepth ?? 1;
|
|
11429
|
+
const block = printBody(diagram.body, findLayoutEnd(headerLayout), source.text.length, bodyDepth, true, headerHiddenEnds);
|
|
10996
11430
|
const header = openingLine(printAtoms(source, headerLayout, {
|
|
10997
11431
|
statement: "",
|
|
10998
11432
|
continuation: ""
|
|
10999
11433
|
}).doc, block, false);
|
|
11000
|
-
return [printAsWritten(source, diagram.range[0], first.start), printDiagramBlock(source, header, block, options)];
|
|
11434
|
+
return [printAsWritten(source, diagram.range[0], first.start), printDiagramBlock(source, header, block, options, bodyDepth)];
|
|
11001
11435
|
/** Only authored body boundaries join lines; inner component gaps do not. */
|
|
11002
11436
|
function collectBodyHidden(body) {
|
|
11003
11437
|
for (const item of body) {
|
|
11004
11438
|
appendItems(allHidden, layouts.prefixes?.(item) ?? []);
|
|
11005
11439
|
if (item.type === layouts.ignoredType) allHidden.push(item);
|
|
11006
11440
|
appendItems(allHidden, layouts.suffixes?.(item) ?? item.textAfter ?? []);
|
|
11007
|
-
const selected = layouts.statement(source, item);
|
|
11441
|
+
const selected = layouts.statement(source, item, options);
|
|
11008
11442
|
if ("body" in selected) collectBodyHidden(selected.body);
|
|
11009
11443
|
}
|
|
11010
11444
|
}
|
|
@@ -11019,7 +11453,7 @@ function createFlatHiddenDiagramPrinter(layouts) {
|
|
|
11019
11453
|
const bodyStatements = new Map(body.map((item) => [item, item]));
|
|
11020
11454
|
const nested = /* @__PURE__ */ new Map();
|
|
11021
11455
|
for (const item of body) {
|
|
11022
|
-
let selected = layouts.statement(source, item);
|
|
11456
|
+
let selected = layouts.statement(source, item, options);
|
|
11023
11457
|
const prefixes = layouts.prefixes?.(item) ?? [];
|
|
11024
11458
|
const prefixEnd = prefixes.at(-1)?.range[1];
|
|
11025
11459
|
const ownedHeader = "body" in selected ? selected.header : selected;
|
|
@@ -11544,6 +11978,7 @@ function layoutRadarStatement(source, statement) {
|
|
|
11544
11978
|
const rules = /* @__PURE__ */ new Map();
|
|
11545
11979
|
const outdented = /* @__PURE__ */ new Set();
|
|
11546
11980
|
const joinedBefore = /* @__PURE__ */ new Set();
|
|
11981
|
+
const hasTrivia = findTriviaBetween(source, start, end).length > 0;
|
|
11547
11982
|
for (const [index, atom] of atoms.entries()) {
|
|
11548
11983
|
const previous = atoms[index - 1];
|
|
11549
11984
|
if (previous === void 0) continue;
|
|
@@ -11552,7 +11987,7 @@ function layoutRadarStatement(source, statement) {
|
|
|
11552
11987
|
const touches = token?.type === "Punctuator" || before?.value === "[" || before?.value === "{";
|
|
11553
11988
|
rules.set(atom.start, touches ? "none" : "space");
|
|
11554
11989
|
if (token?.value === "}") outdented.add(atom.start);
|
|
11555
|
-
if (
|
|
11990
|
+
if (!hasTrivia && !hidden.some((item) => item.range[0] === atom.start || item.range[1] === previous.end) && !hasSemicolon) joinedBefore.add(atom.start);
|
|
11556
11991
|
}
|
|
11557
11992
|
layout = {
|
|
11558
11993
|
atoms,
|
|
@@ -11650,7 +12085,7 @@ function layoutEventmodelingHeader(source, diagram) {
|
|
|
11650
12085
|
* (diagrams/eventmodeling.md, Common statements; docs/eventmodeling.md,
|
|
11651
12086
|
* Common boundaries and Description blocks). Other components use one layout.
|
|
11652
12087
|
*/
|
|
11653
|
-
function layoutEventmodelingStatement(source, statement) {
|
|
12088
|
+
function layoutEventmodelingStatement(source, statement, options) {
|
|
11654
12089
|
const [start, end] = statement.range;
|
|
11655
12090
|
const selected = classifyEventmodelingStatement(statement);
|
|
11656
12091
|
switch (selected.kind) {
|
|
@@ -11659,7 +12094,7 @@ function layoutEventmodelingStatement(source, statement) {
|
|
|
11659
12094
|
case "gwt": {
|
|
11660
12095
|
const gwt = selected.statement;
|
|
11661
12096
|
return {
|
|
11662
|
-
header: layoutComponents$1(source, gwt, start, gwt.sourceFrame.range[1]),
|
|
12097
|
+
header: layoutComponents$1(source, gwt, start, gwt.sourceFrame.range[1], options.tabWidth),
|
|
11663
12098
|
body: [
|
|
11664
12099
|
gwt.given,
|
|
11665
12100
|
...gwt.when === null ? [] : [gwt.when],
|
|
@@ -11671,13 +12106,13 @@ function layoutEventmodelingStatement(source, statement) {
|
|
|
11671
12106
|
case "clause": {
|
|
11672
12107
|
const clause = selected.statement;
|
|
11673
12108
|
return {
|
|
11674
|
-
header: layoutComponents$1(source, clause, start, expectToken(findStructuralToken(source, clause.textBefore.at(-1)?.range[1] ?? start), "a GWT clause").range[1]),
|
|
12109
|
+
header: layoutComponents$1(source, clause, start, expectToken(findStructuralToken(source, clause.textBefore.at(-1)?.range[1] ?? start), "a GWT clause").range[1], options.tabWidth),
|
|
11675
12110
|
body: clause.body,
|
|
11676
12111
|
end
|
|
11677
12112
|
};
|
|
11678
12113
|
}
|
|
11679
12114
|
case "ordinary":
|
|
11680
|
-
case "data": return layoutComponents$1(source, statement, start, end);
|
|
12115
|
+
case "data": return layoutComponents$1(source, statement, start, end, options.tabWidth);
|
|
11681
12116
|
default: throw new Error(`prettier-plugin-mmd: unknown eventmodeling kind ${JSON.stringify(selected)}`);
|
|
11682
12117
|
}
|
|
11683
12118
|
}
|
|
@@ -11687,12 +12122,14 @@ function layoutEventmodelingStatement(source, statement) {
|
|
|
11687
12122
|
* title would become EM_TITLE (diagrams/eventmodeling.md, Data and Common
|
|
11688
12123
|
* statements; docs/eventmodeling.md, Frame components and Qualified names).
|
|
11689
12124
|
*/
|
|
11690
|
-
function layoutComponents$1(source, statement, start, end) {
|
|
12125
|
+
function layoutComponents$1(source, statement, start, end, tabWidth) {
|
|
11691
12126
|
const values = collectValueNodes(statement, eventmodelingValueNodeTypes).filter((node) => start <= node.range[0] && node.range[1] <= end);
|
|
11692
12127
|
const kept = [];
|
|
12128
|
+
let blockOpening;
|
|
11693
12129
|
walk(statement, (node) => {
|
|
11694
12130
|
if ((node.type === "EventmodelingInlineData" || node.type === "EventmodelingDataBlock") && node.range[1] <= end) {
|
|
11695
12131
|
const opening = expectToken(node.value?.type === "StringLiteral" ? findTokenStartingAt(source, node.value.range[0]) : findTokensBetween(source, node.range[0], node.range[1]).find((token) => token.type === "Punctuator" && token.value === "{"), "a data body");
|
|
12132
|
+
if (node.type === "EventmodelingDataBlock") blockOpening = opening.range[0];
|
|
11696
12133
|
kept.push({
|
|
11697
12134
|
start: opening.range[0],
|
|
11698
12135
|
end: node.range[1]
|
|
@@ -11719,29 +12156,66 @@ function layoutComponents$1(source, statement, start, end) {
|
|
|
11719
12156
|
}
|
|
11720
12157
|
if (token?.value === "`") inTag = !inTag;
|
|
11721
12158
|
}
|
|
11722
|
-
|
|
12159
|
+
const protectedLayout = protectHiddenGaps({
|
|
11723
12160
|
atoms: protectSemicolonPrefixes(source, start, end, atoms),
|
|
11724
12161
|
rules,
|
|
11725
12162
|
outdented: /* @__PURE__ */ new Set(),
|
|
11726
12163
|
lineBreaks: "kept",
|
|
11727
12164
|
joinedBefore
|
|
11728
12165
|
}, values.filter((node) => node.type === "EventmodelingIgnoredText"));
|
|
11729
|
-
|
|
11730
|
-
|
|
11731
|
-
|
|
11732
|
-
|
|
11733
|
-
|
|
11734
|
-
|
|
11735
|
-
|
|
11736
|
-
|
|
11737
|
-
|
|
11738
|
-
|
|
11739
|
-
|
|
11740
|
-
|
|
12166
|
+
const layout = {
|
|
12167
|
+
...protectedLayout,
|
|
12168
|
+
writtenGapsBefore: /* @__PURE__ */ new Set([...protectedLayout.writtenGapsBefore ?? [], ...writtenGapsBefore])
|
|
12169
|
+
};
|
|
12170
|
+
return classifyEventmodelingStatement(statement).kind === "data" ? layoutDataBody(source, layout, values, blockOpening, end, tabWidth) : layout;
|
|
12171
|
+
}
|
|
12172
|
+
/**
|
|
12173
|
+
* Aligns a data or note body and retains its required closing padding. Its
|
|
12174
|
+
* final atom is the required body, or a semicolon-protected span covering it.
|
|
12175
|
+
*/
|
|
12176
|
+
function layoutDataBody(source, layout, values, blockOpening, end, tabWidth) {
|
|
12177
|
+
const body = layout.atoms.at(-1);
|
|
12178
|
+
const continuedHeader = !values.some((node) => node.type === "EventmodelingIgnoredText" && node.range[0] < body.start) && layout.atoms.some((atom, index) => {
|
|
12179
|
+
const previous = layout.atoms[index - 1];
|
|
12180
|
+
return previous !== void 0 && !layout.joinedBefore?.has(atom.start) && !layout.writtenGapsBefore?.has(atom.start) && readGap(source, previous.end, atom.start, true).breaksLine;
|
|
12181
|
+
});
|
|
12182
|
+
const bodyDoc = body.start === blockOpening && body.writtenIndentation === void 0 ? indentedDataBlock(source.text.slice(body.start, body.end), tabWidth * (continuedHeader ? 2 : 1)) : void 0;
|
|
12183
|
+
let paddedEnd = end;
|
|
12184
|
+
while (source.text[paddedEnd] === " " || source.text[paddedEnd] === " ") paddedEnd++;
|
|
11741
12185
|
return {
|
|
11742
12186
|
...layout,
|
|
11743
|
-
|
|
11744
|
-
|
|
12187
|
+
atoms: [...layout.atoms.slice(0, -1), {
|
|
12188
|
+
...body,
|
|
12189
|
+
end: paddedEnd,
|
|
12190
|
+
doc: bodyDoc === void 0 ? void 0 : [bodyDoc, printAsWritten(source, body.end, paddedEnd)]
|
|
12191
|
+
}]
|
|
12192
|
+
};
|
|
12193
|
+
}
|
|
12194
|
+
/**
|
|
12195
|
+
* Align nonblank body lines while keeping the space-separated words of
|
|
12196
|
+
* Mermaid's data label. A new space on a later physical line adds a visible
|
|
12197
|
+
* nonbreaking space; tabs, markup and padded openers need their authored text
|
|
12198
|
+
* (docs/eventmodeling.md, Data blocks).
|
|
12199
|
+
*/
|
|
12200
|
+
function indentedDataBlock(text, tabWidth) {
|
|
12201
|
+
if (tabWidth === 0 || !text.startsWith("{\n") || !text.endsWith("\n}") || text.includes("<") || text.includes("&") || text.includes("%%{")) return void 0;
|
|
12202
|
+
const rows = text.slice(2, -2).split("\n");
|
|
12203
|
+
const margins = rows.map((row) => {
|
|
12204
|
+
let margin = 0;
|
|
12205
|
+
while (row[margin] === " ") margin++;
|
|
12206
|
+
return margin;
|
|
12207
|
+
});
|
|
12208
|
+
let hasContent = false;
|
|
12209
|
+
for (const [index, row] of rows.entries()) {
|
|
12210
|
+
if (row.trim() === "") continue;
|
|
12211
|
+
hasContent = true;
|
|
12212
|
+
const margin = margins[index];
|
|
12213
|
+
if (isWhitespace(row[margin]) || index > 0 && margin === 0) return void 0;
|
|
12214
|
+
}
|
|
12215
|
+
if (!hasContent) return void 0;
|
|
12216
|
+
const indentation = " ".repeat(tabWidth);
|
|
12217
|
+
const indented = rows.map((row, index) => row.trim() === "" ? row : indentation + row.slice(margins[index]));
|
|
12218
|
+
return utils.replaceEndOfLine(`{\n${indented.join("\n")}\n}`);
|
|
11745
12219
|
}
|
|
11746
12220
|
//#endregion
|
|
11747
12221
|
//#region src/printers/eventmodeling.ts
|
|
@@ -11749,6 +12223,7 @@ function layoutComponents$1(source, statement, start, end) {
|
|
|
11749
12223
|
const eventmodelingPrinter = createFlatHiddenDiagramPrinter({
|
|
11750
12224
|
type: "EventmodelingDiagram",
|
|
11751
12225
|
ignoredType: "EventmodelingIgnoredText",
|
|
12226
|
+
bodyDepth: 0,
|
|
11752
12227
|
header: layoutEventmodelingHeader,
|
|
11753
12228
|
statement: layoutEventmodelingStatement,
|
|
11754
12229
|
writtenGapBefore: (source, item) => classifyEventmodelingStatement(item).kind === "common" || source.joiningRegions.some((region) => region.end <= item.range[0] && source.text.slice(region.end, item.range[0]).trim() === ""),
|
|
@@ -11966,6 +12441,7 @@ const wardleyPrinter = createFlatHiddenDiagramPrinter({
|
|
|
11966
12441
|
});
|
|
11967
12442
|
//#endregion
|
|
11968
12443
|
//#region src/printers/railroad-layout.ts
|
|
12444
|
+
const { group, hardline, ifBreak, indent, line, literalline, markAsRoot, softline } = builders;
|
|
11969
12445
|
/** Written text leaves retain spelling, quotes and physical value columns. */
|
|
11970
12446
|
const railroadValueNodeTypes = /* @__PURE__ */ new Set([
|
|
11971
12447
|
"Identifier",
|
|
@@ -11990,8 +12466,9 @@ function layoutRailroadStatement(source, statement) {
|
|
|
11990
12466
|
const verbatim = layoutOnVerbatimStyleLine(source, start, end);
|
|
11991
12467
|
if (verbatim !== null) return verbatim;
|
|
11992
12468
|
const values = collectValueNodes(statement, railroadValueNodeTypes);
|
|
11993
|
-
const hidden = values.filter((value) => value.type === "RailroadIgnoredText");
|
|
12469
|
+
const hidden = values.filter((value) => value.type === "RailroadIgnoredText").sort((a, b) => a.range[0] - b.range[0]);
|
|
11994
12470
|
const grammaticalSemicolons = grammaticalSemicolonsOf(source);
|
|
12471
|
+
const wrapsCalls = statement.type === "RailroadRule" && source.root.diagramType === "railroad" && !findTokensBetween(source, start, end).some((token) => source.ignoredSemicolons.has(token.range[0]));
|
|
11995
12472
|
let layout;
|
|
11996
12473
|
switch (statement.type) {
|
|
11997
12474
|
case "RailroadIgnoredText":
|
|
@@ -12014,14 +12491,14 @@ function layoutRailroadStatement(source, statement) {
|
|
|
12014
12491
|
layout = layoutCommonDescription(source, statement, railroadValueNodeTypes);
|
|
12015
12492
|
break;
|
|
12016
12493
|
case "RailroadRule":
|
|
12017
|
-
layout = layoutRule(source, statement, values, hidden, grammaticalSemicolons);
|
|
12494
|
+
layout = layoutRule(source, statement, values, hidden, grammaticalSemicolons, wrapsCalls);
|
|
12018
12495
|
break;
|
|
12019
12496
|
default: throw new Error(`prettier-plugin-mmd: unknown railroad item ${JSON.stringify(statement)}`);
|
|
12020
12497
|
}
|
|
12021
12498
|
return protectHiddenGaps({
|
|
12022
12499
|
...layout,
|
|
12023
|
-
atoms: protectSemicolonPrefixes(source, start, end, layout.atoms, grammaticalSemicolons)
|
|
12024
|
-
}, hidden);
|
|
12500
|
+
atoms: wrapsCalls ? layout.atoms : protectSemicolonPrefixes(source, start, end, layout.atoms, grammaticalSemicolons)
|
|
12501
|
+
}, statement.type === "RailroadRule" && wrapsCalls ? hidden.filter((item) => item.range[0] < statement.definition.range[0] || item.range[1] > statement.definition.range[1]) : hidden);
|
|
12025
12502
|
}
|
|
12026
12503
|
/**
|
|
12027
12504
|
* Calls, groups, postfixes, predicates and repeats attach; binary separators
|
|
@@ -12029,16 +12506,29 @@ function layoutRailroadStatement(source, statement) {
|
|
|
12029
12506
|
* marks in a special sequence never become postfixes (docs/railroad.md,
|
|
12030
12507
|
* Groups, Postfixes, Predicates, Repeats, Calls and Special sequences).
|
|
12031
12508
|
*/
|
|
12032
|
-
function layoutRule(source, statement, values, hidden, grammaticalSemicolons) {
|
|
12509
|
+
function layoutRule(source, statement, values, hidden, grammaticalSemicolons, wrapsCalls) {
|
|
12033
12510
|
const [start, end] = statement.range;
|
|
12034
|
-
|
|
12035
|
-
|
|
12511
|
+
const hasTextualSemicolon = source.text.slice(start, end).split("").some((character, index) => character === ";" && !grammaticalSemicolons.has(start + index));
|
|
12512
|
+
if (!wrapsCalls && source.text.slice(start, end).includes("\n") && (hasTextualSemicolon || findSemicolonLines(source).has(lineStartOf(source, end - 1)))) return keptAsWritten(start, end);
|
|
12513
|
+
const atoms = collectAtoms(source, start, end, values, [...wrapsCalls ? [{
|
|
12514
|
+
start: statement.definition.range[0],
|
|
12515
|
+
end: statement.definition.range[1],
|
|
12516
|
+
doc: printCall(source, statement.definition, hidden)
|
|
12517
|
+
}] : [], {
|
|
12036
12518
|
start: end - 1,
|
|
12037
12519
|
end
|
|
12038
12520
|
}]);
|
|
12039
12521
|
const rules = /* @__PURE__ */ new Map();
|
|
12040
12522
|
const outdented = /* @__PURE__ */ new Set([end - 1]);
|
|
12041
12523
|
const joinedBefore = /* @__PURE__ */ new Set();
|
|
12524
|
+
const alternativeBreaks = /* @__PURE__ */ new Set();
|
|
12525
|
+
if (!wrapsCalls && statement.definition.type === "RailroadChoiceExpression") {
|
|
12526
|
+
alternativeBreaks.add(statement.definition.range[0]);
|
|
12527
|
+
for (let index = 1; index < statement.definition.alternatives.length; index++) {
|
|
12528
|
+
const separator = expectToken(findStructuralToken(source, statement.definition.alternatives[index - 1].range[1]), "the separator between railroad alternatives");
|
|
12529
|
+
alternativeBreaks.add(separator.range[0]);
|
|
12530
|
+
}
|
|
12531
|
+
}
|
|
12042
12532
|
const binary = /* @__PURE__ */ new Set([
|
|
12043
12533
|
"=",
|
|
12044
12534
|
"::=",
|
|
@@ -12054,7 +12544,7 @@ function layoutRule(source, statement, values, hidden, grammaticalSemicolons) {
|
|
|
12054
12544
|
const before = findTokenStartingAt(source, previous.start);
|
|
12055
12545
|
rules.set(atom.start, token?.type === "Punctuator" && binary.has(token.value) || before?.type === "Punctuator" && (binary.has(before.value) || before.value === ",") ? "space" : "none");
|
|
12056
12546
|
if (token?.type === "Punctuator" && (token.value === ")" || token.value === "]" || token.value === "}")) outdented.add(atom.start);
|
|
12057
|
-
if (findTriviaBetween(source, previous.end, atom.start).length === 0 && !hidden.some((item) => item.range[0] === atom.start || item.range[1] === previous.end)) joinedBefore.add(atom.start);
|
|
12547
|
+
if (findTriviaBetween(source, previous.end, atom.start).length === 0 && !hidden.some((item) => item.range[0] === atom.start || item.range[1] === previous.end) && !(alternativeBreaks.has(atom.start) && source.text.slice(previous.end, atom.start).includes("\n"))) joinedBefore.add(atom.start);
|
|
12058
12548
|
}
|
|
12059
12549
|
walk(statement, (node) => {
|
|
12060
12550
|
if (node.type !== "RailroadSequenceExpression") return;
|
|
@@ -12068,6 +12558,109 @@ function layoutRule(source, statement, values, hidden, grammaticalSemicolons) {
|
|
|
12068
12558
|
lineBreaks: "kept"
|
|
12069
12559
|
};
|
|
12070
12560
|
}
|
|
12561
|
+
/** IR calls expose argument structure; simple quoted leaves stay together. */
|
|
12562
|
+
function printCall(source, expression, hidden) {
|
|
12563
|
+
if (expression.type === "StringLiteral") return printAsWritten(source, ...expression.range);
|
|
12564
|
+
let arguments_, members;
|
|
12565
|
+
let valueCall = false;
|
|
12566
|
+
switch (expression.type) {
|
|
12567
|
+
case "RailroadSequenceCall":
|
|
12568
|
+
case "RailroadChoiceCall":
|
|
12569
|
+
members = expression.arguments;
|
|
12570
|
+
arguments_ = members.map((member) => member.expression);
|
|
12571
|
+
break;
|
|
12572
|
+
case "RailroadOptionalCall":
|
|
12573
|
+
case "RailroadOneOrMoreCall":
|
|
12574
|
+
case "RailroadZeroOrMoreCall":
|
|
12575
|
+
arguments_ = [expression.element];
|
|
12576
|
+
break;
|
|
12577
|
+
case "RailroadTerminalCall":
|
|
12578
|
+
arguments_ = [expression.value];
|
|
12579
|
+
valueCall = true;
|
|
12580
|
+
break;
|
|
12581
|
+
case "RailroadNonterminalCall":
|
|
12582
|
+
arguments_ = [expression.name];
|
|
12583
|
+
valueCall = true;
|
|
12584
|
+
break;
|
|
12585
|
+
case "RailroadSpecialCall":
|
|
12586
|
+
arguments_ = [expression.text];
|
|
12587
|
+
valueCall = true;
|
|
12588
|
+
break;
|
|
12589
|
+
default: throw new Error(`prettier-plugin-mmd: ${expression.type} is not an IR call`);
|
|
12590
|
+
}
|
|
12591
|
+
const keyword = expectToken(findTokenStartingAt(source, expression.range[0]), "an IR constructor");
|
|
12592
|
+
const opening = expectToken(findStructuralToken(source, expression.textBeforeOpen.at(-1)?.range[1] ?? keyword.range[1]), "an IR call opening parenthesis");
|
|
12593
|
+
expectValue(opening, "(");
|
|
12594
|
+
const closing = expectToken(findTokenEndingBefore(source, expression.range[1]), "an IR call closing parenthesis");
|
|
12595
|
+
expectValue(closing, ")");
|
|
12596
|
+
const gapOptions = { opaqueNodes: hidden };
|
|
12597
|
+
const constructorGap = readGap(source, keyword.range[1], opening.range[0], true, gapOptions);
|
|
12598
|
+
const firstGap = readGap(source, opening.range[1], arguments_[0].range[0], true, gapOptions);
|
|
12599
|
+
const closingGap = readGap(source, arguments_.at(-1).range[1], closing.range[0], true, gapOptions);
|
|
12600
|
+
const breaksArguments = !valueCall || hasCallTrivia(constructorGap) || hasCallTrivia(firstGap) || hasCallTrivia(closingGap);
|
|
12601
|
+
const contents = [];
|
|
12602
|
+
let previousEnd = opening.range[1];
|
|
12603
|
+
for (const [index, argument] of arguments_.entries()) {
|
|
12604
|
+
if (index > 0) {
|
|
12605
|
+
const comma = expectToken(findStructuralToken(source, members?.[index - 1].range[1] ?? previousEnd), "an IR argument comma");
|
|
12606
|
+
expectValue(comma, ",");
|
|
12607
|
+
contents.push(printCallGap(readGap(source, previousEnd, comma.range[0], true, gapOptions), "", "comma"), ",");
|
|
12608
|
+
previousEnd = comma.range[1];
|
|
12609
|
+
}
|
|
12610
|
+
contents.push(printCallGap(index === 0 ? firstGap : readGap(source, previousEnd, argument.range[0], true, gapOptions), breaksArguments ? index === 0 ? softline : line : "", "leading"), printCall(source, argument, hidden));
|
|
12611
|
+
previousEnd = argument.range[1];
|
|
12612
|
+
}
|
|
12613
|
+
const call = [
|
|
12614
|
+
printCallGap(constructorGap, "", "constructor"),
|
|
12615
|
+
"(",
|
|
12616
|
+
indent(contents),
|
|
12617
|
+
printCallGap(closingGap, breaksArguments ? softline : "", "closing"),
|
|
12618
|
+
")"
|
|
12619
|
+
];
|
|
12620
|
+
return group([printAsWritten(source, ...keyword.range), constructorGap.breaksLine && hasCallTrivia(constructorGap) ? indent(call) : call], { shouldBreak: breaksArguments });
|
|
12621
|
+
}
|
|
12622
|
+
/**
|
|
12623
|
+
* IR call padding is ordinary whitespace, so trivia uses readable outside
|
|
12624
|
+
* spacing at each syntactic boundary (diagrams/railroad.md, IR grammar;
|
|
12625
|
+
* docs/railroad.md, Comments and Global directives).
|
|
12626
|
+
*/
|
|
12627
|
+
function printCallGap(gap, ordinary, placement) {
|
|
12628
|
+
if (!hasCallTrivia(gap)) return ordinary;
|
|
12629
|
+
if (!gap.breaksLine) {
|
|
12630
|
+
const run = gap.leading ?? gap.trailing;
|
|
12631
|
+
if (placement === "leading") return [
|
|
12632
|
+
ordinary,
|
|
12633
|
+
run.doc,
|
|
12634
|
+
" "
|
|
12635
|
+
];
|
|
12636
|
+
return [
|
|
12637
|
+
" ",
|
|
12638
|
+
run.doc,
|
|
12639
|
+
placement === "closing" ? ifBreak(ordinary, "") : placement === "constructor" ? " " : ""
|
|
12640
|
+
];
|
|
12641
|
+
}
|
|
12642
|
+
const trivia = gap.trailing === null ? [] : [" ", gap.trailing.doc];
|
|
12643
|
+
let previous = gap.trailing;
|
|
12644
|
+
for (const item of gap.lines) {
|
|
12645
|
+
trivia.push(triviaBreak(previous, item.blankBefore), item.run.doc);
|
|
12646
|
+
previous = item.run;
|
|
12647
|
+
}
|
|
12648
|
+
if (gap.leading !== null) {
|
|
12649
|
+
trivia.push(triviaBreak(previous, gap.blankAfter), gap.leading.doc);
|
|
12650
|
+
previous = gap.leading;
|
|
12651
|
+
}
|
|
12652
|
+
const after = gap.leading !== null ? placement === "leading" || placement === "constructor" ? " " : "" : triviaBreak(previous, gap.leading === null && gap.blankAfter);
|
|
12653
|
+
return placement === "closing" ? [indent(trivia), after] : [trivia, after];
|
|
12654
|
+
}
|
|
12655
|
+
/** Whitespace-only gaps collapse to their ordinary call separator. */
|
|
12656
|
+
function hasCallTrivia(gap) {
|
|
12657
|
+
return gap.trailing !== null || gap.lines.length > 0 || gap.leading !== null;
|
|
12658
|
+
}
|
|
12659
|
+
/** A literal break keeps comment tails while adopting this call's indentation. */
|
|
12660
|
+
function triviaBreak(previous, blank = false) {
|
|
12661
|
+
const boundary = previous?.endsWithWhitespace === true ? markAsRoot(literalline) : hardline;
|
|
12662
|
+
return blank ? [boundary, hardline] : boundary;
|
|
12663
|
+
}
|
|
12071
12664
|
//#endregion
|
|
12072
12665
|
//#region src/printers/railroad.ts
|
|
12073
12666
|
/** The four dialects share one flat body and its hidden-form boundaries. */
|