skulpt / skulpt

Skulpt is a Javascript implementation of the Python programming language
Other
3.32k stars 897 forks source link

F-strings get transpiled wrongly #1546

Open the-blank-x opened 2 months ago

the-blank-x commented 2 months ago

Steps to Reproduce

  1. Go to https://skulpt.org/
  2. Enter print(repr(f"{'\n' if True else ''}")) in the example box
  3. Click Run or press Ctrl+Enter

Expected behavior

It outputs '\n' It outputs an error (presumably to the Javascript console) about a SyntaxError

Actual behavior

It outputs ' if True else '

Additional information

print(repr(f"{'\n' if True else 'a'}")) causes it to throw a Javascript object that says something about "bad input". This is relatively low priority for me though, so I haven't digged into it yet (I might in the slightly distant future).

s-cork commented 2 months ago

I think the expected behaviour should be

SyntaxError: f-string expression part cannot include a backslash
the-blank-x commented 2 months ago

I forgot that python does not like backslashes in f-strings, thanks