-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Trailing trivia dropped from open curly brace #6982
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
Comments
I've spent some time digging into this bug and I think the problem is in When emitting, the usage of leading and trailing is maybe what you'd naively expect given the terms "leading" and "trailing", which is to say comments that occur before or after the node:
But within
It's not clear to me why whitespace and in particular line breaks are relevant to the notion of whether a comment should emit before or after a node. Any pointers are welcome; I will continue digging otherwise. |
Here's the test case I've been playing with. The comments are numbered so you can see which ones are dropped from the output and which are duplicated: |
Further reduction: {/* trivia1 */1;
/* trivia2 */} drops both comments. The ExpressionStatement node with text "/* trivia1 */1" has neither leading nor trailing comments according to the code. |
This also causes some problems if you have trailing line comments after an opening curly brace. This is a big deal if you need to ignore a single line in JSHint (see Playground example) Context: In a Yeoman generator project, I need to be able to keep JSHint intact for the JS version of the generated app. |
I can no longer reproduce any of the mentioned cases, cc @jakebailey |
The "foo" comment is dropped: http://www.typescriptlang.org/Playground#src=%7B%2F**%20foo%20*%2F%0A%20%20%2F%2F%20bar%0A%20%20let%20x%20%3D%203%3B%0A%7D%0A
Inserting a newline before it preserves the comment:
http://www.typescriptlang.org/Playground#src=%7B%0A%09%2F**%20foo%20*%2F%0A%20%20%2F%2F%20bar%0A%20%20let%20x%20%3D%203%3B%0A%7D%0A
The "foo" comment is dropped:
http://www.typescriptlang.org/Playground#src=var%20x%20%3D%20%2F**%20foo%20*%2F%20()%20%3D%3E%2012%3B
Inserting a newline before the
/**
causes it to be emitted twice(!):http://www.typescriptlang.org/Playground#src=var%20x%20%3D%0A%2F**%20foo%20*%2F%20()%20%3D%3E%2012%3B
The text was updated successfully, but these errors were encountered: