-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Generates empty const
statement
#2112
Comments
It would be very nice if there’s a reproduction/test case of this, to prevent it from reoccurring in the future |
You might be able to ping the people that work on these tools (astro, orta) to help reduce the test case? |
Coming from this issue, I can provide a minimal reproduction of this bug (Stackblitz). I independently came to the same conclusion as @calebeby and fixed my problem in the same way. If anyone else is experiencing this issue, you can temporarily resolve it by applying this patch: diff --git a/lib/plugin/recma-jsx-rewrite.js b/lib/plugin/recma-jsx-rewrite.js
index 1e82a1e41b18b16cb5d2f2a66b07e2d9544c55db..eb5286a273f095bedb693ec587917d6162164108 100644
--- a/lib/plugin/recma-jsx-rewrite.js
+++ b/lib/plugin/recma-jsx-rewrite.js
@@ -387,11 +387,13 @@ export function recmaJsxRewrite(options = {}) {
})
}
- statements.push({
- type: 'VariableDeclaration',
- kind: 'const',
- declarations
- })
+ if (declarations.length > 0) {
+ statements.push({
+ type: 'VariableDeclaration',
+ kind: 'const',
+ declarations
+ })
+ }
}
/** @type {string} */ |
FWIW I have a PR open that is close... I just started school so I'm super busy right now but I'm planning to get back to it soon |
I’m still looking for something smaller: something without Shiki. The smallest possible reproduction. See the related PR for more info :) |
used with remark-shiki-twoslash. @calebeby, who provided the workaround, is the king. - mdx-js/mdx#2123 - mdx-js/mdx#2112
Hello, this might be a good enough repro. It’s using Astro but hopefully that doesn’t really prevent you looking into it. The link to the repro demo is in the linked issue. |
I’m looking for a smaller reproduction. The smallest thing possible. So that we can know why it was occurring and that it won’t regress |
Released in |
Initial checklist
Affected packages and versions
@mdx-js/[email protected]
Link to runnable example
No response
Steps to reproduce
My actual use case is that I have an astro site with an mdx file that uses shiki twoslash to highlight code snippets in the mdx. I haven't been able to narrow it down to a smaller reproducible code example, but I do have a fix!
https://github.com/mdx-js/mdx/blob/main/packages/mdx/lib/plugin/recma-jsx-rewrite.js#L390
This line is generating an empty const statement, which is invalid JS. It should not generate a const statement if there are no declarations.
This fix works:
I can send a PR with this change, but I'm not sure how to write a test for this, since I'm not sure how to narrow it down. Would you be able to help with a test, or would you accept a PR without a test?
Expected behavior
Don't emit an empty const declaration
Actual behavior
It is generating this :(
Runtime
Node v16
Package manager
npm v8
OS
macOS
Build and bundle tools
Astro
The text was updated successfully, but these errors were encountered: