-
Notifications
You must be signed in to change notification settings - Fork 136
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
feat: Add Intl.NumberFormat ES2020 polyfill #642
Conversation
Thanks for this pull request @longlho :-)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this pull request @longlho :-)
I ran the tests on our CI and they look to fail on chrome 29 up to chrome 76, specifically it is the feature detect which is not working correctly when the polyfill is applied.
-> Intl.NumberFormat passes the feature detect
http://bs-local.com:9876/test?includePolyfills=yes&always=no&feature=Intl.NumberFormat
false == true
any suggestion on how to repro (other than asking you to re-run in your pipeline)? |
depends on formatjs/formatjs#1684 |
@longlho now that formatjs/formatjs#1684 is merged, do you know how we bring the update into this pull-request? |
yup ill tackle that today |
fixed :) |
@longlho it looks like the feature detect in Here is the test failure we saw for this in CI:
|
Hmm how is the polyfill loaded btw? It needs to load the |
That is a good point, we should not load in the locale for Perhaps we can have a less thorough feature detect like the other Intl polyfills we have? So instead of this: 'Intl' in self && 'NumberFormat' in self.Intl && (function () {
try {
new Intl.NumberFormat(undefined, {
style: 'unit',
unit: 'byte',
});
} catch (e) {
return false;
}
return true;
})() We have this: 'Intl' in self && 'NumberFormat' in self.Intl Would that detect be enough or do we need to instantiate Intl.NumberFormat with a style? |
@longlho How about this feature detect instead? 'Intl' in self && 'NumberFormat' in self.Intl && (function () {
try {
var options = {
compactDisplay: 'long'
};
var notationSupport = false;
Object.defineProperty(options, 'notation', {
get: function() {
notationSupport = true;
return 'compact';
}
});
var compactDisplaySupport = false;
Object.defineProperty(options, 'compactDisplay', {
get: function() {
compactDisplay = true;
return 'long';
}
});
new Intl.NumberFormat(undefined, options).format(1_807_687.733);
return notationSupport && compactDisplaySupport;
} catch (e) {
return false;
}
return true;
})() |
Let me double check our implementation but that might work. The issue might be that due to https://tc39.es/ecma402/#sec-initializenumberformat step 11 we try to resolve the locale 1st, and since there's no locale it might crap out. |
Yeah it's technically not spec-compliant to not check for a locale, since it expects at least 1 locale (DefaultLocale) to be loaded... |
Ah yes, I think I understand, for the detect to pass we must first insert some locale data into it. Let me see if I need to rework our test-runner to make that possible. |
Our test-runner creates a This means we can write a |
The tests all passed :-) https://github.com/Financial-Times/polyfill-library/runs/758174562 |
awesome thanks a lot @JakeChampion ! |
fixes #553