Faulty padding with triple-quoted strings and empty lines
copygirl opened this issue · 4 comments
There appears to be a problem with empty lines in triple-quoted strings:
"""foo
bar"""
(Note: 3 spaces in the empty line)
Produces the string "foo\n \n bar"
This is similar for when you put foo
on a seperate line. To fix this you'll have to either leave the empty line completely empty, or add an extra space to it. For some reason, less spaces in the empty line means more padding to the rest of the string - if this example had only one space in the empty line, it would produce 3 spaces in front of bar
instead of 1.
I should mention that CoffeeScript doesn't seem to have this issue.
Wondering if we should ignore space-only lines for heredocs as well.
It seems bad when invisible changes matter, not to mention many tools don't like trailing spaces.
I.e.,
'''
0
1
'''
would equal to '0\n\n 1'
no matter how many spaces the empty lines has.
To explicitly indicate space-only lines, we can (already) use \
:
'''
0
\
1
'''
↓↑
'0\n \n 1'
I wouldn't really change it much from the way CoffeeScript does it, and I don't like the \
idea if it was required. To fix the problem of spacing the rest of the string accidentally when having less spaces on empty lines than the rest, maybe add a compile error?
(-
= space)
"""foo
-
---bar"""
would cause this error, whereas the following won't
"""--foo
--- # no spaces would do the same
-----bar"""
and it should produce "--foo\n\n--bar"
.
Also try this with CoffeeScript, it's not how I think it's supposed to be.
Although then I don't know how intentional padding would work with the """
on their own lines.
Nevermind, that's what the \
would be for, I guess, but it's still a bit unintuitive, which I think is not a problem since this is a rare special case.
I wouldn't really change it much from the way CoffeeScript does it
That's certainly safer. I guess I'll open a separate issue for the trimming idea.