Skip to content
This repository was archived by the owner on Dec 17, 2018. It is now read-only.

Commit b4865b0

Browse files
committed
Require valid plural & selectordinal keys
1 parent 018a58f commit b4865b0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

parser.pegjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ token
1515
};
1616
}
1717
/ '{' _ arg:id _ ',' _ type:('plural'/'selectordinal') _ ',' _ offset:offset? cases:pluralCase+ _ '}' {
18+
var ls = ((type === 'selectordinal') ? options.ordinal : options.cardinal);
19+
if (ls && ls.length) cases.forEach(function(c) {
20+
if (isNaN(c.key) && ls.indexOf(c.key) < 0) throw new Error('Invalid ' + type + ' key: ' + c.key);
21+
});
1822
return {
1923
type: type,
2024
arg: arg,
@@ -43,7 +47,9 @@ caseTokens = '{' (_ & '{')? tokens:token* _ '}' { return tokens; }
4347

4448
offset = _ 'offset' _ ':' _ d:digits _ { return d; }
4549

46-
pluralKey = id / '=' d:digits { return d; }
50+
pluralKey
51+
= $('zero'/'one'/'two'/'few'/'many'/'other')
52+
/ '=' d:digits { return d; }
4753

4854
functionParams = _ ',' _ p:id _ { return p; }
4955

0 commit comments

Comments
 (0)