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

sourceType: 'unambiguous' ignores type imports/exports #11627

Open
1 task done
jedwards1211 opened this issue May 27, 2020 · 1 comment
Open
1 task done

sourceType: 'unambiguous' ignores type imports/exports #11627

jedwards1211 opened this issue May 27, 2020 · 1 comment

Comments

@jedwards1211
Copy link
Contributor

jedwards1211 commented May 27, 2020

Bug Report

  • I would like to work on a fix!

Current behavior
A clear and concise description of the behavior.

If a file only contains type imports or exports, Babel seems to assume the source type is script. Consequently, a value import inserted by a plugin (babel-plugin-flow-runtime) never gets transpiled by plugin-transform-modules-commonjs.

gajus/flow-runtime#242

I'm not sure if this is intentional or fixable or not? I know sourceType: 'unambiguous' is probably governed by a grammar spec that doesn't deal with type imports or exports. But maybe the unexpected issue I'm running into with this is worth thinking about.

Input Code

// @flow

export type ConnectionStatus = 'connecting' | 'connected' | 'error'

Expected behavior
A clear and concise description of what you expected to happen (or code).

import statements inserted by plugins get transpiled by plugin-transform-modules-commonjs.

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

  • Filename: babel.config.js
{
  "plugins": [
    ["@babel/plugin-proposal-decorators", {"legacy": true}],
    "babel-plugin-flow-runtime"
  ],
  "presets": [
    ["@babel/preset-env", {"targets": {"node": "current"}}],
    "@babel/preset-flow"
  ],
  "sourceType": "unambiguous"
}

Environment

  System:
    OS: macOS 10.15.3
  Binaries:
    Node: 12.16.2 - ~/.nvm/versions/node/v12.16.2/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.2/bin/npm
  npmPackages:
    @babel/cli: ^7.10.0 => 7.10.0 
    @babel/core: ^7.10.0 => 7.10.0 
    @babel/plugin-proposal-decorators: ^7.10.0 => 7.10.0 
    @babel/preset-env: ^7.10.0 => 7.10.0 
    @babel/preset-flow: ^7.9.0 => 7.9.0 
    babel-plugin-flow-runtime: ^0.19.0 => 0.19.0 
@babel-bot
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants