prettier-plugin-java 2.6.2 → 2.6.3
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/package.json +3 -8
- package/dist/base-cst-printer.js +0 -55
- package/dist/cst-printer.js +0 -29
- package/dist/index.js +0 -66
- package/dist/options.js +0 -256
- package/dist/parser.js +0 -4
- package/dist/printer.js +0 -6
- package/dist/printers/arrays.js +0 -25
- package/dist/printers/blocks-and-statements.js +0 -432
- package/dist/printers/classes.js +0 -709
- package/dist/printers/comments/comments-utils.js +0 -21
- package/dist/printers/comments/format-comments.js +0 -171
- package/dist/printers/comments/handle-comments.js +0 -102
- package/dist/printers/expressions.js +0 -590
- package/dist/printers/interfaces.js +0 -222
- package/dist/printers/lexical-structure.js +0 -31
- package/dist/printers/names.js +0 -29
- package/dist/printers/packages-and-modules.js +0 -171
- package/dist/printers/prettier-builder.js +0 -45
- package/dist/printers/printer-utils.js +0 -596
- package/dist/printers/types-values-and-variables.js +0 -153
- package/dist/types/utils.js +0 -20
- package/dist/utils/index.js +0 -2
- package/dist/utils/isEmptyDoc.js +0 -4
- package/dist/utils/printArgumentListWithBraces.js +0 -37
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { concat, group, indent } from "./prettier-builder.js";
|
|
2
|
-
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
3
|
-
import { handleCommentsParameters } from "./comments/handle-comments.js";
|
|
4
|
-
import { displaySemicolon, getInterfaceBodyDeclarationsSeparator, isStatementEmptyStatement, printArrayList, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortModifiers } from "./printer-utils.js";
|
|
5
|
-
import { builders } from "prettier/doc";
|
|
6
|
-
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
7
|
-
const { line, softline, hardline } = builders;
|
|
8
|
-
export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter {
|
|
9
|
-
interfaceDeclaration(ctx) {
|
|
10
|
-
const modifiers = sortModifiers(ctx.interfaceModifier);
|
|
11
|
-
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
12
|
-
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
13
|
-
const declaration = ctx.normalInterfaceDeclaration
|
|
14
|
-
? this.visit(ctx.normalInterfaceDeclaration)
|
|
15
|
-
: this.visit(ctx.annotationInterfaceDeclaration);
|
|
16
|
-
return rejectAndJoin(hardline, [
|
|
17
|
-
rejectAndJoin(hardline, firstAnnotations),
|
|
18
|
-
rejectAndJoin(" ", [rejectAndJoin(" ", otherModifiers), declaration])
|
|
19
|
-
]);
|
|
20
|
-
}
|
|
21
|
-
normalInterfaceDeclaration(ctx) {
|
|
22
|
-
const typeIdentifier = this.visit(ctx.typeIdentifier);
|
|
23
|
-
const typeParameters = this.visit(ctx.typeParameters);
|
|
24
|
-
const interfaceExtends = this.visit(ctx.interfaceExtends);
|
|
25
|
-
const optionalInterfacePermits = this.visit(ctx.interfacePermits);
|
|
26
|
-
const interfaceBody = this.visit(ctx.interfaceBody);
|
|
27
|
-
let interfaceExtendsPart = "";
|
|
28
|
-
if (interfaceExtends) {
|
|
29
|
-
interfaceExtendsPart = indent(rejectAndConcat([softline, interfaceExtends]));
|
|
30
|
-
}
|
|
31
|
-
let interfacePermits = "";
|
|
32
|
-
if (optionalInterfacePermits) {
|
|
33
|
-
interfacePermits = indent(rejectAndConcat([softline, optionalInterfacePermits]));
|
|
34
|
-
}
|
|
35
|
-
return rejectAndJoin(" ", [
|
|
36
|
-
group(rejectAndJoin(" ", [
|
|
37
|
-
ctx.Interface[0],
|
|
38
|
-
concat([typeIdentifier, typeParameters]),
|
|
39
|
-
interfaceExtendsPart,
|
|
40
|
-
interfacePermits
|
|
41
|
-
])),
|
|
42
|
-
interfaceBody
|
|
43
|
-
]);
|
|
44
|
-
}
|
|
45
|
-
interfaceModifier(ctx) {
|
|
46
|
-
if (ctx.annotation) {
|
|
47
|
-
return this.visitSingle(ctx);
|
|
48
|
-
}
|
|
49
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
50
|
-
}
|
|
51
|
-
interfaceExtends(ctx) {
|
|
52
|
-
const interfaceTypeList = this.visit(ctx.interfaceTypeList);
|
|
53
|
-
return group(rejectAndConcat([
|
|
54
|
-
ctx.Extends[0],
|
|
55
|
-
indent(rejectAndConcat([line, interfaceTypeList]))
|
|
56
|
-
]));
|
|
57
|
-
}
|
|
58
|
-
interfacePermits(ctx) {
|
|
59
|
-
return this.classPermits(ctx);
|
|
60
|
-
}
|
|
61
|
-
interfaceBody(ctx) {
|
|
62
|
-
let joinedInterfaceMemberDeclaration = "";
|
|
63
|
-
if (ctx.interfaceMemberDeclaration !== undefined) {
|
|
64
|
-
const interfaceMemberDeclaration = this.mapVisit(ctx.interfaceMemberDeclaration);
|
|
65
|
-
const separators = getInterfaceBodyDeclarationsSeparator(ctx.interfaceMemberDeclaration);
|
|
66
|
-
joinedInterfaceMemberDeclaration = rejectAndJoinSeps(separators, interfaceMemberDeclaration);
|
|
67
|
-
}
|
|
68
|
-
return putIntoBraces(joinedInterfaceMemberDeclaration, hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
|
69
|
-
}
|
|
70
|
-
interfaceMemberDeclaration(ctx) {
|
|
71
|
-
if (ctx.Semicolon) {
|
|
72
|
-
return displaySemicolon(ctx.Semicolon[0]);
|
|
73
|
-
}
|
|
74
|
-
return this.visitSingle(ctx);
|
|
75
|
-
}
|
|
76
|
-
constantDeclaration(ctx) {
|
|
77
|
-
const modifiers = sortModifiers(ctx.constantModifier);
|
|
78
|
-
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
79
|
-
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
80
|
-
const unannType = this.visit(ctx.unannType);
|
|
81
|
-
const variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
|
|
82
|
-
return rejectAndJoin(hardline, [
|
|
83
|
-
rejectAndJoin(hardline, firstAnnotations),
|
|
84
|
-
rejectAndJoin(" ", [
|
|
85
|
-
rejectAndJoin(" ", otherModifiers),
|
|
86
|
-
unannType,
|
|
87
|
-
rejectAndConcat([variableDeclaratorList, ctx.Semicolon[0]])
|
|
88
|
-
])
|
|
89
|
-
]);
|
|
90
|
-
}
|
|
91
|
-
constantModifier(ctx) {
|
|
92
|
-
if (ctx.annotation) {
|
|
93
|
-
return this.visitSingle(ctx);
|
|
94
|
-
}
|
|
95
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
96
|
-
}
|
|
97
|
-
interfaceMethodDeclaration(ctx) {
|
|
98
|
-
const modifiers = sortModifiers(ctx.interfaceMethodModifier);
|
|
99
|
-
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
100
|
-
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
101
|
-
const methodHeader = this.visit(ctx.methodHeader);
|
|
102
|
-
const methodBody = this.visit(ctx.methodBody);
|
|
103
|
-
const separator = isStatementEmptyStatement(methodBody) ? "" : " ";
|
|
104
|
-
return rejectAndJoin(hardline, [
|
|
105
|
-
rejectAndJoin(hardline, firstAnnotations),
|
|
106
|
-
rejectAndJoin(" ", [
|
|
107
|
-
rejectAndJoin(" ", otherModifiers),
|
|
108
|
-
rejectAndJoin(separator, [methodHeader, methodBody])
|
|
109
|
-
])
|
|
110
|
-
]);
|
|
111
|
-
}
|
|
112
|
-
interfaceMethodModifier(ctx) {
|
|
113
|
-
if (ctx.annotation) {
|
|
114
|
-
return this.visitSingle(ctx);
|
|
115
|
-
}
|
|
116
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
117
|
-
}
|
|
118
|
-
annotationInterfaceDeclaration(ctx) {
|
|
119
|
-
const typeIdentifier = this.visit(ctx.typeIdentifier);
|
|
120
|
-
const annotationInterfaceBody = this.visit(ctx.annotationInterfaceBody);
|
|
121
|
-
return rejectAndJoin(" ", [
|
|
122
|
-
concat([ctx.At[0], ctx.Interface[0]]),
|
|
123
|
-
typeIdentifier,
|
|
124
|
-
annotationInterfaceBody
|
|
125
|
-
]);
|
|
126
|
-
}
|
|
127
|
-
annotationInterfaceBody(ctx) {
|
|
128
|
-
const annotationInterfaceMemberDeclaration = this.mapVisit(ctx.annotationInterfaceMemberDeclaration);
|
|
129
|
-
return rejectAndJoin(line, [
|
|
130
|
-
indent(rejectAndJoin(line, [
|
|
131
|
-
ctx.LCurly[0],
|
|
132
|
-
rejectAndJoin(concat([line, line]), annotationInterfaceMemberDeclaration)
|
|
133
|
-
])),
|
|
134
|
-
ctx.RCurly[0]
|
|
135
|
-
]);
|
|
136
|
-
}
|
|
137
|
-
annotationInterfaceMemberDeclaration(ctx) {
|
|
138
|
-
if (ctx.Semicolon) {
|
|
139
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
140
|
-
}
|
|
141
|
-
return this.visitSingle(ctx);
|
|
142
|
-
}
|
|
143
|
-
annotationInterfaceElementDeclaration(ctx) {
|
|
144
|
-
const modifiers = sortModifiers(ctx.annotationInterfaceElementModifier);
|
|
145
|
-
const firstAnnotations = this.mapVisit(modifiers[0]);
|
|
146
|
-
const otherModifiers = this.mapVisit(modifiers[1]);
|
|
147
|
-
const unannType = this.visit(ctx.unannType);
|
|
148
|
-
const identifier = ctx.Identifier[0];
|
|
149
|
-
const dims = this.visit(ctx.dims);
|
|
150
|
-
const defaultValue = ctx.defaultValue
|
|
151
|
-
? concat([" ", this.visit(ctx.defaultValue)])
|
|
152
|
-
: "";
|
|
153
|
-
return rejectAndJoin(hardline, [
|
|
154
|
-
rejectAndJoin(hardline, firstAnnotations),
|
|
155
|
-
rejectAndJoin(" ", [
|
|
156
|
-
rejectAndJoin(" ", otherModifiers),
|
|
157
|
-
unannType,
|
|
158
|
-
rejectAndConcat([
|
|
159
|
-
identifier,
|
|
160
|
-
concat([ctx.LBrace[0], ctx.RBrace[0]]),
|
|
161
|
-
dims,
|
|
162
|
-
defaultValue,
|
|
163
|
-
ctx.Semicolon[0]
|
|
164
|
-
])
|
|
165
|
-
])
|
|
166
|
-
]);
|
|
167
|
-
}
|
|
168
|
-
annotationInterfaceElementModifier(ctx) {
|
|
169
|
-
if (ctx.annotation) {
|
|
170
|
-
return this.visitSingle(ctx);
|
|
171
|
-
}
|
|
172
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
173
|
-
}
|
|
174
|
-
defaultValue(ctx) {
|
|
175
|
-
const elementValue = this.visit(ctx.elementValue);
|
|
176
|
-
return rejectAndJoin(" ", [ctx.Default[0], elementValue]);
|
|
177
|
-
}
|
|
178
|
-
annotation(ctx) {
|
|
179
|
-
var _a, _b, _c;
|
|
180
|
-
const fqn = this.visit(ctx.typeName);
|
|
181
|
-
let annoArgs = "";
|
|
182
|
-
if (ctx.LBrace) {
|
|
183
|
-
const elementValues = (_c = (_b = (_a = ctx.elementValuePairList) === null || _a === void 0 ? void 0 : _a[0].children.elementValuePair) !== null && _b !== void 0 ? _b : ctx.elementValue) !== null && _c !== void 0 ? _c : [];
|
|
184
|
-
handleCommentsParameters(ctx.LBrace[0], elementValues, ctx.RBrace[0]);
|
|
185
|
-
if (ctx.elementValuePairList) {
|
|
186
|
-
annoArgs = putIntoBraces(this.visit(ctx.elementValuePairList), softline, ctx.LBrace[0], ctx.RBrace[0]);
|
|
187
|
-
}
|
|
188
|
-
else if (ctx.elementValue) {
|
|
189
|
-
annoArgs = putIntoBraces(this.visit(ctx.elementValue), softline, ctx.LBrace[0], ctx.RBrace[0]);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return group(rejectAndConcat([ctx.At[0], fqn, annoArgs]));
|
|
193
|
-
}
|
|
194
|
-
elementValuePairList(ctx) {
|
|
195
|
-
const elementValuePairs = this.mapVisit(ctx.elementValuePair);
|
|
196
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
197
|
-
return rejectAndJoinSeps(commas, elementValuePairs);
|
|
198
|
-
}
|
|
199
|
-
elementValuePair(ctx) {
|
|
200
|
-
const identifier = ctx.Identifier[0];
|
|
201
|
-
const elementValue = this.visit(ctx.elementValue);
|
|
202
|
-
return rejectAndJoin(" ", [identifier, ctx.Equals[0], elementValue]);
|
|
203
|
-
}
|
|
204
|
-
elementValue(ctx) {
|
|
205
|
-
return this.visitSingle(ctx);
|
|
206
|
-
}
|
|
207
|
-
elementValueArrayInitializer(ctx) {
|
|
208
|
-
const elementValueList = this.visit(ctx.elementValueList);
|
|
209
|
-
return printArrayList({
|
|
210
|
-
list: elementValueList,
|
|
211
|
-
extraComma: ctx.Comma,
|
|
212
|
-
LCurly: ctx.LCurly[0],
|
|
213
|
-
RCurly: ctx.RCurly[0],
|
|
214
|
-
trailingComma: this.prettierOptions.trailingComma
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
elementValueList(ctx) {
|
|
218
|
-
const elementValues = this.mapVisit(ctx.elementValue);
|
|
219
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
220
|
-
return group(rejectAndConcat([rejectAndJoinSeps(commas, elementValues)]));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
2
|
-
import { join } from "./prettier-builder.js";
|
|
3
|
-
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
4
|
-
import { builders } from "prettier/doc";
|
|
5
|
-
const { hardline } = builders;
|
|
6
|
-
export class LexicalStructurePrettierVisitor extends BaseCstPrettierPrinter {
|
|
7
|
-
literal(ctx) {
|
|
8
|
-
if (ctx.TextBlock) {
|
|
9
|
-
const lines = ctx.TextBlock[0].image.split("\n");
|
|
10
|
-
const open = lines.shift();
|
|
11
|
-
const baseIndent = Math.min(...lines.map(line => line.search(/\S/)).filter(indent => indent >= 0));
|
|
12
|
-
return join(hardline, [
|
|
13
|
-
open,
|
|
14
|
-
...lines.map(line => line.slice(baseIndent))
|
|
15
|
-
]);
|
|
16
|
-
}
|
|
17
|
-
if (ctx.CharLiteral || ctx.StringLiteral || ctx.Null) {
|
|
18
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
19
|
-
}
|
|
20
|
-
return this.visitSingle(ctx);
|
|
21
|
-
}
|
|
22
|
-
integerLiteral(ctx) {
|
|
23
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
24
|
-
}
|
|
25
|
-
floatingPointLiteral(ctx) {
|
|
26
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
27
|
-
}
|
|
28
|
-
booleanLiteral(ctx) {
|
|
29
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
30
|
-
}
|
|
31
|
-
}
|
package/dist/printers/names.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { buildFqn } from "./printer-utils.js";
|
|
2
|
-
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
3
|
-
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
4
|
-
export class NamesPrettierVisitor extends BaseCstPrettierPrinter {
|
|
5
|
-
typeIdentifier(ctx) {
|
|
6
|
-
return printTokenWithComments(ctx.Identifier[0]);
|
|
7
|
-
}
|
|
8
|
-
moduleName(ctx) {
|
|
9
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
10
|
-
}
|
|
11
|
-
packageName(ctx) {
|
|
12
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
13
|
-
}
|
|
14
|
-
typeName(ctx) {
|
|
15
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
16
|
-
}
|
|
17
|
-
expressionName(ctx) {
|
|
18
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
19
|
-
}
|
|
20
|
-
methodName(ctx) {
|
|
21
|
-
return printTokenWithComments(ctx.Identifier[0]);
|
|
22
|
-
}
|
|
23
|
-
packageOrTypeName(ctx) {
|
|
24
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
25
|
-
}
|
|
26
|
-
ambiguousName(ctx) {
|
|
27
|
-
return buildFqn(ctx.Identifier, ctx.Dot);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { concat, join } from "./prettier-builder.js";
|
|
2
|
-
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
3
|
-
import { buildFqn, displaySemicolon, getBlankLinesSeparator, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortImports } from "./printer-utils.js";
|
|
4
|
-
import { builders } from "prettier/doc";
|
|
5
|
-
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
6
|
-
import { isOrdinaryCompilationUnitCtx } from "../types/utils.js";
|
|
7
|
-
const { line, hardline, indent, group } = builders;
|
|
8
|
-
export class PackagesAndModulesPrettierVisitor extends BaseCstPrettierPrinter {
|
|
9
|
-
compilationUnit(ctx) {
|
|
10
|
-
const compilationUnit = isOrdinaryCompilationUnitCtx(ctx)
|
|
11
|
-
? ctx.ordinaryCompilationUnit
|
|
12
|
-
: ctx.modularCompilationUnit;
|
|
13
|
-
return concat([this.visit(compilationUnit[0]), line]);
|
|
14
|
-
}
|
|
15
|
-
ordinaryCompilationUnit(ctx) {
|
|
16
|
-
const packageDecl = this.visit(ctx.packageDeclaration);
|
|
17
|
-
const sortedImportsDecl = sortImports(ctx.importDeclaration);
|
|
18
|
-
const nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
|
|
19
|
-
const staticImports = this.mapVisit(sortedImportsDecl.staticImports);
|
|
20
|
-
const typesDecl = this.mapVisit(ctx.typeDeclaration);
|
|
21
|
-
// TODO: utility to add item+line (or multiple lines) but only if an item exists
|
|
22
|
-
return rejectAndConcat([
|
|
23
|
-
rejectAndJoin(concat([hardline, hardline]), [
|
|
24
|
-
packageDecl,
|
|
25
|
-
rejectAndJoin(hardline, staticImports),
|
|
26
|
-
rejectAndJoin(hardline, nonStaticImports),
|
|
27
|
-
rejectAndJoin(concat([hardline, hardline]), typesDecl)
|
|
28
|
-
])
|
|
29
|
-
]);
|
|
30
|
-
}
|
|
31
|
-
modularCompilationUnit(ctx) {
|
|
32
|
-
const sortedImportsDecl = sortImports(ctx.importDeclaration);
|
|
33
|
-
const nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
|
|
34
|
-
const staticImports = this.mapVisit(sortedImportsDecl.staticImports);
|
|
35
|
-
const moduleDeclaration = this.visit(ctx.moduleDeclaration);
|
|
36
|
-
return rejectAndConcat([
|
|
37
|
-
rejectAndJoin(concat([hardline, hardline]), [
|
|
38
|
-
rejectAndJoin(hardline, staticImports),
|
|
39
|
-
rejectAndJoin(hardline, nonStaticImports),
|
|
40
|
-
moduleDeclaration
|
|
41
|
-
])
|
|
42
|
-
]);
|
|
43
|
-
}
|
|
44
|
-
packageDeclaration(ctx) {
|
|
45
|
-
const modifiers = this.mapVisit(ctx.packageModifier);
|
|
46
|
-
const name = buildFqn(ctx.Identifier, ctx.Dot);
|
|
47
|
-
return rejectAndJoin(hardline, [
|
|
48
|
-
rejectAndJoin(hardline, modifiers),
|
|
49
|
-
concat([ctx.Package[0], " ", name, ctx.Semicolon[0]])
|
|
50
|
-
]);
|
|
51
|
-
}
|
|
52
|
-
packageModifier(ctx) {
|
|
53
|
-
return this.visitSingle(ctx);
|
|
54
|
-
}
|
|
55
|
-
importDeclaration(ctx) {
|
|
56
|
-
if (ctx.emptyStatement !== undefined) {
|
|
57
|
-
return this.visit(ctx.emptyStatement);
|
|
58
|
-
}
|
|
59
|
-
const optionalStatic = ctx.Static ? ctx.Static[0] : "";
|
|
60
|
-
const packageOrTypeName = this.visit(ctx.packageOrTypeName);
|
|
61
|
-
const optionalDotStar = ctx.Dot ? concat([ctx.Dot[0], ctx.Star[0]]) : "";
|
|
62
|
-
return rejectAndJoin(" ", [
|
|
63
|
-
ctx.Import[0],
|
|
64
|
-
optionalStatic,
|
|
65
|
-
rejectAndConcat([packageOrTypeName, optionalDotStar, ctx.Semicolon[0]])
|
|
66
|
-
]);
|
|
67
|
-
}
|
|
68
|
-
typeDeclaration(ctx) {
|
|
69
|
-
if (ctx.Semicolon) {
|
|
70
|
-
return displaySemicolon(ctx.Semicolon[0]);
|
|
71
|
-
}
|
|
72
|
-
return this.visitSingle(ctx);
|
|
73
|
-
}
|
|
74
|
-
moduleDeclaration(ctx) {
|
|
75
|
-
const annotations = this.mapVisit(ctx.annotation);
|
|
76
|
-
const optionalOpen = ctx.Open ? ctx.Open[0] : "";
|
|
77
|
-
const name = buildFqn(ctx.Identifier, ctx.Dot);
|
|
78
|
-
const moduleDirectives = this.mapVisit(ctx.moduleDirective);
|
|
79
|
-
const content = rejectAndJoinSeps(getBlankLinesSeparator(ctx.moduleDirective), moduleDirectives);
|
|
80
|
-
return rejectAndJoin(" ", [
|
|
81
|
-
join(" ", annotations),
|
|
82
|
-
optionalOpen,
|
|
83
|
-
ctx.Module[0],
|
|
84
|
-
name,
|
|
85
|
-
putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0])
|
|
86
|
-
]);
|
|
87
|
-
}
|
|
88
|
-
moduleDirective(ctx) {
|
|
89
|
-
return this.visitSingle(ctx);
|
|
90
|
-
}
|
|
91
|
-
requiresModuleDirective(ctx) {
|
|
92
|
-
const modifiers = this.mapVisit(ctx.requiresModifier);
|
|
93
|
-
const moduleName = this.visit(ctx.moduleName);
|
|
94
|
-
return rejectAndJoin(" ", [
|
|
95
|
-
ctx.Requires[0],
|
|
96
|
-
join(" ", modifiers),
|
|
97
|
-
concat([moduleName, ctx.Semicolon[0]])
|
|
98
|
-
]);
|
|
99
|
-
}
|
|
100
|
-
exportsModuleDirective(ctx) {
|
|
101
|
-
const packageName = this.visit(ctx.packageName);
|
|
102
|
-
const moduleNames = this.mapVisit(ctx.moduleName);
|
|
103
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
104
|
-
if (ctx.To) {
|
|
105
|
-
return group(rejectAndConcat([
|
|
106
|
-
indent(rejectAndJoin(line, [
|
|
107
|
-
rejectAndJoin(" ", [ctx.Exports[0], packageName]),
|
|
108
|
-
group(indent(rejectAndJoin(line, [
|
|
109
|
-
ctx.To[0],
|
|
110
|
-
rejectAndJoinSeps(commas, moduleNames)
|
|
111
|
-
])))
|
|
112
|
-
])),
|
|
113
|
-
ctx.Semicolon[0]
|
|
114
|
-
]));
|
|
115
|
-
}
|
|
116
|
-
return rejectAndConcat([
|
|
117
|
-
concat([ctx.Exports[0], " "]),
|
|
118
|
-
packageName,
|
|
119
|
-
ctx.Semicolon[0]
|
|
120
|
-
]);
|
|
121
|
-
}
|
|
122
|
-
opensModuleDirective(ctx) {
|
|
123
|
-
const packageName = this.visit(ctx.packageName);
|
|
124
|
-
const to = ctx.To ? ctx.To[0] : "";
|
|
125
|
-
const moduleNames = this.mapVisit(ctx.moduleName);
|
|
126
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
127
|
-
if (ctx.To) {
|
|
128
|
-
return group(rejectAndConcat([
|
|
129
|
-
indent(rejectAndJoin(line, [
|
|
130
|
-
rejectAndJoin(" ", [ctx.Opens[0], packageName]),
|
|
131
|
-
group(indent(rejectAndJoin(line, [
|
|
132
|
-
ctx.To[0],
|
|
133
|
-
rejectAndJoinSeps(commas, moduleNames)
|
|
134
|
-
])))
|
|
135
|
-
])),
|
|
136
|
-
ctx.Semicolon[0]
|
|
137
|
-
]));
|
|
138
|
-
}
|
|
139
|
-
return rejectAndConcat([
|
|
140
|
-
concat([ctx.Opens[0], " "]),
|
|
141
|
-
packageName,
|
|
142
|
-
ctx.Semicolon[0]
|
|
143
|
-
]);
|
|
144
|
-
}
|
|
145
|
-
usesModuleDirective(ctx) {
|
|
146
|
-
const typeName = this.visit(ctx.typeName);
|
|
147
|
-
return rejectAndConcat([
|
|
148
|
-
concat([ctx.Uses[0], " "]),
|
|
149
|
-
typeName,
|
|
150
|
-
ctx.Semicolon[0]
|
|
151
|
-
]);
|
|
152
|
-
}
|
|
153
|
-
providesModuleDirective(ctx) {
|
|
154
|
-
const firstTypeName = this.visit(ctx.typeName[0]);
|
|
155
|
-
const otherTypeNames = this.mapVisit(ctx.typeName.slice(1));
|
|
156
|
-
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
|
|
157
|
-
return group(rejectAndConcat([
|
|
158
|
-
indent(rejectAndJoin(line, [
|
|
159
|
-
rejectAndJoin(" ", [ctx.Provides[0], firstTypeName]),
|
|
160
|
-
group(indent(rejectAndJoin(line, [
|
|
161
|
-
ctx.With[0],
|
|
162
|
-
rejectAndJoinSeps(commas, otherTypeNames)
|
|
163
|
-
])))
|
|
164
|
-
])),
|
|
165
|
-
ctx.Semicolon[0]
|
|
166
|
-
]));
|
|
167
|
-
}
|
|
168
|
-
requiresModifier(ctx) {
|
|
169
|
-
return printTokenWithComments(this.getSingle(ctx));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { builders } from "prettier/doc";
|
|
2
|
-
import * as formatComments from "./comments/format-comments.js";
|
|
3
|
-
const processComments = formatComments.processComments;
|
|
4
|
-
/*
|
|
5
|
-
* ------------------------------------------------------------------
|
|
6
|
-
* Wraps the Prettier builder functions to print tokens with comments
|
|
7
|
-
* ------------------------------------------------------------------
|
|
8
|
-
*/
|
|
9
|
-
export function concat(docs) {
|
|
10
|
-
const concatenation = processComments(docs);
|
|
11
|
-
if (!Array.isArray(docs)) {
|
|
12
|
-
return "";
|
|
13
|
-
}
|
|
14
|
-
return concatenation;
|
|
15
|
-
}
|
|
16
|
-
export function join(sep, docs) {
|
|
17
|
-
return builders.join(processComments(sep), processComments(docs));
|
|
18
|
-
}
|
|
19
|
-
export function group(docs, opts) {
|
|
20
|
-
const group = builders.group(processComments(docs), opts);
|
|
21
|
-
return group.contents === undefined ? "" : group;
|
|
22
|
-
}
|
|
23
|
-
export function fill(docs) {
|
|
24
|
-
return builders.fill(processComments(docs));
|
|
25
|
-
}
|
|
26
|
-
export function indent(doc) {
|
|
27
|
-
const processedDoc = processComments(doc);
|
|
28
|
-
if (processedDoc.length === 0) {
|
|
29
|
-
return "";
|
|
30
|
-
}
|
|
31
|
-
return builders.indent(processedDoc);
|
|
32
|
-
}
|
|
33
|
-
export function dedent(doc) {
|
|
34
|
-
const processedDoc = processComments(doc);
|
|
35
|
-
if (processedDoc.length === 0) {
|
|
36
|
-
return "";
|
|
37
|
-
}
|
|
38
|
-
return builders.dedent(processComments(doc));
|
|
39
|
-
}
|
|
40
|
-
export function ifBreak(breakContents, flatContents) {
|
|
41
|
-
return builders.ifBreak(processComments(breakContents), processComments(flatContents));
|
|
42
|
-
}
|
|
43
|
-
export function indentIfBreak(contents, opts) {
|
|
44
|
-
return builders.indentIfBreak(processComments(contents), opts);
|
|
45
|
-
}
|