Skip to content

Commit a290a1f

Browse files
committedMar 31, 2025·
Support Node.js v20
1 parent 9c9ff05 commit a290a1f

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed
 

‎.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12
1+
20

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"jsbi.d.ts"
2323
],
2424
"scripts": {
25-
"build": "tsc && for f in tsc-out/*.js; do mv -- \"$f\" \"${f%.js}.mjs\"; done && sed -e '/__absoluteDivLarge/,+4d' tsc-out/jsbi.d.ts | grep -v ' __' > jsbi.d.ts && rollup --config rollup.config.js",
25+
"build": "tsc && sed -e '/__absoluteDivLarge/,+4d' tsc-out/jsbi.d.ts | grep -v ' __' > jsbi.d.ts && rollup --config rollup.config.js",
2626
"dev": "tsc --watch",
2727
"test": "set -e; for file in tests/*.mjs; do node --no-warnings --experimental-modules --experimental-specifier-resolution=node --loader ./tests/resolve.source.mjs \"${file}\"; done; for file in benchmarks/*.mjs; do node --no-warnings --experimental-modules --experimental-specifier-resolution=node --loader ./tests/resolve.source.mjs \"${file}\"; done",
2828
"pretest": "npm run build",

‎tests/as-int-n.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import JSBI from '../jsbi';
2-
import { assertTrue } from './assert';
1+
import JSBI from '../dist/jsbi.mjs';
2+
import {assertTrue} from './assert.mjs';
33

44
const intn_data = [
55
{expected: '-1', n: 3, x: '15'},
@@ -295,7 +295,7 @@ for (const test of intn_data) {
295295
const expected = parse(test.expected);
296296
const result = JSBI.asIntN(test.n, x);
297297
assertTrue(JSBI.equal(expected, result),
298-
`Unexpected result for asIntN(${test.n}, ${ test.x }):
298+
`Unexpected result for asIntN(${test.n}, ${ test.x }):
299299
Expected: ${ test.expected }
300300
Actual: ${ result.toString() }`.trim());
301301
}
@@ -305,7 +305,7 @@ for (const test of uintn_data) {
305305
const expected = parse(test.expected);
306306
const result = JSBI.asUintN(test.n, x);
307307
assertTrue(JSBI.equal(expected, result),
308-
`Unexpected result for asUintN(${test.n}, ${ test.x }):
308+
`Unexpected result for asUintN(${test.n}, ${ test.x }):
309309
Expected: ${ test.expected }
310310
Actual: ${ result.toString() }`.trim());
311311
}

‎tests/dataview.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
import JSBI from '../jsbi';
14+
import JSBI from '../dist/jsbi.mjs';
1515

1616
const ab = new ArrayBuffer(16);
1717
const dv = new DataView(ab, 0, 8);
@@ -47,7 +47,7 @@ function dump(dataview) {
4747

4848
function error(what, value, littleEndian, expected, actual) {
4949
throw new Error(`Incorrect ${what} for ${value}, littleEndian=${
50-
littleEndian}: expected ${expected} but got ${actual}`);
50+
littleEndian}: expected ${expected} but got ${actual}`);
5151
}
5252

5353
function test(value) {

‎tests/resolve.source.mjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
*/
55

66
import fs from 'fs';
7-
const PKG = JSON.parse(fs.readFileSync('package.json', { encoding: 'utf-8' }));
7+
const PKG = JSON.parse(fs.readFileSync('package.json', {encoding: 'utf-8'}));
88
export function resolve(specifier, parent, defaultResolve) {
99
if (specifier === PKG.name) {
1010
specifier = new URL('../dist/jsbi', import.meta.url).toString();
1111
} else if (specifier == '../jsbi') {
12-
specifier = new URL(specifier.replace('../', '../tsc-out/'), import.meta.url).toString();
12+
specifier = new URL(
13+
specifier.replace('../', '../tsc-out/'),
14+
import.meta.url,
15+
).toString();
1316
}
1417
return defaultResolve(specifier, parent);
1518
}

‎tests/tests.mjs

+13-10
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
import JSBI from '../jsbi';
15-
import { assertEqual, assertTrue } from './assert';
14+
/* eslint-disable max-len */
15+
import JSBI from '../dist/jsbi.mjs';
16+
import {assertEqual, assertTrue} from './assert.mjs';
1617

1718
{
1819
// Test the example from the README.
@@ -51,7 +52,7 @@ import { assertEqual, assertTrue } from './assert';
5152
// Emulate an environment that doesn't have Symbol (e.g. IE11)
5253
// and make sure we can still coerce to primitive values.
5354
// See #74.
54-
const globalSymbol = globalThis.Symbol;
55+
const globalSymbol = globalThis.Symbol;
5556
try {
5657
globalThis.Symbol = undefined;
5758
assertTrue(JSBI.EQ(JSBI.BigInt(0x7FFFFFFF), {
@@ -104,7 +105,7 @@ const TESTS = [
104105
b: '-0b1111111111111111111111111111111111111111111111111111111111111111',
105106
expected: '-0b1111111111111111111111111111111111111111111111111111111111111111',
106107
},
107-
{ // https://github.com/GoogleChromeLabs/jsbi/issues/57
108+
{ // https://github.com/GoogleChromeLabs/jsbi/issues/57
108109
operation: 'signedRightShift',
109110
a: '-0xFFFFFFFFFFFFFFFF',
110111
b: '32',
@@ -116,15 +117,15 @@ const TESTS = [
116117
(function() {
117118
const VALID = ['123', ' 123 ', ' 123 '];
118119
const INVALID = ['x123', 'x 123', ' 123x', '123 x', '123 xx', '123 ?a',
119-
'-0o0', '-0x0', '-0b0', '-0x1'];
120+
'-0o0', '-0x0', '-0b0', '-0x1'];
120121
for (const v of VALID) {
121122
const result = JSBI.BigInt(v);
122123
assertTrue(JSBI.equal(result, JSBI.BigInt(123)));
123124
}
124125
for (const i of INVALID) {
125126
try {
126127
const result = JSBI.BigInt(i);
127-
throw "unreachable";
128+
throw 'unreachable';
128129
} catch (exception) {
129130
assertTrue(exception instanceof SyntaxError);
130131
}
@@ -135,7 +136,9 @@ const TESTS = [
135136
(function() {
136137
const o = {
137138
num: 123,
138-
[Symbol.toPrimitive]: function() { return this.num; }
139+
[Symbol.toPrimitive]: function() {
140+
return this.num;
141+
},
139142
};
140143
const result = JSBI.BigInt(o);
141144
assertTrue(JSBI.equal(result, JSBI.BigInt(123)));
@@ -162,12 +165,12 @@ for (const test of TESTS) {
162165
const expected = parse(test.expected);
163166
const result = JSBI[operation](a, b);
164167
assertTrue(
165-
JSBI.equal(result, expected),
166-
`
168+
JSBI.equal(result, expected),
169+
`
167170
Unexpected result.
168171
${ hex(a) } ${ operation } ${ hex(b) }
169172
Expected: ${ hex(expected) }
170173
Actual: ${ hex(result) }
171-
`.trim().replace(/\t/g, '')
174+
`.trim().replace(/\t/g, ''),
172175
);
173176
}

0 commit comments

Comments
 (0)