@@ -133,26 +133,51 @@ export class Long extends BSONValue {
133133
134134 /**
135135 * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
136- * See the from* functions below for more convenient ways of constructing Longs.
137- *
138- * Acceptable signatures are:
139- * - Long(low, high, unsigned?)
140- * - Long(bigint, unsigned?)
141- * - Long(string, unsigned?)
142136 *
143137 * @param low - The low (signed) 32 bits of the long
144138 * @param high - The high (signed) 32 bits of the long
145139 * @param unsigned - Whether unsigned or not, defaults to signed
146140 */
147- constructor ( low : number | bigint | string = 0 , high ?: number | boolean , unsigned ?: boolean ) {
141+ constructor ( low : number , high ?: number , unsigned ?: boolean ) ;
142+ /**
143+ * Constructs a 64 bit two's-complement integer, given a bigint representation.
144+ *
145+ * @param value - BigInt representation of the long value
146+ * @param unsigned - Whether unsigned or not, defaults to signed
147+ */
148+ constructor ( value : bigint , unsigned ?: boolean ) ;
149+ /**
150+ * Constructs a 64 bit two's-complement integer, given a string representation.
151+ *
152+ * @param value - 32 bit number representation of the Long
153+ * @param unsigned - Whether unsigned or not, defaults to signed
154+ */
155+ constructor ( value : number , unsigned ?: boolean ) ;
156+ /**
157+ * Constructs a 64 bit two's-complement integer, given a string representation.
158+ *
159+ * @param value - String representation of the long value
160+ * @param unsigned - Whether unsigned or not, defaults to signed
161+ */
162+ constructor ( value : string , unsigned ?: boolean ) ;
163+ constructor (
164+ lowOrValue : number | bigint | string = 0 ,
165+ highOrUnsigned ?: number | boolean ,
166+ unsigned ?: boolean
167+ ) {
148168 super ( ) ;
149- if ( typeof low === 'bigint' ) {
150- Object . assign ( this , Long . fromBigInt ( low , ! ! high ) ) ;
151- } else if ( typeof low === 'string' ) {
152- Object . assign ( this , Long . fromString ( low , ! ! high ) ) ;
169+ unsigned = typeof highOrUnsigned === 'boolean' ? highOrUnsigned : ! ! unsigned ;
170+ const high = typeof highOrUnsigned === 'number' ? highOrUnsigned : 0 ;
171+ if ( typeof lowOrValue === 'bigint' ) {
172+ const longFromBigInt = Long . fromBigInt ( lowOrValue , unsigned ) ;
173+ this . low = longFromBigInt . low ;
174+ this . high = longFromBigInt . high ;
175+ this . unsigned = longFromBigInt . unsigned ;
176+ } else if ( typeof lowOrValue === 'string' ) {
177+ Object . assign ( this , Long . fromString ( lowOrValue , unsigned ) ) ;
153178 } else {
154- this . low = low | 0 ;
155- this . high = ( high as number ) | 0 ;
179+ this . low = lowOrValue | 0 ;
180+ this . high = high | 0 ;
156181 this . unsigned = ! ! unsigned ;
157182 }
158183 }
@@ -176,17 +201,6 @@ export class Long extends BSONValue {
176201 /** Minimum signed value. */
177202 static MIN_VALUE = Long . fromBits ( 0 , 0x80000000 | 0 , false ) ;
178203
179- /**
180- * @internal
181- * bit mask used for fromBigInt method, lazy loaded
182- */
183- static FROM_BIGINT_BIT_MASK : bigint ;
184-
185- /**
186- * @internal
187- * bit shift used for fromBigInt method, lazy loaded */
188- static FROM_BIGINT_BIT_SHIFT : bigint ;
189-
190204 /**
191205 * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits.
192206 * Each is assumed to use 32 bits.
@@ -255,12 +269,12 @@ export class Long extends BSONValue {
255269 */
256270 static fromBigInt ( value : bigint , unsigned ?: boolean ) : Long {
257271 // eslint-disable-next-line no-restricted-globals
258- Long . FROM_BIGINT_BIT_MASK ?? = BigInt ( 0xffffffff ) ;
272+ const FROM_BIGINT_BIT_MASK = BigInt ( 0xffffffff ) ;
259273 // eslint-disable-next-line no-restricted-globals
260- Long . FROM_BIGINT_BIT_SHIFT ?? = BigInt ( 32 ) ;
274+ const FROM_BIGINT_BIT_SHIFT = BigInt ( 32 ) ;
261275 return new Long (
262- Number ( value & Long . FROM_BIGINT_BIT_MASK ) ,
263- Number ( ( value >> Long . FROM_BIGINT_BIT_SHIFT ) & Long . FROM_BIGINT_BIT_MASK ) ,
276+ Number ( value & FROM_BIGINT_BIT_MASK ) ,
277+ Number ( ( value >> FROM_BIGINT_BIT_SHIFT ) & FROM_BIGINT_BIT_MASK ) ,
264278 unsigned
265279 ) ;
266280 }
0 commit comments