Skip to content

Recover from incomplete ESM using acorn-loose#528

Open
jp-knj wants to merge 2 commits intomdx-js:mainfrom
jp-knj:issue-267-investigate-acorn-recovery
Open

Recover from incomplete ESM using acorn-loose#528
jp-knj wants to merge 2 commits intomdx-js:mainfrom
jp-knj:issue-267-investigate-acorn-recovery

Conversation

@jp-knj
Copy link
Copy Markdown

@jp-knj jp-knj commented Mar 18, 2026

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

Closes #267

Problem

When users type incomplete ESM (e.g. export const x = or import { } from) in an MDX file, the strict acorn parser fails and the language service loses all IntelliSense — completions, diagnostics, and hover information disappear for the entire file until the syntax is corrected.

This is a poor editing experience because ESM is always incomplete while the user is actively typing it.

Approach

Introduce a "hybrid acorn" strategy that uses acorn-loose for ESM parsing and the strict acorn parser (with JSX) for expressions

Long-term perspective

This is a minimal, low-risk first step. Possible future improvements include working with micromark-extension-mdxjs-esm to support pluggable error recovery, reducing the need for patching at the language-service level.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 18, 2026

⚠️ No Changeset found

Latest commit: ce0c182

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added the 👋 phase/new Post is being triaged automatically label Mar 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hi! It seems you removed the template which we require. Here are our templates (pick the one you want to use and click *raw* to see its source):

I won’t send you any further notifications about this, but I’ll keep on updating this comment, and hide it when done!

Thanks,
— bb

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.47%. Comparing base (660067a) to head (ce0c182).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #528      +/-   ##
==========================================
+ Coverage   92.43%   92.47%   +0.04%     
==========================================
  Files          13       13              
  Lines        1982     1994      +12     
==========================================
+ Hits         1832     1844      +12     
  Misses        150      150              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

👋 phase/new Post is being triaged automatically

Development

Successfully merging this pull request may close these issues.

Support loose (invalid) JavaScript

1 participant