Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A formatter call with default args should call the same compiled formatter as one with no args #35

Open
casey-speer opened this issue Aug 3, 2017 · 1 comment

Comments

@casey-speer
Copy link

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.

@casey-speer
Copy link
Author

Note: this might be an issue with globalize as well, not only the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant