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

Nested JSX with hanging > #1318

Closed
ChristopherBiscardi opened this issue Oct 31, 2020 · 2 comments
Closed

Nested JSX with hanging > #1318

ChristopherBiscardi opened this issue Oct 31, 2020 · 2 comments
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 👶 semver/patch This is a backwards-compatible fix 🐛 type/bug This is a problem

Comments

@ChristopherBiscardi
Copy link
Member

Subject of the issue

Parse error. Something to do with the way children are wrapped inside of JSX I think because the issue only appears with content above the child and also a hanging >

Your environment

Steps to reproduce

<Box>
  Original:
  <Box
    as="a"
    href="https://stackoverflow.com/questions/28732670/getting-recently-updated-packages/29104122#29104122"
  >
    s
  </Box>
</Box>

repro script for the above file:

const mdx = require("@mdx-js/mdx");
const fs = require("fs").promises;

async function process() {
  try {
    const file = await fs.readFile("./thing.mdx", "utf-8");
    const result = await mdx(file);
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}
process();

Expected behaviour

dunno, seems weird that this breaks on parsing.

Actual behaviour

[5:108: Unexpected end of file before attribute name, expected a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag] {
  reason: 'Unexpected end of file before attribute name, expected a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag',
  line: 5,
  column: 108,
  location: {
    start: { line: 5, column: 108, offset: 143, index: 123 },
    end: { line: null, column: null }
  },
  source: 'remark-mdx',
  ruleId: 'unexpected-eof',
  fatal: true
}
@wooorm
Copy link
Member

wooorm commented Oct 31, 2020

I'm not 100% why it's parsing as a span instead of a block (early in the am for me), but the > is making a block quote: https://github.com/micromark/mdx-state-machine#742-u003e-greater-than--seen-as-block-quote

wooorm added a commit that referenced this issue Dec 11, 2020
This updates MDX to use and support remark@13, which comes with a new internal
parser (micromark), and supports CommonMark.
See <https://github.com/remarkjs/remark/releases/tag/13.0.0> for more
information.
In short, this means MDX parses markdown closer to what folks expect.
And it means all latest plugins work (again).

But it also means that parsing MDX syntax (JSX, expressions, ESM) got an update.
See: <https://github.com/micromark/micromark-extension-mdxjs> and
<https://github.com/syntax-tree/mdast-util-mdx> for the syntax.
In short, this means MDX parsing is now JavaScript-aware: import/exports are
actually parsed for being valid JavaScript.
Expressions previously counted braces, but now can include braces in strings or
comments or whatnot.
This also means we can drop Babel (in a future PR) because we already have a
JavaScript AST.

This also deprecates the packages `remark-mdxjs` (which is now the default in
`remark-mdx`), `remark-mdx-remove-exports`, and `remark-mdx-remove-imports`.

Related to GH-704.
Related to GH-1041.

Closes GH-720.
Closes GH-1028.
Closes GH-1050.
Closes GH-1081.
Closes GH-1193.
Closes GH-1238.
Closes GH-1283.
Closes GH-1316.
Closes GH-1318.
Closes GH-1341.
wooorm added a commit that referenced this issue Dec 15, 2020
This updates MDX to use and support remark@13, which comes with a new internal
parser (micromark), and supports CommonMark.
See <https://github.com/remarkjs/remark/releases/tag/13.0.0> for more
information.
In short, this means MDX parses markdown closer to what folks expect.
And it means all latest plugins work (again).

But it also means that parsing MDX syntax (JSX, expressions, ESM) got an update.
See: <https://github.com/micromark/micromark-extension-mdxjs> and
<https://github.com/syntax-tree/mdast-util-mdx> for the syntax.
In short, this means MDX parsing is now JavaScript-aware: import/exports are
actually parsed for being valid JavaScript.
Expressions previously counted braces, but now can include braces in strings or
comments or whatnot.
This also means we can drop Babel (in a future PR) because we already have a
JavaScript AST.

This also deprecates the packages `remark-mdxjs` (which is now the default in
`remark-mdx`), `remark-mdx-remove-exports`, and `remark-mdx-remove-imports`.

Related to GH-704.
Related to GH-1041.

Closes GH-720.
Closes GH-1028.
Closes GH-1050.
Closes GH-1081.
Closes GH-1193.
Closes GH-1238.
Closes GH-1283.
Closes GH-1316.
Closes GH-1318.
Closes GH-1341.
Closes GH-1367.

Reviewed-by: Christian Murphy <[email protected]>
@wooorm
Copy link
Member

wooorm commented Dec 18, 2020

I just confirmed that this now renders nicely on main. Assuming the shortcodes aren’t passed, the result is:

<div><p>Original:</p><div as="a" href="https://stackoverflow.com/questions/28732670/getting-recently-updated-packages/29104122#29104122"><p>s</p></div></div>

Which seems to make sense.

@wooorm wooorm closed this as completed Dec 18, 2020
@wooorm wooorm added ⛵️ status/released 👶 semver/patch This is a backwards-compatible fix 🗄 area/interface This affects the public interface and removed 🔍 status/open labels Dec 18, 2020
@wooorm wooorm added the 💪 phase/solved Post is done label Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 👶 semver/patch This is a backwards-compatible fix 🐛 type/bug This is a problem
Development

No branches or pull requests

2 participants