Skip to content

Commit caa1efa

Browse files
authored
fixes bug 1451450, parse VariantExpressions with a MessageReference inside (#62)
This switches the props of VariantExpression from having a string `id` to a `MessageReference` `ref`
1 parent 0cd11c9 commit caa1efa

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

fluent/syntax/ast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ def __init__(self, id, name, **kwargs):
245245

246246

247247
class VariantExpression(Expression):
248-
def __init__(self, id, key, **kwargs):
248+
def __init__(self, ref, key, **kwargs):
249249
super(VariantExpression, self).__init__(**kwargs)
250-
self.id = id
250+
self.ref = ref
251251
self.key = key
252252

253253

fluent/syntax/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def get_selector_expression(self, ps):
518518
ps.next()
519519
key = self.get_variant_key(ps)
520520
ps.expect_char(']')
521-
return ast.VariantExpression(literal.id, key)
521+
return ast.VariantExpression(literal, key)
522522

523523
if (ch == '('):
524524
ps.next()

fluent/syntax/serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def serialize_attribute_expression(expr):
235235

236236
def serialize_variant_expression(expr):
237237
return "{}[{}]".format(
238-
serialize_identifier(expr.id),
238+
serialize_expression(expr.ref),
239239
serialize_variant_key(expr.key),
240240
)
241241

tests/syntax/fixtures_structure/term.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,17 @@
189189
"type": "Placeable",
190190
"expression": {
191191
"type": "VariantExpression",
192-
"id": {
193-
"type": "Identifier",
194-
"name": "-brand-name",
192+
"ref": {
193+
"type": "MessageReference",
194+
"id": {
195+
"type": "Identifier",
196+
"name": "-brand-name",
197+
"span": {
198+
"type": "Span",
199+
"start": 145,
200+
"end": 156
201+
}
202+
},
195203
"span": {
196204
"type": "Span",
197205
"start": 145,

0 commit comments

Comments
 (0)