Skip to content

Commit

Permalink
fix: macros generates invalid ICU message for nested selects (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodge authored and tricoder42 committed Oct 15, 2018
1 parent a9750ed commit 28aea44
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/macro/src/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default function({ types: t }) {
value = props.text
} else if (t.isCallExpression(attr.value)) {
props = transformMethod(attr.value, file, { ...props, text: "" })
value = props.text
value = `{${props.text}}`
} else {
value = attr.value.value
}
Expand Down
11 changes: 11 additions & 0 deletions packages/macro/test/fixtures/select/actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ select('id', {
female: `She is ${gender}`,
other: `They is ${gender}`
});

select('id', {
value: "male",
"male": select({
value: true,
true: "He invites guests",
other: "He does not invite guests"
}),
female: `She is ${gender}`,
other: `They is ${gender}`
});
16 changes: 13 additions & 3 deletions packages/macro/test/fixtures/select/expected.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
( /*i18n*/{
id: "{gender, select, male {numOfGuests, plural, one {He invites one guest} other {He invites # guests}} female {She is {gender}} other {They is {gender}}}",
id: "{gender, select, male {{numOfGuests, plural, one {He invites one guest} other {He invites # guests}}} female {She is {gender}} other {They is {gender}}}",
values: {
gender: gender,
numOfGuests: numOfGuests
Expand All @@ -8,7 +8,7 @@

( /*i18n*/{
id: "id",
defaults: "{0, select, male {1, plural, one {He invites one guest} other {He invites # guests}} female {She is {gender}} other {They is {gender}}}",
defaults: "{0, select, male {{1, plural, one {He invites one guest} other {He invites # guests}}} female {She is {gender}} other {They is {gender}}}",
values: {
0: "male",
1: 42,
Expand All @@ -18,10 +18,20 @@

/*i18n: description*/({
id: "id",
defaults: "{0, select, male {1, plural, one {He invites one guest} other {He invites # guests}} female {She is {gender}} other {They is {gender}}}",
defaults: "{0, select, male {{1, plural, one {He invites one guest} other {He invites # guests}}} female {She is {gender}} other {They is {gender}}}",
values: {
0: "male",
1: 42,
gender: gender
}
});

( /*i18n*/{
id: "id",
defaults: "{0, select, male {{1, select, true {He invites guests} other {He does not invite guests}}} female {She is {gender}} other {They is {gender}}}",
values: {
0: "male",
1: true,
gender: gender
}
});

0 comments on commit 28aea44

Please sign in to comment.