globalizejs / globalizejs/globalize-compiler
A formatter call with default args should call the same compiled formatter as one with no args
- Dominant language
- JavaScript
- Stars
- 10
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
Say I have this code:
```
let pgencard = Globalize.pluralGenerator({type: 'cardinal'});
let pgenord = Globalize.pluralGenerator({type: 'ordinal'});
let pgendefault = Globalize.pluralGenerator();
```
Compiled, I get something like this (excerpt, transpiled with babel):
```
_globalizeRuntime2.default.a1662346136 = pluralGeneratorFn(function (n) {
var s = String(n).split('.'),
v0 = !s[1];
return n == 1 && v0 ? 'one' : 'other';
});
_globalizeRuntime2.default.b996364137 = pluralGeneratorFn(function (n) {
var s = String(n).split('.'),
t0 = Number(s[0]) == n,
n10 = t0 && s[0].slice(-1),
n100 = t0 && s[0].slice(-2);
return n10 == 1 && n100 != 11 ? 'one' : n10 == 2 && n100 != 12 ? 'two' : n10 == 3 && n100 != 13 ? 'few' : 'other';
;
});
_globalizeRuntime2.default.b1125263556 = pluralGeneratorFn(function (n) {
var s = String(n).split('.'),
v0 = !s[1];
return n == 1 && v0 ? 'one' : 'other';
});
```
Notice that the cardinal plural generator and the default plural generator have the same function body. Calling without args should reference the same function as calling with default args, else there is duplication in the compiled code.
Contributor guide
Assessment
This issue has not been assessed yet.