Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform BigInt syntax into BigInt calls (12n --> BigInt(12)) #4049

Closed
cyan-2048 opened this issue Jan 24, 2025 · 2 comments
Closed

Transform BigInt syntax into BigInt calls (12n --> BigInt(12)) #4049

cyan-2048 opened this issue Jan 24, 2025 · 2 comments

Comments

@cyan-2048
Copy link

currently when using BigInt and having the target environment to be es6 you get this error
Image

however no errors occur when you do BigInt(0)

this is actually what some libraries do to test BigInt support, although sometimes for some reason some test BigInt by using the syntax (weird? maybe they weren't informed that using newer syntax on older environments results to everything else in the code not working)

slight suggestion: add a warning if this transform happens as this will still create errors when using on environments where BigInt does not exist

another suggestion: when the BigInt can be represented as a normal JS number (1, 2, anything less than the Number.MAX_SAFE_INTEGER) transform it to BigInt(n) else wrap it in a string BigInt("n")

@evanw
Copy link
Owner

evanw commented Jan 24, 2025

this is actually what some libraries do to test BigInt support, although sometimes for some reason some test BigInt by using the syntax (weird? maybe they weren't informed that using newer syntax on older environments results to everything else in the code not working)

Which libraries specifically? This sounds like a bug with the library.

@cyan-2048
Copy link
Author

this is actually what some libraries do to test BigInt support, although sometimes for some reason some test BigInt by using the syntax (weird? maybe they weren't informed that using newer syntax on older environments results to everything else in the code not working)

Which libraries specifically? This sounds like a bug with the library.

yes the library is also at fault, however this transform would definitely make life easier.

The library I was using was using an outdated version of nodejs/readable-stream
https://github.com/javascriptke/bun/blob/5108e3e0d9f7806c3884e5a678a81dedd61791bc/src/js/node/stream.ts#L605
(this is not the library but I could not find it so I'm citing a different source)

This syntax can also be found in the buffer npm package
https://github.com/feross/buffer/blob/02c782a9127b0fea99c74465c046d4af7e3c839d/index.js#L1528
some libraries use an older version of this package

If this syntax is not transformed to something older runtimes support, the entire code will not run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants