feat: don't limit server script to head

This commit is contained in:
Ayo 2023-10-10 22:50:11 +02:00
parent 69499d61ab
commit b87f7ee5dc
3 changed files with 9 additions and 5 deletions

View file

@ -47,12 +47,10 @@ function doSetUp(html: string) {
const { attributes } = node;
const attributeKeys = Object.keys(attributes ?? {});
const isServerScript = attributeKeys.some((key) => key.includes("server:"));
const isInHead = node.parent?.name === "head";
if (
node.type === ELEMENT_NODE &&
node.name === "script" &&
isServerScript &&
isInHead
isServerScript
) {
const scripts = node.children.map((child) => child.value);
serverScripts.push(scripts.join(" "));

View file

@ -1 +1,4 @@
wow we can't find that
<script server:setup>
let greeting = "hello";
</script>
{{greeting}}!! wow we can't find that

View file

@ -4,9 +4,12 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>top about</title>
<script server:setup>
let greeting = "hello";
</script>
</head>
<body>
<a href="/">Home</a>
<h1>Top Level About</h1>
<h1>{{greeting}}!!! Top Level About</h1>
</body>
</html>