Sha256: 84e156221b9bebbb24c89ac763ff74376da2192d93a40e04e94085fb780a842b

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

module React
  module JSX
    # A {React::JSX}-compliant transformer which uses the deprecated `JSXTransformer.js` to transform JSX.
    class JSXTransformer
      DEFAULT_ASSET_PATH = 'JSXTransformer.js'

      def initialize(options)
        @transform_options = {
          stripTypes: options.fetch(:strip_types, false),
          harmony:    options.fetch(:harmony, false)
        }

        @asset_path = options.fetch(:asset_path, DEFAULT_ASSET_PATH)

        # If execjs uses therubyracer, there is no 'global'. Make sure
        # we have it so JSX script can work properly.
        js_code = 'var global = global || this;' + jsx_transform_code
        @context = ExecJS.compile(js_code)
      end

      def transform(code)
        result = @context.call('JSXTransformer.transform', code, @transform_options)
        result['code']
      end

      # search for transformer file using sprockets - allows user to override
      # this file in their own application
      def jsx_transform_code
        ::Rails.application.assets[@asset_path].to_s
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
react-rails-2.7.1 lib/react/jsx/jsx_transformer.rb
react-rails-2.7.0 lib/react/jsx/jsx_transformer.rb
react-rails-2.7.0.rc.2 lib/react/jsx/jsx_transformer.rb
react-rails-2.7.0.rc.1 lib/react/jsx/jsx_transformer.rb
react-rails-2.7.0.rc.0 lib/react/jsx/jsx_transformer.rb
react-rails-2.6.2 lib/react/jsx/jsx_transformer.rb
react-rails-2.6.1 lib/react/jsx/jsx_transformer.rb
react-rails-2.6.0 lib/react/jsx/jsx_transformer.rb
react-rails-2.5.0 lib/react/jsx/jsx_transformer.rb
react-rails-2.4.7 lib/react/jsx/jsx_transformer.rb