Skip to content

Commit 0de68cd

Browse files
committed
Changes from code reviews
1 parent 4463243 commit 0de68cd

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
@@ -4780,8 +4780,8 @@ export function RoundDuration(
47804780
// First convert time units up to days, if rounding to days or higher units.
47814781
// If rounding relative to a ZonedDateTime, then some days may not be 24h.
47824782
// TS doesn't know that `dayLengthNs` is only used if the unit is day or
4783-
// larger. This makes the cast below acceptable.
4784-
let dayLengthNs: JSBI = undefined as unknown as JSBI;
4783+
// larger. We'll cast away `undefined` when it's used lower down below.
4784+
let dayLengthNs: JSBI | undefined;
47854785
if (unit === 'year' || unit === 'month' || unit === 'week' || unit === 'day') {
47864786
nanoseconds = TotalDurationNanoseconds(0, hours, minutes, seconds, milliseconds, microseconds, nanosecondsParam, 0);
47874787
let intermediate;
@@ -4847,9 +4847,12 @@ export function RoundDuration(
48474847
// the duration. This lets us do days-or-larger rounding using BigInt
48484848
// math which reduces precision loss.
48494849
oneYearDays = MathAbs(oneYearDays);
4850-
const divisor = JSBI.multiply(JSBI.BigInt(oneYearDays), dayLengthNs);
4850+
// dayLengthNs is never undefined if unit is `day` or larger.
4851+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4852+
const divisor = JSBI.multiply(JSBI.BigInt(oneYearDays), dayLengthNs!);
48514853
nanoseconds = JSBI.add(
4852-
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(years)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs)),
4854+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4855+
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(years)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs!)),
48534856
nanoseconds
48544857
);
48554858
const rounded = RoundNumberToIncrement(
@@ -4903,9 +4906,12 @@ export function RoundDuration(
49034906
({ relativeTo, days: oneMonthDays } = MoveRelativeDate(calendar, relativeTo, oneMonth));
49044907
}
49054908
oneMonthDays = MathAbs(oneMonthDays);
4906-
const divisor = JSBI.multiply(JSBI.BigInt(oneMonthDays), dayLengthNs);
4909+
// dayLengthNs is never undefined if unit is `day` or larger.
4910+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4911+
const divisor = JSBI.multiply(JSBI.BigInt(oneMonthDays), dayLengthNs!);
49074912
nanoseconds = JSBI.add(
4908-
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(months)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs)),
4913+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4914+
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(months)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs!)),
49094915
nanoseconds
49104916
);
49114917
const rounded = RoundNumberToIncrement(
@@ -4933,9 +4939,12 @@ export function RoundDuration(
49334939
({ relativeTo, days: oneWeekDays } = MoveRelativeDate(calendar, relativeTo, oneWeek));
49344940
}
49354941
oneWeekDays = MathAbs(oneWeekDays);
4936-
const divisor = JSBI.multiply(JSBI.BigInt(oneWeekDays), dayLengthNs);
4942+
// dayLengthNs is never undefined if unit is `day` or larger.
4943+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4944+
const divisor = JSBI.multiply(JSBI.BigInt(oneWeekDays), dayLengthNs!);
49374945
nanoseconds = JSBI.add(
4938-
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(weeks)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs)),
4946+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4947+
JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(weeks)), JSBI.multiply(JSBI.BigInt(days), dayLengthNs!)),
49394948
nanoseconds
49404949
);
49414950
const rounded = RoundNumberToIncrement(
@@ -4950,7 +4959,9 @@ export function RoundDuration(
49504959
break;
49514960
}
49524961
case 'day': {
4953-
const divisor = dayLengthNs;
4962+
// dayLengthNs is never undefined if unit is `day` or larger.
4963+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4964+
const divisor = dayLengthNs!;
49544965
nanoseconds = JSBI.add(JSBI.multiply(divisor, JSBI.BigInt(days)), nanoseconds);
49554966
const rounded = RoundNumberToIncrement(
49564967
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)