diff --git a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts index f2b3e44e..2202d413 100644 --- a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts +++ b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts @@ -19,7 +19,7 @@ const Components = { Fragment: 'Fragment', Template: 'Template', Dialog: 'Dialog', -} +}; const getJSXAttributeValue = ( path: NodePath, @@ -174,12 +174,12 @@ const genProps = (props: t.ObjectExpression) => { const genComponent = (component: t.Identifier | t.StringLiteral) => { return t.objectProperty( - t.identifier('component'), - t.isStringLiteral(component) + t.identifier('component'), + t.isStringLiteral(component) ? component - : component.name.indexOf(":") > -1 - ? t.stringLiteral(component.name) - : component + : component.name.indexOf(':') > -1 + ? t.stringLiteral(component.name) + : component ); }; @@ -215,7 +215,9 @@ const isNamedSlot = (slot: t.Expression) => { } }); if (componentPropertyIdx > -1) { - const componentProperty = properties[componentPropertyIdx] as t.ObjectProperty; + const componentProperty = properties[ + componentPropertyIdx + ] as t.ObjectProperty; const oldVal = (componentProperty.value as t.StringLiteral).value; const slotName = oldVal.split(':')[1]; properties.splice(componentPropertyIdx, 1); @@ -224,16 +226,28 @@ const isNamedSlot = (slot: t.Expression) => { return ''; }; -const genButtonsSlot = (slot: t.ObjectExpression) => { - const targetSlots = (slot as t.ObjectExpression).properties.find(v => { +const genChildSlot = (slot: t.ObjectExpression, slotName: string) => { + const targetSlots = (slot as t.ObjectExpression).properties.find((v) => { return t.isObjectProperty(v) && (v.key as t.Identifier).name === 'slots'; })! as t.ObjectProperty; - const targetDefault = (targetSlots.value as t.ObjectExpression).properties.find(v => { + if (!targetSlots) { + return slot; + } + + const targetDefault = ( + targetSlots.value as t.ObjectExpression + ).properties.find((v) => { return t.isObjectProperty(v) && (v.key as t.Identifier).name === 'default'; - })! + })!; const value = (targetDefault as t.ObjectProperty).value; - return t.isArrayExpression(value) ? value : t.arrayExpression([value as t.ObjectExpression]); -} + if (slotName === 'buttons') { + return t.isArrayExpression(value) + ? value + : t.arrayExpression([value as t.ObjectExpression]); + } else { + return value; + } +}; const genSlots = (slots: t.Expression[]) => { const defaultSlots = [] as t.Expression[]; @@ -243,21 +257,17 @@ const genSlots = (slots: t.Expression[]) => { const properties = (slot as t.ObjectExpression).properties; const slotName = isNamedSlot(slot); if (slotName) { - // 对于 buttons 的具名插槽特殊处理 - if (slotName === 'buttons') { - namedSlots[slotName] = genButtonsSlot(slot as t.ObjectExpression); - } else { - namedSlots[slotName] = slot; - } + // 对于具名插槽特殊处理 + namedSlots[slotName] = genChildSlot(slot as t.ObjectExpression, slotName); } else if (properties) { const componentPropertyIdx = properties.findIndex((item) => { if (t.isObjectProperty(item)) { return ( (item.key as t.Identifier).name === 'component' && - ( - t.isStringLiteral(item.value) && item.value.value === Components.Dialog || - t.isIdentifier(item.value) && item.value.name === Components.Dialog - ) + ((t.isStringLiteral(item.value) && + item.value.value === Components.Dialog) || + (t.isIdentifier(item.value) && + item.value.name === Components.Dialog)) ); } }); @@ -302,7 +312,7 @@ const isTemplate = (tag: t.Identifier) => { const isFragment = (tag: t.Identifier) => { return tag.name === Components.Fragment; -} +}; const hasSlot = (path: NodePath, state: State) => { const attributes = path.get('openingElement').get('attributes'); @@ -327,11 +337,13 @@ const transformJSXElement = ( const { tag, props } = buildProps(path, state); if (isFragment(tag)) { - return t.objectExpression([ - genKey(path, state), - ...genProps(props as t.ObjectExpression), - genSlots(children), - ]) + return t.objectExpression( + [ + genKey(path, state), + ...genProps(props as t.ObjectExpression), + children.length && genSlots(children), + ].filter(Boolean) as t.ObjectProperty[] + ); } const slotName = hasSlot(path, state); @@ -339,12 +351,14 @@ const transformJSXElement = ( tag.name += `:${slotName}`; } - return t.objectExpression([ - genKey(path, state), - genComponent(tag), - ...genProps(props as t.ObjectExpression), - genSlots(children), - ]); + return t.objectExpression( + [ + genKey(path, state), + genComponent(tag), + ...genProps(props as t.ObjectExpression), + children.length && genSlots(children), + ].filter(Boolean) as t.ObjectProperty[] + ); }; const visitor: Visitor = { diff --git a/packages/jsx-explorer/dist/assets/cssMode-153b17a8.js b/packages/jsx-explorer/dist/assets/cssMode-271b4f52.js similarity index 99% rename from packages/jsx-explorer/dist/assets/cssMode-153b17a8.js rename to packages/jsx-explorer/dist/assets/cssMode-271b4f52.js index d1956e14..de37bed1 100644 --- a/packages/jsx-explorer/dist/assets/cssMode-153b17a8.js +++ b/packages/jsx-explorer/dist/assets/cssMode-271b4f52.js @@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; -import { m as monaco_editor_core_star } from "./index-97bacbf1.js"; +import { m as monaco_editor_core_star } from "./index-d310fd64.js"; /*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166) diff --git a/packages/jsx-explorer/dist/assets/freemarker2-a034e277.js b/packages/jsx-explorer/dist/assets/freemarker2-d2483059.js similarity index 99% rename from packages/jsx-explorer/dist/assets/freemarker2-a034e277.js rename to packages/jsx-explorer/dist/assets/freemarker2-d2483059.js index 904bbea3..4b505aeb 100644 --- a/packages/jsx-explorer/dist/assets/freemarker2-a034e277.js +++ b/packages/jsx-explorer/dist/assets/freemarker2-d2483059.js @@ -1,4 +1,4 @@ -import { m as monaco_editor_core_star } from "./index-97bacbf1.js"; +import { m as monaco_editor_core_star } from "./index-d310fd64.js"; /*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166) diff --git a/packages/jsx-explorer/dist/assets/handlebars-ea33f7a7.js b/packages/jsx-explorer/dist/assets/handlebars-90f14e46.js similarity index 99% rename from packages/jsx-explorer/dist/assets/handlebars-ea33f7a7.js rename to packages/jsx-explorer/dist/assets/handlebars-90f14e46.js index dbf5e0ed..d6a62942 100644 --- a/packages/jsx-explorer/dist/assets/handlebars-ea33f7a7.js +++ b/packages/jsx-explorer/dist/assets/handlebars-90f14e46.js @@ -1,4 +1,4 @@ -import { m as monaco_editor_core_star } from "./index-97bacbf1.js"; +import { m as monaco_editor_core_star } from "./index-d310fd64.js"; /*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166) diff --git a/packages/jsx-explorer/dist/assets/html-07533a4f.js b/packages/jsx-explorer/dist/assets/html-048c3aad.js similarity index 99% rename from packages/jsx-explorer/dist/assets/html-07533a4f.js rename to packages/jsx-explorer/dist/assets/html-048c3aad.js index 7920a13b..4082730e 100644 --- a/packages/jsx-explorer/dist/assets/html-07533a4f.js +++ b/packages/jsx-explorer/dist/assets/html-048c3aad.js @@ -1,4 +1,4 @@ -import { m as monaco_editor_core_star } from "./index-97bacbf1.js"; +import { m as monaco_editor_core_star } from "./index-d310fd64.js"; /*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166) diff --git a/packages/jsx-explorer/dist/assets/htmlMode-22b79c2c.js b/packages/jsx-explorer/dist/assets/htmlMode-0a7c49eb.js similarity index 99% rename from packages/jsx-explorer/dist/assets/htmlMode-22b79c2c.js rename to packages/jsx-explorer/dist/assets/htmlMode-0a7c49eb.js index b7830ae4..47c947a4 100644 --- a/packages/jsx-explorer/dist/assets/htmlMode-22b79c2c.js +++ b/packages/jsx-explorer/dist/assets/htmlMode-0a7c49eb.js @@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; -import { m as monaco_editor_core_star } from "./index-97bacbf1.js"; +import { m as monaco_editor_core_star } from "./index-d310fd64.js"; /*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166) diff --git a/packages/jsx-explorer/dist/assets/index-97bacbf1.js b/packages/jsx-explorer/dist/assets/index-d310fd64.js similarity index 99% rename from packages/jsx-explorer/dist/assets/index-97bacbf1.js rename to packages/jsx-explorer/dist/assets/index-d310fd64.js index 29157d86..47f51650 100644 --- a/packages/jsx-explorer/dist/assets/index-97bacbf1.js +++ b/packages/jsx-explorer/dist/assets/index-d310fd64.js @@ -110997,7 +110997,7 @@ registerLanguage({ aliases: ["FreeMarker2", "Apache FreeMarker2"], loader: () => { { - return __vitePreload(() => import("./freemarker2-a034e277.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationDollar); + return __vitePreload(() => import("./freemarker2-d2483059.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationDollar); } } }); @@ -111006,7 +111006,7 @@ registerLanguage({ aliases: ["FreeMarker2 (Angle/Dollar)", "Apache FreeMarker2 (Angle/Dollar)"], loader: () => { { - return __vitePreload(() => import("./freemarker2-a034e277.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAngleInterpolationDollar); + return __vitePreload(() => import("./freemarker2-d2483059.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAngleInterpolationDollar); } } }); @@ -111015,7 +111015,7 @@ registerLanguage({ aliases: ["FreeMarker2 (Bracket/Dollar)", "Apache FreeMarker2 (Bracket/Dollar)"], loader: () => { { - return __vitePreload(() => import("./freemarker2-a034e277.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagBracketInterpolationDollar); + return __vitePreload(() => import("./freemarker2-d2483059.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagBracketInterpolationDollar); } } }); @@ -111024,7 +111024,7 @@ registerLanguage({ aliases: ["FreeMarker2 (Angle/Bracket)", "Apache FreeMarker2 (Angle/Bracket)"], loader: () => { { - return __vitePreload(() => import("./freemarker2-a034e277.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAngleInterpolationBracket); + return __vitePreload(() => import("./freemarker2-d2483059.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAngleInterpolationBracket); } } }); @@ -111033,7 +111033,7 @@ registerLanguage({ aliases: ["FreeMarker2 (Bracket/Bracket)", "Apache FreeMarker2 (Bracket/Bracket)"], loader: () => { { - return __vitePreload(() => import("./freemarker2-a034e277.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagBracketInterpolationBracket); + return __vitePreload(() => import("./freemarker2-d2483059.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagBracketInterpolationBracket); } } }); @@ -111042,7 +111042,7 @@ registerLanguage({ aliases: ["FreeMarker2 (Auto/Dollar)", "Apache FreeMarker2 (Auto/Dollar)"], loader: () => { { - return __vitePreload(() => import("./freemarker2-a034e277.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationDollar); + return __vitePreload(() => import("./freemarker2-d2483059.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationDollar); } } }); @@ -111051,7 +111051,7 @@ registerLanguage({ aliases: ["FreeMarker2 (Auto/Bracket)", "Apache FreeMarker2 (Auto/Bracket)"], loader: () => { { - return __vitePreload(() => import("./freemarker2-a034e277.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationBracket); + return __vitePreload(() => import("./freemarker2-d2483059.js"), true ? [] : void 0, import.meta.url).then((m) => m.TagAutoInterpolationBracket); } } }); @@ -111083,7 +111083,7 @@ registerLanguage({ mimetypes: ["text/x-handlebars-template"], loader: () => { { - return __vitePreload(() => import("./handlebars-ea33f7a7.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./handlebars-90f14e46.js"), true ? [] : void 0, import.meta.url); } } }); @@ -111104,7 +111104,7 @@ registerLanguage({ mimetypes: ["text/html", "text/x-jshtm", "text/template", "text/ng-template"], loader: () => { { - return __vitePreload(() => import("./html-07533a4f.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./html-048c3aad.js"), true ? [] : void 0, import.meta.url); } } }); @@ -111139,7 +111139,7 @@ registerLanguage({ mimetypes: ["text/javascript"], loader: () => { { - return __vitePreload(() => import("./javascript-94770727.js"), true ? ["./javascript-94770727.js","./typescript-d5b7d56f.js"] : void 0, import.meta.url); + return __vitePreload(() => import("./javascript-f898e63a.js"), true ? ["./javascript-f898e63a.js","./typescript-1f3a807b.js"] : void 0, import.meta.url); } } }); @@ -111202,7 +111202,7 @@ registerLanguage({ mimetypes: ["application/liquid"], loader: () => { { - return __vitePreload(() => import("./liquid-b9ade9da.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./liquid-68b5b2d1.js"), true ? [] : void 0, import.meta.url); } } }); @@ -111232,7 +111232,7 @@ registerLanguage({ aliases: ["MDX", "mdx"], loader: () => { { - return __vitePreload(() => import("./mdx-d3d44f70.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./mdx-4a89fe90.js"), true ? [] : void 0, import.meta.url); } } }); @@ -111395,7 +111395,7 @@ registerLanguage({ firstLine: "^#!/.*\\bpython[0-9.-]*\\b", loader: () => { { - return __vitePreload(() => import("./python-50ca6b49.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./python-546a1571.js"), true ? [] : void 0, import.meta.url); } } }); @@ -111426,7 +111426,7 @@ registerLanguage({ mimetypes: ["text/x-cshtml"], loader: () => { { - return __vitePreload(() => import("./razor-88e24764.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./razor-e87df5ed.js"), true ? [] : void 0, import.meta.url); } } }); @@ -111642,7 +111642,7 @@ registerLanguage({ mimetypes: ["text/typescript"], loader: () => { { - return __vitePreload(() => import("./typescript-d5b7d56f.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./typescript-1f3a807b.js"), true ? [] : void 0, import.meta.url); } } }); @@ -111692,7 +111692,7 @@ registerLanguage({ mimetypes: ["text/xml", "application/xml", "application/xaml+xml", "application/xml-dtd"], loader: () => { { - return __vitePreload(() => import("./xml-f113747d.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./xml-6a18d563.js"), true ? [] : void 0, import.meta.url); } } }); @@ -111703,7 +111703,7 @@ registerLanguage({ mimetypes: ["application/x-yaml", "text/x-yaml"], loader: () => { { - return __vitePreload(() => import("./yaml-dcf06003.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./yaml-020a47c0.js"), true ? [] : void 0, import.meta.url); } } }); @@ -111818,7 +111818,7 @@ var lessDefaults = new LanguageServiceDefaultsImpl$3("less", optionsDefault$1, m monaco_editor_core_exports$3.languages.css = { cssDefaults, lessDefaults, scssDefaults }; function getMode$3() { { - return __vitePreload(() => import("./cssMode-153b17a8.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./cssMode-271b4f52.js"), true ? [] : void 0, import.meta.url); } } monaco_editor_core_exports$3.languages.onLanguage("less", () => { @@ -111937,7 +111937,7 @@ monaco_editor_core_exports$2.languages.html = { }; function getMode$2() { { - return __vitePreload(() => import("./htmlMode-22b79c2c.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./htmlMode-0a7c49eb.js"), true ? [] : void 0, import.meta.url); } } function registerHTMLLanguageService(languageId, options2 = optionsDefault, modeConfiguration = getConfigurationDefault(languageId)) { @@ -112033,7 +112033,7 @@ var jsonDefaults = new LanguageServiceDefaultsImpl$1("json", diagnosticDefault, monaco_editor_core_exports$1.languages.json = { jsonDefaults }; function getMode$1() { { - return __vitePreload(() => import("./jsonMode-662fc4c5.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./jsonMode-33be39be.js"), true ? [] : void 0, import.meta.url); } } monaco_editor_core_exports$1.languages.register({ @@ -112306,7 +112306,7 @@ monaco_editor_core_exports.languages.typescript = { }; function getMode() { { - return __vitePreload(() => import("./tsMode-776ccc52.js"), true ? [] : void 0, import.meta.url); + return __vitePreload(() => import("./tsMode-9c85ef37.js"), true ? [] : void 0, import.meta.url); } } monaco_editor_core_exports.languages.onLanguage("typescript", () => { @@ -198651,7 +198651,7 @@ function requireLib$9() { UnterminatedJsxContent: "Unterminated JSX contents.", UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...?" }); - function isFragment(object) { + function isFragment2(object) { return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false; } function getQualifiedJSXName(object) { @@ -198953,16 +198953,16 @@ function requireLib$9() { this.unexpected(); } } - if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) { + if (isFragment2(openingElement) && !isFragment2(closingElement) && closingElement !== null) { this.raise(JsxErrors.MissingClosingTagFragment, { at: closingElement }); - } else if (!isFragment(openingElement) && isFragment(closingElement)) { + } else if (!isFragment2(openingElement) && isFragment2(closingElement)) { this.raise(JsxErrors.MissingClosingTagElement, { at: closingElement, openingTagName: getQualifiedJSXName(openingElement.name) }); - } else if (!isFragment(openingElement) && !isFragment(closingElement)) { + } else if (!isFragment2(openingElement) && !isFragment2(closingElement)) { if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) { this.raise(JsxErrors.MissingClosingTagElement, { at: closingElement, @@ -198971,7 +198971,7 @@ function requireLib$9() { } } } - if (isFragment(openingElement)) { + if (isFragment2(openingElement)) { node2.openingFragment = openingElement; node2.closingFragment = closingElement; } else { @@ -198984,7 +198984,7 @@ function requireLib$9() { at: this.state.startLoc }); } - return isFragment(openingElement) ? this.finishNode(node2, "JSXFragment") : this.finishNode(node2, "JSXElement"); + return isFragment2(openingElement) ? this.finishNode(node2, "JSXFragment") : this.finishNode(node2, "JSXElement"); } jsxParseElement() { const startLoc = this.state.startLoc; @@ -231818,10 +231818,8 @@ const checkIsComponent = (path2, state) => { return shouldTransformedToSlots(namePath.node.property.name); } const tag = namePath.node.name; - if (tag === "template") { - return true; - } - return !((_b2 = (_a2 = state.opts).isCustomElement) == null ? void 0 : _b2.call(_a2, tag)) && shouldTransformedToSlots(tag) && !htmlTags$1.includes(tag) && !svgTags.includes(tag); + return !((_b2 = (_a2 = state.opts).isCustomElement) == null ? void 0 : _b2.call(_a2, tag)) && // shouldTransformedToSlots(tag) && + !htmlTags$1.includes(tag) && !svgTags.includes(tag); }; const transformJSXMemberExpression = (path2) => { const objectPath = path2.node.object; @@ -231836,9 +231834,8 @@ const getTag = (path2, state) => { const namePath = path2.get("openingElement").get("name"); if (namePath.isJSXIdentifier()) { const { name } = namePath.node; - if (name === "template" || !htmlTags$1.includes(name) && !svgTags.includes(name)) { - console.log(name); - return libExports$1.stringLiteral(name); + if (!htmlTags$1.includes(name) && !svgTags.includes(name)) { + return path2.scope.hasBinding(name) ? libExports$1.identifier(name) : libExports$1.stringLiteral(name); } return libExports$1.stringLiteral(name); } @@ -231900,6 +231897,11 @@ const walksScope = (path2, name, slotFlag) => { }; const onRE = /^on[^a-z]/; const isOn = (key) => onRE.test(key); +const Components = { + Fragment: "Fragment", + Template: "Template", + Dialog: "Dialog" +}; const getJSXAttributeValue = (path2, state) => { const valuePath = path2.get("value"); if (valuePath.isJSXElement()) { @@ -232016,7 +232018,10 @@ const genProps = (props) => { return result; }; const genComponent = (component) => { - return libExports$1.objectProperty(libExports$1.identifier("component"), component); + return libExports$1.objectProperty( + libExports$1.identifier("component"), + libExports$1.isStringLiteral(component) ? component : component.name.indexOf(":") > -1 ? libExports$1.stringLiteral(component.name) : component + ); }; const genKey = (() => { let idx = 0; @@ -232040,19 +232045,35 @@ const isNamedSlot = (slot) => { const properties = slot.properties; const componentPropertyIdx = properties.findIndex((item2) => { if (libExports$1.isObjectProperty(item2)) { - return item2.key.name === "component" && item2.value.value.startsWith("template:"); + return item2.key.name === "component" && libExports$1.isStringLiteral(item2.value) && item2.value.value.startsWith(`${Components.Template}:`); } }); if (componentPropertyIdx > -1) { const componentProperty = properties[componentPropertyIdx]; const oldVal = componentProperty.value.value; const slotName = oldVal.split(":")[1]; - componentProperty.value.value = "template"; properties.splice(componentPropertyIdx, 1); return slotName; } return ""; }; +const genChildSlot = (slot, slotName) => { + const targetSlots = slot.properties.find((v) => { + return libExports$1.isObjectProperty(v) && v.key.name === "slots"; + }); + if (!targetSlots) { + return slot; + } + const targetDefault = targetSlots.value.properties.find((v) => { + return libExports$1.isObjectProperty(v) && v.key.name === "default"; + }); + const value2 = targetDefault.value; + if (slotName === "buttons") { + return libExports$1.isArrayExpression(value2) ? value2 : libExports$1.arrayExpression([value2]); + } else { + return value2; + } +}; const genSlots = (slots) => { const defaultSlots = []; const namedSlots = {}; @@ -232061,11 +232082,11 @@ const genSlots = (slots) => { const properties = slot.properties; const slotName = isNamedSlot(slot); if (slotName) { - namedSlots[slotName] = slot; + namedSlots[slotName] = genChildSlot(slot, slotName); } else if (properties) { const componentPropertyIdx = properties.findIndex((item2) => { if (libExports$1.isObjectProperty(item2)) { - return item2.key.name === "component" && item2.value.value === "Modal"; + return item2.key.name === "component" && (libExports$1.isStringLiteral(item2.value) && item2.value.value === Components.Dialog || libExports$1.isIdentifier(item2.value) && item2.value.name === Components.Dialog); } }); if (componentPropertyIdx > -1) { @@ -232091,14 +232112,17 @@ const genSlots = (slots) => { }), dialogSlots.length && libExports$1.objectProperty( libExports$1.identifier("dialog"), - dialogSlots.length <= 1 ? (dialogSlots == null ? void 0 : dialogSlots[0]) || libExports$1.objectExpression([]) : libExports$1.arrayExpression(dialogSlots) + libExports$1.arrayExpression(dialogSlots) ) ].filter(Boolean) ) ); }; const isTemplate = (tag) => { - return tag.value === "template"; + return tag.name === Components.Template; +}; +const isFragment = (tag) => { + return tag.name === Components.Fragment; }; const hasSlot = (path2, state) => { const attributes = path2.get("openingElement").get("attributes"); @@ -232117,16 +232141,27 @@ const hasSlot = (path2, state) => { const transformJSXElement = (path2, state) => { const children = getChildren(path2.get("children"), state); const { tag, props } = buildProps(path2, state); + if (isFragment(tag)) { + return libExports$1.objectExpression( + [ + genKey(path2, state), + ...genProps(props), + children.length && genSlots(children) + ].filter(Boolean) + ); + } const slotName = hasSlot(path2, state); if (isTemplate(tag) && slotName) { - tag.value += `:${slotName}`; - } - return libExports$1.objectExpression([ - genKey(path2, state), - genComponent(tag), - ...genProps(props), - genSlots(children) - ]); + tag.name += `:${slotName}`; + } + return libExports$1.objectExpression( + [ + genKey(path2, state), + genComponent(tag), + ...genProps(props), + children.length && genSlots(children) + ].filter(Boolean) + ); }; const visitor$1 = { "JSXFragment|JSXText": { @@ -232147,8 +232182,8 @@ const visitor$1 = { return; } const parent = path2.findParent((parentPath) => parentPath.isJSXElement()); - const { reactiveWrapRoot } = state.opts; - const nodes = !parent && reactiveWrapRoot ? libExports$1.callExpression(createIdentifier(state, "reactive"), [ + const { isReactiveRoot } = state.opts; + const nodes = !parent && isReactiveRoot ? libExports$1.callExpression(createIdentifier(state, "reactive"), [ transformJSXElement(path2, state) ]) : transformJSXElement(path2, state); path2.replaceWith(nodes); @@ -235627,7 +235662,7 @@ const compilerOptions = reactive({ enableObjectSlots: true, isTSX: true, librarySource: "vue", - reactiveWrapRoot: true, + isReactiveRoot: true, customKey: "ONE_JSX_LOADER" }); const App = { @@ -235646,7 +235681,7 @@ const App = { ); } }, - "one-jsx-loader" + "babel-plugin-jsx explorer" ), h("div", { id: "options-wrapper" }, [ h("div", { id: "options-label" }, "Options ↘"), @@ -235663,17 +235698,17 @@ const App = { }), h("label", { for: "isTSX" }, "isTSX") ]), - // reactiveWrapRoot + // isReactiveRoot h("li", [ h("input", { type: "checkbox", - id: "reactiveWrapRoot", - checked: compilerOptions.reactiveWrapRoot, + id: "isReactiveRoot", + checked: compilerOptions.isReactiveRoot, onChange(e) { - compilerOptions.reactiveWrapRoot = e.target.checked; + compilerOptions.isReactiveRoot = e.target.checked; } }), - h("label", { for: "reactiveWrapRoot" }, "reactiveWrapRoot") + h("label", { for: "isReactiveRoot" }, "isReactiveRoot") ]), // select library source h("li", [ @@ -235733,23 +235768,67 @@ function initOptions() { createApp(App).mount(document.getElementById("header")); } const index = ""; -const templateStr = `export function useFn() { +const templateStr = `// @ts-expect-error +import { Template, Fragment, Dialog } from 'one-jsx-loader' +// @ts-expect-error +import { Form, FormItem, Grid, Column, Icon, Tag, Button, Input, Select } from './components' + +function useHeader() { + return +} + +function useForm() { return
- + + +
} + +function useGrid() { + const handleFocus = () => {} + const handleChange = () => {} + return + + + { + return { + props: { + light: 'light', + type: 'error', + value: row.status + } + } + }} /> + + + + +