-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Bug Report
EDIT: See my comment #9916 (comment) below, there is a strange inconsistency depending on the location of import statements.
Running Babel with nothing but @babel/plugin-transform-typescript removes all but the very first of many JSDoc @typedef comments.
Those comments are for (and just above) Typescript type definitions (export type, export interface). When the Typescript types are stripped, so are the JSDoc comments. When I run jsdoc3 to generate the HTML API docs this tool too runs Babel and this plugin in order to be able to parse the file. Obviously, the removal of the JSDoc is counterproductive especially in this use case.
Environment
-
Babel version(s): 7.4.4
-
Node/npm version: 11.14
-
jsdoc 3.5.5
-
OS: Linux
-
How you are using Babel: jsdoc3, config (jsdoc.json, babel section):
"babel": {
"extensions": ["js","ts","jsx","tsx"],
"presets": ["@babel/preset-typescript"],
"plugins": [],
"babelrc": false
},
Example
Here is an excerpt of the beginning of a file with many TS type definitions and there accompanying JSDoc comments.
/**
* This defines the creation status string constants for files
* @global
* @typedef {("new"|"exists")} FileCreationStatus
*/
export type FileCreationStatus = typeof CREATION_STATUS[keyof typeof CREATION_STATUS];
/**
* @global
* @typedef {Object} FileCreation
* @property {SHA256Hash} hash - The SHA-256 hash of the contents of a versioned ONE object
* @property {FileCreationStatus} status - A string constant showing whether the file
* already existed or if it had to be created.
*/
export interface FileCreation {
hash: SHA256Hash;
status: FileCreationStatus;
}
/**
* This defines the creation status string constants for objects.
* @global
* @typedef {FileCreationStatus} ObjectCreationStatus
*/
export type ObjectCreationStatus = FileCreationStatus;After the transformation only this is left of these comments:
/**
* This defines the creation status string constants for files
* @global
* @typedef {("new"|"exists")} FileCreationStatus
*/
export type FileCreationStatus = typeof CREATION_STATUS[keyof typeof CREATION_STATUS];Lots and lots of comments erased while there were nothing but Typescript type definitions encountered by the parser. Only when there was actual JS code again did the comment removal stop.
Proposed solution
Don't delete any JSDoc (or any) comments. Comment removal should be left to the boolean "comment" Babel configuration property and whatever Babel code is following that instruction. If it is not set to true no comments should be removed, especially not JSDoc @typedef ones.