forked from jhipster/prettier-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexical-structure.ts
More file actions
55 lines (48 loc) · 1.6 KB
/
Copy pathlexical-structure.ts
File metadata and controls
55 lines (48 loc) · 1.6 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
51
52
53
54
55
import { builders } from "prettier/doc";
import { SyntaxType } from "../node-types.ts";
import {
printTextBlock,
printValue,
textBlockContents,
type NamedNodePrinters
} from "./helpers.ts";
const { group, hardline, indent, join, softline } = builders;
export default {
string_literal(path, print) {
const hasInterpolations = path.node.namedChildren.some(
({ type }) => type === SyntaxType.StringInterpolation
);
if (hasInterpolations || path.node.children[0].value === '"') {
return path.map(print, "children");
}
return printTextBlock(
path,
join(hardline, textBlockContents(path.node).split("\n"))
);
},
string_fragment: printValue,
multiline_string_fragment: printValue,
string_interpolation(path, print) {
const expressionType = path.node.namedChildren[0].type;
const expression = path.call(print, "namedChildren", 0);
return expressionType === SyntaxType.BinaryExpression ||
expressionType === SyntaxType.TernaryExpression
? group(["\\{", indent([softline, expression]), softline, "}"])
: ["\\{", expression, "}"];
},
escape_sequence: printValue,
character_literal: printValue,
binary_integer_literal: printValue,
decimal_integer_literal: printValue,
hex_integer_literal: printValue,
octal_integer_literal: printValue,
decimal_floating_point_literal: printValue,
hex_floating_point_literal: printValue,
null_literal: printValue,
true: printValue,
false: printValue,
this: printValue,
super: printValue,
underscore_pattern: printValue,
asterisk: printValue
} satisfies Partial<NamedNodePrinters>;