Skip to content

Commit cdcc213

Browse files
committed
chore: fix test-coverage for new custom recma plugin
1 parent 43339b8 commit cdcc213

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/utils/recma-mdx-import-react.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import type { Node, Program, VariableDeclaration } from "estree";
33
import { CONTINUE, EXIT, visit } from "estree-util-visit";
44

55
/**
6-
* It is a recma plugin which ensure getting React from argument[0]
7-
* It is a work around for the issue
6+
*
7+
* It is a recma plugin which ensure getting React from argument[0] in the compiled source
8+
*
9+
* It is a work around for the issue https://github.com/vercel/next.js/issues/76395
10+
*
811
*/
912
const plugin: Plugin<void[], Program> = () => {
1013
return (tree: Node) => {
@@ -32,18 +35,19 @@ const plugin: Plugin<void[], Program> = () => {
3235
kind: "const",
3336
};
3437

35-
visit(tree, (node, _, index) => {
38+
visit(tree, (node, _, index, ancestors) => {
3639
if (index === undefined) return;
3740

38-
if (node.type !== "VariableDeclaration") return CONTINUE;
41+
if (node.type === "VariableDeclaration") {
42+
const parent = ancestors[0] as Program;
3943

40-
if (tree.type === "Program") {
41-
tree["body"].splice(index, 0, variableDeclaration);
44+
if ("body" in parent) {
45+
parent["body"].splice(index, 0, variableDeclaration);
4246

43-
return EXIT;
47+
return EXIT;
48+
}
4449
}
4550

46-
/* istanbul ignore next */
4751
return CONTINUE;
4852
});
4953
};

0 commit comments

Comments
 (0)