Skip to content
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

feat: Support .mdx extension hook #85

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,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 @@ -344,6 +347,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 @@ -48,7 +48,9 @@ function cleanup() {
}

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

var maxVersions = {};

Expand Down Expand Up @@ -180,6 +182,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