Skip to content

Commit 0038a08

Browse files
committed
fix(bundle): Handle selector with no variants as a syntax error
1 parent 1c78691 commit 0038a08

File tree

5 files changed

+5
-76
lines changed

5 files changed

+5
-76
lines changed

fluent-bundle/src/resource.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ function parseMessage(source: string, cursor: number, id: string): Message {
273273
type: "select",
274274
selector: expression,
275275
...variants,
276-
} as SelectExpression; // TODO: FIXME
276+
} satisfies SelectExpression;
277277
}
278278

279279
throw new SyntaxError("Unclosed placeable");
@@ -363,30 +363,25 @@ function parseMessage(source: string, cursor: number, id: string): Message {
363363
function parseVariants(): {
364364
variants: Array<Variant>;
365365
star: number;
366-
} | null {
366+
} {
367367
const variants: Array<Variant> = [];
368-
let count = 0;
369368
let star;
370369

371370
RE_VARIANT_START.lastIndex = cursor;
372371
while (RE_VARIANT_START.test(source)) {
373372
if (consumeChar("*")) {
374-
star = count;
373+
star = variants.length;
375374
}
376375

377376
const key = parseVariantKey();
378377
const value = parsePattern();
379378
if (value === null) {
380379
throw new SyntaxError("Expected variant value");
381380
}
382-
variants[count++] = { key, value };
381+
variants.push({ key, value });
383382
RE_VARIANT_START.lastIndex = cursor;
384383
}
385384

386-
if (count === 0) {
387-
return null;
388-
}
389-
390385
if (star === undefined) {
391386
throw new SyntaxError("Expected default variant");
392387
}

fluent-bundle/test/fixtures_reference/cr.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,6 @@
2121
"attributes": {
2222
"title": "Title"
2323
}
24-
},
25-
{
26-
"id": "err05",
27-
"value": [
28-
{
29-
"type": "select",
30-
"selector": {
31-
"type": "var",
32-
"name": "sel"
33-
}
34-
}
35-
],
36-
"attributes": {}
3724
}
3825
]
3926
}

fluent-bundle/test/fixtures_reference/crlf.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515
"attributes": {
1616
"title": "Title"
1717
}
18-
},
19-
{
20-
"id": "err04",
21-
"value": [
22-
{
23-
"type": "select",
24-
"selector": {
25-
"type": "var",
26-
"name": "sel"
27-
}
28-
}
29-
],
30-
"attributes": {}
3118
}
3219
]
3320
}

fluent-bundle/test/fixtures_structure/crlf.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515
"attributes": {
1616
"title": "Title"
1717
}
18-
},
19-
{
20-
"id": "err04",
21-
"value": [
22-
{
23-
"type": "select",
24-
"selector": {
25-
"type": "var",
26-
"name": "sel"
27-
}
28-
}
29-
],
30-
"attributes": {}
3118
}
3219
]
3320
}
Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
11
{
2-
"body": [
3-
{
4-
"id": "err01",
5-
"value": [
6-
{
7-
"type": "select",
8-
"selector": {
9-
"type": "var",
10-
"name": "foo"
11-
}
12-
}
13-
],
14-
"attributes": {}
15-
},
16-
{
17-
"id": "err02",
18-
"value": [
19-
{
20-
"type": "select",
21-
"selector": {
22-
"type": "var",
23-
"name": "foo"
24-
}
25-
}
26-
],
27-
"attributes": {}
28-
}
29-
]
2+
"body": []
303
}

0 commit comments

Comments
 (0)