You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
babel.plural.to_javascript() generates a plural function that selects different categories from PluralRule for negative counts.
Steps to Reproduce
On current master (9a3ef47), generate a JavaScript function:
frombabel.pluralimportPluralRule, to_javascriptrule=PluralRule({'one': 'n is 1', 'few': 'n in 2..4'})
print(rule(-1), rule(-2)) # one fewprint(to_javascript(rule))
Run the generated function in JavaScript:
constplural=(function(n){return(parseInt(n,10)==n&&((n>=2&&n<=4))) ? 'few' : (n==1) ? 'one' : 'other';});console.log(plural(-1),plural(-2));// other other
Actual Results
The generated JavaScript uses signed n, so negative counts miss categories that their positive counterparts match. This also affects integer-operand and modulo rules.
Expected Results
Negative counts should use their absolute value before evaluating the rules, matching PluralRule and the Unicode plural operand definition.
Reproducibility
Reproduced with CPython 3.15.0 and Node.js 22.23.3. Four new JavaScript execution regressions fail against the unchanged source and pass after normalizing the input.
Additional Information
A focused fix normalizes n once at the start of the generated function. Positive inputs and zero keep their existing categories.
Activity