Skip to content

Commit f1ff76f

Browse files
committed
fix: some comments
1 parent 5ba2da9 commit f1ff76f

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

src/main.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import typeHandlers from "./handlers/types.ts";
2121
import validateExpressionHandlers from "./handlers/validateExpressions.ts";
2222
import type { Handler } from "./handlers/util/Handler.ts";
2323

24-
const { line, group } = prettier.doc.builders;
24+
const { line, group, hardline, join, fill } = prettier.doc.builders;
2525
const { getPreferredQuote } = prettier.util;
2626

2727
// Handlers are split up based on their placement in the XQuery specification. FLWOR by FLWOR,
@@ -135,7 +135,19 @@ const xqueryPrinter: Printer<Node> = {
135135
},
136136
printComment(path: AstPath<Node>) {
137137
const value = path.getNode() as CommentNode;
138-
return group(value.value);
138+
const lines = value.value.split('\n')
139+
140+
if (lines.length == 1) {
141+
return fill(lines)
142+
}
143+
144+
const [first, ...rest] = lines
145+
const trimmed = rest.map(line => {
146+
const t = line.trim()
147+
const alignment = t.startsWith(':') ? ' ' : ' '
148+
return alignment + t
149+
})
150+
return group([first, hardline, join(hardline, trimmed)]);
139151
},
140152
print(path: AstPath<Node>, options, print: Print, _args) {
141153
if (path.node instanceof LeafNode) {

test/example.spec.ts.snapshot

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ module namespace body = "http://e-editiones.org/roaster/body";
2424

2525
import module namespace errors = "http://e-editiones.org/roaster/errors";
2626

27-
declare
28-
variable $bla := "bla"; (: A variable to check if it works :)
27+
declare variable $bla := "bla"; (: A variable to check if it works :)
2928

30-
(:~
29+
(:~
3130
: Try to retrieve and convert the request body if specified
3231
:)
3332

@@ -39,11 +38,11 @@ declare function body:parse ($request as map(*)) {
3938
case "form-data" return
4039
body:parse-form-data($request?schema)
4140
(:
42-
Parse body contents to XQuery data structure for media types
43-
that were identified as being in JSON format.
44-
NOTE: The data needs to be serialized again before it can be stored.
45-
NOTE: For application/json-patch+json request:get-data returns an xs:string.
46-
:)
41+
Parse body contents to XQuery data structure for media types
42+
that were identified as being in JSON format.
43+
NOTE: The data needs to be serialized again before it can be stored.
44+
NOTE: For application/json-patch+json request:get-data returns an xs:string.
45+
:)
4746
case "json" return
4847
let $data := request:get-data()
4948
return typeswitch ($data)
@@ -53,10 +52,10 @@ declare function body:parse ($request as map(*)) {
5352
default return
5453
util:binary-to-string($data) => parse-json()
5554
(:
56-
Workaround for eXist-DB specific behaviour,
57-
this way we will get parse errors as early as possible
58-
while still having access to the data afterwards.
59-
:)
55+
Workaround for eXist-DB specific behaviour,
56+
this way we will get parse errors as early as possible
57+
while still having access to the data afterwards.
58+
:)
6059
case "xml" return
6160
let $data := request:get-data()
6261
return typeswitch ($data)

0 commit comments

Comments
 (0)