Skip to content

feat(React::JSX): add JSX.transform_options #136

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

Merged
merged 3 commits into from
Jan 5, 2015
Merged

feat(React::JSX): add JSX.transform_options #136

merged 3 commits into from
Jan 5, 2015

Conversation

rmosolgo
Copy link
Member

I want the feature from #107 :)

Now you can say in application.rb:

config.react.jsx_transform_options = {harmony: true}

And you'll get es6 features in your .jsx assets. What do you think about this implementation?

  • Take a config
  • Assign it to a module variable
  • Use that when rendering with React::JSX::Template

I had to change the requires in the dummy application.js so that the ES6 file wouldn't wreck other tests.

I've used it with a test component in my app and it works!

React::JSX.transform_options = {harmony: true}
get '/assets/harmony_example.js'
assert_response :success
assert_match(/generateGreeting:function\(\)/, @response.body, "object literal methods")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this slightly more flexible in case whitespace changes. It's pretty unlikely we'll eve add it before the colon but after is pretty reasonable (in fact, I may go get somebody to fix that because it's bothering me now :D).

@zpao
Copy link
Member

zpao commented Dec 29, 2014

Thanks for picking this up, I think it's a great thing to do. You should be able to remove that 2nd commit now that #137 is in (thanks for the help btw).

@zpao
Copy link
Member

zpao commented Dec 29, 2014

We could also consider documenting the stripTypes option for anybody who wants to give flow a shot. Maybe we should do ruby -> js conversion (options.strip_types -> stripTypes)?

@rmosolgo
Copy link
Member Author

@zpao added :strip_types option. It's accepted Ruby-style strip_types and converted to stripTypes under the hood.

I found that stripTypes didn't work unless harmony: true. Is that a known thing? I didn't see any mention of it on https://github.com/facebook/react/blob/master/npm-react-tools/README.md. My local react-source is 0.12.0:

$ bundle show react-source
/Users/rmosolgo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/react-source-0.12.0

@rmosolgo
Copy link
Member Author

rmosolgo commented Jan 5, 2015

Oops, had to add a leading / for the tests to pass

@zpao
Copy link
Member

zpao commented Jan 5, 2015

Let's do it.

zpao added a commit that referenced this pull request Jan 5, 2015
feat(React::JSX): add JSX.transform_options
@zpao zpao merged commit 434834e into reactjs:master Jan 5, 2015
@rmosolgo rmosolgo deleted the harmony-option branch July 1, 2015 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants