Closed tsouza closed 7 years ago
That's expected behaviour.
What you actually have is the triple-quoted string """test"""
, followed by a lone double-quote character.
It's equivalent to this in normal JS:
"test""
Which would give a very similar error.
Thanks.
I am sorry, but I need to disagree with you. I don't think this is expected behavior because:
"""test " test"""
into "test \" test"
. """"test"""
into "\"test test"
So why a double-quote in the end should be considered different?
Clearly there is bug. Either the above should be or it should be able to parse a double-quote in the end.
I would expect it to transform: """test""""
into "test\""
or fail with the above input.
It's different because triple quotes are matched greedily. This behaviour is also consistent with Python's triple-quoted strings, which will give a similar syntax error.
If you need a double-quote character at the end you should probably use triple-single-quotes. I would purposely do this anyway because it's pretty hard to see the difference between three double quotes and four!
Also, I have never found a suitable use for single-line triple-quoted strings. I always put them on multiple lines for readability- in which case you can safely end with a double-quote character like this:
var x = """
foo "bar"
""";
It should be noted that the parser is specifically designed to handle whitespace properly, so you can safely use a more-readable syntax as above without it making a mess of the output.
Apparently it fails to parse when string ends with double-quotes. Trying to parse a file with:
Fails with: