-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Retain synthetic comments on exports. #25604
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
Conversation
/CC @weswigham |
410ca8d
to
075690d
Compare
@weswigham I'm not 100% sure we want the changes in the last commit, i.e. retaining comments on export specifiers. The code paths setting allowComments=false (or rather, not passing it) sound as if they expect the comments to be emitted elsewhere, at least for export assignment and hoisted exports. |
71f0393
to
eba8e49
Compare
Actually I take it back, emitting comments for export specifiers is not a good idea. I'm having a really productive conversation with myself here, it seems ;-) |
eba8e49
to
cdfed60
Compare
@rbuckton can you please review this change. |
This pulls in the changes from microsoft/TypeScript#25604 that are required for tsickle to run purely based on transformers. This allows deleting a number of hacks in `transformer_utils.ts` on our side.
@rbuckton I'm seeing other problems, such as comments on initialized comments being emitted, e.g. from: class Foo {
// comment goes here
bar = 1;
} If I set class Foo {
constructor() {
// my synthetic comment
// comment goes here
this.bar = 1;
}
} The cause in this case I think is: https://github.com/Microsoft/TypeScript/blob/master/src/compiler/factory.ts#L3141 The code sets the text range of the new code, but ignores emit flags such as NoComments |
30a650a
to
f35428c
Compare
Variables that do not have a local variable created get transformed into a single exports assignment expression. TypeScript previously just created a new expression and set the text range to retain original comments, but for synthetic comments, merging the emit nodes by setting the original node is required.
Previously, TypeScript would only set the text range when transforming import and export declarations, leading it to drop synthetic comments and emit flags. This commit sets the original node on the statements that contains the generated `require()` call (or similar, depending on module system), retaining emit flags and synthetic comments.
f35428c
to
b7ee0e9
Compare
This pulls in the changes from microsoft/TypeScript#25604 that are required for tsickle to run purely based on transformers. This allows deleting a number of hacks in `transformer_utils.ts` on our side.
Keep emit flags set on the original node on a namespace or enum node. This prevents dropping flags like NoComments, which caused duplicated comment emits. Additionally, TypeScript would emit synthetic comments twice, once for the variable declaration, once for the module statement. This explicitly clears away synthetic comments on namespaces and enums if their synthetic comments have already been emitted on the corresponding variable statement.
11681ef
to
c50a6f7
Compare
The approach that I'm taking in a7224ec now is to not consider comments "consumed" if a container node has a |
@rbuckton friendly ping. |
This pulls in the changes from microsoft/TypeScript#25604 that are required for tsickle to run purely based on transformers. This allows deleting a number of hacks in `transformer_utils.ts` on our side.
This pulls in the changes from microsoft/TypeScript#25604 that are required for tsickle to run purely based on transformers. This allows deleting a number of hacks in `transformer_utils.ts` on our side.
This pulls in the changes from microsoft/TypeScript#25604 that are required for tsickle to run purely based on transformers. This allows deleting a number of hacks in `transformer_utils.ts` on our side.
This pulls in the changes from microsoft/TypeScript#25604 that are required for tsickle to run purely based on transformers. This allows deleting a number of hacks in `transformer_utils.ts` on our side.
src/compiler/transformers/ts.ts
Outdated
@@ -2977,8 +2986,13 @@ namespace ts { | |||
); | |||
|
|||
setOriginalNode(moduleStatement, node); | |||
if (varAdded) { | |||
// If a variable was added, synthetic comments are mitted on it, not on the moduleStatement. |
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.
Typo: mitted
src/compiler/transformers/ts.ts
Outdated
@@ -2689,8 +2692,13 @@ namespace ts { | |||
); | |||
|
|||
setOriginalNode(enumStatement, node); | |||
if (varAdded) { | |||
// If a variable was added, synthetic comments are mitted on it, not on the moduleStatement. |
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.
Typo: mitted
thanks! |
Variables that do not have a local variable created get transformed into
a single exports assignment expression. TypeScript previously just
created a new expression and set the text range to retain original
comments, but for synthetic comments, merging the emit nodes by setting
the original node is required.
Fixes #17594