Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit 4460cb1

Browse files
committed
* fixing the resolution of the ancestor by traversing until we find date calendar / numbers fields, this should fix the problems with fr-FR vs fr, which are suppose to be the exact same.
* removing dead code from tasks * removing old tasks.
1 parent 5e34203 commit 4460cb1

8 files changed

+56
-357
lines changed

tasks/compile-data.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* jshint node:true */
2+
13
/**
24
* Compiles all JSON data into the polyfill and saves it as Intl.complete.js
35
*/

tasks/extract-cldr-data.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* jshint node:true */
2+
13
/**
24
* Compiles all JSON data into the polyfill and saves it as Intl.complete.js
35
*/

tasks/getIntlData.js

-161
This file was deleted.

tasks/update-tests.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* jshint node:true */
2+
13
/* updating tests from tests/test262 */
24

35
var LIBS = {
@@ -147,8 +149,8 @@ function processTest(content) {
147149
// Make sure to use our version (not one the browser might have).
148150
content = content.replace(/\bIntl\b/g, 'IntlPolyfill');
149151

150-
var explainV8OptOut = '// This test is disabled to avoid the v8 bug outlined at https://code.google.com/p/v8/issues/detail?id=2694',
151-
explainES6OptOut = '// This test is disabled because it relies on ES 2015 behaviour, which is not implemented in environments that need this polyfill',
152+
var explainV8OptOut = '// This test is disabled to avoid the v8 bug outlined at https://code.google.com/p/v8/issues/detail?id=2694';
153+
var explainES6OptOut = '// This test is disabled because it relies on ES 2015 behaviour, which is not implemented in environments that need this polyfill';
152154

153155
// Due to a bug in v8, we need to disable parts of the _L15 tests that
154156
// check the function property `length` is not writable

tasks/utils/extract-calendars.js

+13-34
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
/*
2-
* Copyright 2015, Yahoo Inc.
3-
* Copyrights licensed under the New BSD License.
4-
* See the accompanying LICENSE file for terms.
5-
*/
1+
/* jshint node:true */
2+
63
'use strict';
74

85
var path = require('path');
@@ -31,48 +28,30 @@ module.exports = function extractCalendars(locales) {
3128
}
3229
}
3330

34-
// Hashes and caches the `calendars` for a given `locale` to avoid hashing more
35-
// than once since it could be expensive.
36-
function hashCalendars(locale, calendars) {
37-
var hash = hashes[locale];
38-
if (hash) {
39-
return hash;
31+
// This will traverse the hierarchy for the
32+
// given `locale` until it finds an ancestor with date calendars.
33+
function findLocaleWithCalendar(locale) {
34+
// The "root" locale is the top level ancestor.
35+
if (locale === 'root') {
36+
return 'root';
4037
}
4138

42-
hash = hashes[locale] = JSON.stringify(calendars);
43-
return hash;
44-
}
45-
46-
// We want to de-dup data that can be referenced from upstream in the
47-
// `locale`'s hierarchy when that locale's date calendars are the _exact_
48-
// same as one of its ancestors. This will traverse the hierarchy for the
49-
// given `locale` until it finds an ancestor with same same date calendars.
50-
// When an ancestor can't be found, a data entry must be created for the
51-
// `locale` since its date calendars are unique.
52-
function findGreatestAncestor(locale) {
53-
// The "root" locale is not a suitable ancestor, because there won't be
54-
// an entry for "root" in the final data object.
55-
var parentLocale = getParentLocale(locale);
56-
if (!parentLocale || parentLocale === 'root') {
57-
return 'root';
39+
if (hasCalendars(locale)) {
40+
return locale;
5841
}
5942

6043
// When the `locale` doesn't have calendars data, we need to traverse up
6144
// its hierarchy to find suitable date calendars data.
62-
if (!hasCalendars(locale)) {
63-
return findGreatestAncestor(parentLocale);
64-
}
65-
66-
return locale;
45+
return findLocaleWithCalendar(getParentLocale(locale));
6746
}
6847

6948
return locales.reduce(function (calendars, locale) {
7049
locale = normalizeLocale(locale);
7150

7251
// Walk the `locale`'s hierarchy to look for suitable ancestor with the
73-
// _exact_ same date calendars. If no ancestor is found, the given
52+
// date calendars. If no ancestor is found, the given
7453
// `locale` will be returned.
75-
var resolvedLocale = hasCalendars(locale) ? locale : findGreatestAncestor(locale);
54+
var resolvedLocale = findLocaleWithCalendar(locale);
7655

7756
// Add an entry for the `locale`, which might be an ancestor. If the
7857
// locale doesn't have relative fields, then we fallback to the "root"

tasks/utils/extract-numbers.js

+13-30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* jshint node:true */
2+
13
'use strict';
24

35
var path = require('path');
@@ -24,49 +26,30 @@ module.exports = function extractNumbersFields(locales) {
2426
}
2527
}
2628

27-
// Hashes and caches the `numbers` for a given `locale` to avoid hashing more
28-
// than once since it could be expensive.
29-
function hashNumbers(locale, numbers) {
30-
var hash = hashes[locale];
31-
if (hash) {
32-
return hash;
29+
// This will traverse the hierarchy for the
30+
// given `locale` until it finds an ancestor with numbers fields.
31+
function findLocaleWithNumbersFields(locale) {
32+
// The "root" locale is the top level ancestor.
33+
if (locale === 'root') {
34+
return 'root';
3335
}
3436

35-
hash = hashes[locale] = JSON.stringify(numbers);
36-
return hash;
37-
}
38-
39-
// We want to de-dup data that can be referenced from upstream in the
40-
// `locale`'s hierarchy when that locale's numbers fields are the _exact_
41-
// same as one of its ancestors. This will traverse the hierarchy for the
42-
// given `locale` until it finds an ancestor with same same numbers fields.
43-
// When an ancestor can't be found, a data entry must be created for the
44-
// `locale` since its numbers fields are unique.
45-
function findGreatestAncestor(locale) {
46-
// The "root" locale is not a suitable ancestor, because there won't be
47-
// an entry for "root" in the final data object.
48-
var parentLocale = getParentLocale(locale);
49-
50-
if (!parentLocale || parentLocale === 'root') {
51-
return 'root';
37+
if (hasNumbersFields(locale)) {
38+
return locale;
5239
}
5340

5441
// When the `locale` doesn't have numbers fields, we need to traverse up
5542
// its hierarchy to find suitable numbers fields data.
56-
if (!hasNumbersFields(locale)) {
57-
return findGreatestAncestor(parentLocale);
58-
}
59-
60-
return locale;
43+
return findLocaleWithNumbersFields(getParentLocale(locale));
6144
}
6245

6346
return locales.reduce(function (numbers, locale) {
6447
locale = normalizeLocale(locale);
6548

6649
// Walk the `locale`'s hierarchy to look for suitable ancestor with the
67-
// _exact_ same numbers fields. If no ancestor is found, the given
50+
// date calendars. If no ancestor is found, the given
6851
// `locale` will be returned.
69-
var resolvedLocale = hasNumbersFields(locale) ? locale : findGreatestAncestor(locale);
52+
var resolvedLocale = findLocaleWithNumbersFields(locale);
7053

7154
// Add an entry for the `locale`, which might be an ancestor. If the
7255
// locale doesn't have relative fields, then we fallback to the "root"

tasks/utils/locales.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* jshint node:true */
2+
13
'use strict';
24

35
var glob = require('glob');

0 commit comments

Comments
 (0)