From eb84a0305c5bd713f6266a3962ce07150fe4bc1d Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Mon, 1 Feb 2021 15:46:17 -0800 Subject: [PATCH] Cleanup bigint literals (#2302) * fix: cleanup bigint literals --- packages/dapp-svelte-wallet/ui/src/display.js | 14 +++++----- packages/marshal/test/test-marshal.js | 6 ++--- packages/swingset-runner/src/main.js | 2 +- packages/tame-metering/.eslintrc.js | 27 ------------------- packages/tame-metering/src/tame.js | 1 - packages/transform-metering/.eslintrc.js | 27 ------------------- packages/transform-metering/src/meter.js | 5 ++-- .../transform-metering/test/test-meter.js | 1 - .../transform-metering/test/test-zzz-eval.js | 1 - .../zoe/src/contractSupport/bondingCurves.js | 3 --- .../contractSupport/test-percentMath.js | 2 +- 11 files changed, 14 insertions(+), 75 deletions(-) delete mode 100644 packages/tame-metering/.eslintrc.js delete mode 100644 packages/transform-metering/.eslintrc.js diff --git a/packages/dapp-svelte-wallet/ui/src/display.js b/packages/dapp-svelte-wallet/ui/src/display.js index 90726fa43ef..d45276fda5b 100644 --- a/packages/dapp-svelte-wallet/ui/src/display.js +++ b/packages/dapp-svelte-wallet/ui/src/display.js @@ -10,9 +10,9 @@ const CONVENTIONAL_DECIMAL_PLACES = 2; */ /** - * - * @param {string} str - * @param {AmountDisplayInfo} displayInfo + * + * @param {string} str + * @param {AmountDisplayInfo} displayInfo */ export function parseValue(str, displayInfo) { const { amountMathKind = MathKind.NAT, decimalPlaces = 0 } = displayInfo || {}; @@ -47,14 +47,14 @@ export function parseValue(str, displayInfo) { } /** - * - * @param {any} value + * + * @param {any} value * @param {AmountDisplayInfo} [displayInfo] * @returns {string} */ export function stringifyValue(value, displayInfo = undefined) { const { amountMathKind = MathKind.NAT, decimalPlaces = 0 } = displayInfo || {}; - + if (amountMathKind !== MathKind.NAT) { // Just return the size of the set. return `${value.length}`; @@ -66,7 +66,7 @@ export function stringifyValue(value, displayInfo = undefined) { return `${bValue}`; } - const bScale = BigInt(10) ** BigInt(decimalPlaces); + const bScale = 10n ** BigInt(decimalPlaces); // Take integer division of the value by the scale. const unitstr = `${bValue / bScale}`; diff --git a/packages/marshal/test/test-marshal.js b/packages/marshal/test/test-marshal.js index 1e796eb38ce..2ecd598ccac 100644 --- a/packages/marshal/test/test-marshal.js +++ b/packages/marshal/test/test-marshal.js @@ -51,7 +51,7 @@ test('serialize static data', t => { }); let bn; try { - bn = BigInt(4); + bn = 4n; } catch (e) { if (!(e instanceof ReferenceError)) { throw e; @@ -112,14 +112,14 @@ test('unserialize static data', t => { t.deepEqual(uns('{"foo": {"@qclass":"undefined"}}'), { foo: undefined }); let bn; try { - bn = BigInt(4); + bn = 4n; } catch (e) { if (!(e instanceof ReferenceError)) { throw e; } } if (bn) { - t.deepEqual(uns('{"@qclass":"bigint","digits":"1234"}'), BigInt(1234)); + t.deepEqual(uns('{"@qclass":"bigint","digits":"1234"}'), 1234n); } const em1 = uns( diff --git a/packages/swingset-runner/src/main.js b/packages/swingset-runner/src/main.js index e0a26371aa7..20d739ed6c3 100644 --- a/packages/swingset-runner/src/main.js +++ b/packages/swingset-runner/src/main.js @@ -512,7 +512,7 @@ export async function main() { const statsPre = controller.getStats(); const args = { body: '[]', slots: [] }; let totalSteps = 0; - let totalDeltaT = BigInt(0); + let totalDeltaT = 0n; for (let i = 0; i < rounds; i += 1) { const roundResult = controller.queueToVatExport( launchIndirectly ? 'launcher' : 'bootstrap', diff --git a/packages/tame-metering/.eslintrc.js b/packages/tame-metering/.eslintrc.js deleted file mode 100644 index 128816de880..00000000000 --- a/packages/tame-metering/.eslintrc.js +++ /dev/null @@ -1,27 +0,0 @@ -/* global module */ -module.exports = { - extends: ['airbnb-base', 'plugin:prettier/recommended'], - env: { - es6: true, // supports new ES6 globals (e.g., new types such as Set) - }, - rules: { - 'implicit-arrow-linebreak': 'off', - 'function-paren-newline': 'off', - 'arrow-parens': 'off', - strict: 'off', - 'prefer-destructuring': 'off', - 'no-else-return': 'off', - 'no-console': 'off', - 'no-unused-vars': ['error', { - argsIgnorePattern: '^_', - varsIgnorePattern: '^_', - }], - 'no-return-assign': 'off', - 'no-param-reassign': 'off', - 'no-restricted-syntax': ['off', 'ForOfStatement'], - 'no-unused-expressions': 'off', - 'no-loop-func': 'off', - 'no-inner-declarations': 'off', - 'import/prefer-default-export': 'off', - }, -}; diff --git a/packages/tame-metering/src/tame.js b/packages/tame-metering/src/tame.js index f148205142b..b85cfa3b1db 100644 --- a/packages/tame-metering/src/tame.js +++ b/packages/tame-metering/src/tame.js @@ -1,4 +1,3 @@ -/* global globalThis */ import * as c from './constants'; let replaceGlobalMeter; diff --git a/packages/transform-metering/.eslintrc.js b/packages/transform-metering/.eslintrc.js deleted file mode 100644 index 128816de880..00000000000 --- a/packages/transform-metering/.eslintrc.js +++ /dev/null @@ -1,27 +0,0 @@ -/* global module */ -module.exports = { - extends: ['airbnb-base', 'plugin:prettier/recommended'], - env: { - es6: true, // supports new ES6 globals (e.g., new types such as Set) - }, - rules: { - 'implicit-arrow-linebreak': 'off', - 'function-paren-newline': 'off', - 'arrow-parens': 'off', - strict: 'off', - 'prefer-destructuring': 'off', - 'no-else-return': 'off', - 'no-console': 'off', - 'no-unused-vars': ['error', { - argsIgnorePattern: '^_', - varsIgnorePattern: '^_', - }], - 'no-return-assign': 'off', - 'no-param-reassign': 'off', - 'no-restricted-syntax': ['off', 'ForOfStatement'], - 'no-unused-expressions': 'off', - 'no-loop-func': 'off', - 'no-inner-declarations': 'off', - 'import/prefer-default-export': 'off', - }, -}; diff --git a/packages/transform-metering/src/meter.js b/packages/transform-metering/src/meter.js index 6d202358a7d..f4abc5b7bbc 100644 --- a/packages/transform-metering/src/meter.js +++ b/packages/transform-metering/src/meter.js @@ -1,4 +1,3 @@ -/* global BigInt */ import * as c from './constants'; const { isArray } = Array; @@ -7,8 +6,8 @@ const { ceil } = Math; const ObjectConstructor = Object; // eslint-disable-next-line no-bitwise -const bigIntWord = typeof BigInt !== 'undefined' && BigInt(2) ** BigInt(64); -const bigIntZero = bigIntWord && BigInt(0); +const bigIntWord = typeof BigInt !== 'undefined' && 2n ** 64n; +const bigIntZero = bigIntWord && 0n; // Stop deducting when we reach a negative number. const makeCounter = initBalance => { diff --git a/packages/transform-metering/test/test-meter.js b/packages/transform-metering/test/test-meter.js index be27c5f8e23..a5ca89ff8b7 100644 --- a/packages/transform-metering/test/test-meter.js +++ b/packages/transform-metering/test/test-meter.js @@ -1,4 +1,3 @@ -/* globals BigInt */ /* eslint-disable no-await-in-loop */ import test from 'ava'; diff --git a/packages/transform-metering/test/test-zzz-eval.js b/packages/transform-metering/test/test-zzz-eval.js index e2607a25f37..dcd448297a3 100644 --- a/packages/transform-metering/test/test-zzz-eval.js +++ b/packages/transform-metering/test/test-zzz-eval.js @@ -1,4 +1,3 @@ -/* global Compartment */ // eslint-disable-next-line import/order import { replaceGlobalMeter } from './install-metering'; import '@agoric/install-ses'; // calls lockdown() diff --git a/packages/zoe/src/contractSupport/bondingCurves.js b/packages/zoe/src/contractSupport/bondingCurves.js index 52818b62f1c..01809547969 100644 --- a/packages/zoe/src/contractSupport/bondingCurves.js +++ b/packages/zoe/src/contractSupport/bondingCurves.js @@ -4,9 +4,6 @@ import { natSafeMath } from './safeMath'; const { multiply, floorDivide } = natSafeMath; -// TODO(2196): use 10000n instead of BigInt(10000) -// We use this workaround due to some parser in our toolchain that can't parse -// bigint literals. const BIG_10000 = 10000n; const BIG_ONE = 1n; diff --git a/packages/zoe/test/unitTests/contractSupport/test-percentMath.js b/packages/zoe/test/unitTests/contractSupport/test-percentMath.js index 118c79d6b3f..47fdf6449d0 100644 --- a/packages/zoe/test/unitTests/contractSupport/test-percentMath.js +++ b/packages/zoe/test/unitTests/contractSupport/test-percentMath.js @@ -114,7 +114,7 @@ test('percentMath - Nats only', t => { message: 'not a safe integer', }); - t.throws(() => makePercent(BigInt(47), amountMath), { + t.throws(() => makePercent(47n, amountMath), { message: 'not a safe integer', }); });