effekt
effekt copied to clipboard
Cannot escape double quotes in extern strings
Minimal example:
extern pure def foo(): String = "\"this is a string\""
throws an error as \"
is not allowed in extern strings:
However, double quote escaping works in normal strings:
val foo = "\"this is my quoted string\"
I believe that my actual use case needs the double quotes in an extern string because it's a separate parameter that I have to provide:
extern type ByteArray
extern pure def fromString(s: String): ByteArray = "(new TextEncoder().encode(s))"
extern pure def toString(b: ByteArray): String = "(new TextDecoder(\"utf-8\").decode(b))"
Related: #350, #202
If this is for the JS backend you can use "(new TextDecoder('utf-8').decode(b))"
as a workaround for now.
Another workaround is to use multiline strings:
extern pure def toString(b: Bytes): String = """
(new TextDecoder("utf-8").decode(b))
"""