0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

[ci] format

This commit is contained in:
bholmesdev 2022-07-15 15:27:19 +00:00 committed by fredkbot
parent f5d4ebf0e2
commit 6809a0d289
3 changed files with 32 additions and 17 deletions

View file

@ -1,8 +1,8 @@
import type { PluginMetadata } from '../vite-plugin-astro/types';
import type { PluginObj, NodePath } from '@babel/core';
import type { PluginObj } from '@babel/core';
import * as t from '@babel/types';
import { pathToFileURL } from 'node:url'
import { pathToFileURL } from 'node:url';
import { ClientOnlyPlaceholder } from '../runtime/server/index.js';
import type { PluginMetadata } from '../vite-plugin-astro/types';
function isComponent(tagName: string) {
return (
@ -52,7 +52,10 @@ function jsxAttributeToString(attr: t.JSXAttribute): string {
return `${attr.name.name}`;
}
function addClientMetadata(node: t.JSXElement, meta: { resolvedPath: string; path: string; name: string }) {
function addClientMetadata(
node: t.JSXElement,
meta: { resolvedPath: string; path: string; name: string }
) {
const existingAttributes = node.openingElement.attributes.map((attr) =>
t.isJSXAttribute(attr) ? jsxAttributeToString(attr) : null
);
@ -81,11 +84,17 @@ function addClientMetadata(node: t.JSXElement, meta: { resolvedPath: string; pat
}
}
function addClientOnlyMetadata(node: t.JSXElement, meta: { resolvedPath: string; path: string; name: string }) {
function addClientOnlyMetadata(
node: t.JSXElement,
meta: { resolvedPath: string; path: string; name: string }
) {
const tagName = getTagName(node);
node.openingElement = t.jsxOpeningElement(t.jsxIdentifier(ClientOnlyPlaceholder), node.openingElement.attributes)
node.openingElement = t.jsxOpeningElement(
t.jsxIdentifier(ClientOnlyPlaceholder),
node.openingElement.attributes
);
if (node.closingElement) {
node.closingElement = t.jsxClosingElement(t.jsxIdentifier(ClientOnlyPlaceholder))
node.closingElement = t.jsxClosingElement(t.jsxIdentifier(ClientOnlyPlaceholder));
}
const existingAttributes = node.openingElement.attributes.map((attr) =>
t.isJSXAttribute(attr) ? jsxAttributeToString(attr) : null
@ -132,7 +141,7 @@ export default function astroJSX(): PluginObj {
clientOnlyComponents: [],
hydratedComponents: [],
scripts: [],
}
};
}
path.node.body.splice(
0,
@ -142,7 +151,7 @@ export default function astroJSX(): PluginObj {
t.stringLiteral('astro/jsx-runtime')
)
);
}
},
},
ImportDeclaration(path, state) {
const source = path.node.source.value;
@ -210,8 +219,8 @@ export default function astroJSX(): PluginObj {
(state.file.metadata as PluginMetadata).astro.clientOnlyComponents.push({
exportName: meta.name,
specifier: meta.name,
resolvedPath
})
resolvedPath,
});
meta.resolvedPath = resolvedPath;
addClientOnlyMetadata(parentNode, meta);
@ -219,8 +228,8 @@ export default function astroJSX(): PluginObj {
(state.file.metadata as PluginMetadata).astro.hydratedComponents.push({
exportName: meta.name,
specifier: meta.name,
resolvedPath
})
resolvedPath,
});
meta.resolvedPath = resolvedPath;
addClientMetadata(parentNode, meta);

View file

@ -2,8 +2,8 @@
import { SSRResult } from '../../@types/astro.js';
import { AstroJSX, isVNode } from '../../jsx-runtime/index.js';
import {
escapeHTML,
ClientOnlyPlaceholder,
escapeHTML,
HTMLString,
markHTMLString,
renderComponent,
@ -108,7 +108,13 @@ export async function renderJSX(result: SSRResult, vnode: any): Promise<any> {
slots
);
} else {
output = await renderComponent(result, typeof vnode.type === 'function' ? vnode.type.name : vnode.type, vnode.type, props, slots);
output = await renderComponent(
result,
typeof vnode.type === 'function' ? vnode.type.name : vnode.type,
vnode.type,
props,
slots
);
}
return markHTMLString(output);
}