Skip to content

Conversation

@inottn
Copy link
Contributor

@inottn inottn commented Feb 4, 2025

Summary

The compiler currently doesn't support BigInt. As a primitive type in JS, I believe it can be implemented using existing Primitive kind. However, in the AST obtained via Babel, the value of BigIntLiteral is also of string type. Therefore, a new field is needed to distinguish it from a actual string. I've temporarily named it isBigInt, as the name is quite intuitive.

I realized that I can convert the value corresponding to BigIntLiteral to the bigint type directly, which would eliminate the need for a new field to identify it.

How did you test this change?

Added a test. I tried modifying the existing test cases, but the results looked messy, so I added new test cases instead.

Comment on lines 346 to +350
result = {kind: 'Primitive', value: lhs + rhs, loc: value.loc};
} else if (typeof lhs === 'string' && typeof rhs === 'string') {
result = {kind: 'Primitive', value: lhs + rhs, loc: value.loc};
} else if (typeof lhs === 'bigint' && typeof rhs === 'bigint') {
result = {kind: 'Primitive', value: lhs + rhs, loc: value.loc};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code appears to be somewhat redundant. For example, multiple if/else-if conditions could be combined, and the condition typeof lhs === 'number' && typeof rhs === 'number' could be moved to an outer layer. However, I'm not sure why this wasn't done before—perhaps it was intentional—so I've chosen to keep the original implementation.

Comment on lines 354 to +358
case '-': {
if (typeof lhs === 'number' && typeof rhs === 'number') {
result = {kind: 'Primitive', value: lhs - rhs, loc: value.loc};
} else if (typeof lhs === 'bigint' && typeof rhs === 'bigint') {
result = {kind: 'Primitive', value: lhs - rhs, loc: value.loc};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not apply this code to every operation. Specifically, I excluded operators such as *, **, and << because they might compute extremely large values, which could significantly increase the size of the compiled code.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

@inottn inottn marked this pull request as ready for review February 5, 2025 12:16
@Receptua
Copy link

Receptua commented Feb 6, 2025

++

@github-actions
Copy link

github-actions bot commented Jun 6, 2025

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Jun 6, 2025
@github-actions
Copy link

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

@github-actions github-actions bot closed this Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Resolution: Stale Automatically closed due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants