tc39 / proposal-intl-numberformat-v3

Additional features for Intl.NumberFormat to solve key pain points.
MIT License
53 stars 12 forks source link

Fix #74 #92

Closed romulocintra closed 2 years ago

romulocintra commented 2 years ago

closes #74

sffc commented 2 years ago

Hmm. Before, we had

        1. Let _value_ be ? Get(_options_, _property_).
        1. If _value_ is *undefined*, return _fallback_.
        1. If _value_ is *true*, return _trueValue_.
        1. Let _valueBoolean_ be ToBoolean(_value_).
        1. If _valueBoolean_ is *false*, return _falsyValue_.
        1. Let _value_ be ? ToString(_value_).
        1. If _values_ does not contain an element equal to _value_, throw a *RangeError* exception.
        1. Return _value_.

What if we just change the exception to return _trueValue_, like

        1. Let _value_ be ? Get(_options_, _property_).
        1. If _value_ is *undefined*, return _fallback_.
        1. If _value_ is *true*, return _trueValue_.
        1. Let _valueBoolean_ be ToBoolean(_value_).
        1. If _valueBoolean_ is *false*, return _falsyValue_.
        1. Let _value_ be ? ToString(_value_).
        1. If _values_ does not contain an element equal to _value_, return _trueValue_.
        1. Return _value_.
romulocintra commented 2 years ago

What if we just change the exception to return _trueValue_, like

        1. Let _value_ be ? Get(_options_, _property_).
        1. If _value_ is *undefined*, return _fallback_.
        1. If _value_ is *true*, return _trueValue_.
        1. Let _valueBoolean_ be ToBoolean(_value_).
        1. If _valueBoolean_ is *false*, return _falsyValue_.
        1. Let _value_ be ? ToString(_value_).
        1. If _values_ does not contain an element equal to _value_, return _trueValue_.
        1. Return _value_.

In that case, all strings not contained in list of valid ones will have trueValue behaviour of "always" that might be confusing due to that defaultGrouping it's auto. And how about the use case string "false"?

sffc commented 2 years ago

OK, how about

        1. Let _value_ be ? Get(_options_, _property_).
        1. If _value_ is *undefined*, return _fallback_.
        1. If _value_ is *true*, return _trueValue_.
        1. Let _valueBoolean_ be ToBoolean(_value_).
        1. If _valueBoolean_ is *false*, return _falsyValue_.
        1. Let _value_ be ? ToString(_value_).
        1. If _values_ does not contain an element equal to _value_, return _fallback_.
        1. Return _value_.

This retains the current web reality behavior because true is currently just "auto".

romulocintra commented 2 years ago

Updated the PR addressing your comments and LGTM,

OK, how about

        1. Let _value_ be ? Get(_options_, _property_).
        1. If _value_ is *undefined*, return _fallback_.
        1. If _value_ is *true*, return _trueValue_.
        1. Let _valueBoolean_ be ToBoolean(_value_).
        1. If _valueBoolean_ is *false*, return _falsyValue_.
        1. Let _value_ be ? ToString(_value_).
        1. If _values_ does not contain an element equal to _value_, return _fallback_.
        1. Return _value_.

This retains the current web reality behavior because true is currently just "auto".

This way there is no risk of breaking current web behaviour and the issue it's solved, on the other hand, throwing an error makes it more consistent with GetOption and other methods that use it.

sffc commented 2 years ago

The current behavior is

Let _useGrouping_ be ? StringOrBooleanOption(options, "useGrouping", "boolean", undefined, true).

This never fails, because the undefined means "accept all values".

sffc commented 2 years ago

@anba @FrankYFTang @constellation Take note of this change. useGrouping should not throw a RangeError any more on malformed arguments.

FrankYFTang commented 2 years ago

so.. now it will not only accept {'useGrouping': 'true'} but also {'useGrouping': 'HelloWorld'} ? Isn't that too loose?

sffc commented 2 years ago

The issue is that it already accepts {'useGrouping': 'HelloWorld'}

> new Intl.NumberFormat("en", {useGrouping: "HelloWorld"}).resolvedOptions().useGrouping
true

So this is a web compat fix.