babel / babel

🐠 Babel is a compiler for writing next generation JavaScript.
https://babel.dev
MIT License
43.17k stars 5.64k forks source link

Comments are stripped when all code from a file is removed by @babel/plugin-transform-typescript #11803

Open andsouto opened 4 years ago

andsouto commented 4 years ago

Bug Report

Current behavior When processing a file where all its contents is removed during transpilation, comments are also removed. If some code is kept, comments are kept.

But if you add any additional code to the file it works in the exepcted way:

Input Code

/**
 * @typedef {object} user
 * @property {string} [id]
 */
export interface User {
    id?: string;
}

Expected behavior Comments are kept even when all the content is stripped.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

{
    plugins: [
        '@babel/plugin-transform-typescript',
    ],
}

Environment

babel-bot commented 4 years ago

Hey @kai670! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."