Class: JSX::Transformer

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeTransformer

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