Skip to content
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

Emit comments even if related code is not emitted #1665

Closed
zzm2q opened this issue Jan 14, 2015 · 9 comments
Closed

Emit comments even if related code is not emitted #1665

zzm2q opened this issue Jan 14, 2015 · 9 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript

Comments

@zzm2q
Copy link

zzm2q commented Jan 14, 2015

for example:

class A {
  /**
   *  some document
   */
  prop:number;
  constructor(prop:number) {
  }
}

the document part would be removed unless prop initialized with a value after compiled, i think it should be remained in compiled file.

@DanielRosenwasser
Copy link
Member

I'm sorry, do you mean that the comment preceding prop isn't being emitted but should be?

@basarat
Copy link
Contributor

basarat commented Jan 14, 2015

@zzm2q just FYI the following

class A {
  prop:number;
  constructor(prop:number) {
  }
}

is not the same as (perhaps what you want):

class A {
  constructor(public prop:number) {
  }
}

@mhegazy
Copy link
Contributor

mhegazy commented Jan 14, 2015

Also note that the field declaration does not have a JavaScript equivalent; do this is a pure typescript construct that does not get translated. The comment in your example is attached to the field declaration.

@zzm2q
Copy link
Author

zzm2q commented Jan 14, 2015

em, i guess i didn't described clearly.
@DanielRosenwasser yeah, i mean that the comment preceding prop isn't being emitted but should be.

@zzm2q
Copy link
Author

zzm2q commented Jan 14, 2015

There are tow way to walk around it:

class A {
  /**
   * comment would be emitted with first case.
   */
  prop:number = 0; // 1. initialized with a value
  constructor(prop:number) {
    /**
     * 2. comment here also works.
     */
    this.prop = prop;
  }
}

that's ok but not convenient and not obvious。

@danquirk
Copy link
Member

Do you want the comment preserved even though the field isn't emitted? The field is not emitted without an initializer (by design) and so neither is its comment.

@zzm2q
Copy link
Author

zzm2q commented Jan 15, 2015

Yeah, that's what i want, it's not strong demand. I want this since i was using jsduck to generate document of my library from ts files but fail to. And then, i successfully generated from compiled js but lost some that comments of property without an initializer.

@danquirk danquirk added the Suggestion An idea for TypeScript label Jan 15, 2015
@danquirk danquirk changed the title Document should be remained in compiled file. Emit comments even if related code is not emitted Jan 15, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Dec 8, 2015

the correct fix here is to allow an extensiblity layer in the emitter and allow such customization if/when needed. #5595 tracks moving the emitter to a transformation based pipeline, and that should get us most of the way to enabling such scenarios. the OP however is out of scope of the TypeScript project.

@mhegazy mhegazy closed this as completed Dec 8, 2015
@mhegazy mhegazy added Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints labels Dec 8, 2015
@cardiffman
Copy link

I'm trying to get a "//EOL" comment between declarations at the top level of a file to be preserved. When I researched the necessary option for preserving comments, I was surprised to see that the compiler is configured to preserve comments by default, and you have to ask for comments to be removed. So what I see in the documentation is that comments are 100% supposed to be preserved. The option is not defined as "remove the comments we didn't already remove".

The project I'm considering TS for has an "include" file system which adds in additional files. The system has a handful of different implementations depending on whether scripts come from the filesystem (in one of two different layouts) or from a database. The early version of the database was prone to appending small amounts of trash characters, so we arrived at putting "//EOL" in the file at the end. Then we started using that like the "if name == 'main'" idiom of Python to put a unit test in the file. With the "//EOL" in between, the file would work as a main file when the EOL was ignored. So now we have dozens of files like this. If comments were truly preserved, then the activation energy I would need to transition the project to TS would be much lower, because I could do one file this week, 10 files next week, advertise the benefits, continue converting files lazily until budget was approved. If not, I have to speculate about the benefits achieved based on one or two files, which I manually restore the //EOL in, and then basically get approval to convert the whole thing because I need to plan a big-bang conversion of the include file system up front.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants