Skip to content

Commit 53f32e0

Browse files
authored
Stop reassigning function parameters in all files except ecmascript.ts. (#72)
1 parent 429273e commit 53f32e0

12 files changed

+411
-358
lines changed

.eslintrc.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ rules:
5656
- error
5757
- max: 1
5858
no-trailing-spaces: error
59+
no-param-reassign:
60+
- error
61+
- props: false
5962
object-curly-spacing:
6063
- error
6164
- always
@@ -88,3 +91,10 @@ overrides:
8891
- test/validStrings.mjs
8992
rules:
9093
no-console: off
94+
- files:
95+
- test/*.mjs
96+
- test/**/*
97+
# TODO Fix these files!
98+
- lib/ecmascript.ts
99+
rules:
100+
no-param-reassign: off

lib/calendar.ts

Lines changed: 97 additions & 69 deletions
Large diffs are not rendered by default.

lib/duration.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ import { Temporal } from '..';
2020

2121
export class Duration implements Temporal.Duration {
2222
constructor(
23-
years = 0,
24-
months = 0,
25-
weeks = 0,
26-
days = 0,
27-
hours = 0,
28-
minutes = 0,
29-
seconds = 0,
30-
milliseconds = 0,
31-
microseconds = 0,
32-
nanoseconds = 0
23+
yearsParam = 0,
24+
monthsParam = 0,
25+
weeksParam = 0,
26+
daysParam = 0,
27+
hoursParam = 0,
28+
minutesParam = 0,
29+
secondsParam = 0,
30+
millisecondsParam = 0,
31+
microsecondsParam = 0,
32+
nanosecondsParam = 0
3333
) {
34-
years = ES.ToIntegerThrowOnInfinity(years);
35-
months = ES.ToIntegerThrowOnInfinity(months);
36-
weeks = ES.ToIntegerThrowOnInfinity(weeks);
37-
days = ES.ToIntegerThrowOnInfinity(days);
38-
hours = ES.ToIntegerThrowOnInfinity(hours);
39-
minutes = ES.ToIntegerThrowOnInfinity(minutes);
40-
seconds = ES.ToIntegerThrowOnInfinity(seconds);
41-
milliseconds = ES.ToIntegerThrowOnInfinity(milliseconds);
42-
microseconds = ES.ToIntegerThrowOnInfinity(microseconds);
43-
nanoseconds = ES.ToIntegerThrowOnInfinity(nanoseconds);
34+
const years = ES.ToIntegerThrowOnInfinity(yearsParam);
35+
const months = ES.ToIntegerThrowOnInfinity(monthsParam);
36+
const weeks = ES.ToIntegerThrowOnInfinity(weeksParam);
37+
const days = ES.ToIntegerThrowOnInfinity(daysParam);
38+
const hours = ES.ToIntegerThrowOnInfinity(hoursParam);
39+
const minutes = ES.ToIntegerThrowOnInfinity(minutesParam);
40+
const seconds = ES.ToIntegerThrowOnInfinity(secondsParam);
41+
const milliseconds = ES.ToIntegerThrowOnInfinity(millisecondsParam);
42+
const microseconds = ES.ToIntegerThrowOnInfinity(microsecondsParam);
43+
const nanoseconds = ES.ToIntegerThrowOnInfinity(nanosecondsParam);
4444

4545
const sign = ES.DurationSign(
4646
years,
@@ -203,11 +203,11 @@ export class Duration implements Temporal.Duration {
203203
Math.abs(GetSlot(this, NANOSECONDS))
204204
);
205205
}
206-
add(other, options = undefined) {
206+
add(other, optionsParam = undefined) {
207207
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
208208
let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
209209
ES.ToLimitedTemporalDuration(other);
210-
options = ES.GetOptionsObject(options);
210+
const options = ES.GetOptionsObject(optionsParam);
211211
const relativeTo = ES.ToRelativeTemporalObject(options);
212212
({ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = ES.AddDuration(
213213
GetSlot(this, YEARS),
@@ -234,11 +234,11 @@ export class Duration implements Temporal.Duration {
234234
));
235235
return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
236236
}
237-
subtract(other, options = undefined) {
237+
subtract(other, optionsParam = undefined) {
238238
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
239239
let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
240240
ES.ToLimitedTemporalDuration(other);
241-
options = ES.GetOptionsObject(options);
241+
const options = ES.GetOptionsObject(optionsParam);
242242
const relativeTo = ES.ToRelativeTemporalObject(options);
243243
({ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = ES.AddDuration(
244244
GetSlot(this, YEARS),
@@ -265,9 +265,9 @@ export class Duration implements Temporal.Duration {
265265
));
266266
return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
267267
}
268-
round(options) {
268+
round(optionsParam) {
269269
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
270-
if (options === undefined) throw new TypeError('options parameter is required');
270+
if (optionsParam === undefined) throw new TypeError('options parameter is required');
271271
let years = GetSlot(this, YEARS);
272272
let months = GetSlot(this, MONTHS);
273273
let weeks = GetSlot(this, WEEKS);
@@ -291,7 +291,7 @@ export class Duration implements Temporal.Duration {
291291
microseconds,
292292
nanoseconds
293293
);
294-
options = ES.GetOptionsObject(options);
294+
const options = ES.GetOptionsObject(optionsParam);
295295
let smallestUnit = ES.ToSmallestTemporalUnit(options, undefined);
296296
let smallestUnitPresent = true;
297297
if (!smallestUnit) {
@@ -374,7 +374,7 @@ export class Duration implements Temporal.Duration {
374374

375375
return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
376376
}
377-
total(options) {
377+
total(optionsParam) {
378378
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
379379
let years = GetSlot(this, YEARS);
380380
let months = GetSlot(this, MONTHS);
@@ -387,8 +387,8 @@ export class Duration implements Temporal.Duration {
387387
let microseconds = GetSlot(this, MICROSECONDS);
388388
let nanoseconds = GetSlot(this, NANOSECONDS);
389389

390-
if (options === undefined) throw new TypeError('options argument is required');
391-
options = ES.GetOptionsObject(options);
390+
if (optionsParam === undefined) throw new TypeError('options argument is required');
391+
const options = ES.GetOptionsObject(optionsParam);
392392
const unit = ES.ToTemporalDurationTotalUnit(options);
393393
if (unit === undefined) throw new RangeError('unit option is required');
394394
const relativeTo = ES.ToRelativeTemporalObject(options);
@@ -430,9 +430,9 @@ export class Duration implements Temporal.Duration {
430430
);
431431
return total;
432432
}
433-
toString(options = undefined) {
433+
toString(optionsParam = undefined) {
434434
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
435-
options = ES.GetOptionsObject(options);
435+
const options = ES.GetOptionsObject(optionsParam);
436436
const { precision, unit, increment } = ES.ToSecondsStringPrecision(options);
437437
if (precision === 'minute') throw new RangeError('smallestUnit must not be "minute"');
438438
const roundingMode = ES.ToTemporalRoundingMode(options, 'trunc');
@@ -470,10 +470,10 @@ export class Duration implements Temporal.Duration {
470470
}
471471
return ES.ToTemporalDuration(item);
472472
}
473-
static compare(one, two, options = undefined) {
474-
one = ES.ToTemporalDuration(one);
475-
two = ES.ToTemporalDuration(two);
476-
options = ES.GetOptionsObject(options);
473+
static compare(oneParam, twoParam, optionsParam = undefined) {
474+
const one = ES.ToTemporalDuration(oneParam);
475+
const two = ES.ToTemporalDuration(twoParam);
476+
const options = ES.GetOptionsObject(optionsParam);
477477
const relativeTo = ES.ToRelativeTemporalObject(options);
478478
const y1 = GetSlot(one, YEARS);
479479
const mon1 = GetSlot(one, MONTHS);

lib/instant.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ export class Instant implements Temporal.Instant {
9595
);
9696
return new Instant(ns);
9797
}
98-
until(other, options = undefined) {
98+
until(otherParam, optionsParam = undefined) {
9999
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
100-
other = ES.ToTemporalInstant(other);
101-
options = ES.GetOptionsObject(options);
100+
const other = ES.ToTemporalInstant(otherParam);
101+
const options = ES.GetOptionsObject(optionsParam);
102102
const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond', DISALLOWED_UNITS);
103103
const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('second', smallestUnit);
104104
const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, defaultLargestUnit);
@@ -128,10 +128,10 @@ export class Instant implements Temporal.Instant {
128128
const Duration = GetIntrinsic('%Temporal.Duration%');
129129
return new Duration(0, 0, 0, 0, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
130130
}
131-
since(other, options = undefined) {
131+
since(otherParam, optionsParam = undefined) {
132132
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
133-
other = ES.ToTemporalInstant(other);
134-
options = ES.GetOptionsObject(options);
133+
const other = ES.ToTemporalInstant(otherParam);
134+
const options = ES.GetOptionsObject(optionsParam);
135135
const smallestUnit = ES.ToSmallestTemporalUnit(options, 'nanosecond', DISALLOWED_UNITS);
136136
const defaultLargestUnit = ES.LargerOfTwoTemporalUnits('second', smallestUnit);
137137
const largestUnit = ES.ToLargestTemporalUnit(options, 'auto', DISALLOWED_UNITS, defaultLargestUnit);
@@ -161,10 +161,10 @@ export class Instant implements Temporal.Instant {
161161
const Duration = GetIntrinsic('%Temporal.Duration%');
162162
return new Duration(0, 0, 0, 0, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
163163
}
164-
round(options) {
164+
round(optionsParam) {
165165
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
166-
if (options === undefined) throw new TypeError('options parameter is required');
167-
options = ES.GetOptionsObject(options);
166+
if (optionsParam === undefined) throw new TypeError('options parameter is required');
167+
const options = ES.GetOptionsObject(optionsParam);
168168
const smallestUnit = ES.ToSmallestTemporalUnit(options, undefined, DISALLOWED_UNITS);
169169
if (smallestUnit === undefined) throw new RangeError('smallestUnit is required');
170170
const roundingMode = ES.ToTemporalRoundingMode(options, 'halfExpand');
@@ -181,16 +181,16 @@ export class Instant implements Temporal.Instant {
181181
const roundedNs = ES.RoundInstant(ns, roundingIncrement, smallestUnit, roundingMode);
182182
return new Instant(roundedNs);
183183
}
184-
equals(other) {
184+
equals(otherParam) {
185185
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
186-
other = ES.ToTemporalInstant(other);
186+
const other = ES.ToTemporalInstant(otherParam);
187187
const one = GetSlot(this, EPOCHNANOSECONDS);
188188
const two = GetSlot(other, EPOCHNANOSECONDS);
189189
return bigInt(one).equals(two);
190190
}
191-
toString(options = undefined) {
191+
toString(optionsParam = undefined) {
192192
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
193-
options = ES.GetOptionsObject(options);
193+
const options = ES.GetOptionsObject(optionsParam);
194194
let timeZone = options.timeZone;
195195
if (timeZone !== undefined) timeZone = ES.ToTemporalTimeZone(timeZone);
196196
const { precision, unit, increment } = ES.ToSecondsStringPrecision(options);
@@ -228,7 +228,8 @@ export class Instant implements Temporal.Instant {
228228
const timeZone = ES.ToTemporalTimeZone(temporalTimeZoneLike);
229229
return ES.CreateTemporalZonedDateTime(GetSlot(this, EPOCHNANOSECONDS), timeZone, calendar);
230230
}
231-
toZonedDateTimeISO(item) {
231+
toZonedDateTimeISO(itemParam) {
232+
let item = itemParam;
232233
if (!ES.IsTemporalInstant(this)) throw new TypeError('invalid receiver');
233234
if (ES.IsObject(item)) {
234235
const timeZoneProperty = item.timeZone;
@@ -241,26 +242,26 @@ export class Instant implements Temporal.Instant {
241242
return ES.CreateTemporalZonedDateTime(GetSlot(this, EPOCHNANOSECONDS), timeZone, calendar);
242243
}
243244

244-
static fromEpochSeconds(epochSeconds) {
245-
epochSeconds = ES.ToNumber(epochSeconds);
245+
static fromEpochSeconds(epochSecondsParam) {
246+
const epochSeconds = ES.ToNumber(epochSecondsParam);
246247
const epochNanoseconds = bigInt(epochSeconds).multiply(1e9);
247248
ES.ValidateEpochNanoseconds(epochNanoseconds);
248249
return new Instant(epochNanoseconds);
249250
}
250-
static fromEpochMilliseconds(epochMilliseconds) {
251-
epochMilliseconds = ES.ToNumber(epochMilliseconds);
251+
static fromEpochMilliseconds(epochMillisecondsParam) {
252+
const epochMilliseconds = ES.ToNumber(epochMillisecondsParam);
252253
const epochNanoseconds = bigInt(epochMilliseconds).multiply(1e6);
253254
ES.ValidateEpochNanoseconds(epochNanoseconds);
254255
return new Instant(epochNanoseconds);
255256
}
256-
static fromEpochMicroseconds(epochMicroseconds) {
257-
epochMicroseconds = ES.ToBigInt(epochMicroseconds);
257+
static fromEpochMicroseconds(epochMicrosecondsParam) {
258+
const epochMicroseconds = ES.ToBigInt(epochMicrosecondsParam);
258259
const epochNanoseconds = epochMicroseconds.multiply(1e3);
259260
ES.ValidateEpochNanoseconds(epochNanoseconds);
260261
return new Instant(epochNanoseconds);
261262
}
262-
static fromEpochNanoseconds(epochNanoseconds) {
263-
epochNanoseconds = ES.ToBigInt(epochNanoseconds);
263+
static fromEpochNanoseconds(epochNanosecondsParam) {
264+
const epochNanoseconds = ES.ToBigInt(epochNanosecondsParam);
264265
ES.ValidateEpochNanoseconds(epochNanoseconds);
265266
return new Instant(epochNanoseconds);
266267
}
@@ -270,13 +271,13 @@ export class Instant implements Temporal.Instant {
270271
}
271272
return ES.ToTemporalInstant(item);
272273
}
273-
static compare(one, two) {
274-
one = ES.ToTemporalInstant(one);
275-
two = ES.ToTemporalInstant(two);
276-
one = GetSlot(one, EPOCHNANOSECONDS);
277-
two = GetSlot(two, EPOCHNANOSECONDS);
278-
if (bigInt(one).lesser(two)) return -1;
279-
if (bigInt(one).greater(two)) return 1;
274+
static compare(oneParam, twoParam) {
275+
const one = ES.ToTemporalInstant(oneParam);
276+
const two = ES.ToTemporalInstant(twoParam);
277+
const oneNs = GetSlot(one, EPOCHNANOSECONDS);
278+
const twoNs = GetSlot(two, EPOCHNANOSECONDS);
279+
if (bigInt(oneNs).lesser(twoNs)) return -1;
280+
if (bigInt(oneNs).greater(twoNs)) return 1;
280281
return 0;
281282
}
282283
[Symbol.toStringTag]!: 'Temporal.Instant';

lib/intl.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ function getResolvedTimeZoneLazy(obj) {
6969
export function DateTimeFormat(
7070
this: Intl.DateTimeFormat,
7171
locale = undefined,
72-
options: Partial<Intl.DateTimeFormatOptions> = {}
72+
optionsParam: Partial<Intl.DateTimeFormatOptions> = {}
7373
): void {
74-
if (!(this instanceof DateTimeFormat)) return new DateTimeFormat(locale, options);
75-
const hasOptions = typeof options !== 'undefined';
76-
options = hasOptions ? ObjectAssign({}, options) : {};
74+
if (!(this instanceof DateTimeFormat)) return new DateTimeFormat(locale, optionsParam);
75+
const hasOptions = typeof optionsParam !== 'undefined';
76+
const options = hasOptions ? ObjectAssign({}, optionsParam) : {};
7777
const original = new IntlDateTimeFormat(locale, options);
7878
const ro = original.resolvedOptions();
7979

@@ -200,8 +200,8 @@ function formatRangeToParts(this: typeof DateTimeFormat, a, b) {
200200
return this[ORIGINAL].formatRangeToParts(a, b);
201201
}
202202

203-
function amend(options = {}, amended = {}) {
204-
options = ObjectAssign({}, options);
203+
function amend(optionsParam = {}, amended = {}) {
204+
const options = ObjectAssign({}, optionsParam);
205205
for (const opt of [
206206
'year',
207207
'month',
@@ -221,8 +221,8 @@ function amend(options = {}, amended = {}) {
221221
return options;
222222
}
223223

224-
function timeAmend(options) {
225-
options = amend(options, {
224+
function timeAmend(optionsParam) {
225+
let options = amend(optionsParam, {
226226
year: false,
227227
month: false,
228228
day: false,
@@ -240,8 +240,8 @@ function timeAmend(options) {
240240
return options;
241241
}
242242

243-
function yearMonthAmend(options) {
244-
options = amend(options, {
243+
function yearMonthAmend(optionsParam) {
244+
let options = amend(optionsParam, {
245245
day: false,
246246
hour: false,
247247
minute: false,
@@ -258,8 +258,8 @@ function yearMonthAmend(options) {
258258
return options;
259259
}
260260

261-
function monthDayAmend(options) {
262-
options = amend(options, {
261+
function monthDayAmend(optionsParam) {
262+
let options = amend(optionsParam, {
263263
year: false,
264264
hour: false,
265265
minute: false,
@@ -276,8 +276,8 @@ function monthDayAmend(options) {
276276
return options;
277277
}
278278

279-
function dateAmend(options) {
280-
options = amend(options, {
279+
function dateAmend(optionsParam) {
280+
let options = amend(optionsParam, {
281281
hour: false,
282282
minute: false,
283283
second: false,
@@ -295,8 +295,8 @@ function dateAmend(options) {
295295
return options;
296296
}
297297

298-
function datetimeAmend(options) {
299-
options = amend(options, { timeZoneName: false });
298+
function datetimeAmend(optionsParam) {
299+
let options = amend(optionsParam, { timeZoneName: false });
300300
if (!hasTimeOptions(options) && !hasDateOptions(options)) {
301301
options = ObjectAssign({}, options, {
302302
year: 'numeric',
@@ -310,7 +310,8 @@ function datetimeAmend(options) {
310310
return options;
311311
}
312312

313-
function zonedDateTimeAmend(options) {
313+
function zonedDateTimeAmend(optionsParam) {
314+
let options = optionsParam;
314315
if (!hasTimeOptions(options) && !hasDateOptions(options)) {
315316
options = ObjectAssign({}, options, {
316317
year: 'numeric',
@@ -325,7 +326,8 @@ function zonedDateTimeAmend(options) {
325326
return options;
326327
}
327328

328-
function instantAmend(options) {
329+
function instantAmend(optionsParam) {
330+
let options = optionsParam;
329331
if (!hasTimeOptions(options) && !hasDateOptions(options)) {
330332
options = ObjectAssign({}, options, {
331333
year: 'numeric',

0 commit comments

Comments
 (0)