Skip to content

Commit 97d20d6

Browse files
committed
Polyfill: Access Call directly in calendar.mjs, not via ES object
To eventually break the circular dependency between calendar.mjs and ecmascript.mjs, we will need to stop accessing the ES object in the latter file. Since we already import Call directly from es-abstract, this is a trivial step down that path.
1 parent 878f93d commit 97d20d6

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

polyfill/lib/calendar.mjs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ const nonIsoHelperBase = {
480480
}
481481

482482
try {
483-
return ES.Call(IntlDateTimeFormatPrototypeFormatToParts, dateTimeFormat, [legacyDate]);
483+
return Call(IntlDateTimeFormatPrototypeFormatToParts, dateTimeFormat, [legacyDate]);
484484
} catch (e) {
485485
throw new RangeErrorCtor(`Invalid ISO date: ${isoString}`);
486486
}
@@ -505,7 +505,7 @@ const nonIsoHelperBase = {
505505
}
506506
}
507507
if (type === 'month') {
508-
const matches = ES.Call(RegExpPrototypeExec, /^([0-9]*)(.*?)$/, [value]);
508+
const matches = Call(RegExpPrototypeExec, /^([0-9]*)(.*?)$/, [value]);
509509
if (!matches || matches.length != 3 || (!matches[1] && !matches[2])) {
510510
throw new RangeErrorCtor(`Unexpected month: ${value}`);
511511
}
@@ -544,11 +544,11 @@ const nonIsoHelperBase = {
544544
// The call to normalize() and the replacement regex deals with era
545545
// names that contain non-ASCII characters like Japanese eras. Also
546546
// ignore extra content in parentheses like JPN era date ranges.
547-
value = ES.Call(StringPrototypeSplit, value, [' ('])[0];
548-
value = ES.Call(StringPrototypeNormalize, value, ['NFD']);
549-
value = ES.Call(StringPrototypeReplace, value, [/[^-0-9 \p{L}]/gu, '']);
550-
value = ES.Call(StringPrototypeReplace, value, [/ /g, '-']);
551-
value = ES.Call(StringPrototypeToLowerCase, value, []);
547+
value = Call(StringPrototypeSplit, value, [' ('])[0];
548+
value = Call(StringPrototypeNormalize, value, ['NFD']);
549+
value = Call(StringPrototypeReplace, value, [/[^-0-9 \p{L}]/gu, '']);
550+
value = Call(StringPrototypeReplace, value, [/ /g, '-']);
551+
value = Call(StringPrototypeToLowerCase, value, []);
552552
result.era = value;
553553
}
554554
}
@@ -561,7 +561,7 @@ const nonIsoHelperBase = {
561561
}
562562
// Translate old ICU era codes "ERA0" etc. into canonical era names.
563563
if (hasEra) {
564-
const replacement = ES.Call(ArrayPrototypeFind, this.eras, [(e) => result.era === e.genericName]);
564+
const replacement = Call(ArrayPrototypeFind, this.eras, [(e) => result.era === e.genericName]);
565565
if (replacement) result.era = replacement.code;
566566
}
567567
// Translate eras that may be handled differently by Temporal vs. by Intl
@@ -591,7 +591,7 @@ const nonIsoHelperBase = {
591591
});
592592
cache.set(keyReverse, isoDate);
593593
};
594-
ES.Call(ArrayPrototypeForEach, ['constrain', 'reject'], [cacheReverse]);
594+
Call(ArrayPrototypeForEach, ['constrain', 'reject'], [cacheReverse]);
595595
return calendarDate;
596596
},
597597
validateCalendarDate(calendarDate) {
@@ -605,7 +605,7 @@ const nonIsoHelperBase = {
605605
if (monthCode !== undefined) {
606606
if (typeof monthCode !== 'string') {
607607
throw new RangeErrorCtor(
608-
`monthCode must be a string, not ${ES.Call(StringPrototypeToLowerCase, Type(monthCode), [])}`
608+
`monthCode must be a string, not ${Call(StringPrototypeToLowerCase, Type(monthCode), [])}`
609609
);
610610
}
611611
const { monthNumber } = ParseMonthCode(monthCode);
@@ -622,7 +622,7 @@ const nonIsoHelperBase = {
622622
const eraFromYear = (year) => {
623623
let eraYear;
624624
const adjustedCalendarDate = { ...calendarDate, year };
625-
const ix = ES.Call(ArrayPrototypeFindIndex, this.eras, [
625+
const ix = Call(ArrayPrototypeFindIndex, this.eras, [
626626
(e, i) => {
627627
if (i === this.eras.length - 1) {
628628
if (e.skip) {
@@ -663,16 +663,16 @@ const nonIsoHelperBase = {
663663
if (
664664
calendarDate.era !== undefined &&
665665
calendarDate.era !== era &&
666-
!ES.Call(ArrayPrototypeIncludes, matchData?.eraNames ?? [], [calendarDate.era])
666+
!Call(ArrayPrototypeIncludes, matchData?.eraNames ?? [], [calendarDate.era])
667667
) {
668668
throw new RangeErrorCtor(`Input era ${calendarDate.era} doesn't match calculated value ${era}`);
669669
}
670670
if (calendarDate.eraYear !== undefined && calendarDate.eraYear !== eraYear) {
671671
throw new RangeErrorCtor(`Input eraYear ${calendarDate.eraYear} doesn't match calculated value ${eraYear}`);
672672
}
673673
} else if (eraYear !== undefined) {
674-
const matchingEra = ES.Call(ArrayPrototypeFind, this.eras, [
675-
({ code, names = [] }) => code === era || ES.Call(ArrayPrototypeIncludes, names, [era])
674+
const matchingEra = Call(ArrayPrototypeFind, this.eras, [
675+
({ code, names = [] }) => code === era || Call(ArrayPrototypeIncludes, names, [era])
676676
]);
677677
if (!matchingEra) throw new RangeErrorCtor(`Era ${era} (ISO year ${eraYear}) was not matched by any era`);
678678
if (matchingEra.reverseOf) {
@@ -1126,7 +1126,7 @@ const helperHebrew = makeNonISOHelper([{ code: 'am', isoEpoch: { year: -3760, mo
11261126
minMaxMonthLength(calendarDate, minOrMax) {
11271127
const { month, year } = calendarDate;
11281128
const monthCode = this.getMonthCode(year, month);
1129-
const monthInfo = ES.Call(ArrayPrototypeFind, ObjectEntries(this.months), [(m) => m[1].monthCode === monthCode]);
1129+
const monthInfo = Call(ArrayPrototypeFind, ObjectEntries(this.months), [(m) => m[1].monthCode === monthCode]);
11301130
if (monthInfo === undefined) throw new RangeErrorCtor(`unmatched Hebrew month: ${month}`);
11311131
const daysInMonth = monthInfo[1].days;
11321132
return typeof daysInMonth === 'number' ? daysInMonth : daysInMonth[minOrMax];
@@ -1365,7 +1365,7 @@ const helperIndian = makeNonISOHelper([{ code: 'shaka', isoEpoch: { year: 79, mo
13651365
// in Node 12 0000-01-01 is calculated as 6146/12/-583 instead of 10/11/-79 as
13661366
// expected.
13671367
vulnerableToBceBug:
1368-
ES.Call(DatePrototypeToLocaleDateString, new DateCtor('0000-01-01T00:00Z'), [
1368+
Call(DatePrototypeToLocaleDateString, new DateCtor('0000-01-01T00:00Z'), [
13691369
'en-US-u-ca-indian',
13701370
{ timeZone: 'UTC' }
13711371
]) !== '10/11/-79 Saka',
@@ -1442,15 +1442,15 @@ function adjustEras(eras) {
14421442
if (eras.length === 1 && !eras[0].code) {
14431443
throw new RangeErrorCtor('Invalid era data: at least one named era is required');
14441444
}
1445-
if (ES.Call(ArrayPrototypeFilter, eras, [(e) => e.reverseOf != null]).length > 1) {
1445+
if (Call(ArrayPrototypeFilter, eras, [(e) => e.reverseOf != null]).length > 1) {
14461446
throw new RangeErrorCtor('Invalid era data: only one era can count years backwards');
14471447
}
14481448

14491449
// Find the "anchor era" which is the era used for (era-less) `year`. Reversed
14501450
// eras can never be anchors. The era without an `anchorEpoch` property is the
14511451
// anchor.
14521452
let anchorEra;
1453-
ES.Call(ArrayPrototypeForEach, eras, [
1453+
Call(ArrayPrototypeForEach, eras, [
14541454
(e) => {
14551455
if (e.isAnchor || (!e.anchorEpoch && !e.reverseOf)) {
14561456
if (anchorEra) throw new RangeErrorCtor('Invalid era data: cannot have multiple anchor eras');
@@ -1466,16 +1466,16 @@ function adjustEras(eras) {
14661466
// with eras at all. For example, Japanese `year` is always the same as ISO
14671467
// `year`. So this "era" is the anchor era but isn't used for era matching.
14681468
// Strip it from the list that's returned.
1469-
eras = ES.Call(ArrayPrototypeFilter, eras, [(e) => e.code]);
1469+
eras = Call(ArrayPrototypeFilter, eras, [(e) => e.code]);
14701470

1471-
ES.Call(ArrayPrototypeForEach, eras, [
1471+
Call(ArrayPrototypeForEach, eras, [
14721472
(e) => {
14731473
// Some eras are mirror images of another era e.g. B.C. is the reverse of A.D.
14741474
// Replace the string-valued "reverseOf" property with the actual era object
14751475
// that's reversed.
14761476
const { reverseOf } = e;
14771477
if (reverseOf) {
1478-
const reversedEra = ES.Call(ArrayPrototypeFind, eras, [(era) => era.code === reverseOf]);
1478+
const reversedEra = Call(ArrayPrototypeFind, eras, [(era) => era.code === reverseOf]);
14791479
if (reversedEra === undefined) {
14801480
throw new RangeErrorCtor(`Invalid era data: unmatched reverseOf era: ${reverseOf}`);
14811481
}
@@ -1512,7 +1512,7 @@ function adjustEras(eras) {
15121512
// Finally, add a "genericName" property in the format "era{n} where `n` is
15131513
// zero-based index, with the oldest era being zero. This format is used by
15141514
// older versions of ICU data.
1515-
ES.Call(ArrayPrototypeForEach, eras, [
1515+
Call(ArrayPrototypeForEach, eras, [
15161516
(e, i) => {
15171517
e.genericName = `era${eras.length - 1 - i}`;
15181518
}
@@ -1543,7 +1543,7 @@ const makeHelperGregorian = (id, originalEras) => {
15431543
minimumMonthLength(calendarDate) {
15441544
const { month } = calendarDate;
15451545
if (month === 2) return this.inLeapYear(calendarDate) ? 29 : 28;
1546-
return ES.Call(ArrayPrototypeIndexOf, [4, 6, 9, 11], [month]) >= 0 ? 30 : 31;
1546+
return Call(ArrayPrototypeIndexOf, [4, 6, 9, 11], [month]) >= 0 ? 30 : 31;
15471547
},
15481548
maximumMonthLength(calendarDate) {
15491549
return this.minimumMonthLength(calendarDate);
@@ -1722,7 +1722,7 @@ const helperJapanese = ObjectAssign(
17221722
reviseIntlEra(calendarDate, isoDate) {
17231723
const { era, eraYear } = calendarDate;
17241724
const { year: isoYear } = isoDate;
1725-
if (ES.Call(ArrayPrototypeFind, this.eras, [(e) => e.code === era])) return { era, eraYear };
1725+
if (Call(ArrayPrototypeFind, this.eras, [(e) => e.code === era])) return { era, eraYear };
17261726
return isoYear < 1 ? { era: 'bce', eraYear: 1 - isoYear } : { era: 'ce', eraYear: isoYear };
17271727
}
17281728
}
@@ -1800,11 +1800,11 @@ const helperChinese = ObjectAssign({}, nonIsoHelperBase, {
18001800
const isoStringFeb1 = toUtcIsoDateString({ isoYear, isoMonth: 2, isoDay: 1 });
18011801
const legacyDate = new DateCtor(isoStringFeb1);
18021802
// Now add the requested number of days, which may wrap to the next month.
1803-
ES.Call(DatePrototypeSetUTCDate, legacyDate, [daysPastFeb1 + 1]);
1804-
const newYearGuess = ES.Call(IntlDateTimeFormatPrototypeFormatToParts, dateTimeFormat, [legacyDate]);
1805-
const calendarMonthString = ES.Call(ArrayPrototypeFind, newYearGuess, [(tv) => tv.type === 'month']).value;
1806-
const calendarDay = +ES.Call(ArrayPrototypeFind, newYearGuess, [(tv) => tv.type === 'day']).value;
1807-
let calendarYearToVerify = ES.Call(ArrayPrototypeFind, newYearGuess, [(tv) => tv.type === 'relatedYear']);
1803+
Call(DatePrototypeSetUTCDate, legacyDate, [daysPastFeb1 + 1]);
1804+
const newYearGuess = Call(IntlDateTimeFormatPrototypeFormatToParts, dateTimeFormat, [legacyDate]);
1805+
const calendarMonthString = Call(ArrayPrototypeFind, newYearGuess, [(tv) => tv.type === 'month']).value;
1806+
const calendarDay = +Call(ArrayPrototypeFind, newYearGuess, [(tv) => tv.type === 'day']).value;
1807+
let calendarYearToVerify = Call(ArrayPrototypeFind, newYearGuess, [(tv) => tv.type === 'relatedYear']);
18081808
if (calendarYearToVerify !== undefined) {
18091809
calendarYearToVerify = +calendarYearToVerify.value;
18101810
} else {
@@ -1911,15 +1911,13 @@ const helperChinese = ObjectAssign({}, nonIsoHelperBase, {
19111911
month = ES.ConstrainToRange(month, 1, largestMonth);
19121912
day = ES.ConstrainToRange(day, 1, this.maximumMonthLength());
19131913
}
1914-
const matchingMonthEntry = ES.Call(ArrayPrototypeFind, monthEntries, [
1915-
(entry) => entry[1].monthIndex === month
1916-
]);
1914+
const matchingMonthEntry = Call(ArrayPrototypeFind, monthEntries, [(entry) => entry[1].monthIndex === month]);
19171915
if (matchingMonthEntry === undefined) {
19181916
throw new RangeErrorCtor(`Invalid month ${month} in Chinese year ${year}`);
19191917
}
19201918
monthCode = CreateMonthCode(
1921-
ES.Call(StringPrototypeReplace, matchingMonthEntry[0], ['bis', '']),
1922-
ES.Call(StringPrototypeIndexOf, matchingMonthEntry[0], ['bis']) !== -1
1919+
Call(StringPrototypeReplace, matchingMonthEntry[0], ['bis', '']),
1920+
Call(StringPrototypeIndexOf, matchingMonthEntry[0], ['bis']) !== -1
19231921
);
19241922
} else {
19251923
// Both month and monthCode are present. Make sure they don't conflict.
@@ -2064,7 +2062,7 @@ const nonIsoGeneralImpl = {
20642062
};
20652063

20662064
impl['hebrew'] = ObjectAssign({}, nonIsoGeneralImpl, { helper: helperHebrew });
2067-
ES.Call(
2065+
Call(
20682066
ArrayPrototypeForEach,
20692067
[
20702068
{ id: 'islamic-umalqura', firstDay: 20 },

0 commit comments

Comments
 (0)