Skip to content

Commit

Permalink
feat: Support .mdx extension hook (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Apr 8, 2022
1 parent 7989161 commit cd24c39
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ var extensions = {
'sucrase/register/jsx',
],
'.litcoffee': 'coffeescript/register',
// The mdx loader hooks both `.md` and `.mdx` when it is imported
// but we only install the hook if `.mdx` is the first file
'.mdx': '@mdx-js/register',
'.mjs': mjsStub,
'.node': null,
'.sucrase.js': {
Expand Down Expand Up @@ -347,6 +350,7 @@ var jsVariantExtensions = [
'.esm.js',
'.jsx',
'.litcoffee',
'.mdx',
'.mjs',
'.sucrase.js',
'.sucrase.jsx',
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/mdx/0/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"@mdx-js/register": "^2.1.1",
"react": "^18.0.0"
}
}
9 changes: 9 additions & 0 deletions test/fixtures/mdx/0/test.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const Thing = () => {
var trueKey = true;
var falseKey = false;
var subKey = { subProp: 1 };
// Test harmony object short notation
return { data: { trueKey, falseKey, subKey } };
}

<Thing />
19 changes: 18 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ function cleanup() {
}

// These modules need newer node features
var minVersions = {};
var minVersions = {
'@mdx-js/register': { major: 12 }
};

var maxVersions = {};

Expand Down Expand Up @@ -181,6 +183,21 @@ describe('interpret.extensions', function () {
expect(require(fixture)).toEqual(expected);
break;

case '.mdx':
expected = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
},
};
var component = require(fixture);
// React internals :shrug:
expect(component().type()).toEqual(expected);
break;

case '.toml':
expected = Object.create(null);
expected.data = Object.create(null);
Expand Down

0 comments on commit cd24c39

Please sign in to comment.