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

Bug: incorrectly transpiled (Flow) comment #9810

Open
mrtnzlml opened this Issue Apr 2, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@mrtnzlml
Copy link

commented Apr 2, 2019

Bug Report

It is kind of related to Flow, however, Flow plugins are not involved in this.

Current Behavior
Input:

/*:: type TestType = number; */

const testFunction = () /*: TestType */ => 42;

Flow returns No errors!. However, Babel (with or without Flow plugins, doesn' matter) transpiles this into:

/*:: type TestType = number; */
const testFunction = () =>
/*: TestType */
42;

Which is invalid Flow code:

3: /*: TestType */
   ^ Unexpected token :

Expected behavior/code
Transpiled code is still valid Flow code.

Babel Configuration (.babelrc, package.json, cli command)
No config needed.

Environment

  • Babel version(s): ^7
  • Node/npm version: Node 11.12.0 / Yarn 1.15.2 (irrelevant?)
  • OS: OSX 10.14.3 (irrelevant?)
  • Monorepo: yes, Yarn workspaces
  • How you are using Babel: cli, register, loader, REPL

Additional context/Screenshots
Screenshot 2019-04-02 at 09 46 42

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Apr 2, 2019

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

@mrtnzlml

This comment has been minimized.

Copy link
Author

commented Apr 2, 2019

Seems like one possible workaround is to use retainLines: true. I am looking for a solution though... :)

mrtnzlml added a commit to kiwicom/babel-preset-kiwicom that referenced this issue Apr 3, 2019

Babel preset: fix incorrect transpilation of Flow comments
Hopefully, this is just a temporary workaround. Re-releasing all the affected modules.

See: babel/babel#9810

Closes: https://gitlab.skypicker.com/incubator/universe/issues/467

mrtnzlml added a commit to kiwicom/eslint-config-kiwicom that referenced this issue Apr 3, 2019

Babel preset: fix incorrect transpilation of Flow comments
Hopefully, this is just a temporary workaround. Re-releasing all the affected modules.

See: babel/babel#9810

Closes: https://gitlab.skypicker.com/incubator/universe/issues/467

mrtnzlml added a commit to kiwicom/monorepo-utils that referenced this issue Apr 3, 2019

Babel preset: fix incorrect transpilation of Flow comments
Hopefully, this is just a temporary workaround. Re-releasing all the affected modules.

See: babel/babel#9810

Closes: https://gitlab.skypicker.com/incubator/universe/issues/467

mrtnzlml added a commit to kiwicom/babel-preset-kiwicom that referenced this issue Apr 3, 2019

Babel preset: fix incorrect transpilation of Flow comments
Hopefully, this is just a temporary workaround. Re-releasing all the affected modules.

See: babel/babel#9810

Closes: https://gitlab.skypicker.com/incubator/universe/issues/467

kiwicom-source-id: 3292322215286d0103e570daee668a3371a308f7

mrtnzlml added a commit to kiwicom/eslint-config-kiwicom that referenced this issue Apr 3, 2019

Babel preset: fix incorrect transpilation of Flow comments
Hopefully, this is just a temporary workaround. Re-releasing all the affected modules.

See: babel/babel#9810

Closes: https://gitlab.skypicker.com/incubator/universe/issues/467

kiwicom-source-id: 3292322215286d0103e570daee668a3371a308f7

mrtnzlml added a commit to kiwicom/monorepo-utils that referenced this issue Apr 3, 2019

Babel preset: fix incorrect transpilation of Flow comments
Hopefully, this is just a temporary workaround. Re-releasing all the affected modules.

See: babel/babel#9810

Closes: https://gitlab.skypicker.com/incubator/universe/issues/467

kiwicom-source-id: 3292322215286d0103e570daee668a3371a308f7
@mrtnzlml

This comment has been minimized.

Copy link
Author

commented Apr 4, 2019

We tried retainLines: true but it didn't really solve the problem. It still yields wrong code when the function is more complex and parameters are defined on multiple lines. One other workaround is to use normal function (not arrow definition):

/*:: type TestType = number; */

const testFunction1 = () /*: TestType */ => 42; // yields invalid code

const testFunction2 = () /*: TestType */ => { return 42 } // yields invalid code

function testFunction3() /*: TestType */ {
  return 42;
}

Only the testFunction3 is a valid code after transformation:

/*:: type TestType = number; */
const testFunction1 = () =>
/*: TestType */
42; // yields invalid code


const testFunction2 = () =>
/*: TestType */
{
  return 42;
}; // yields invalid code


function testFunction3()
/*: TestType */
{
  return 42;
}

See: https://flow.org/try/#0PQKgXGAEAuCeAOBTSAVRBnaKHILyQDsBXAWwCNEAnAbkhGACgBjAewMxg2gDEiCnoASzYBGSPgAUASnEA+BqChpM2JHUYAWAEy1gwSLEGIANgBN0kQQQBuAQ2ODTkVqcQN3rdtE6Ze-IWxa4pDScgrgqFyqyPQMAN4MkJCUiNBElASQ2tQMAL66+oYm5pY29o7OLK7uDABmfALCmdBcfo1sAMzS4UpROOrxicmp6ZnZeUA

kiwicom-github-bot added a commit to kiwicom/monorepo-npm-publisher that referenced this issue Apr 8, 2019

Babel preset: fix incorrect transpilation of Flow comments
Hopefully, this is just a temporary workaround. Re-releasing all the affected modules.

See: babel/babel#9810

Closes: https://gitlab.skypicker.com/incubator/universe/issues/467

kiwicom-source-id: 3292322215286d0103e570daee668a3371a308f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.