Should acornOptions be exposed to @mdx-js/mdx compile? #1828
-
Should @mdx-js/mdx compile/evaluate support async top level functions via an option? Right now, the acorn parsing yields an error for the following:
Just traced the issue all the way through the mdx dependencies, looks like acornOptions can be injected all the way from
But there's no exposed option in the @mdx-js/mdx api to actually inject the proper acorn setting. It's potentially useful as it allows things like asynchronous api calls for initializing data within the mdx documents directly. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 16 replies
-
For your use case: I’d recommend against it. The whole module has to wait for an HTTP call while it’s being imported. And the module is only loaded once so the top-level await runs once for your whole app’s lifetime. I think it’d be much better to use your frameworks data loading features to run async work when a component is mounted for example. Top-level await is useful. But I’d rather switch to a moving target of current JavaScript features rather than exposing all the possible internals. Similar to how we follow latest CommonMark, it’s on 2020 now (also in a couple other places). Not sure what the policy should be when to switch to 2022 (which include TLA) |
Beta Was this translation helpful? Give feedback.
-
My use case is actually implementing an easy-to-use option for defining headless pdf report generation from arbitrary API data sources - so it's actually precisely what I'm looking for. I can obviously patch the source though, it's not explicitly an issue. But I was surprised that synchronous functions are accepted in javascript expressions by the parser, whereas async are not, given it's not even truly executing in top-level-await when you use evaluate/run but merely inside the body of an async function. Obviously this wouldn't work for full program outputs unless the environment supports it. |
Beta Was this translation helpful? Give feedback.
For your use case: I’d recommend against it. The whole module has to wait for an HTTP call while it’s being imported. And the module is only loaded once so the top-level await runs once for your whole app’s lifetime. I think it’d be much better to use your frameworks data loading features to run async work when a component is mounted for example.
Top-level await is useful. But I’d rather switch to a moving target of current JavaScript features rather than exposing all the possible internals. Similar to how we follow latest CommonMark, it’s on 2020 now (also in a couple other places). Not sure what the policy should be when to switch to 2022 (which include TLA)