Class: JSX::Transformer
- Inherits:
-
Object
- Object
- JSX::Transformer
- Includes:
- Singleton
- Defined in:
- lib/jsx/transformer.rb
Constant Summary collapse
- JSX_SOURCE_PATH =
React::Source.bundled_path_for('JSXTransformer.js')
Instance Method Summary collapse
- #call(code, strip_types: false, harmony: false) ⇒ Object
-
#initialize ⇒ Transformer
constructor
A new instance of Transformer.
Constructor Details
#initialize ⇒ Transformer
Returns a new instance of Transformer.
10 11 12 13 14 15 |
# File 'lib/jsx/transformer.rb', line 10 def initialize # If execjs uses therubyracer, there is no 'global'. Make sure # we have it so JSX script can work properly. contents = 'var global = global || this;' + File.read(JSX_SOURCE_PATH) @context = ExecJS.compile(contents) end |
Instance Method Details
#call(code, strip_types: false, harmony: false) ⇒ Object
17 18 19 20 |
# File 'lib/jsx/transformer.rb', line 17 def call(code, strip_types: false, harmony: false) result = @context.call('JSXTransformer.transform', code, stripTypes: strip_types, harmony: harmony) result['code'] end |