-
Notifications
You must be signed in to change notification settings - Fork 2k
[CS2] Fix #4629: interpolations (whether in strings or CSX tags) with only comments #4659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CS2] Fix #4629: interpolations (whether in strings or CSX tags) with only comments #4659
Conversation
…hat contain nothing but comments should not be optimized out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good for the JSX case! 👍
Unfortunately, "a#{###test###}b" becomes
`a${/*test*/}b`, which is invalid JS.
|
Huh. I had no idea So what should we do for strings? Compile to |
|
Empty interpolations are invalid in JS. I don't know why but that's how it is. I think your solution with the empty string looks good. |
…if we only have a comment to put in there, toss in an empty string as well
|
Done! |
|
We should probably make |
|
@connec You mean empty interpolations in general? |
|
Yeh, I don't think it's useful to allow empty interpolations. That said, I think I misunderstood the outcome of the PR - treating empty interpolations as |
|
It would be a breaking change to no longer allow |
Fixes #4629.
An optimization in interpolated strings (which CSX tags essentially are) ignored empty interpolations:
"a#{}b"compiled to just`ab`, not`a${}b`. This meant that an interpolation that had nothing but comments, like"a#{### comment ###}b", was also getting output as just`ab`, with the comment lost.This PR preserves both the optimization and the comments. If an “empty” interpolation has no comments, the current behavior remains. However if it has comments but no other tokens, a zero-length
JStoken is created in the interpolation to hold the comments; and the optimization isn’t performed.