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

transform-flow-strip-types removes all jsdoc comments. #6898

Closed
ozum opened this issue Nov 24, 2017 · 6 comments
Closed

transform-flow-strip-types removes all jsdoc comments. #6898

ozum opened this issue Nov 24, 2017 · 6 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@ozum
Copy link

ozum commented Nov 24, 2017

This is a bug report.

babel-plugin-transform-flow-strip-types removes all jsdoc comments, if source file contains only flowtype code and no regular javascript. When there is some regular javascript code i.e. const a = 1, jsdoc comments are preserved.

Input Code

// @flow
/**
 * Description of type
 * @typedef  {Object} SomeType
 * @property {string} name - name
 */
export type SomeType = {| name: string |};

Babel/Babylon Configuration (.babelrc, package.json, cli command)

{
  "presets": [
    "flow", ["env", { "targets": { "node": "current" }, "useBuiltIns": true }]
  ],
  "plugins": [
    "add-module-exports",
    "transform-export-extensions"
  ],
  "env": {
    "test": {
      "plugins": [
        ["istanbul", { "useInlineSourceMaps": false }]
      ]
    }
  }
}

Expected Behavior

"use strict";
//# sourceMappingURL=rule-config.js.map
/**
 * Description of type
 * @typedef  {Object} SomeType
 * @property {string} name - name
 */

Current Behavior

"use strict";
//# sourceMappingURL=rule-config.js.map

Possible Solution

Comments should be preserved, even there is no js code.

Context

I'm using flow for static type checking and jsdoc for documentation purposes. Since babel-plugin-transform-flow-strip-types removes all jsdoc comments, documentation affected negatively.

Your Environment

software version(s)
Babel 6.26.0
Babylon
node 9.2.0
npm 5.5.1
Operating System macOS 10.12.6
@babel-bot
Copy link
Collaborator

Hey @ozum! 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.

@Arfey
Copy link

Arfey commented Dec 3, 2017

Are you sure that it's transform-flow-strip-types remove comments?
transform-flow-strip-types remove only comments that including @flow.

You can see test for your case:
actual
https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-directive/actual.js
expected
https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-directive/expected.js

@nicolo-ribaudo
Copy link
Member

It's because that comment is attatched to the tpe declaration node, which is removed.

@ozum
Copy link
Author

ozum commented Dec 3, 2017

@Arfey, I'm sure it's from transform-flow-strip-types, I tried by removing all other plugins.

@nicolo-ribaudo, yes it is a type declaration comment, but not a flow comment. As @Arfey said, only comments that includes @flow should be removed. Also if I add a single expression, comments are not deleted. Please see two examples below:

Without regular JS

// @flow
/**
 * Description of type
 * @typedef  {Object} SomeType
 * @property {string} name - name
 */
export type SomeType = {| name: string |};

is transpiled to

"use strict";
//# sourceMappingURL=fields.js.map

With regular JS

// @flow
/**
 * Description of type
 * @typedef  {Object} SomeType
 * @property {string} name - name
 */
export type SomeType = {| name: string |};
1;

is transpiled to:

"use strict";

1;

/**
 * Description of type
 * @typedef  {Object} SomeType
 * @property {string} name - name
 */
//# sourceMappingURL=fields.js.map

@loganfsmyth
Copy link
Member

Hmm, this is a tough one. We probably can address this with special logic if we decide to, but no matter what you'll kind of be walking a fine line. We don't generally guarantee that comments will pass through as-is, for Babel transforms because our parsed representation isn't exact for comments.

@xtuc
Copy link
Member

xtuc commented Nov 6, 2018

Closing, out of scope for now.

@xtuc xtuc closed this as completed Nov 6, 2018
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

6 participants