Skip to content

Commit d4cfdec

Browse files
committed
Bug 1451450 - Parse VariantExpressions with MessageReferences inside
Change the `Identifier`-typed `id` field of VariantExpression to an `Expression`-typed `ref` field, so that it can hold a `MessageReference`.
1 parent de35e58 commit d4cfdec

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

fluent-syntax/src/ast.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ export class AttributeExpression extends Expression {
142142
}
143143

144144
export class VariantExpression extends Expression {
145-
constructor(id, key) {
145+
constructor(ref, key) {
146146
super();
147147
this.type = "VariantExpression";
148-
this.id = id;
148+
this.ref = ref;
149149
this.key = key;
150150
}
151151
}

fluent-syntax/src/parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ export default class FluentParser {
619619

620620
ps.expectChar("]");
621621

622-
return new AST.VariantExpression(literal.id, key);
622+
return new AST.VariantExpression(literal, key);
623623
}
624624

625625
if (ch === "(") {

fluent-syntax/src/serializer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ function serializeAttributeExpression(expr) {
269269

270270

271271
function serializeVariantExpression(expr) {
272-
const id = serializeIdentifier(expr.id);
272+
const ref = serializeExpression(expr.ref);
273273
const key = serializeVariantKey(expr.key);
274-
return `${id}[${key}]`;
274+
return `${ref}[${key}]`;
275275
}
276276

277277

fluent-syntax/test/fixtures_structure/term.json

+11-3
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)