Skip to content

Conversation

@Jack-sh1
Copy link

@Jack-sh1 Jack-sh1 commented Dec 7, 2025

Since version 0.64.0, transformer-attributify-jsx switched to @babel/parser, which treats the content as strict JS/TS. It fails when parsing .md or .mdx files (e.g., due to Frontmatter or Markdown syntax), causing build errors in frameworks like Astro.

This PR adds a check to explicitly ignore .md and .mdx files in transformer-attributify-jsx to prevent these parser crashes, as this transformer is intended for JSX/TSX content.
Fixes #4999

@Jack-sh1 Jack-sh1 requested review from antfu and zyyv as code owners December 7, 2025 11:02
@netlify
Copy link

netlify bot commented Dec 7, 2025

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6791208
🔍 Latest deploy log https://app.netlify.com/projects/unocss/deploys/6943e351b538990008cb7c4a
😎 Deploy Preview https://deploy-preview-5013--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 8, 2025

Open in StackBlitz

commit: 26d813b

@zyyv
Copy link
Member

zyyv commented Dec 8, 2025

I don't think we can remove support for .md files, since extraction already supports .md by default.

Alternatively, we could fall back to plain text transform when babel parse throw an error. I think this is a bit troublesome.

@zyyv zyyv self-requested a review December 8, 2025 07:32
@Jack-sh1
Copy link
Author

Jack-sh1 commented Dec 8, 2025

Okay, let me think about how to solve this

@Jack-sh1
Copy link
Author

Jack-sh1 commented Dec 8, 2025

I've updated the PR with a try-catch block and a regex fallback for .md/.mdx files. Please verify

export default {
plugins: {
unocss: plugin,
'@unocss': plugin,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a unrelated change and it's also a breaking change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've modified it.

iiio2 and others added 2 commits December 18, 2025 19:19
…n Babel parsing fails

- Add regex-based fallback transformation for Markdown files
- Wrap Babel parsing in try-catch with graceful error handling
- Fallback to regex patterns for .md/.mdx files when AST parsing fails
- Maintain Babel AST parsing for JSX/TSX files (high performance)
- Update default include pattern to explicitly support .mdx files
- Fixes unocss#4999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attributify-JSX breaks Astro+MDX

4 participants