Skip to content

Commit

Permalink
feat: Add sucrase hook as alternative for .jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Apr 7, 2022
1 parent 6dbe2a7 commit 58f678e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
21 changes: 12 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,19 @@ var extensions = {
'.js': null,
'.json': null,
'.json5': 'json5/lib/register',
'.jsx': {
module: '@babel/register',
register: function (hook) {
hook({
extensions: '.jsx',
rootMode: 'upward-optional',
overrides: [{ only: [endsInJsx] }],
});
'.jsx': [
{
module: '@babel/register',
register: function (hook) {
hook({
extensions: '.jsx',
rootMode: 'upward-optional',
overrides: [{ only: [endsInJsx] }],
});
},
},
},
'sucrase/register/jsx'
],
'.litcoffee': 'coffeescript/register',
'.mjs': mjsStub,
'.node': null,
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/jsx/1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"sucrase": "^3.12.1"
}
}
17 changes: 17 additions & 0 deletions test/fixtures/jsx/1/test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const React = {
createElement: function (Component) {
return Component();
},
};

// Test harmony arrow functions
const Component = () => {
var trueKey = true;
var falseKey = false;
var subKey = { subProp: 1 };
// Test harmony object short notation
return { data: { trueKey, falseKey, subKey } };
};

// Test JSX syntax
module.exports = <Component />;

0 comments on commit 58f678e

Please sign in to comment.