Skip to content

Ability to emit jsdocs ending on previous line instead of same line? #7492

@dsherret

Description

@dsherret

Describe the feature

Currently code like the following:

/** Test */
function test() {}

/** Test */
export class Test {
  /**
   * Multi-line
   */
  method() {}
}

Will emit with comments like so:

/** Test */ function test() {}
/** Test */ export class Test {
    /**
   * Multi-line
   */ method() {}
}

https://play.swc.rs/?version=1.3.62&code=H4sIAAAAAAAAA9PX0lIISS0uUdDS5%2BVKK81LLsnMz1MoAYpoaCpU1%2FJy8XLpIytJrSjILypRSM5JLC6GiFbzcikoANWAKAUtBd%2FSnJJM3ZzMvFSIgD6Iyk0tychPgZpYCwCN0JyldAAAAA%3D%3D&config=H4sIAAAAAAAAA11Ru27DMAzc8xWG5gxthg7dihTe%2BhGEQjsq9DBIOqgR%2BN8rKpLrdJHEu%2BPxofuh68w3W%2FPe3fMzBxMQI21xRniJAj8ZMbJMyJbcJObYWGGlhGYsyHqsNoTZ5oYf3p9TCBiFq6wKBGhEUVfk08vp1TScIPKQKOxbmBk%2FcXAR%2B0RnD8y9Q395dswyQrCyyyt9wBhAy1y3nje4z6dSemuLewXNUVxApa1WdNZUcn0a1KfEqhrAc5stuOiGZT9AgDj6f7IM2xR0UdyIQ%2FMv7iaky1yy6t%2Fo%2Fh8bezN%2FolZsszaOv1pm%2BZj1F5W1tcznAQAA

I'm emitting some typescript declarations using swc where only the jsdoc comments are preserved and the output doesn't look great because of this (I'd rather avoid doing post-processing on it, but it's not a big deal if I have to do that)

What are your thoughts on making swc do this? For a fast implementation, perhaps it should only do it for block comments that start with * and preceed declarations?

Both Babel and TypeScript keep the jsdoc on the previous line, but will also keep it on the same line if the person has the code that way.

Babel plugin or link to the feature description

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions