Skip to content

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

@casey-speer

Description

@casey-speer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions