-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix JSXTransformer when therubyracer is used by execjs #16
Conversation
We had a longer discussion on IRC about gemfiles and decided to have them in the repo. AFAIK argument no. 2, i.e. developer-specific paths, is either already outdated or will soon be, because (thoughtbot/appraisal#49) bundler 1.4 makes these paths relative. I haven't checked yet though. Anyway, such changes as including I would ask you to be patient for a few next days, because I will be finishing #15 and #12 even though they are (especially #12) seemingly dead. I hope we'll then have your PR rebased against master and we'll rethink if it's an optimal solution. |
First, thanks for catching this (and adding a test)! I'll have a few comments inline. But first... Ok, I thought about the |
Also, I don't want to block anybody if it can be avoided, so whichever doesn't get it first will need to rebase and test appropriately. |
@@ -6,12 +6,14 @@ module React | |||
module JSX | |||
def self.context | |||
# TODO: create React::Source::contents_for | |||
contents = File.read(React::Source.bundled_path_for('JSXTransformer.js')) | |||
contents = | |||
'if("undefined"==typeof global)global={};' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's cleanup the JS a bit and then reformat while we're here. We'll take advantage of the fact that we're in a clean context so this
is the global which is guaranteed to exist.
contents =
'var global = global || this;' +
File.read(React::Source.bundled_path_for('JSXTransformer.js'))
Can you also add a comment above saying why we're doing this (JSXTransformer has UMD wrapper which only checks for window, global, and self but a clean context in therubyracer doesn't have any of those)
Thanks a lot for the quick followup! I actually think I'll push out a release today with just this. #15 is already in. #12 is going to include a major version bump and start diverging from the React version number scheme we have now. Or at least it was from what I remember, though that change isn't in there now. |
Fix JSXTransformer when therubyracer is used by execjs
The
execjs
gem will try to use native v8 js library therubyracer if it is available. Otherwiseexecjs
will try to execute externalnode
, which is the case in current tests.The problem is,
node
hasglobal
defined buttherubyracer
doesn't:JSX cannot work properly with neither
global
norwindow
defined. This pull request fixes it by definingglobal
. I also added tests for the change and fix some other small issues I found.For adding
gemfiles
directory to.gitignore
, I know the community may suggest include Gemfile and Gemfile.lock in source control. But here is different. Reasons:That being said, the Gemfile and Gemfile.lock at the root directory should not be removed.