Sha256: 3bd4e2807060858697ce7eb17017c724fddbc81f31cfc1062f77d42f77124687

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require "babel/transpiler"
module React
  module JSX
    # A {React::JSX}-compliant transformer which uses `Babel::Transpiler` to transform JSX.
    class BabelTransformer
      DEPRECATED_OPTIONS = %i[harmony strip_types asset_path].freeze
      DEFAULT_TRANSFORM_OPTIONS = { blacklist: ["spec.functionName", "validation.react", "strict"] }.freeze
      def initialize(options)
        if (options.keys & DEPRECATED_OPTIONS).any?
          ActiveSupport::Deprecation.warn(
            <<-MSG
              Setting config.react.jsx_transform_options for :harmony, :strip_types, and :asset_path keys is now deprecated and has no effect with the default Babel Transformer.
              Please use new Babel Transformer options :whitelist, :plugin instead.
            MSG
          )
        end

        @transform_options = DEFAULT_TRANSFORM_OPTIONS.merge(options)
      end

      def transform(code)
        Babel::Transpiler.transform(code, @transform_options)["code"]
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
react-rails-3.2.0 lib/react/jsx/babel_transformer.rb
react-rails-3.1.1 lib/react/jsx/babel_transformer.rb
react-rails-3.1.0 lib/react/jsx/babel_transformer.rb
react-rails-3.0.0 lib/react/jsx/babel_transformer.rb
react-rails-3.0.0.rc.0 lib/react/jsx/babel_transformer.rb