Skip to content

Commit cc3216b

Browse files
committed
fix: rename startMark to directivesEndMarker, endMark to documentEndMarker
1 parent a024502 commit cc3216b

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file. See [standa
1010

1111
### Features
1212

13-
- add `startMark` and `endMark` information to `Document` ([#298](https://github.com/prettier/yaml-unist-parser/issues/298)) ([7c4de43](https://github.com/prettier/yaml-unist-parser/commit/7c4de437de33793b6cacfc5bd87e0e08d45faf04))
13+
- add `directivesEndMarker` and `documentEndMarker` information to `Document` ([#298](https://github.com/prettier/yaml-unist-parser/issues/298)) ([7c4de43](https://github.com/prettier/yaml-unist-parser/commit/7c4de437de33793b6cacfc5bd87e0e08d45faf04))
1414

1515
## [2.0.5](https://github.com/prettier/yaml-unist-parser/compare/v2.0.4...v2.0.5) (2025-03-21)
1616

src/factories/document.ts

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

1111
export function createDocument(
1212
position: Position,
13-
startMark: boolean,
14-
endMark: boolean,
13+
directivesEndMarker: boolean,
14+
documentEndMarker: boolean,
1515
head: DocumentHead,
1616
body: DocumentBody,
1717
trailingComment: null | Comment,
1818
): Document {
1919
return {
2020
...createNode("document", position),
2121
...createTrailingCommentAttachable(trailingComment),
22-
startMark,
23-
endMark,
22+
directivesEndMarker,
23+
documentEndMarker,
2424
children: [head, body],
2525
};
2626
}

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

src/transforms/document-head.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function transformDocumentHead(
1515
context,
1616
);
1717

18-
const { position, endMarkerPoint } = getPosition(
18+
const { position, documentEndMarkererPoint } = getPosition(
1919
cstNode,
2020
directives,
2121
context,
@@ -39,7 +39,7 @@ export function transformDocumentHead(
3939

4040
return {
4141
createDocumentHeadWithTrailingComment,
42-
documentHeadEndMarkerPoint: endMarkerPoint,
42+
documentHeadEndMarkerPoint: documentEndMarkererPoint,
4343
};
4444
}
4545

@@ -71,24 +71,27 @@ function getPosition(
7171
directives: Directive[],
7272
context: Context,
7373
) {
74-
let endMarkerIndex = getMatchIndex(
74+
let documentEndMarkererIndex = getMatchIndex(
7575
context.text.slice(0, document.valueRange!.origStart),
7676
/---\s*$/,
7777
);
7878
// end marker should start with the first character on the line
79-
if (endMarkerIndex > 0 && !/[\r\n]/.test(context.text[endMarkerIndex - 1])) {
80-
endMarkerIndex = -1;
79+
if (
80+
documentEndMarkererIndex > 0 &&
81+
!/[\r\n]/.test(context.text[documentEndMarkererIndex - 1])
82+
) {
83+
documentEndMarkererIndex = -1;
8184
}
8285

8386
const range: Range =
84-
endMarkerIndex === -1
87+
documentEndMarkererIndex === -1
8588
? {
8689
origStart: document.valueRange!.origStart!,
8790
origEnd: document.valueRange!.origStart!,
8891
}
8992
: {
90-
origStart: endMarkerIndex!,
91-
origEnd: endMarkerIndex + 3,
93+
origStart: documentEndMarkererIndex!,
94+
origEnd: documentEndMarkererIndex + 3,
9295
};
9396

9497
if (directives.length !== 0) {
@@ -97,7 +100,9 @@ function getPosition(
97100

98101
return {
99102
position: context.transformRange(range),
100-
endMarkerPoint:
101-
endMarkerIndex === -1 ? null : context.transformOffset(endMarkerIndex),
103+
documentEndMarkererPoint:
104+
documentEndMarkererIndex === -1
105+
? null
106+
: context.transformOffset(documentEndMarkererIndex),
102107
};
103108
}

src/types.ts

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

120120
export interface Document extends Parent, TrailingCommentAttachable {
121121
type: "document";
122-
startMark: boolean;
123-
endMark: boolean;
122+
directivesEndMarker: boolean;
123+
documentEndMarker: boolean;
124124
children: [DocumentHead, DocumentBody];
125125
}
126126

0 commit comments

Comments
 (0)