Skip to content

Use ES6 in ComponentGenerator for Webpacker #822

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 1 commit into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/generators/react/component_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ class ComponentGenerator < ::Rails::Generators::NamedBase
}

def create_component_file
template_extension = case
when options[:es6]
'es6.jsx'
when options[:coffee]
template_extension = if options[:coffee]
'js.jsx.coffee'
elsif options[:es6] || webpacker?
'es6.jsx'
else
'js.jsx'
end
Expand Down
7 changes: 7 additions & 0 deletions test/generators/coffee_component_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class CoffeeComponentGeneratorTest < Rails::Generators::TestCase
def filename
'app/javascript/components/GeneratedComponent.coffee'
end

test 'that Webpacker defaults to ES6' do
run_generator %w(GeneratedComponent name)

es6 = File.read(File.join(destination_root, 'app/javascript/components/GeneratedComponent.js'))
assert_match(%r{extends React.Component}, es6)
end
else
def filename
'app/assets/javascripts/components/generated_component.js.jsx.coffee'
Expand Down