-
Notifications
You must be signed in to change notification settings - Fork 22
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
JSX Support #53
Open
jtomaszewski
wants to merge
9
commits into
Shopify:master
Choose a base branch
from
jtomaszewski:jsx-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
JSX Support #53
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
704e6ab
Add support for jsx files
3den d6e6b9b
test tests to allowedextensions
3den 2c60ce1
fix typo
3den e1e6242
update index.js
3den 5a01694
Merge remote-tracking branch '3den/master'
jtomaszewski 34b4cab
Set default rake task to :test
jtomaszewski b7c60f2
Register jsx mime_type in sprockets. Add test for react js file
jtomaszewski e29abbe
Merge branch 'master' of github.com:Shopify/sprockets-commoner into j…
jtomaszewski a45906a
Fix react_test
jtomaszewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Sprockets | ||
module Commoner | ||
class JSXProcessor | ||
def self.call(input) | ||
{ data: input[:data] } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'test_helper' | ||
|
||
class AllowedExtensionsTest < MiniTest::Test | ||
def setup | ||
@env = Sprockets::Environment.new(File.join(__dir__, 'fixtures')) | ||
@processor = Sprockets::Commoner::Processor.new(@env.root) | ||
end | ||
|
||
def test_allowed_extensions | ||
assert @processor.send('should_process?', "#{@env.root}/my-lib.js") | ||
assert @processor.send('should_process?', "#{@env.root}/my-lib.js.erb") | ||
assert @processor.send('should_process?', "#{@env.root}/my-lib.json") | ||
assert @processor.send('should_process?', "#{@env.root}/my-lib.json.erb") | ||
assert @processor.send('should_process?', "#{@env.root}/myComponent.jsx") | ||
assert @processor.send('should_process?', "#{@env.root}/myComponent.jsx.erb") | ||
end | ||
|
||
def test_forbidden_extensions | ||
assert [email protected]('should_process?', "#{@env.root}/my-lib.jso") | ||
assert [email protected]('should_process?', "#{@env.root}/my-lib.jsxon") | ||
assert [email protected]('should_process?', "#{@env.root}/my-lib.jsonx") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
presets: ["react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./render'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ReactDOM.render( | ||
<h1>Hello, world!</h1>, | ||
document.getElementById('root') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'test_helper' | ||
|
||
class ReactTest < MiniTest::Test | ||
def setup | ||
@env = Sprockets::Environment.new(File.join(__dir__, 'fixtures')) | ||
@env.append_path File.join(__dir__, 'fixtures') | ||
end | ||
|
||
def test_react | ||
assert asset = @env['react.js'] | ||
assert_equal <<-JS.chomp, asset.to_s.chomp | ||
!function(global) { | ||
var __commoner_initialize_module__ = function(f) { | ||
var module = {exports: {}}; | ||
f.call(module.exports, module, module.exports); | ||
return module.exports; | ||
}; | ||
|
||
var __commoner_module__react$render_jsx = __commoner_initialize_module__(function (module, exports) { | ||
ReactDOM.render(React.createElement( | ||
'h1', | ||
null, | ||
'Hello, world!' | ||
), document.getElementById('root')); | ||
}); | ||
var __commoner_module__react$index_js = {}; | ||
}(typeof global != 'undefined' ? global : typeof window != 'undefined' ? window : this); | ||
JS | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what is this for?
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.
Not much for.. it just tells the sprockets that 'application/jsx' can be transformed into 'application/javascript' so it can be later included in the 'js' files.
Or we could just tell it that '.jsx' files are '.js' files stright away , by:
Or maybe there's some another better way to do it. I'm not sure, I'm not really familiar with sprockets yet
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.
I think just adding the
.jsx
extension as an acceptableapplication/javascript
extension is better