diff --git a/.changeset/lovely-houses-rule.md b/.changeset/lovely-houses-rule.md new file mode 100644 index 00000000..9faa6bb9 --- /dev/null +++ b/.changeset/lovely-houses-rule.md @@ -0,0 +1,5 @@ +--- +"codehike": patch +--- + +Fix `jsxDEV` warning diff --git a/apps/web/content/blog/from-remark-to-rsc.mdx b/apps/web/content/blog/from-remark-to-rsc.mdx index bf2e7ec5..e79b9f42 100644 --- a/apps/web/content/blog/from-remark-to-rsc.mdx +++ b/apps/web/content/blog/from-remark-to-rsc.mdx @@ -6,4 +6,6 @@ authors: [pomber] draft: true --- +Content usually needs some kind of transformation before being rendered. + A remark plugin is a function that transforms pieces of a markdown file. diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs index ca8fd3e7..cc3ac2bc 100644 --- a/apps/web/next.config.mjs +++ b/apps/web/next.config.mjs @@ -1,5 +1,16 @@ import createNextDocsMDX from "next-docs-mdx/config" import { remarkCodeHike, recmaCodeHike } from "codehike/mdx" +// import fs from "node:fs" +// import { jsx, toJs } from "estree-util-to-js" +// function recmaPlugin() { +// return (tree) => { +// const result = toJs(tree, { handlers: jsx }) +// // console.log("```js") +// // console.log(result.value) +// // console.log("```") +// fs.writeFileSync("recma.js", result.value) +// } +// } /** @type {import('codehike/mdx').CodeHikeConfig} */ const chConfig = { @@ -17,7 +28,7 @@ const withMDX = createNextDocsMDX({ mdxOptions: { remarkPlugins: [[remarkCodeHike, chConfig]], recmaPlugins: [[recmaCodeHike, chConfig]], - jsx: true, + // jsx: true, }, }) diff --git a/apps/web/package.json b/apps/web/package.json index 7f40fd92..a45766c4 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -24,6 +24,7 @@ "codehike": "workspace:*", "diff": "^5.1.0", "dotenv": "^16.4.1", + "estree-util-to-js": "^2.0.0", "lucide-react": "^0.303.0", "next": "14.1.0", "next-docs-mdx": "7.1.2", diff --git a/packages/codehike/src/mdx/3.transform-hike-props.ts b/packages/codehike/src/mdx/3.transform-hike-props.ts index 4f3df438..5b53f2e9 100644 --- a/packages/codehike/src/mdx/3.transform-hike-props.ts +++ b/packages/codehike/src/mdx/3.transform-hike-props.ts @@ -137,7 +137,7 @@ function forEachHikeElementMoveChildrenToHikeProp(root: any, jsxOn: boolean) { visit(root, (node: any) => { if (isElementWithHikeAttribute(node, jsxOn)) { if (jsxOn) { - moveChildrenToHikePropJSX(node, jsxOn) + moveChildrenToHikePropJSX(node) } else { moveChildrenToHikeProp(node) } @@ -157,7 +157,7 @@ function isElementWithHikeAttribute(node: any, jsxOn: boolean) { ) } -function moveChildrenToHikePropJSX(node: any, jsxOn: boolean) { +function moveChildrenToHikePropJSX(node: any) { // dictionary of children by path const childrenByPath: any = {} node.children.forEach((slot: any) => { @@ -252,8 +252,8 @@ function moveChildrenToHikeProp(node: any) { (p: any) => p.key.name !== "children", ) - // jsxs calls can only have arrays as children, so we turn any jsxs without array into jsx call visit(node, function (node: any) { + // jsxs calls can only have arrays as children, so we turn any jsxs without array into jsx call if (node.type === "CallExpression" && node.callee.name === "_jsxs") { const childrenProp = node.arguments[1].properties.find( (p: any) => p.key.value === "children", @@ -262,6 +262,16 @@ function moveChildrenToHikeProp(node: any) { node.callee.name = "_jsx" } } + + // same, but in dev mode the name is _jsxDEV, and we should change the `isStaticChildren` argument + if (node.type === "CallExpression" && node.callee.name === "_jsxDEV") { + const childrenProp = node.arguments[1].properties.find( + (p: any) => p.key.value === "children", + ) + if (childrenProp && childrenProp.value.type !== "ArrayExpression") { + node.arguments[3] = { type: "Literal", value: false } + } + } }) } diff --git a/packages/codehike/tests/md-suite/basic.0.mdx b/packages/codehike/tests/md-suite/basic.0.mdx index b67c9c81..898f8d35 100644 --- a/packages/codehike/tests/md-suite/basic.0.mdx +++ b/packages/codehike/tests/md-suite/basic.0.mdx @@ -7,14 +7,18 @@ snapshots: - before-recma-compiled-jsx - before-recma-compiled-function - before-recma-js + - before-recma-js-dev - before-recma-jsx - after-recma-js + - after-recma-js-dev - after-recma-jsx - compiled-js + - compiled-js-dev - compiled-jsx - compiled-function - parsed-jsx - rendered + - rendered-dev --- # Lorem diff --git a/packages/codehike/tests/md-suite/basic.5.before-recma-js-dev.json b/packages/codehike/tests/md-suite/basic.5.before-recma-js-dev.json new file mode 100644 index 00000000..140048cd --- /dev/null +++ b/packages/codehike/tests/md-suite/basic.5.before-recma-js-dev.json @@ -0,0 +1,540 @@ +{ + "type": "Program", + "body": [ + { + "type": "ImportDeclaration", + "specifiers": [ + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "jsxDEV" }, + "local": { "type": "Identifier", "name": "_jsxDEV" } + } + ], + "source": { "type": "Literal", "value": "react/jsx-dev-runtime" } + }, + { + "type": "FunctionDeclaration", + "async": false, + "id": { "type": "Identifier", "name": "_createMdxContent" }, + "params": [{ "type": "Identifier", "name": "props" }], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { "type": "Identifier", "name": "_components" }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "h1" }, + "value": { "type": "Literal", "value": "h1" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "slot" }, + "value": { "type": "Literal", "value": "slot" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "SpreadElement", + "argument": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + } + } + ] + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxDEV" }, + "arguments": [ + { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "_components" }, + "property": { "type": "Identifier", "name": "slot" }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { "type": "Identifier", "name": "__hike" }, + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Literal", "value": "children" }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Literal", "value": "title" }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Literal", "value": "_data" }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "header" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + } + ] + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Literal", "value": "hello" }, + "kind": "init", + "value": { + "type": "Literal", + "value": "world", + "raw": "\"world\"" + } + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxDEV" }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "slot" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { "type": "Identifier", "name": "path" }, + "value": { "type": "Literal", "value": "" }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "h1" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "Lorem" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "fileName" }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + } + ] + } + }, + { + "type": "ExportDefaultDeclaration", + "declaration": { + "type": "FunctionDeclaration", + "id": { "type": "Identifier", "name": "MDXContent" }, + "params": [ + { + "type": "AssignmentPattern", + "left": { "type": "Identifier", "name": "props" }, + "right": { "type": "ObjectExpression", "properties": [] } + } + ], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "wrapper" }, + "value": { "type": "Identifier", "name": "MDXLayout" }, + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + "init": { + "type": "LogicalExpression", + "operator": "||", + "left": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + }, + "right": { "type": "ObjectExpression", "properties": [] } + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "ConditionalExpression", + "test": { "type": "Identifier", "name": "MDXLayout" }, + "consequent": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxDEV" }, + "arguments": [ + { "type": "Identifier", "name": "MDXLayout" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { "type": "Identifier", "name": "props" } + }, + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "Identifier", + "name": "_createMdxContent" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { + "type": "Identifier", + "name": "props" + } + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "fileName" }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "alternate": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_createMdxContent" + }, + "arguments": [{ "type": "Identifier", "name": "props" }], + "optional": false + } + } + } + ] + } + } + } + ], + "sourceType": "module", + "comments": [] +} diff --git a/packages/codehike/tests/md-suite/basic.6.after-recma-js-dev.json b/packages/codehike/tests/md-suite/basic.6.after-recma-js-dev.json new file mode 100644 index 00000000..a789d402 --- /dev/null +++ b/packages/codehike/tests/md-suite/basic.6.after-recma-js-dev.json @@ -0,0 +1,422 @@ +{ + "type": "Program", + "body": [ + { + "type": "ImportDeclaration", + "specifiers": [ + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "jsxDEV" }, + "local": { "type": "Identifier", "name": "_jsxDEV" } + } + ], + "source": { "type": "Literal", "value": "react/jsx-dev-runtime" } + }, + { + "type": "FunctionDeclaration", + "async": false, + "id": { "type": "Identifier", "name": "_createMdxContent" }, + "params": [{ "type": "Identifier", "name": "props" }], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { "type": "Identifier", "name": "_components" }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "h1" }, + "value": { "type": "Literal", "value": "h1" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "slot" }, + "value": { "type": "Literal", "value": "slot" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "SpreadElement", + "argument": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + } + } + ] + } + } + ] + }, + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { "type": "Identifier", "name": "_blocks" }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Literal", "value": "children" }, + "kind": "init", + "value": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxDEV" }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { "type": "Identifier", "name": "h1" }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "Lorem" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { "type": "Literal", "value": 1 } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { "type": "Literal", "value": 1 } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Literal", "value": "title" }, + "kind": "init", + "value": { "type": "Literal", "value": "", "raw": "\"\"" } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Literal", "value": "_data" }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Literal", "value": "header" }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + } + ] + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { "type": "Literal", "value": "hello" }, + "kind": "init", + "value": { + "type": "Literal", + "value": "world", + "raw": "\"world\"" + } + } + ] + } + } + ] + }, + { + "type": "IfStatement", + "test": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { "type": "Identifier", "name": "_returnBlocks" } + }, + "consequent": { + "type": "BlockStatement", + "body": [ + { + "type": "ReturnStatement", + "argument": { "type": "Identifier", "name": "_blocks" } + } + ] + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "_blocks" }, + "property": { "type": "Identifier", "name": "children" } + } + } + ] + } + }, + { + "type": "ExportDefaultDeclaration", + "declaration": { + "type": "FunctionDeclaration", + "id": { "type": "Identifier", "name": "MDXContent" }, + "params": [ + { + "type": "AssignmentPattern", + "left": { "type": "Identifier", "name": "props" }, + "right": { "type": "ObjectExpression", "properties": [] } + } + ], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "wrapper" }, + "value": { "type": "Identifier", "name": "MDXLayout" }, + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + "init": { + "type": "LogicalExpression", + "operator": "||", + "left": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + }, + "right": { "type": "ObjectExpression", "properties": [] } + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "ConditionalExpression", + "test": { "type": "Identifier", "name": "MDXLayout" }, + "consequent": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxDEV" }, + "arguments": [ + { "type": "Identifier", "name": "MDXLayout" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { "type": "Identifier", "name": "props" } + }, + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "Identifier", + "name": "_createMdxContent" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { + "type": "Identifier", + "name": "props" + } + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "fileName" }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "alternate": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_createMdxContent" + }, + "arguments": [{ "type": "Identifier", "name": "props" }], + "optional": false + } + } + } + ] + } + } + } + ], + "sourceType": "module", + "comments": [] +} diff --git a/packages/codehike/tests/md-suite/basic.7.compiled-js-dev.js b/packages/codehike/tests/md-suite/basic.7.compiled-js-dev.js new file mode 100644 index 00000000..42f39317 --- /dev/null +++ b/packages/codehike/tests/md-suite/basic.7.compiled-js-dev.js @@ -0,0 +1,65 @@ +import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime" +function _createMdxContent(props) { + const _components = { + h1: "h1", + slot: "slot", + ...props.components, + } + const _blocks = { + children: _jsxDEV( + _components.h1, + { + children: "Lorem", + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx", + lineNumber: 1, + columnNumber: 1, + }, + this, + ), + title: "", + _data: { + header: "", + }, + hello: "world", + } + if (props._returnBlocks) { + return _blocks + } + return _blocks.children +} +export default function MDXContent(props = {}) { + const { wrapper: MDXLayout } = props.components || {} + return MDXLayout + ? _jsxDEV( + MDXLayout, + { + ...props, + children: _jsxDEV( + _createMdxContent, + { + ...props, + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx", + }, + this, + ), + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\basic.0.mdx", + }, + this, + ) + : _createMdxContent(props) +} diff --git a/packages/codehike/tests/md-suite/basic.9.rendered-dev.html b/packages/codehike/tests/md-suite/basic.9.rendered-dev.html new file mode 100644 index 00000000..214f117e --- /dev/null +++ b/packages/codehike/tests/md-suite/basic.9.rendered-dev.html @@ -0,0 +1 @@ +

Lorem

diff --git a/packages/codehike/tests/md-suite/static-children.0.mdx b/packages/codehike/tests/md-suite/static-children.0.mdx new file mode 100644 index 00000000..4044d6cc --- /dev/null +++ b/packages/codehike/tests/md-suite/static-children.0.mdx @@ -0,0 +1,32 @@ +--- +snapshots: + - before-recma-compiled-js + - before-recma-js-dev + - before-recma-js + - after-recma-js + - after-recma-js-dev + - compiled-js + - compiled-js-dev + - rendered-dev +issue: https://github.com/code-hike/codehike/issues/433 +--- + +
+ +hey + +ho + +## !foo + +bar + +
+ +
+ +asdf + +aa + +
diff --git a/packages/codehike/tests/md-suite/static-children.5.before-recma-compiled-js.js b/packages/codehike/tests/md-suite/static-children.5.before-recma-compiled-js.js new file mode 100644 index 00000000..85400db3 --- /dev/null +++ b/packages/codehike/tests/md-suite/static-children.5.before-recma-compiled-js.js @@ -0,0 +1,75 @@ +import { + Fragment as _Fragment, + jsx as _jsx, + jsxs as _jsxs, +} from "react/jsx-runtime" +function _createMdxContent(props) { + const _components = { + p: "p", + slot: "slot", + ...props.components, + } + return _jsxs(_Fragment, { + children: [ + _jsxs("div", { + __hike: { + children: "", + title: "", + _data: { + header: "", + }, + foo: { + children: "foo", + title: "", + _data: { + header: "## !foo", + }, + }, + }, + children: [ + _jsx(_components.slot, { + path: "", + children: _jsxs(_Fragment, { + children: [ + _jsx(_components.p, { + children: "hey", + }), + _jsx(_components.p, { + children: "ho", + }), + ], + }), + }), + _jsx(_components.slot, { + path: "foo", + children: _jsx(_components.p, { + children: "bar", + }), + }), + ], + }), + "\n", + _jsxs("section", { + children: [ + _jsx(_components.p, { + children: "asdf", + }), + _jsx(_components.p, { + children: "aa", + }), + ], + }), + ], + }) +} +export default function MDXContent(props = {}) { + const { wrapper: MDXLayout } = props.components || {} + return MDXLayout + ? _jsx(MDXLayout, { + ...props, + children: _jsx(_createMdxContent, { + ...props, + }), + }) + : _createMdxContent(props) +} diff --git a/packages/codehike/tests/md-suite/static-children.5.before-recma-js-dev.json b/packages/codehike/tests/md-suite/static-children.5.before-recma-js-dev.json new file mode 100644 index 00000000..0c85f37a --- /dev/null +++ b/packages/codehike/tests/md-suite/static-children.5.before-recma-js-dev.json @@ -0,0 +1,1381 @@ +{ + "type": "Program", + "body": [ + { + "type": "ImportDeclaration", + "specifiers": [ + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "Fragment" }, + "local": { "type": "Identifier", "name": "_Fragment" } + }, + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "jsxDEV" }, + "local": { "type": "Identifier", "name": "_jsxDEV" } + } + ], + "source": { "type": "Literal", "value": "react/jsx-dev-runtime" } + }, + { + "type": "FunctionDeclaration", + "async": false, + "id": { "type": "Identifier", "name": "_createMdxContent" }, + "params": [{ "type": "Identifier", "name": "props" }], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { "type": "Identifier", "name": "_components" }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "p" }, + "value": { "type": "Literal", "value": "p" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "slot" }, + "value": { "type": "Literal", "value": "slot" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "SpreadElement", + "argument": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + } + } + ] + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxDEV" }, + "arguments": [ + { "type": "Identifier", "name": "_Fragment" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { "type": "Literal", "value": "div" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "__hike" + }, + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "children" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "title" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "_data" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "header" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + } + ] + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "foo" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "children" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "foo", + "raw": "\"foo\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "title" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "_data" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "header" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "## !foo", + "raw": "\"## !foo\"" + } + } + ] + } + } + ] + } + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "slot" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "path" + }, + "value": { + "type": "Literal", + "value": "" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "Identifier", + "name": "_Fragment" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "hey" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 3 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { + "type": "ThisExpression" + } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "ho" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 5 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { + "type": "ThisExpression" + } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": true + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + } + ] + }, + { + "type": "ThisExpression" + } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "slot" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "path" + }, + "value": { + "type": "Literal", + "value": "foo" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "bar" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 9 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { + "type": "ThisExpression" + } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": true }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { "type": "Literal", "value": 1 } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { "type": "Literal", "value": 1 } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + { "type": "Literal", "value": "\n" }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { "type": "Literal", "value": "section" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "asdf" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 15 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "aa" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 17 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": true }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { "type": "Literal", "value": 13 } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { "type": "Literal", "value": 1 } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": true }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "fileName" }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "lineNumber" }, + "value": { "type": "Literal", "value": 1 } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "columnNumber" }, + "value": { "type": "Literal", "value": 1 } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + } + ] + } + }, + { + "type": "ExportDefaultDeclaration", + "declaration": { + "type": "FunctionDeclaration", + "id": { "type": "Identifier", "name": "MDXContent" }, + "params": [ + { + "type": "AssignmentPattern", + "left": { "type": "Identifier", "name": "props" }, + "right": { "type": "ObjectExpression", "properties": [] } + } + ], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "wrapper" }, + "value": { "type": "Identifier", "name": "MDXLayout" }, + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + "init": { + "type": "LogicalExpression", + "operator": "||", + "left": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + }, + "right": { "type": "ObjectExpression", "properties": [] } + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "ConditionalExpression", + "test": { "type": "Identifier", "name": "MDXLayout" }, + "consequent": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxDEV" }, + "arguments": [ + { "type": "Identifier", "name": "MDXLayout" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { "type": "Identifier", "name": "props" } + }, + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "Identifier", + "name": "_createMdxContent" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { + "type": "Identifier", + "name": "props" + } + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "fileName" }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "alternate": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_createMdxContent" + }, + "arguments": [{ "type": "Identifier", "name": "props" }], + "optional": false + } + } + } + ] + } + } + } + ], + "sourceType": "module", + "comments": [] +} diff --git a/packages/codehike/tests/md-suite/static-children.5.before-recma-js.json b/packages/codehike/tests/md-suite/static-children.5.before-recma-js.json new file mode 100644 index 00000000..15040402 --- /dev/null +++ b/packages/codehike/tests/md-suite/static-children.5.before-recma-js.json @@ -0,0 +1,812 @@ +{ + "type": "Program", + "body": [ + { + "type": "ImportDeclaration", + "specifiers": [ + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "Fragment" }, + "local": { "type": "Identifier", "name": "_Fragment" } + }, + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "jsx" }, + "local": { "type": "Identifier", "name": "_jsx" } + }, + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "jsxs" }, + "local": { "type": "Identifier", "name": "_jsxs" } + } + ], + "source": { "type": "Literal", "value": "react/jsx-runtime" } + }, + { + "type": "FunctionDeclaration", + "async": false, + "id": { "type": "Identifier", "name": "_createMdxContent" }, + "params": [{ "type": "Identifier", "name": "props" }], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { "type": "Identifier", "name": "_components" }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "p" }, + "value": { "type": "Literal", "value": "p" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "slot" }, + "value": { "type": "Literal", "value": "slot" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "SpreadElement", + "argument": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + } + } + ] + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxs" }, + "arguments": [ + { "type": "Identifier", "name": "_Fragment" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxs" }, + "arguments": [ + { "type": "Literal", "value": "div" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "__hike" + }, + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "children" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "title" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "_data" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "header" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + } + ] + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "foo" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "children" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "foo", + "raw": "\"foo\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "title" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "_data" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "header" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "## !foo", + "raw": "\"## !foo\"" + } + } + ] + } + } + ] + } + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "slot" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "path" + }, + "value": { + "type": "Literal", + "value": "" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxs" + }, + "arguments": [ + { + "type": "Identifier", + "name": "_Fragment" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "hey" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "ho" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "slot" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "path" + }, + "value": { + "type": "Literal", + "value": "foo" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "bar" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + { "type": "Literal", "value": "\n" }, + { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxs" }, + "arguments": [ + { "type": "Literal", "value": "section" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "asdf" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "aa" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + } + ] + } + }, + { + "type": "ExportDefaultDeclaration", + "declaration": { + "type": "FunctionDeclaration", + "id": { "type": "Identifier", "name": "MDXContent" }, + "params": [ + { + "type": "AssignmentPattern", + "left": { "type": "Identifier", "name": "props" }, + "right": { "type": "ObjectExpression", "properties": [] } + } + ], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "wrapper" }, + "value": { "type": "Identifier", "name": "MDXLayout" }, + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + "init": { + "type": "LogicalExpression", + "operator": "||", + "left": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + }, + "right": { "type": "ObjectExpression", "properties": [] } + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "ConditionalExpression", + "test": { "type": "Identifier", "name": "MDXLayout" }, + "consequent": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsx" }, + "arguments": [ + { "type": "Identifier", "name": "MDXLayout" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { "type": "Identifier", "name": "props" } + }, + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsx" }, + "arguments": [ + { + "type": "Identifier", + "name": "_createMdxContent" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { + "type": "Identifier", + "name": "props" + } + } + ] + } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + "alternate": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_createMdxContent" + }, + "arguments": [{ "type": "Identifier", "name": "props" }], + "optional": false + } + } + } + ] + } + } + } + ], + "sourceType": "module", + "comments": [] +} diff --git a/packages/codehike/tests/md-suite/static-children.6.after-recma-js-dev.json b/packages/codehike/tests/md-suite/static-children.6.after-recma-js-dev.json new file mode 100644 index 00000000..2762afba --- /dev/null +++ b/packages/codehike/tests/md-suite/static-children.6.after-recma-js-dev.json @@ -0,0 +1,1166 @@ +{ + "type": "Program", + "body": [ + { + "type": "ImportDeclaration", + "specifiers": [ + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "Fragment" }, + "local": { "type": "Identifier", "name": "_Fragment" } + }, + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "jsxDEV" }, + "local": { "type": "Identifier", "name": "_jsxDEV" } + } + ], + "source": { "type": "Literal", "value": "react/jsx-dev-runtime" } + }, + { + "type": "FunctionDeclaration", + "async": false, + "id": { "type": "Identifier", "name": "_createMdxContent" }, + "params": [{ "type": "Identifier", "name": "props" }], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { "type": "Identifier", "name": "_components" }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "p" }, + "value": { "type": "Literal", "value": "p" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "slot" }, + "value": { "type": "Literal", "value": "slot" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "SpreadElement", + "argument": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + } + } + ] + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxDEV" }, + "arguments": [ + { "type": "Identifier", "name": "_Fragment" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { "type": "Literal", "value": "div" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "children" + }, + "kind": "init", + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "Identifier", + "name": "_Fragment" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "hey" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 3 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { + "type": "ThisExpression" + } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "ho" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 5 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { + "type": "ThisExpression" + } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { "type": "Literal", "value": true }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "title" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "_data" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "header" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + } + ] + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "foo" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "children" + }, + "kind": "init", + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "bar" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 9 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "title" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "_data" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "header" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "## !foo", + "raw": "\"## !foo\"" + } + } + ] + } + } + ] + } + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { "type": "Literal", "value": 1 } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { "type": "Literal", "value": 1 } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + { "type": "Literal", "value": "\n" }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { "type": "Literal", "value": "section" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "asdf" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 15 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "aa" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { + "type": "Identifier", + "name": "undefined" + }, + { + "type": "Literal", + "value": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { + "type": "Literal", + "value": 17 + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { + "type": "Literal", + "value": 1 + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": true }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "lineNumber" + }, + "value": { "type": "Literal", "value": 13 } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "columnNumber" + }, + "value": { "type": "Literal", "value": 1 } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": true }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "fileName" }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "lineNumber" }, + "value": { "type": "Literal", "value": 1 } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "columnNumber" }, + "value": { "type": "Literal", "value": 1 } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + } + } + ] + } + }, + { + "type": "ExportDefaultDeclaration", + "declaration": { + "type": "FunctionDeclaration", + "id": { "type": "Identifier", "name": "MDXContent" }, + "params": [ + { + "type": "AssignmentPattern", + "left": { "type": "Identifier", "name": "props" }, + "right": { "type": "ObjectExpression", "properties": [] } + } + ], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "wrapper" }, + "value": { "type": "Identifier", "name": "MDXLayout" }, + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + "init": { + "type": "LogicalExpression", + "operator": "||", + "left": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + }, + "right": { "type": "ObjectExpression", "properties": [] } + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "ConditionalExpression", + "test": { "type": "Identifier", "name": "MDXLayout" }, + "consequent": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxDEV" }, + "arguments": [ + { "type": "Identifier", "name": "MDXLayout" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { "type": "Identifier", "name": "props" } + }, + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxDEV" + }, + "arguments": [ + { + "type": "Identifier", + "name": "_createMdxContent" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { + "type": "Identifier", + "name": "props" + } + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { + "type": "Identifier", + "name": "fileName" + }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + { "type": "Identifier", "name": "undefined" }, + { "type": "Literal", "value": false }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "kind": "init", + "key": { "type": "Identifier", "name": "fileName" }, + "value": { + "type": "Literal", + "value": "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx" + } + } + ] + }, + { "type": "ThisExpression" } + ], + "optional": false + }, + "alternate": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_createMdxContent" + }, + "arguments": [{ "type": "Identifier", "name": "props" }], + "optional": false + } + } + } + ] + } + } + } + ], + "sourceType": "module", + "comments": [] +} diff --git a/packages/codehike/tests/md-suite/static-children.6.after-recma-js.json b/packages/codehike/tests/md-suite/static-children.6.after-recma-js.json new file mode 100644 index 00000000..c6ea0a3f --- /dev/null +++ b/packages/codehike/tests/md-suite/static-children.6.after-recma-js.json @@ -0,0 +1,662 @@ +{ + "type": "Program", + "body": [ + { + "type": "ImportDeclaration", + "specifiers": [ + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "Fragment" }, + "local": { "type": "Identifier", "name": "_Fragment" } + }, + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "jsx" }, + "local": { "type": "Identifier", "name": "_jsx" } + }, + { + "type": "ImportSpecifier", + "imported": { "type": "Identifier", "name": "jsxs" }, + "local": { "type": "Identifier", "name": "_jsxs" } + } + ], + "source": { "type": "Literal", "value": "react/jsx-runtime" } + }, + { + "type": "FunctionDeclaration", + "async": false, + "id": { "type": "Identifier", "name": "_createMdxContent" }, + "params": [{ "type": "Identifier", "name": "props" }], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { "type": "Identifier", "name": "_components" }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "p" }, + "value": { "type": "Literal", "value": "p" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "slot" }, + "value": { "type": "Literal", "value": "slot" }, + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "SpreadElement", + "argument": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + } + } + ] + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxs" }, + "arguments": [ + { "type": "Identifier", "name": "_Fragment" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsx" }, + "arguments": [ + { "type": "Literal", "value": "div" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "children" + }, + "kind": "init", + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsxs" + }, + "arguments": [ + { + "type": "Identifier", + "name": "_Fragment" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "hey" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "ho" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "title" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "_data" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "header" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + } + ] + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "foo" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "children" + }, + "kind": "init", + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "bar" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "title" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "", + "raw": "\"\"" + } + }, + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "_data" + }, + "kind": "init", + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Literal", + "value": "header" + }, + "kind": "init", + "value": { + "type": "Literal", + "value": "## !foo", + "raw": "\"## !foo\"" + } + } + ] + } + } + ] + } + } + ] + } + ], + "optional": false + }, + { "type": "Literal", "value": "\n" }, + { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsxs" }, + "arguments": [ + { "type": "Literal", "value": "section" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "asdf" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_jsx" + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "_components" + }, + "property": { + "type": "Identifier", + "name": "p" + }, + "computed": false, + "optional": false + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "children" + }, + "value": { + "type": "Literal", + "value": "aa" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + } + } + ] + } + }, + { + "type": "ExportDefaultDeclaration", + "declaration": { + "type": "FunctionDeclaration", + "id": { "type": "Identifier", "name": "MDXContent" }, + "params": [ + { + "type": "AssignmentPattern", + "left": { "type": "Identifier", "name": "props" }, + "right": { "type": "ObjectExpression", "properties": [] } + } + ], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "key": { "type": "Identifier", "name": "wrapper" }, + "value": { "type": "Identifier", "name": "MDXLayout" }, + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + "init": { + "type": "LogicalExpression", + "operator": "||", + "left": { + "type": "MemberExpression", + "object": { "type": "Identifier", "name": "props" }, + "property": { + "type": "Identifier", + "name": "components" + }, + "computed": false, + "optional": false + }, + "right": { "type": "ObjectExpression", "properties": [] } + } + } + ] + }, + { + "type": "ReturnStatement", + "argument": { + "type": "ConditionalExpression", + "test": { "type": "Identifier", "name": "MDXLayout" }, + "consequent": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsx" }, + "arguments": [ + { "type": "Identifier", "name": "MDXLayout" }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { "type": "Identifier", "name": "props" } + }, + { + "type": "Property", + "key": { "type": "Identifier", "name": "children" }, + "value": { + "type": "CallExpression", + "callee": { "type": "Identifier", "name": "_jsx" }, + "arguments": [ + { + "type": "Identifier", + "name": "_createMdxContent" + }, + { + "type": "ObjectExpression", + "properties": [ + { + "type": "SpreadElement", + "argument": { + "type": "Identifier", + "name": "props" + } + } + ] + } + ], + "optional": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ], + "optional": false + }, + "alternate": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "_createMdxContent" + }, + "arguments": [{ "type": "Identifier", "name": "props" }], + "optional": false + } + } + } + ] + } + } + } + ], + "sourceType": "module", + "comments": [] +} diff --git a/packages/codehike/tests/md-suite/static-children.7.compiled-js-dev.js b/packages/codehike/tests/md-suite/static-children.7.compiled-js-dev.js new file mode 100644 index 00000000..4d68649c --- /dev/null +++ b/packages/codehike/tests/md-suite/static-children.7.compiled-js-dev.js @@ -0,0 +1,185 @@ +import { Fragment as _Fragment, jsxDEV as _jsxDEV } from "react/jsx-dev-runtime" +function _createMdxContent(props) { + const _components = { + p: "p", + slot: "slot", + ...props.components, + } + return _jsxDEV( + _Fragment, + { + children: [ + _jsxDEV( + "div", + { + children: _jsxDEV( + _Fragment, + { + children: [ + _jsxDEV( + _components.p, + { + children: "hey", + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + lineNumber: 3, + columnNumber: 1, + }, + this, + ), + _jsxDEV( + _components.p, + { + children: "ho", + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + lineNumber: 5, + columnNumber: 1, + }, + this, + ), + ], + }, + undefined, + true, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + }, + this, + ), + title: "", + _data: { + header: "", + }, + foo: { + children: _jsxDEV( + _components.p, + { + children: "bar", + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + lineNumber: 9, + columnNumber: 1, + }, + this, + ), + title: "", + _data: { + header: "## !foo", + }, + }, + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + lineNumber: 1, + columnNumber: 1, + }, + this, + ), + "\n", + _jsxDEV( + "section", + { + children: [ + _jsxDEV( + _components.p, + { + children: "asdf", + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + lineNumber: 15, + columnNumber: 1, + }, + this, + ), + _jsxDEV( + _components.p, + { + children: "aa", + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + lineNumber: 17, + columnNumber: 1, + }, + this, + ), + ], + }, + undefined, + true, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + lineNumber: 13, + columnNumber: 1, + }, + this, + ), + ], + }, + undefined, + true, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + lineNumber: 1, + columnNumber: 1, + }, + this, + ) +} +export default function MDXContent(props = {}) { + const { wrapper: MDXLayout } = props.components || {} + return MDXLayout + ? _jsxDEV( + MDXLayout, + { + ...props, + children: _jsxDEV( + _createMdxContent, + { + ...props, + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + }, + this, + ), + }, + undefined, + false, + { + fileName: + "C:\\p\\dev\\codehike\\packages\\codehike\\tests\\md-suite\\static-children.0.mdx", + }, + this, + ) + : _createMdxContent(props) +} diff --git a/packages/codehike/tests/md-suite/static-children.7.compiled-js.js b/packages/codehike/tests/md-suite/static-children.7.compiled-js.js new file mode 100644 index 00000000..1b88de1b --- /dev/null +++ b/packages/codehike/tests/md-suite/static-children.7.compiled-js.js @@ -0,0 +1,63 @@ +import { + Fragment as _Fragment, + jsx as _jsx, + jsxs as _jsxs, +} from "react/jsx-runtime" +function _createMdxContent(props) { + const _components = { + p: "p", + slot: "slot", + ...props.components, + } + return _jsxs(_Fragment, { + children: [ + _jsx("div", { + children: _jsxs(_Fragment, { + children: [ + _jsx(_components.p, { + children: "hey", + }), + _jsx(_components.p, { + children: "ho", + }), + ], + }), + title: "", + _data: { + header: "", + }, + foo: { + children: _jsx(_components.p, { + children: "bar", + }), + title: "", + _data: { + header: "## !foo", + }, + }, + }), + "\n", + _jsxs("section", { + children: [ + _jsx(_components.p, { + children: "asdf", + }), + _jsx(_components.p, { + children: "aa", + }), + ], + }), + ], + }) +} +export default function MDXContent(props = {}) { + const { wrapper: MDXLayout } = props.components || {} + return MDXLayout + ? _jsx(MDXLayout, { + ...props, + children: _jsx(_createMdxContent, { + ...props, + }), + }) + : _createMdxContent(props) +} diff --git a/packages/codehike/tests/md-suite/static-children.9.rendered-dev.html b/packages/codehike/tests/md-suite/static-children.9.rendered-dev.html new file mode 100644 index 00000000..a5d4ed6e --- /dev/null +++ b/packages/codehike/tests/md-suite/static-children.9.rendered-dev.html @@ -0,0 +1,8 @@ +
+

hey

+

ho

+
+
+

asdf

+

aa

+
diff --git a/packages/codehike/tests/md.test.tsx b/packages/codehike/tests/md.test.tsx index d7283ef6..8e39fccb 100644 --- a/packages/codehike/tests/md.test.tsx +++ b/packages/codehike/tests/md.test.tsx @@ -69,7 +69,7 @@ testNames.forEach(async (filename) => { }) }) -const js = ["before-recma-compiled-js", "compiled-js"] +const js = ["before-recma-compiled-js", "compiled-js", "compiled-js-dev"] const jsx = [ "before-recma-compiled-jsx", "compiled-jsx", @@ -82,7 +82,7 @@ function sn(filename: string, step: string) { const extention = step === "error" ? "md" - : step === "rendered" + : step === "rendered" || step === "rendered-dev" ? "html" : js.includes(step) ? "js" @@ -101,14 +101,18 @@ const indexes = { "before-recma-compiled-jsx": 5, "before-recma-compiled-function": 5, "before-recma-js": 5, + "before-recma-js-dev": 5, "before-recma-jsx": 5, "after-recma-js": 6, + "after-recma-js-dev": 6, "after-recma-jsx": 6, "compiled-js": 7, + "compiled-js-dev": 7, "compiled-jsx": 7, "compiled-function": 7, "parsed-jsx": 8, rendered: 9, + "rendered-dev": 9, } async function getStepOutput( @@ -153,12 +157,26 @@ async function getStepOutput( remarkPlugins: [[remarkCodeHike, chConfig]], recmaPlugins: [X], })) + case "before-recma-js-dev": + return await compileAST(file, (X) => ({ + jsx: false, + development: true, + remarkPlugins: [[remarkCodeHike, chConfig]], + recmaPlugins: [X], + })) case "after-recma-js": return await compileAST(file, (X) => ({ jsx: false, remarkPlugins: [[remarkCodeHike, chConfig]], recmaPlugins: [[recmaCodeHike, chConfig], X], })) + case "after-recma-js-dev": + return await compileAST(file, (X) => ({ + jsx: false, + development: true, + remarkPlugins: [[remarkCodeHike, chConfig]], + recmaPlugins: [[recmaCodeHike, chConfig], X], + })) case "before-recma-jsx": return await compileAST(file, (X) => ({ jsx: true, @@ -171,6 +189,13 @@ async function getStepOutput( remarkPlugins: [[remarkCodeHike, chConfig]], recmaPlugins: [[recmaCodeHike, chConfig], X], })) + case "compiled-js-dev": + return await compileJS(file, { + jsx: false, + development: true, + remarkPlugins: [[remarkCodeHike, chConfig]], + recmaPlugins: [[recmaCodeHike, chConfig]], + }) case "compiled-js": return await compileJS(file, { jsx: false, @@ -201,6 +226,18 @@ async function getStepOutput( { remarkPlugins: [[remarkCodeHike, chConfig]], recmaPlugins: [[recmaCodeHike, chConfig]], + jsx: false, + }, + render, + ) + case "rendered-dev": + return await renderHTML( + file, + { + remarkPlugins: [[remarkCodeHike, chConfig]], + recmaPlugins: [[recmaCodeHike, chConfig]], + jsx: false, + development: true, }, render, ) diff --git a/packages/codehike/tests/utils.ast.tsx b/packages/codehike/tests/utils.ast.tsx index 25a9b3ff..05c15afc 100644 --- a/packages/codehike/tests/utils.ast.tsx +++ b/packages/codehike/tests/utils.ast.tsx @@ -2,6 +2,7 @@ import * as prettier from "prettier" import { compile, CompileOptions, run } from "@mdx-js/mdx" import { Pluggable } from "unified" import * as runtime from "react/jsx-runtime" +import * as devRuntime from "react/jsx-dev-runtime" import { parse } from "../src/" import { renderToReadableStream } from "react-dom/server.edge" import React from "react" @@ -53,7 +54,10 @@ export async function parsedJS(file: MDFile, options: CompileOptions) { outputFormat: "function-body", jsx: false, }) - const { default: Content } = await run(result, runtime as any) + const { default: Content } = await run( + result, + (options.development ? devRuntime : runtime) as any, + ) const block = parse(Content) return { block } } @@ -67,7 +71,10 @@ export async function renderHTML( ...options, outputFormat: "function-body", }) - const { default: Content } = await run(result, runtime as any) + const { default: Content } = await run( + result, + (options.development ? devRuntime : runtime) as any, + ) const html = await rscToHTML(render(Content)) return html diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bb03f941..215c6d8b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -68,6 +68,9 @@ importers: dotenv: specifier: ^16.4.1 version: 16.4.1 + estree-util-to-js: + specifier: ^2.0.0 + version: 2.0.0 lucide-react: specifier: ^0.303.0 version: 0.303.0(react@18.2.0)