Skip to content

Commit caa8df4

Browse files
committed
- Added Babel Transformer test to verify that the transformer accepts transformation options
- Fixed passing of transform options to the transformer
1 parent 9f97a06 commit caa8df4

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

lib/react/jsx/babel_transformer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ def initialize(options)
1010
"Please use new Babel Transformer options :whitelist, :plugin instead.")
1111
end
1212

13-
DEFAULT_TRANSFORM_OPTIONS.merge(options)
13+
@transform_options = DEFAULT_TRANSFORM_OPTIONS.merge(options)
1414
end
1515

1616
def transform(code)
17-
Babel::Transpiler.transform(code)['code']
17+
Babel::Transpiler.transform(code, @transform_options)['code']
1818
end
1919
end
2020
end

test/react/jsx_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ class JSXTransformTest < ActionDispatch::IntegrationTest
6767
assert_equal "TRANSFORMED CODE!;\n", @response.body
6868
end
6969

70+
def test_babel_transformer_accepts_babel_transformation_options
71+
React::JSX.transform_options = {blacklist: ['spec.functionName', 'validation.react', "strict"]}
72+
get '/assets/example.js'
73+
assert_response :success
74+
75+
assert_not_includes @response.body, 'strict'
76+
end
77+
7078
end
7179

7280
class JSXTransformerTest < ActionDispatch::IntegrationTest

test/test_helper.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ def clear_sprockets_cache
2929
# so override `fresh?` to mark it as expired.
3030
def manually_expire_asset(asset_name)
3131
asset = Rails.application.assets[asset_name]
32-
33-
def asset.fresh?(env)
34-
; false;
35-
end
32+
def asset.fresh?(env); false; end
3633
end
3734

3835
# Load support files

0 commit comments

Comments
 (0)