Skip to content

Commit c1d0d84

Browse files
committed
Additonal validation for hard-coded era data
This adds an additional check to make sure that the (hard-coded) era definitions for each calendar aren't missing required `isoEpoch` properties. Note that this code is only run once at load time, not each time calendars are accessed, so there's no runtime impact.
1 parent fe846a3 commit c1d0d84

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/calendar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,7 @@ function adjustEras(erasParam: InputEra[]): { eras: Era[]; anchorEra: Era } {
16541654
ArraySort.call(eras, (e1, e2) => {
16551655
if (e1.reverseOf) return 1;
16561656
if (e2.reverseOf) return -1;
1657+
if (!e1.isoEpoch || !e2.isoEpoch) throw new RangeError('Invalid era data: missing ISO epoch');
16571658
return e2.isoEpoch.year - e1.isoEpoch.year;
16581659
});
16591660

0 commit comments

Comments
 (0)