Transcrypt icon indicating copy to clipboard operation
Transcrypt copied to clipboard

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

Open chopin opened this issue 2 years ago • 1 comments

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 avatar Jun 11 '23 05:06 chopin

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?

chopin avatar Jun 11 '23 05:06 chopin