Skip to content

Commit 273d815

Browse files
authored
Merge pull request #822 from BookOfGreg/webpacker-es6-gen
Use ES6 in ComponentGenerator for Webpacker
2 parents 16503ee + 2cc345c commit 273d815

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/generators/react/component_generator.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@ class ComponentGenerator < ::Rails::Generators::NamedBase
9090
}
9191

9292
def create_component_file
93-
template_extension = case
94-
when options[:es6]
95-
'es6.jsx'
96-
when options[:coffee]
93+
template_extension = if options[:coffee]
9794
'js.jsx.coffee'
95+
elsif options[:es6] || webpacker?
96+
'es6.jsx'
9897
else
9998
'js.jsx'
10099
end

test/generators/coffee_component_generator_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ class CoffeeComponentGeneratorTest < Rails::Generators::TestCase
1010
def filename
1111
'app/javascript/components/GeneratedComponent.coffee'
1212
end
13+
14+
test 'that Webpacker defaults to ES6' do
15+
run_generator %w(GeneratedComponent name)
16+
17+
es6 = File.read(File.join(destination_root, 'app/javascript/components/GeneratedComponent.js'))
18+
assert_match(%r{extends React.Component}, es6)
19+
end
1320
else
1421
def filename
1522
'app/assets/javascripts/components/generated_component.js.jsx.coffee'

0 commit comments

Comments
 (0)