@timvir/mdx 0.1.30 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +32 -3
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1 +1 @@
1
- export function remarkPlugin(options: any): (tree: any, file: any) => void;
1
+ export function remarkPlugin(options: any): (tree: any, file: any) => Promise<any>;
package/index.js CHANGED
@@ -5,11 +5,12 @@ import { mdxjs } from "micromark-extension-mdxjs";
5
5
  import * as crypto from "crypto";
6
6
  import * as path from "path";
7
7
  import { visit } from "unist-util-visit";
8
+ import * as espree from "espree";
8
9
 
9
- export function remarkPlugin(options) {
10
+ export function remarkPlugin() {
10
11
  let counter = 0;
11
12
 
12
- return (tree, file) => {
13
+ return async (tree, file) => {
13
14
  const filename = file.history[0];
14
15
 
15
16
  visit(tree, "mdxJsxFlowElement", (node) => {
@@ -59,7 +60,33 @@ export function remarkPlugin(options) {
59
60
  node.name = name;
60
61
  node.attributes = [...otherAttributes];
61
62
  if (props?.value) {
62
- node.attributes.push({ type: "mdxJsxExpressionAttribute", value: `...${props.value}` });
63
+ const estree = espree.parse(`export default { ...${props.value} }`, {
64
+ ecmaVersion: 2020,
65
+ sourceType: "module",
66
+ });
67
+
68
+ node.attributes.push({
69
+ type: "mdxJsxExpressionAttribute",
70
+ value: `...${props.value}`,
71
+ data: {
72
+ estree: {
73
+ body: [
74
+ {
75
+ type: "ExpressionStatement",
76
+ expression: {
77
+ type: "ObjectExpression",
78
+ properties: [
79
+ {
80
+ type: "SpreadElement",
81
+ argument: estree.body[0].declaration.properties[0].argument,
82
+ },
83
+ ],
84
+ },
85
+ },
86
+ ],
87
+ },
88
+ },
89
+ });
63
90
  }
64
91
  },
65
92
  source: () => {
@@ -87,6 +114,8 @@ export function remarkPlugin(options) {
87
114
  }[as]());
88
115
  }
89
116
  });
117
+
118
+ return tree;
90
119
  };
91
120
  }
92
121
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@timvir/mdx",
4
- "version": "0.1.30",
4
+ "version": "0.1.31",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "exports": {