Skip to content

Commit

Permalink
feat(@formatjs/icu-messageformat-parser): set requiresOtherClause to …
Browse files Browse the repository at this point in the history
…true

BREAKING CHANGE: This is so that we're consistent with icu4j, fix #2855
  • Loading branch information
longlho committed May 2, 2021
1 parent b6e2953 commit 976c79a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/icu-messageformat-parser/index.ts
Expand Up @@ -36,6 +36,7 @@ function pruneLocation(els: MessageFormatElement[]): void {
export function parse(message: string, opts: ParserOptions = {}) {
opts = {
shouldParseSkeletons: true,
requiresOtherClause: true,
...opts,
}
const result = new Parser(message, opts).parse()
Expand Down
@@ -1,19 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`hoist some random case 1 1`] = `"{p1,plural,one{{foo,select,bar{one two other{other} } baz{one three other{other} }}}}"`;
exports[`hoist some random case 1 1`] = `"{p1,plural,one{{foo,select,bar{one two} baz{one three} other{one other}}} other{other}}"`;

exports[`should hoist plural & select and tag 1`] = `
"{count,plural,one{{gender,select,male{{count,plural,one{{gender,select,male{I have a male <b>dog</b>
and a male <strong>cat</strong>
} female{I have a male <b>dog</b>
and a female <strong>cat</strong>
} other{I have a male <b>dog</b>
and a male <strong>cat</strong>
}}} other{I have a male <b>dog</b>
and many cats}}} female{{count,plural,one{{gender,select,male{I have a female <b>dog</b>
and a male <strong>cat</strong>
} female{I have a female <b>dog</b>
and a female <strong>cat</strong>
} other{I have a female <b>dog</b>
and a male <strong>cat</strong>
}}} other{I have a female <b>dog</b>
and many cats}}} other{{count,plural,one{{gender,select,male{I have a male <b>dog</b>
and a male <strong>cat</strong>
} female{I have a male <b>dog</b>
and a female <strong>cat</strong>
} other{I have a male <b>dog</b>
and a male <strong>cat</strong>
}}} other{I have a male <b>dog</b>
and many cats}}}}} other{{count,plural,one{{gender,select,male{I have many dogs and a male <strong>cat</strong>
} female{I have many dogs and a female <strong>cat</strong>
} other{I have many dogs and a male <strong>cat</strong>
}}} other{I have many dogs and many cats}}}}"
`;
4 changes: 3 additions & 1 deletion packages/icu-messageformat-parser/tests/manipulator.test.ts
Expand Up @@ -17,7 +17,7 @@ test('hoist some random case 1', function () {
printAST(
hoistSelectors(
parse(
'{p1, plural, one{one {foo, select, bar{two} baz{three}} other{other} }}'
'{p1, plural, one{one {foo, select, bar{two} baz{three} other{other}}} other{other}}'
)
)
)
Expand All @@ -33,13 +33,15 @@ test('should hoist plural & select and tag', function () {
gender, select,
male{male}
female{female}
other{male}
} <b>dog</b>
}
other{many dogs}} and {count, plural,
one{a {
gender, select,
male{male}
female{female}
other{male}
} <strong>cat</strong>
}
other{many cats}}`)
Expand Down

0 comments on commit 976c79a

Please sign in to comment.