Skip to content

[Bug]: A 'return' statement can only be used within a function body. #1555

Description

@AdamJSoftware

What happened?

When finishing the setup and getting to the /done page. The following occurs:

A 'return' statement can only be used within a function body.
shared/Code.astro:46:21
---
import '../../styles/code-component.css';

interface Props {
	code: string;
	ins?: string;
	del?: string;

	__test_mode?: boolean;
}

const { code, del, ins, __test_mode = false } = Astro.props;

const escapeHtml = (s: string) =>
	s
		.replaceAll('&', '&')
		.replaceAll('<', '&lt;')
		.replaceAll('>', '&gt;')
		.replaceAll('"', '&quot;')
		.replaceAll("'", '&#39;');

const htmlCode = code
	.split('\n')
	.map((line) => `<span class="line">${escapeHtml(line)}</span>`)
	.join('\n');

const props: Record<string, string> = {};

/* v8 ignore start */
if (del) {
	props['data-lines-deleted'] = del;
}

if (ins) {
	props['data-lines-inserted'] = ins;
}
/* v8 ignore stop */

const id = __test_mode ? 'test-id' : Math.random().toString(36).substring(2, 9);
---

<pre class="code-container scrollbar"><code id={id} class:list={["custom-code", (del || ins) ? 'diff' : '']} {...props} set:html={htmlCode} /></pre>
<script is:inline define:vars={{ id: id }}>
	const codesWithDiff = document.getElementById(id);

	if (!codesWithDiff) return;^

	const code = codesWithDiff.classList.contains("diff");

	if (!code) return;

	const linesInserted = codesWithDiff.getAttribute("data-lines-inserted");
	const linesDeleted = codesWithDiff.getAttribute("data-lines-deleted");

	if (!linesInserted && !linesDeleted) return;

	const parsedInsertedLines =
		linesInserted?.split(",").map((line) => parseInt(line, 10)) || [];
	const parsedDeletedLines =
		linesDeleted?.split(",").map((line) => parseInt(line, 10)) || [];

	const codeLines = codesWithDiff.querySelectorAll(".line");

	codeLines.forEach((line, index) => {
		if (parsedInsertedLines.includes(index + 1)) {
			line.classList.add("diff", "ins");
		}

		if (parsedDeletedLines.includes(index + 1)) {
			line.classList.add("diff", "del");
		}
	});
</script>
Stack Trace
CompilerError: A 'return' statement can only be used within a function body.
    at handleCompileResultErrors (file:///node_modules/.pnpm/astro@7.0.6_@emnapi+core@1.11.1_@emnapi+runtime@1.11.1_@types

Stack trace:

CompilerError: A 'return' statement can only be used within a function body.
    at handleCompileResultErrors (file:///node_modules/.pnpm/astro@7.0.6_@emnapi+core@1.11.1_@emnapi+runtime@1.11.1_@types+node@24.13.2_jiti@2.4.2_rollup@4.41.1_yaml@2.9.0/node_modules/astro/dist/core/compile/compile.js:67:11)
    at compile (file:///node_modules/.pnpm/astro@7.0.6_@emnapi+core@1.11.1_@emnapi+runtime@1.11.1_@types+node@24.13.2_jiti@2.4.2_rollup@4.41.1_yaml@2.9.0/node_modules/astro/dist/core/compile/compile.js:55:3)
    at async compileAstro (file:///node_modules/.pnpm/astro@7.0.6_@emnapi+core@1.11.1_@emnapi+runtime@1.11.1_@types+node@24.13.2_jiti@2.4.2_rollup@4.41.1_yaml@2.9.0/node_modules/astro/dist/vite-plugin-astro/compile.js:7:27)
    at async TransformPluginContext.handler (file://node_modules/.pnpm/astro@7.0.6_@emnapi+core@1.11.1_@emnapi+runtime@1.11.1_@types+node@24.13.2_jiti@2.4.2_rollup@4.41.1_yaml@2.9.0/node_modules/astro/dist/vite-plugin-astro/index.js:216:35)
    at async EnvironmentPluginContainer.transform (file://node_modules/.pnpm/vite@8.1.3_@types+node@24.13.2_esbuild@0.28.1_jiti@2.4.2_yaml@2.9.0/node_modules/vite/dist/node/chunks/node.js:29745:14)
    at async loadAndTransform (file://node_modules/.pnpm/vite@8.1.3_@types+node@24.13.2_esbuild@0.28.1_jiti@2.4.2_yaml@2.9.0/node_modules/vite/dist/node/chunks/node.js:19729:26)

Package

studiocms

Version

0.4.4

Debug output

[09:28:23.760] ERROR (#18):
  Error: Failed to load config: Cannot read properties of undefined (reading 'PROD')

What browsers are you seeing the problem on?

Chrome

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions