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

A boolean operator is translated to a bitwise operator, not a boolean operator #856

Open
chopin opened this issue Jun 11, 2023 · 1 comment

Comments

@chopin
Copy link

chopin commented Jun 11, 2023

I found that Python boolean operator '|=' was translated to '|=' in Javascript. They look the same, but they are not the same.

In Javascript, '|=' is a bitwise operator returning 1 or 0, not true or false. Javascript has another operator for boolean operations, '||=' returning true or false. Following is examples showing the difference:

// Javascript example:
var b= false;
b||= true;
console.log("after b||= true; b= ", b);
b|= true;
console.log("after b|= true; b= ", b);

output result:

after b||= true; b=  true
after b|= true; b=  1

Thanks.

@chopin chopin changed the title A boolean operation is translated to a bitwise operation, not a boolean operation A boolean operator is translated to a bitwise operator, not a boolean operator Jun 11, 2023
@chopin
Copy link
Author

chopin commented Jun 11, 2023

It seems that Python |= operates either in boolean or in bitwise depending on the types of its operands, but Javascript doesn't. Does Transcyprt have an option to translate it correctly? Should I modified all Python source code using boolean operators?

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

1 participant