-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Some comments not emitted - upgrade 1.0.1 to 1.3.0 #1311
Comments
Just to be clear, when you say 1.0.3, do you mean 1.3.0? |
Yip, corrected the title. I attempted a patch here: Tried to get rid of the trailingSeparator logic, still a few fixes needed. |
Not to deflect from your current work, but it may be worth seeing what @sheetalkamat has to say about this issue and what the most appropriate fix is in general |
Thanks @DanielRosenwasser, I'll wait for feedback. Updated the patch with a couple of fixes. 2729 tests failing though most are because newlines are preserved for single line comments. |
So I think I found the right idea to fix & improve, mainly simplify scanner & parser using: export interface CommentRange extends TextRange {
leadingWhitespace?: string;
trailingWhitespace?: string;
isAttached?: boolean; /* attached to a Node (trailingWhitespace has at most 1 newline) */
isFollowed?: boolean; /* followed *//* by another comment */
} The other bit is not emitting comments attached to !isDeclarationVisible(node) As a heads up, only working on compiler scanner.ts emitter.ts, parser.ts |
Hey @jbondc I'm going to be doing a little bit of work related to this. Namely, the introduction of an EndOfFile node to the ast. This should address the case where Note: it is by design that |
Super @CyrusNajmabadi, EndOfFile node sounds great. Pushed latest experiment and test case I'm using: Thought: when scanning can determine 'isAttached', 'isFollowed' & keep whitespace? Would avoid re-scanning (though don't know about services.ts / keeping in memory): |
The bug still exists in 1.5.3. And it's not all blocks: function hello(ok: boolean) {
if (ok) {
console.log("ok1");
// will be removed
}
// will be removed too
else {
console.log("ok2");
}
// will stay
}
hello(true); compiles to function hello(ok) {
if (ok) {
console.log("ok1");
}
else {
console.log("ok2");
}
// will stay
}
hello(true); |
So, this reproduces in TypeScript 1.6 as well Here's another case where it gets stripped out export = Main;
module Main {
// stays
class Foo {
// stays
public bar = 5;
// gets removed
}
// gets removed
} |
The last example is solved and it looks likes the first post is now correct to; only |
Another cases (moved from #26079 (comment)): index.ts // comment 1
import * as Module from './module';
// comment 2
import { SomeInterface } from './module';
export type A = typeof Module & SomeInterface; module.ts export interface SomeInterface {} After compiling we get the next content in // comment 1 (it seems that new line after/before comment does not help - #26079 (comment)) function foo() {
return {
foo: 5,
// this comment will be emitted
bar: 10,
// but this one wouldn't
};
} |
Looks like comments after a 'block' aren't emitted. Could it be a missing emitTrailingComments(node) ?
The text was updated successfully, but these errors were encountered: