Skip to content

Commit 245b568

Browse files
committed
Changes from code reviews
1 parent d5a6c76 commit 245b568

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

lib/calendar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,9 +1459,9 @@ const helperHebrew: HelperPerCalendarImpl = ObjectAssign({}, helperSharedImpl as
14591459
if (monthExtra) {
14601460
const monthInfo = this.months[monthExtra];
14611461
if (!monthInfo) throw new RangeError(`Unrecognized month from formatToParts: ${monthExtra}`);
1462-
month = (this.inLeapYear({ year }) ? monthInfo.leap : monthInfo.regular) as number;
1462+
month = this.inLeapYear({ year }) ? monthInfo.leap : monthInfo.regular;
14631463
}
1464-
// if we're getting data from legacy Date, then `month` will always be present
1464+
// Because we're getting data from legacy Date, then `month` will always be present
14651465
monthCode = this.getMonthCode(year, month as number);
14661466
const result = { year, month, day, era: undefined as string | undefined, eraYear, monthCode };
14671467
return result;

lib/ecmascript.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4756,8 +4756,8 @@ export function RoundDuration(
47564756
// First convert time units up to days, if rounding to days or higher units.
47574757
// If rounding relative to a ZonedDateTime, then some days may not be 24h.
47584758
// TS doesn't know that `dayLengthNs` is only used if the unit is day or
4759-
// larger. This makes the cast below acceptable.
4760-
let dayLengthNs: JSBI = undefined as unknown as JSBI;
4759+
// larger. We'll cast away `undefined` when it's used lower down below.
4760+
let dayLengthNs: JSBI | undefined;
47614761
if (unit === 'year' || unit === 'month' || unit === 'week' || unit === 'day') {
47624762
nanoseconds = TotalDurationNanoseconds(0, hours, minutes, seconds, milliseconds, microseconds, nanosecondsParam, 0);
47634763
let intermediate;
@@ -4823,9 +4823,12 @@ export function RoundDuration(
48234823
// the duration. This lets us do days-or-larger rounding using BigInt
48244824
// math which reduces precision loss.
48254825
oneYearDays = MathAbs(oneYearDays);
4826-
const divisor = JSBI.multiply(JSBI.BigInt(oneYearDays), dayLengthNs);
4826+
// dayLengthNs is never undefined if unit is `day` or larger.
4827+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4828+
const divisor = JSBI.multiply(JSBI.BigInt(oneYearDays), dayLengthNs!);
48274829
nanoseconds = JSBI.add(
4828-
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(years)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs)),
4830+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4831+
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(years)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs!)),
48294832
nanoseconds
48304833
);
48314834
const rounded = RoundNumberToIncrement(
@@ -4879,9 +4882,12 @@ export function RoundDuration(
48794882
({ relativeTo, days: oneMonthDays } = MoveRelativeDate(calendar, relativeTo, oneMonth));
48804883
}
48814884
oneMonthDays = MathAbs(oneMonthDays);
4882-
const divisor = JSBI.multiply(JSBI.BigInt(oneMonthDays), dayLengthNs);
4885+
// dayLengthNs is never undefined if unit is `day` or larger.
4886+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4887+
const divisor = JSBI.multiply(JSBI.BigInt(oneMonthDays), dayLengthNs!);
48834888
nanoseconds = JSBI.add(
4884-
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(months)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs)),
4889+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4890+
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(months)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs!)),
48854891
nanoseconds
48864892
);
48874893
const rounded = RoundNumberToIncrement(
@@ -4909,9 +4915,12 @@ export function RoundDuration(
49094915
({ relativeTo, days: oneWeekDays } = MoveRelativeDate(calendar, relativeTo, oneWeek));
49104916
}
49114917
oneWeekDays = MathAbs(oneWeekDays);
4912-
const divisor = JSBI.multiply(JSBI.BigInt(oneWeekDays), dayLengthNs);
4918+
// dayLengthNs is never undefined if unit is `day` or larger.
4919+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4920+
const divisor = JSBI.multiply(JSBI.BigInt(oneWeekDays), dayLengthNs!);
49134921
nanoseconds = JSBI.add(
4914-
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(weeks)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs)),
4922+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4923+
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(weeks)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs!)),
49154924
nanoseconds
49164925
);
49174926
const rounded = RoundNumberToIncrement(
@@ -4926,7 +4935,9 @@ export function RoundDuration(
49264935
break;
49274936
}
49284937
case 'day': {
4929-
const divisor = dayLengthNs;
4938+
// dayLengthNs is never undefined if unit is `day` or larger.
4939+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4940+
const divisor = dayLengthNs!;
49304941
nanoseconds = JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(days)), nanoseconds);
49314942
const rounded = RoundNumberToIncrement(
49324943
nanoseconds,

lib/intrinsicclass.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,17 @@ export function MakeIntrinsicClass(
9696
});
9797
}
9898
for (const prop of Object.getOwnPropertyNames(Class)) {
99-
const desc = Object.getOwnPropertyDescriptor(Class, prop) as PropertyDescriptor;
99+
// we know that `prop` is present, so the descriptor is never undefined
100+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
101+
const desc = Object.getOwnPropertyDescriptor(Class, prop)!;
100102
if (!desc.configurable || !desc.enumerable) continue;
101103
desc.enumerable = false;
102104
Object.defineProperty(Class, prop, desc);
103105
}
104106
for (const prop of Object.getOwnPropertyNames(Class.prototype)) {
105-
const desc = Object.getOwnPropertyDescriptor(Class.prototype, prop) as PropertyDescriptor;
107+
// we know that `prop` is present, so the descriptor is never undefined
108+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
109+
const desc = Object.getOwnPropertyDescriptor(Class.prototype, prop)!;
106110
if (!desc.configurable || !desc.enumerable) continue;
107111
desc.enumerable = false;
108112
Object.defineProperty(Class.prototype, prop, desc);

0 commit comments

Comments
 (0)