Skip to content

Commit 3f0cd3e

Browse files
authored
Fix Comment span to include the terminal line break (#257)
Comments' content includes the terminal line break and the span should reflect it. The end span should be the offset of the beginning of the next line following the Comment, not the offset of the Comment's terminal line break. This also means that we can remvoe the special case in skipBlankLines. The meaning changes slightly: skipBlankLines now return the number of all line breaks skipped, regardless of whether they belonged to fully-blank lines or not. This is OK for our use-case, however.
1 parent 1df9147 commit 3f0cd3e

12 files changed

+25
-27
lines changed

fluent-syntax/src/ftlstream.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ export class FTLParserStream extends ParserStream {
2828
}
2929

3030
skipBlankLines() {
31-
// Many Parser methods leave the cursor at the line break
32-
// without going into the next line. We want to count fully blank lines in
33-
// this case. Starting the count at -1 will give the right number.
34-
let lineCount = this.currentIs("\n") ? -1 : 0;
35-
31+
let lineCount = 0;
3632
while (true) {
3733
this.peekInlineWS();
3834

fluent-syntax/src/parser.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,21 @@ export default class FluentParser {
190190
}
191191
}
192192

193-
if (!ps.currentIs(undefined)) {
194-
content += "\n";
195-
} else {
196-
break;
197-
}
198-
199193
if (ps.isPeekNextLineComment(level)) {
194+
content += ps.current();
200195
ps.next();
201196
} else {
202197
break;
203198
}
204199
}
205200

201+
// Add the terminal line break.
202+
if (!ps.currentIs(undefined)) {
203+
content += ps.current();
204+
ps.next();
205+
}
206+
207+
206208
let Comment;
207209
switch (level) {
208210
case 0:

fluent-syntax/test/fixtures_structure/escape_sequences.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"span": {
165165
"type": "Span",
166166
"start": 149,
167-
"end": 170
167+
"end": 171
168168
}
169169
},
170170
{

fluent-syntax/test/fixtures_structure/leading_dots.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@
328328
"span": {
329329
"type": "Span",
330330
"start": 142,
331-
"end": 185
331+
"end": 186
332332
}
333333
},
334334
{
@@ -362,7 +362,7 @@
362362
"span": {
363363
"type": "Span",
364364
"start": 216,
365-
"end": 255
365+
"end": 256
366366
}
367367
},
368368
{
@@ -396,7 +396,7 @@
396396
"span": {
397397
"type": "Span",
398398
"start": 276,
399-
"end": 315
399+
"end": 316
400400
}
401401
},
402402
{
@@ -883,7 +883,7 @@
883883
"span": {
884884
"type": "Span",
885885
"start": 687,
886-
"end": 722
886+
"end": 723
887887
}
888888
},
889889
{
@@ -915,7 +915,7 @@
915915
"span": {
916916
"type": "Span",
917917
"start": 781,
918-
"end": 809
918+
"end": 810
919919
}
920920
},
921921
{

fluent-syntax/test/fixtures_structure/message_with_empty_multiline_pattern.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"span": {
99
"type": "Span",
1010
"start": 0,
11-
"end": 316
11+
"end": 317
1212
}
1313
},
1414
{

fluent-syntax/test/fixtures_structure/message_with_empty_pattern.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"span": {
99
"type": "Span",
1010
"start": 0,
11-
"end": 327
11+
"end": 328
1212
}
1313
},
1414
{

fluent-syntax/test/fixtures_structure/multiline-comment.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"span": {
99
"type": "Span",
1010
"start": 1,
11-
"end": 48
11+
"end": 49
1212
}
1313
},
1414
{

fluent-syntax/test/fixtures_structure/resource_comment.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"span": {
99
"type": "Span",
1010
"start": 0,
11-
"end": 54
11+
"end": 55
1212
}
1313
}
1414
],

fluent-syntax/test/fixtures_structure/resource_comment_trailing_line.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"span": {
99
"type": "Span",
1010
"start": 0,
11-
"end": 55
11+
"end": 56
1212
}
1313
}
1414
],

fluent-syntax/test/fixtures_structure/standalone_comment.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"span": {
4848
"type": "Span",
4949
"start": 13,
50-
"end": 43
50+
"end": 44
5151
}
5252
}
5353
],

fluent-syntax/test/fixtures_structure/whitespace_leading.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"span": {
4141
"type": "Span",
4242
"start": 0,
43-
"end": 20
43+
"end": 21
4444
}
4545
},
4646
"span": {
@@ -88,7 +88,7 @@
8888
"span": {
8989
"type": "Span",
9090
"start": 48,
91-
"end": 64
91+
"end": 65
9292
}
9393
},
9494
"span": {

fluent-syntax/test/fixtures_structure/whitespace_trailing.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"span": {
4141
"type": "Span",
4242
"start": 0,
43-
"end": 26
43+
"end": 27
4444
}
4545
},
4646
"span": {
@@ -88,7 +88,7 @@
8888
"span": {
8989
"type": "Span",
9090
"start": 55,
91-
"end": 76
91+
"end": 77
9292
}
9393
},
9494
"span": {

0 commit comments

Comments
 (0)