Skip to content

Commit 7c4de43

Browse files
authored
feat: add startMark and endMark information to Document (#298)
1 parent 5b73153 commit 7c4de43

File tree

10 files changed

+985
-957
lines changed

10 files changed

+985
-957
lines changed

.yarn/releases/yarn-4.11.0.cjs

Lines changed: 942 additions & 0 deletions
Large diffs are not rendered by default.

.yarn/releases/yarn-4.7.0.cjs

Lines changed: 0 additions & 935 deletions
This file was deleted.

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ plugins:
1010
- .yarn/plugins/plugin-setup-editor.cjs
1111
- .yarn/plugins/plugin-run-patch-package.cjs
1212

13-
yarnPath: .yarn/releases/yarn-4.7.0.cjs
13+
yarnPath: .yarn/releases/yarn-4.11.0.cjs

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@
5959
},
6060
"files": [
6161
"/lib/**/*"
62-
]
62+
],
63+
"packageManager": "yarn@4.11.0"
6364
}

patches/yaml+1.10.2.patch

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ index 53eb011..dcb722e 100644
2222
schema: Schema
2323
}
2424
diff --git a/node_modules/yaml/parse-cst.d.ts b/node_modules/yaml/parse-cst.d.ts
25-
index 9fd2ebf..45c1923 100644
25+
index 9fd2ebf..4e25756 100644
2626
--- a/node_modules/yaml/parse-cst.d.ts
2727
+++ b/node_modules/yaml/parse-cst.d.ts
2828
@@ -10,8 +10,8 @@ export namespace CST {
@@ -45,14 +45,18 @@ index 9fd2ebf..45c1923 100644
4545
}
4646

4747
interface FlowCollection extends Node {
48-
@@ -184,6 +184,7 @@ export namespace CST {
48+
@@ -184,8 +184,11 @@ export namespace CST {
4949
type: Type.DOCUMENT
5050
directives: Array<BlankLine | Comment | Directive>
5151
contents: Array<BlankLine | Comment | ContentNode>
5252
+ setOrigRanges(cr: number[], offset: number): number
5353
readonly anchor: null
5454
readonly comment: null
5555
readonly tag: null
56+
+ readonly directivesEndMarker: Range | null
57+
+ readonly documentEndMarker: Range | null
58+
}
59+
}
5660
diff --git a/node_modules/yaml/types.d.ts b/node_modules/yaml/types.d.ts
5761
index 411e74e..0c60eb0 100644
5862
--- a/node_modules/yaml/types.d.ts

src/factories/document.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ import { createTrailingCommentAttachable } from "./trailing-comment-attachable.j
1010

1111
export function createDocument(
1212
position: Position,
13+
startMark: boolean,
14+
endMark: boolean,
1315
head: DocumentHead,
1416
body: DocumentBody,
1517
trailingComment: null | Comment,
1618
): Document {
1719
return {
1820
...createNode("document", position),
1921
...createTrailingCommentAttachable(trailingComment),
22+
startMark,
23+
endMark,
2024
children: [head, body],
2125
};
2226
}

src/helpers.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,12 @@ function stringifyNode(
179179
return "<null />";
180180
}
181181

182-
const attributes = Object.keys(node)
183-
.filter(key => {
182+
const attributes = Object.entries(node)
183+
.filter(([key, value]) => {
184+
if (value === false) {
185+
return false;
186+
}
187+
184188
switch (key) {
185189
case "type":
186190
case "position":
@@ -198,7 +202,9 @@ function stringifyNode(
198202
return true;
199203
}
200204
})
201-
.map(key => `${key}=${JSON.stringify(node[key as keyof typeof node])}`)
205+
.map(([key, value]) =>
206+
value === true ? key : `${key}=${JSON.stringify(value)}`,
207+
)
202208
.sort()
203209
.map((attribute, index) => (index === 0 ? " " + attribute : attribute))
204210
.join(" ");

src/transforms/__snapshots__/document.test.ts.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ document (1:1 ~ 3:4)
6060
7 | ¶
6161
8 | ¶
6262
9 | ·¶
63-
<document>
63+
<document endMark>
6464
<trailingComment value="123">
6565
<documentHead>
6666
@@ -188,7 +188,7 @@ document (1:1 ~ 1:4)
188188
3 | #¶
189189
4 | ¶
190190
5 | ¶
191-
<document>
191+
<document endMark>
192192
<documentHead>
193193
194194
</documentHead>
@@ -310,7 +310,7 @@ document (2:1 ~ 6:4)
310310
11 | 456¶
311311
12 | ¶
312312
13 | ¶
313-
<document>
313+
<document endMark startMark>
314314
<documentHead>
315315
<directive name="AAA" parameters=[] />
316316
</documentHead>
@@ -385,7 +385,7 @@ document (8:1 ~ 13:1)
385385
| ^
386386
13 | ¶
387387
| ^
388-
<document>
388+
<document startMark>
389389
<documentHead>
390390
<directive name="BBB" parameters=[] />
391391
</documentHead>
@@ -459,7 +459,7 @@ document (2:1 ~ 6:4)
459459
10 | 456¶
460460
11 | ¶
461461
12 | ¶
462-
<document>
462+
<document endMark startMark>
463463
<documentHead>
464464
<directive name="AAA" parameters=[] />
465465
</documentHead>
@@ -530,7 +530,7 @@ document (8:1 ~ 12:1)
530530
| ^
531531
12 | ¶
532532
| ^
533-
<document>
533+
<document startMark>
534534
<documentHead>
535535
536536
</documentHead>
@@ -599,7 +599,7 @@ document (2:1 ~ 6:4)
599599
8 | 456¶
600600
9 | ¶
601601
10 | ¶
602-
<document>
602+
<document endMark startMark>
603603
<documentHead>
604604
<directive name="AAA" parameters=[] />
605605
</documentHead>
@@ -726,7 +726,7 @@ document (2:1 ~ 6:1)
726726
8 | 456¶
727727
9 | ¶
728728
10 | ¶
729-
<document>
729+
<document startMark>
730730
<documentHead>
731731
<directive name="AAA" parameters=[] />
732732
</documentHead>
@@ -791,7 +791,7 @@ document (6:1 ~ 10:1)
791791
| ^
792792
10 | ¶
793793
| ^
794-
<document>
794+
<document startMark>
795795
<documentHead>
796796
797797
</documentHead>
@@ -852,7 +852,7 @@ document (2:1 ~ 4:4)
852852
6 | 456¶
853853
7 | ¶
854854
8 | ¶
855-
<document>
855+
<document endMark>
856856
<documentHead>
857857
858858
</documentHead>
@@ -1022,7 +1022,7 @@ document (4:1 ~ 8:1)
10221022
| ^
10231023
8 | ¶
10241024
| ^
1025-
<document>
1025+
<document startMark>
10261026
<documentHead>
10271027
10281028
</documentHead>
@@ -1127,7 +1127,7 @@ document (3:1 ~ 4:6)
11271127
| ^^^^
11281128
4 | -·BBB¶
11291129
| ^^^^^
1130-
<document>
1130+
<document startMark>
11311131
<documentHead>
11321132
11331133
</documentHead>
@@ -1178,7 +1178,7 @@ document (1:1 ~ 3:4)
11781178
3 | ...·#documentEndComment¶
11791179
| ^^^
11801180
4 | ¶
1181-
<document>
1181+
<document endMark startMark>
11821182
<trailingComment value="documentEndComment">
11831183
<documentHead>
11841184
@@ -1196,7 +1196,7 @@ document (1:1 ~ 2:4)
11961196
2 | ...¶
11971197
| ^^^
11981198
3 | 456¶
1199-
<document>
1199+
<document endMark>
12001200
<documentHead>
12011201
12021202
</documentHead>
@@ -1234,7 +1234,7 @@ root (1:1 ~ 3:4)
12341234
<plain value="123" />
12351235
</documentBody>
12361236
</document>
1237-
<document>
1237+
<document startMark>
12381238
<documentHead>
12391239
<trailingComment value="666">
12401240
</documentHead>

src/transforms/document.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ export function transformDocument(
2828
context.comments.push(documentTrailingComment);
2929
}
3030

31+
const cstNode = document.cstNode!;
32+
3133
return createDocument(
3234
createPosition(documentHead.position.start, documentEndPoint),
35+
Boolean(cstNode.directivesEndMarker),
36+
Boolean(cstNode.documentEndMarker),
3337
documentHead,
3438
documentBody,
3539
documentTrailingComment,

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export interface Root extends Parent {
119119

120120
export interface Document extends Parent, TrailingCommentAttachable {
121121
type: "document";
122+
startMark: boolean;
123+
endMark: boolean;
122124
children: [DocumentHead, DocumentBody];
123125
}
124126

0 commit comments

Comments
 (0)