Transcrypt icon indicating copy to clipboard operation
Transcrypt copied to clipboard

Literal bytes >=128: b"\x80"

Open crusaderky opened this issue 5 years ago • 2 comments

This is broken:

x = b"\x80"
$ python -m transcrypt -b -m  x.py
Error while compiling (offending file last):
        File 'x', line 1, namely:
        
        Error while compiling (offending file last):
        File 'x', line 1, namely:
        

Aborted

b"\x81" is also broken, while b"\x7F" works fine.

This workaround compiles with the -n flag, but breaks when minified:

x = (0x80).to_bytes(1, "big")
$ python -m transcrypt -b -m  x.py
Saving minified target code in: /Users/crusaderky/PycharmProjects/10char/__target__/x.js
x.pretty.js:4: ERROR - Parse error. Semi-colon expected
export var x = 128.to_bytes (1, 'big');
                   ^

This compiles (but I didn't test yet if it actually runs):

x = 0x80
y = x.to_bytes(1, "big")

This also compiles:

x = chr(0x80)

crusaderky avatar Feb 19 '20 10:02 crusaderky

int.to_bytes doesn't seem to have been implemented

crusaderky avatar Feb 19 '20 10:02 crusaderky

The whole distinction between UTF-8 strings and bytes objects isn't there either. str.encode() crashes.

crusaderky avatar Feb 19 '20 13:02 crusaderky