Skip to content

Commit

Permalink
Normative: Remove support for nested calendar property bags
Browse files Browse the repository at this point in the history
Previously, "nested" calendar property bags were unwrapped up to one
level. That is, this object:
{
  calendar: {
     // ...Temporal.Calendar methods
  }
}
would not be considered to implement the Calendar protocol, but would have
its calendar property used instead, if it were passed to an API that
required a Calendar protocol object.

These nested property bags are no longer supported. Discussion:
tc39/proposal-temporal#2104 (comment)

See: #2104

UPSTREAM_COMMIT=f431988a6eb4b02c056af820aa7f3c0d0d973d22
  • Loading branch information
ptomato authored and justingrant committed Apr 25, 2023
1 parent 1b3a754 commit 661bac0
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions lib/ecmascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2401,35 +2401,23 @@ export function CalendarInLeapYear(calendar: CalendarSlot, dateLike: CalendarPro
return result;
}

export function ToTemporalCalendarSlotValue(calendarLikeParam: string | { calendar: string }): string;
export function ToTemporalCalendarSlotValue(calendarLike: string | { calendar: string }): string;
export function ToTemporalCalendarSlotValue(
calendarLikeParam: Temporal.CalendarProtocol | { calendar: Temporal.CalendarProtocol }
calendarLike: Temporal.CalendarProtocol | { calendar: Temporal.CalendarProtocol }
): Temporal.CalendarProtocol;
export function ToTemporalCalendarSlotValue(
calendarLikeParam: string | Temporal.CalendarProtocol | { calendar: string | Temporal.CalendarProtocol }
calendarLike: string | Temporal.CalendarProtocol | { calendar: string | Temporal.CalendarProtocol }
): string | Temporal.CalendarProtocol;
export function ToTemporalCalendarSlotValue(calendarLikeParam: CalendarParams['from'][0]) {
let calendarLike = calendarLikeParam;
export function ToTemporalCalendarSlotValue(calendarLike: CalendarParams['from'][0]) {
if (IsObject(calendarLike)) {
if (IsTemporalCalendar(calendarLike)) return calendarLike;
if (HasSlot(calendarLike, CALENDAR)) return GetSlot(calendarLike, CALENDAR);
if (IsTemporalTime(calendarLike)) {
throw new RangeError('Expected a calendar object but received a Temporal.PlainTime');
}
if (IsTemporalTimeZone(calendarLike)) {
throw new RangeError('Expected a calendar object but received a Temporal.TimeZone');
}
if (!('calendar' in calendarLike)) return calendarLike;
calendarLike = (calendarLike as { calendar: string | Temporal.CalendarProtocol }).calendar;
if (IsObject(calendarLike)) {
if (IsTemporalTime(calendarLike)) {
throw new RangeError('Expected a calendar object as the calendar property but received a Temporal.PlainTime');
}
if (IsTemporalTimeZone(calendarLike)) {
throw new RangeError('Expected a calendar object as the calendar property but received a Temporal.TimeZone');
}
if (!('calendar' in calendarLike)) return calendarLike;
}
return calendarLike;
}
const identifier = ToString(calendarLike);
if (IsBuiltinCalendar(identifier)) return ASCIILowercase(identifier);
Expand Down

0 comments on commit 661bac0

Please sign in to comment.