Skip to content

Commit 86f4046

Browse files
committed
fix(mf2): Unsupported statement parsing
1 parent 75580fb commit 86f4046

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

packages/mf2-messageformat/src/__fixtures/test-core.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,25 @@
176176
{ "type": "fallback", "source": "?" }
177177
],
178178
"errors": [{ "type": "unsupported-annotation" }]
179+
},
180+
{
181+
"src": ".foo {42} {{bar}}",
182+
"exp": "bar",
183+
"parts": [{ "type": "literal", "value": "bar" }],
184+
"errors": [{ "type": "unsupported-statement" }]
185+
},
186+
{
187+
"src": ".foo{42}{{bar}}",
188+
"cleanSrc": ".foo {42} {{bar}}",
189+
"exp": "bar",
190+
"parts": [{ "type": "literal", "value": "bar" }],
191+
"errors": [{ "type": "unsupported-statement" }]
192+
},
193+
{
194+
"src": ".foo |}lit{| {42}{{bar}}",
195+
"cleanSrc": ".foo |}lit{| {42} {{bar}}",
196+
"exp": "bar",
197+
"parts": [{ "type": "literal", "value": "bar" }],
198+
"errors": [{ "type": "unsupported-statement" }]
179199
}
180200
]

packages/mf2-messageformat/src/cst/declarations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ function parseReservedStatement(
121121

122122
const values: CST.Expression[] = [];
123123
while (ctx.source[pos] === '{') {
124+
if (ctx.source.startsWith('{{', pos)) break;
124125
const value = parseExpression(ctx, pos);
126+
values.push(value)
125127
end = value.end;
126128
pos = end + whitespaces(ctx.source, end);
127129
}

packages/mf2-messageformat/src/cst/expression.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ export function parseReservedBody(
260260
pos = parseQuotedLiteral(ctx, pos).end;
261261
break;
262262
case '@':
263+
case '{':
263264
case '}':
264265
break loop;
265266
default: {
@@ -273,7 +274,7 @@ export function parseReservedBody(
273274
}
274275
}
275276
let prev = ctx.source[pos - 1];
276-
while (whitespaceChars.includes(prev)) {
277+
while (pos > start && whitespaceChars.includes(prev)) {
277278
pos -= 1;
278279
prev = ctx.source[pos - 1];
279280
}

packages/mf2-messageformat/src/cst/stringify-cst.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function stringifyCST(cst: CST.Message): string {
2727
}
2828
case 'reserved-statement': {
2929
str += kw;
30-
if (decl.body) str += ' ' + decl.body;
30+
if (decl.body.value) str += ' ' + decl.body.value;
3131
for (const exp of decl.values) str += ' ' + stringifyExpression(exp);
3232
str += '\n';
3333
break;

0 commit comments

Comments
 (0)