-
Notifications
You must be signed in to change notification settings - Fork 964
[ts-transformers] Some comments are not preserved #2158
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
aomarks
added a commit
to lit/lit.dev
that referenced
this issue
Sep 14, 2021
- Replace home-page-specific language toggle with the new global one. - Replace the separate JavaScript vs TypeScript "Hello World" Playground examples with a unified one. I'm keeping the JS output hand-rolled for this example for now, because the `static properties` block isn't in the perfect position, and this is a very prominent example. Will fix in lit/lit#2159 as followup. - Fix home page highlight positions when in JS mode. This actually broke in #495 where I forgot to update the ranges for the yellow-highlight effect. - Added a check for generated samples that have lost or re-ordered playground fold/hide comments. This should help detect weird cases that might need hand-rolling going forward. - Hand-roll two examples that are losing fold comments, and move one comment to be trailing so that it's not lost, that I found via the above check. Filed lit/lit#2158 to hopefully address in the transformers in the future. - Remove some unnecessary TypeScript vs JavaScript language, and add a few more switchable samples. - Remove `jsSamples` mod feature flag to launch JS docs. Fixes #332 Fixes #490
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are a few locations for comments where TypeScript's normal behavior is to drop the comment entirely.
One place this can happen is at the end of a class declaration.
For example, in this case the trailing
fold-end
comment will be dropped, meaning any code after it will be unintentionally hidden when displayed in a Playground:This is a known issue with TypeScript, but which has been decided should not be fixed (see microsoft/TypeScript#32813).
The core issue is that TypeScript does not represent comments as first-class nodes in the AST, rather they only exist if they are associated as a leading or trailing comment of some node. In this case, the
/* playground-fold */
comment is a leading comment of therender
method, but the/* playground-fold-end */
comment has no node to be associated with.There might be something we can do in the transformers to at least partially recover these comments, though. For example, the
/* playground-fold-end */
comment above could be detected by manually scanning the text of the class node for a trailing comment, and then re-attaching it as a trailing comment of therender
function -- as though it had been written as:The text was updated successfully, but these errors were encountered: