Skip to content

Commit 6e562b6

Browse files
committed
Transform only TextElements
1 parent ae0c97d commit 6e562b6

29 files changed

+479
-124
lines changed

fluent/src/resolver.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ function getArguments(scope, args) {
101101

102102
// Resolve an expression to a Fluent type.
103103
function resolveExpression(scope, expr) {
104-
// A special case for VariantKeys.
105-
// XXX Should not go through bundle._transform.
106-
if (typeof expr === "string") {
107-
return scope.bundle._transform(expr);
108-
}
109-
110104
switch (expr.type) {
111105
case "str":
112106
return expr.value;

fluent/src/resource.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ export default class FluentResource extends Array {
255255
if (element.type === "indent") {
256256
// Dedent indented lines by the maximum common indent.
257257
element = element.value.slice(0, element.value.length - commonIndent);
258-
} else if (element.type === "str") {
259-
// Optimize StringLiterals into their value.
260-
element = element.value;
261258
}
262259
if (element) {
263260
baked.push(element);
@@ -387,7 +384,7 @@ export default class FluentResource extends Array {
387384
consumeToken(TOKEN_BRACKET_OPEN, FluentError);
388385
let key = test(RE_NUMBER_LITERAL)
389386
? parseNumberLiteral()
390-
: match1(RE_IDENTIFIER);
387+
: {type: "str", value: match1(RE_IDENTIFIER)};
391388
consumeToken(TOKEN_BRACKET_CLOSE, FluentError);
392389
return key;
393390
}

fluent/test/fixtures_reference/astral.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@
1717
{
1818
"id": "surrogates-in-string",
1919
"value": [
20-
"��"
20+
{
21+
"type": "str",
22+
"value": "��"
23+
}
2124
],
2225
"attributes": {}
2326
},
2427
{
2528
"id": "surrogates-in-adjacent-strings",
2629
"value": [
27-
"",
28-
""
30+
{
31+
"type": "str",
32+
"value": ""
33+
},
34+
{
35+
"type": "str",
36+
"value": ""
37+
}
2938
],
3039
"attributes": {}
3140
},
@@ -37,7 +46,10 @@
3746
{
3847
"id": "emoji-in-string",
3948
"value": [
40-
"A face 😂 with tears of joy."
49+
{
50+
"type": "str",
51+
"value": "A face 😂 with tears of joy."
52+
}
4153
],
4254
"attributes": {}
4355
}

fluent/test/fixtures_reference/callee_expressions.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
},
4747
"variants": [
4848
{
49-
"key": "key",
49+
"key": {
50+
"type": "str",
51+
"value": "key"
52+
},
5053
"value": "Value"
5154
}
5255
],
@@ -68,7 +71,10 @@
6871
},
6972
"variants": [
7073
{
71-
"key": "key",
74+
"key": {
75+
"type": "str",
76+
"value": "key"
77+
},
7278
"value": "Value"
7379
}
7480
],
@@ -90,7 +96,10 @@
9096
},
9197
"variants": [
9298
{
93-
"key": "key",
99+
"key": {
100+
"type": "str",
101+
"value": "key"
102+
},
94103
"value": "Value"
95104
}
96105
],

fluent/test/fixtures_reference/escaped_characters.json

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,64 +34,91 @@
3434
{
3535
"id": "quote-in-string",
3636
"value": [
37-
"\""
37+
{
38+
"type": "str",
39+
"value": "\""
40+
}
3841
],
3942
"attributes": {}
4043
},
4144
{
4245
"id": "backslash-in-string",
4346
"value": [
44-
"\\"
47+
{
48+
"type": "str",
49+
"value": "\\"
50+
}
4551
],
4652
"attributes": {}
4753
},
4854
{
4955
"id": "string-unicode-4digits",
5056
"value": [
51-
"A"
57+
{
58+
"type": "str",
59+
"value": "A"
60+
}
5261
],
5362
"attributes": {}
5463
},
5564
{
5665
"id": "escape-unicode-4digits",
5766
"value": [
58-
"\\u0041"
67+
{
68+
"type": "str",
69+
"value": "\\u0041"
70+
}
5971
],
6072
"attributes": {}
6173
},
6274
{
6375
"id": "string-unicode-6digits",
6476
"value": [
65-
"😂"
77+
{
78+
"type": "str",
79+
"value": "😂"
80+
}
6681
],
6782
"attributes": {}
6883
},
6984
{
7085
"id": "escape-unicode-6digits",
7186
"value": [
72-
"\\U01F602"
87+
{
88+
"type": "str",
89+
"value": "\\U01F602"
90+
}
7391
],
7492
"attributes": {}
7593
},
7694
{
7795
"id": "string-too-many-4digits",
7896
"value": [
79-
"A00"
97+
{
98+
"type": "str",
99+
"value": "A00"
100+
}
80101
],
81102
"attributes": {}
82103
},
83104
{
84105
"id": "string-too-many-6digits",
85106
"value": [
86-
"😂00"
107+
{
108+
"type": "str",
109+
"value": "😂00"
110+
}
87111
],
88112
"attributes": {}
89113
},
90114
{
91115
"id": "brace-open",
92116
"value": [
93117
"An opening ",
94-
"{",
118+
{
119+
"type": "str",
120+
"value": "{"
121+
},
95122
" brace."
96123
],
97124
"attributes": {}
@@ -100,7 +127,10 @@
100127
"id": "brace-close",
101128
"value": [
102129
"A closing ",
103-
"}",
130+
{
131+
"type": "str",
132+
"value": "}"
133+
},
104134
" brace."
105135
],
106136
"attributes": {}

fluent/test/fixtures_reference/leading_dots.json

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@
1212
{
1313
"id": "key03",
1414
"value": [
15-
".",
15+
{
16+
"type": "str",
17+
"value": "."
18+
},
1619
"Value"
1720
],
1821
"attributes": {}
1922
},
2023
{
2124
"id": "key04",
2225
"value": [
23-
".",
26+
{
27+
"type": "str",
28+
"value": "."
29+
},
2430
"Value"
2531
],
2632
"attributes": {}
@@ -30,7 +36,10 @@
3036
"value": [
3137
"Value",
3238
"\n",
33-
".",
39+
{
40+
"type": "str",
41+
"value": "."
42+
},
3443
"Continued"
3544
],
3645
"attributes": {}
@@ -40,7 +49,10 @@
4049
"value": [
4150
".Value",
4251
"\n",
43-
".",
52+
{
53+
"type": "str",
54+
"value": "."
55+
},
4456
"Continued"
4557
],
4658
"attributes": {}
@@ -64,7 +76,10 @@
6476
{
6577
"id": "key11",
6678
"value": [
67-
".",
79+
{
80+
"type": "str",
81+
"value": "."
82+
},
6883
"Value = which looks like an attribute",
6984
"\n",
7085
"Continued"
@@ -92,7 +107,10 @@
92107
"value": null,
93108
"attributes": {
94109
"attribute": [
95-
".",
110+
{
111+
"type": "str",
112+
"value": "."
113+
},
96114
"Value"
97115
]
98116
}
@@ -109,13 +127,22 @@
109127
},
110128
"variants": [
111129
{
112-
"key": "one",
130+
"key": {
131+
"type": "str",
132+
"value": "one"
133+
},
113134
"value": ".Value"
114135
},
115136
{
116-
"key": "other",
137+
"key": {
138+
"type": "str",
139+
"value": "other"
140+
},
117141
"value": [
118-
".",
142+
{
143+
"type": "str",
144+
"value": "."
145+
},
119146
"Value"
120147
]
121148
}
@@ -139,7 +166,10 @@
139166
{
140167
"id": "key20",
141168
"value": [
142-
".",
169+
{
170+
"type": "str",
171+
"value": "."
172+
},
143173
"Value"
144174
],
145175
"attributes": {}

fluent/test/fixtures_reference/literal_expressions.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
{
33
"id": "string-expression",
44
"value": [
5-
"abc"
5+
{
6+
"type": "str",
7+
"value": "abc"
8+
}
69
],
710
"attributes": {}
811
},

fluent/test/fixtures_reference/member_expressions.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
},
3636
"variants": [
3737
{
38-
"key": "key",
38+
"key": {
39+
"type": "str",
40+
"value": "key"
41+
},
3942
"value": "Value"
4043
}
4144
],
@@ -56,7 +59,10 @@
5659
},
5760
"variants": [
5861
{
59-
"key": "key",
62+
"key": {
63+
"type": "str",
64+
"value": "key"
65+
},
6066
"value": "Value"
6167
}
6268
],

fluent/test/fixtures_reference/messages.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@
4343
},
4444
{
4545
"id": "key06",
46-
"value": [],
46+
"value": [
47+
{
48+
"type": "str",
49+
"value": ""
50+
}
51+
],
4752
"attributes": {}
4853
},
4954
{

0 commit comments

Comments
 (0)