diff --git a/README.md b/README.md index 5c0eb0f43..34e80b9d7 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,16 @@ MyApp::Application.configure do end ``` +### Compile options + +To enable the "Harmony" compile functionality of the JSX compiler (which turns on JS transformations such as ES6 classes, etc.): + +```ruby +MyApp::Application.configure do + config.react.harmony = true +end +``` + ## CoffeeScript diff --git a/lib/react/jsx.rb b/lib/react/jsx.rb index f58d00a36..256b1d284 100644 --- a/lib/react/jsx.rb +++ b/lib/react/jsx.rb @@ -5,6 +5,7 @@ module React module JSX + def self.context # lazily loaded during first request and reloaded every time when in dev or test unless @context && ::Rails.env.production? @@ -24,7 +25,8 @@ def self.context end def self.transform(code) - result = context.call('JSXTransformer.transform', code) + result = context.call('JSXTransformer.transform', code, + harmony: ::Rails.application.config.react.harmony) return result['code'] end end diff --git a/lib/react/rails/railtie.rb b/lib/react/rails/railtie.rb index ad287f41d..f5cb59487 100644 --- a/lib/react/rails/railtie.rb +++ b/lib/react/rails/railtie.rb @@ -13,6 +13,7 @@ class Railtie < ::Rails::Railtie config.react.timeout = 20 #seconds config.react.react_js = lambda {File.read(::Rails.application.assets.resolve('react.js'))} config.react.component_filenames = ['components.js'] + config.react.harmony = false # default to harmony compilation disabled # Watch .jsx files for changes in dev, so we can reload the JS VMs with the new JS code. initializer "react_rails.add_watchable_files" do |app| diff --git a/test/dummy/app/assets/javascripts/example4.js.jsx b/test/dummy/app/assets/javascripts/example4.js.jsx new file mode 100644 index 000000000..3b6639e23 --- /dev/null +++ b/test/dummy/app/assets/javascripts/example4.js.jsx @@ -0,0 +1,3 @@ +/** @jsx React.DOM */ +class Example4{} +var e=new Example4(); \ No newline at end of file diff --git a/test/jsxtransform_test.rb b/test/jsxtransform_test.rb index 6906eaba1..e20d85d2e 100644 --- a/test/jsxtransform_test.rb +++ b/test/jsxtransform_test.rb @@ -23,6 +23,14 @@ }).call(this); eos +EXPECTED_JS_4 = <