forked from OKEAMAH/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequence.js
More file actions
50 lines (45 loc) · 1.31 KB
/
sequence.js
File metadata and controls
50 lines (45 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { hardline, line } from "../../document/builders.js";
import isFrontMatter from "../../utils/front-matter/is-front-matter.js";
import hasNewline from "../../utils/has-newline.js";
import isNextLineEmpty from "../../utils/is-next-line-empty.js";
import { locEnd, locStart } from "../loc.js";
function printSequence(path, options, print) {
const parts = [];
path.each(() => {
const { node, previous } = path;
if (
previous?.type === "css-comment" &&
previous.text.trim() === "prettier-ignore"
) {
parts.push(options.originalText.slice(locStart(node), locEnd(node)));
} else {
parts.push(print());
}
if (path.isLast) {
return;
}
const { next } = path;
if (
(next.type === "css-comment" &&
!hasNewline(options.originalText, locStart(next), {
backwards: true,
}) &&
!isFrontMatter(node)) ||
(next.type === "css-atrule" &&
next.name === "else" &&
node.type !== "css-comment")
) {
parts.push(" ");
} else {
parts.push(options.__isHTMLStyleAttribute ? line : hardline);
if (
isNextLineEmpty(options.originalText, locEnd(node)) &&
!isFrontMatter(node)
) {
parts.push(hardline);
}
}
}, "nodes");
return parts;
}
export default printSequence;