babel / ruby-babel-transpiler

Ruby Babel is a bridge to the JS Babel transpiler.
https://github.com/babel/ruby-babel-transpiler
MIT License
160 stars 27 forks source link

Babel plugin support? #286

Closed c-lliope closed 8 years ago

c-lliope commented 8 years ago

Hello! I'm trying out Flow on my Rails app, and I'm trying to set up ruby-babel-transpiler to strip out Flow type annotations.

There's an existing Babel plugin that can take care of this, but it doesn't look like it's available in ruby-babel-transpiler.

I've added this configuration to my config/application.rb file:

    config.react.jsx_transform_options = {
      "plugins" => ["transform-flow-strip-types"],
    }

And in the browser, I get an error:

ReferenceError: Unknown plugin "transform-flow-strip-types"

I'm curious - is there a plan to make babel plugins available through this project? Would they be packaged as separate gems? If so, what would the structure of those gems look like?

ralekna commented 8 years ago

As far as I know Babel automatically strips Flow annotations itself during transpilation and it doesn't need additional plugin for that. Have in mind that Flow is just a static type checker and doesn't add any code transformations and is more a code documentation tool.

c-lliope commented 8 years ago

@ralekna thanks for the fast response!

According to Flow's documentation, a special plugin is needed to strip out Flow annotations. I've tried using Flow in my Rails project without the plugin, and I got syntax errors that prevented the JS on the page from running.

The bottom section of this page shows what the flow plugin is doing when it transforms the input.

hzoo commented 8 years ago

The http://babeljs.io/docs/plugins/transform-flow-strip-types/ plugin is for babel 6 which has no plugins by default thus everything is opt-in.

ralekna commented 8 years ago

@graysonwright it's a bit strange because as I see a PR for Babel v.6 (https://github.com/babel/ruby-babel-transpiler/pull/282) is not yet merged into master. Are you really sure that those syntax errors are cause by Flow markup? I use current version of this gem with Flow annotations and it works like a charm without adding any plugins.

c-lliope commented 8 years ago

@ralekna - sorry for letting this get stale. I no longer have access to the app, so I'm not able to reproduce. It seems like it's working well for everyone else, so I'm OK closing this.

Thanks for your help!

selvagsz commented 6 years ago

Getting the same error while using transform-decorators plugin. Are there any plans to merge the babel v6 PR ?