Skip to content

fix(transformer-attributify-jsx): ignore .md and .mdx files to avoid parser errors#5013

Closed
jack-old-archive wants to merge 3 commits into
unocss:mainfrom
jack-old-archive:fix/astro-attributify-mdx
Closed

fix(transformer-attributify-jsx): ignore .md and .mdx files to avoid parser errors#5013
jack-old-archive wants to merge 3 commits into
unocss:mainfrom
jack-old-archive:fix/astro-attributify-mdx

Conversation

@jack-old-archive

Copy link
Copy Markdown
Contributor

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

@netlify

netlify Bot commented Dec 7, 2025

Copy link
Copy Markdown

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

pkg-pr-new Bot commented Dec 8, 2025

Copy link
Copy Markdown

Open in StackBlitz

commit: 26d813b

@zyyv

zyyv commented Dec 8, 2025

Copy link
Copy Markdown
Member

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-old-archive

Copy link
Copy Markdown
Contributor Author

Okay, let me think about how to solve this

@jack-old-archive

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
Contributor 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 #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