Comparing version 1.0.0-alpha.16 to 1.0.0-alpha.17
@@ -63,8 +63,26 @@ import { getObjectAttribute } from "./estree.js"; | ||
function sectionContainer(section, path) { | ||
const elements = section.children.map((child) => { | ||
return { | ||
type: "mdxJsxFlowElement", | ||
name: "slot", | ||
attributes: [ | ||
{ | ||
type: "mdxJsxAttribute", | ||
name: "path", | ||
value: path, | ||
}, | ||
], | ||
children: sectionChildren(section), | ||
}; | ||
} | ||
function sectionChildren(section) { | ||
const elements = section.children | ||
.map((child) => { | ||
if (child.type === "content") { | ||
return child.value; | ||
} | ||
return placeholder(child.name, child.index); | ||
}); | ||
if (child.type === "section") { | ||
return placeholder(child); | ||
} | ||
}) | ||
.filter((x) => !!x); | ||
const child = elements.length == 1 | ||
@@ -79,21 +97,15 @@ ? elements[0] | ||
}; | ||
return { | ||
type: "mdxJsxFlowElement", | ||
name: "slot", | ||
attributes: [ | ||
{ | ||
type: "mdxJsxAttribute", | ||
name: "path", | ||
value: path, | ||
}, | ||
], | ||
children: child ? [child] : [], | ||
}; | ||
return child ? [child] : []; | ||
} | ||
function placeholder(name, index) { | ||
function placeholder(node) { | ||
const { name, index } = node; | ||
const startsWithLowercase = name && name.charAt(0) === name.charAt(0).toLowerCase(); | ||
if (startsWithLowercase) { | ||
return null; | ||
} | ||
const attributes = [ | ||
{ | ||
type: "mdxJsxAttribute", | ||
name: "name", | ||
value: name, | ||
name: "title", | ||
value: node.title, | ||
}, | ||
@@ -130,6 +142,6 @@ ]; | ||
type: "mdxJsxFlowElement", | ||
name: "slot", | ||
name: name, | ||
attributes, | ||
children: [], | ||
children: sectionChildren(node), | ||
}; | ||
} |
@@ -123,3 +123,6 @@ import { SKIP, visit } from "estree-util-visit"; | ||
const elements = childrenByPath[path].shift(); | ||
node.value = elements[0]; | ||
node.value = elements[0] || { | ||
type: "Identifier", | ||
name: "undefined", | ||
}; | ||
return SKIP; | ||
@@ -146,6 +149,6 @@ } | ||
children.forEach((callExpression) => { | ||
var _a; | ||
var _a, _b; | ||
const props = (_a = callExpression.arguments[1]) === null || _a === void 0 ? void 0 : _a.properties; | ||
const path = props.find((p) => p.key.name === "path").value.value; | ||
let slotChildren = props.find((p) => p.key.name === "children").value; | ||
let slotChildren = (_b = props.find((p) => p.key.name === "children")) === null || _b === void 0 ? void 0 : _b.value; | ||
childrenByPath[path] = childrenByPath[path] || []; | ||
@@ -163,3 +166,6 @@ childrenByPath[path].push(slotChildren); | ||
const elements = childrenByPath[path].shift(); | ||
node.value = elements; | ||
node.value = elements || { | ||
type: "Identifier", | ||
name: "undefined", | ||
}; | ||
return SKIP; | ||
@@ -166,0 +172,0 @@ } |
{ | ||
"name": "codehike", | ||
"version": "1.0.0-alpha.16", | ||
"version": "1.0.0-alpha.17", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232531
5456