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

Ensure compiling hast doesn't fail if path contains export #912

Merged
merged 1 commit into from
Jan 16, 2020

Conversation

zephraph
Copy link
Contributor

@zephraph zephraph commented Jan 16, 2020

Okay, so this one threw me for a hell of a loop.

I was writing a test for another plugin that wraps mdx loader and it kept inexplicably failing. I went as far as copying a passing test from somewhere else and it was still failing.

The error was pretty mysterious too:

ReferenceError: s is not defined

      292 | 
      293 | const layoutProps = {
    > 294 |   s
          |   ^
      295 | };
      296 | const MDXLayout = docs_page({
      297 |   layout: 'docs-page',

Turns out, in mdx-hast-to-jsx.js, the calculation of exportNames will fail if there is a directory named export in the exported file path. Since my test directory was called layouts-exports-ssg it caused layoutProps to output garbage because the regex had a miss-match.

You can check the regex here: https://regexr.com/4sar8

@vercel
Copy link

vercel bot commented Jan 16, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/mdx/mdx/6luar10wj
✅ Preview: https://mdx-git-fork-zephraph-fix-mysterious-regex-crash.mdx.now.sh

@vercel vercel bot temporarily deployed to Preview January 16, 2020 06:45 Inactive
@zephraph zephraph requested a review from johno January 16, 2020 19:54
@johno
Copy link
Member

johno commented Jan 16, 2020

Oh, whoa! Thanks for tracking this down and providing a fix <3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants