Skip to content

Commit 7b75612

Browse files
committed
feat(strip_types) accept strip_types config
1 parent 3ad32d3 commit 7b75612

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ Component = React.createClass
6868
`<ExampleComponent videos={this.props.videos} />`
6969
```
7070

71-
You can use the `--harmony` option by adding a configuration to `application.rb`:
71+
You can use the `--harmony` or `--strip-types` options by adding a configuration to `application.rb`:
7272

7373
```ruby
74-
config.react.jsx_transform_options = {harmony: true}
74+
config.react.jsx_transform_options = {
75+
harmony: true,
76+
strip_types: true, # for removing Flow type annotations
77+
}
7578
```
7679

7780
### Unobtrusive JavaScript

lib/react/jsx.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ def self.context
2626
end
2727

2828
def self.transform(code, options={})
29-
result = context.call('JSXTransformer.transform', code, options)
29+
js_options = {
30+
stripTypes: options[:strip_types],
31+
harmony: options[:harmony],
32+
}
33+
result = context.call('JSXTransformer.transform', code, js_options)
3034
return result['code']
3135
end
3236
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function flowTypesExample(i: number, name: string): string {
2+
return "OK"
3+
}

test/jsxtransform_test.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,17 @@ class JSXTransformTest < ActionDispatch::IntegrationTest
5454

5555
test 'accepts harmony: true option' do
5656
React::JSX.transform_options = {harmony: true}
57-
get 'assets/harmony_example.js'
57+
get '/assets/harmony_example.js'
5858
assert_response :success
5959
assert_match(/generateGreeting:\s*function\(\)/, @response.body, "object literal methods")
6060
assert_match(/React.__spread/, @response.body, "spreading props")
6161
assert_match(/Your greeting is: '" \+ insertedGreeting \+ "'/, @response.body, "string interpolation")
6262
end
63+
64+
test 'accepts strip_types: true option' do
65+
React::JSX.transform_options = {strip_types: true, harmony: true}
66+
get '/assets/flow_types_example.js'
67+
assert_response :success
68+
assert_match(/\(i\s*,\s*name\s*\)\s*\{/, @response.body, "type annotations are removed")
69+
end
6370
end

0 commit comments

Comments
 (0)