This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Avoid using ** with BigInt
#6506
Merged
Muhammad-Altabba
merged 7 commits into
4.x
from
6187-typeerror-cannot-convert-a-bigint-value-to-a-number
Oct 16, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
45f317d
user static numbers to remove ** at web3-utils converters.ts
Muhammad-Altabba 59b9731
precalculate numbers limits to avoid **
Muhammad-Altabba d3a1a18
implement bigintPower to avoid ** with bigint
Muhammad-Altabba 85a5b37
Merge branch '4.x' into 6187-typeerror-cannot-convert-a-bigint-value-…
Muhammad-Altabba 827f28e
Merge branch '4.x' into 6187-typeerror-cannot-convert-a-bigint-value-…
Muhammad-Altabba 70b0e70
update CHANGELOG.md files
Muhammad-Altabba 628cacf
fill `numberLimits` in a loop
Muhammad-Altabba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| This file is part of web3.js. | ||
|
|
||
| web3.js is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU Lesser General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| web3.js is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU Lesser General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Lesser General Public License | ||
| along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| /* | ||
| * this variable contains the precalculated limits for all the numbers for uint and int types | ||
| */ | ||
| export const numberLimits = new Map<string, { min: bigint; max: bigint }>(); | ||
|
|
||
| let base = BigInt(256); // 2 ^ 8 = 256 | ||
| for (let i = 8; i <= 256; i += 8) { | ||
| numberLimits.set(`uint${i}`, { | ||
| min: BigInt(0), | ||
| max: base - BigInt(1), | ||
| }); | ||
| numberLimits.set(`int${i}`, { | ||
| min: -base / BigInt(2), | ||
| max: base / BigInt(2) - BigInt(1), | ||
| }); | ||
| base *= BigInt(256); | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| numberLimits.set(`int`, numberLimits.get('int256')!); | ||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| numberLimits.set(`uint`, numberLimits.get('uint256')!); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exponentiation Operator usage issue was solved by specifying min browser versions in one of issue?
Its supported in ECMAScript 2016 and
Chrome 52 | Edge 14 | Firefox 52 | Safari 10.1 | Opera 39
Jul 2016 | Aug 2016 | Mar 2017 | Mar 2017 | Aug 2016
so react with older browsers is causing this problem only, and if some one specify min browsers list in react config and use on ECMAScript 2016 supporting browser there is no issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the issue is present with the latest as well as any older version of React . And any other framework that uses babel (the latest version of babel and any older version as well).
And this is what happens:
**toMath.pow.Math.powdoes not work withBigInt.Currently, the only way to avoid this behavior is to add configuration to
package.jsonas mentioned in: babel/babel#13109 (comment) and applied in #6187 (comment)And this MR propose changes so the users do not need to add configurations to their
package.json.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to have our own bigint pow function right now. and wait while Babel starts supporting it