Skip to content

Commit c1081ab

Browse files
committed
Merge pull request #16 from quark-zju/fix-with-therubyracer
Fix JSXTransformer when therubyracer is used by execjs
2 parents 6123e2e + d42d295 commit c1081ab

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Appraisals

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ end
99
appraise "rails-4.0" do
1010
gem 'rails', '~> 4.0'
1111
end
12+
13+
appraise "rails-4.0-with-therubyracer" do
14+
gem 'rails', '~> 4.0'
15+
gem 'therubyracer', '0.12.0', :platform => :mri
16+
end

lib/react/jsx.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ module React
66
module JSX
77
def self.context
88
# TODO: create React::Source::contents_for
9-
contents = File.read(React::Source.bundled_path_for('JSXTransformer.js'))
9+
contents =
10+
# If execjs uses therubyracer, there is no 'global'. Make sure
11+
# we have it so JSX script can work properly.
12+
'var global = global || this;' +
13+
File.read(React::Source.bundled_path_for('JSXTransformer.js'))
1014
@context ||= ExecJS.compile(contents)
1115
end
1216

test/test_helper.rb

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
Rails.backtrace_cleaner.remove_silencers!
88

9+
# Remove cached files
10+
Rails.root.join('tmp').tap do |tmp|
11+
tmp.rmtree
12+
tmp.mkpath
13+
end
14+
915
# Load support files
1016
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
1117

0 commit comments

Comments
 (0)