Skip to content

Function Overloading Bugging Rollup when Reading .svelte Files #14455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
elizeuangelo opened this issue Nov 27, 2024 · 1 comment · Fixed by #14458
Closed

Function Overloading Bugging Rollup when Reading .svelte Files #14455

elizeuangelo opened this issue Nov 27, 2024 · 1 comment · Fixed by #14458

Comments

@elizeuangelo
Copy link

elizeuangelo commented Nov 27, 2024

Describe the bug

When I have a component which includes function overloading (inside <script module>):

export function test(
		type: 'test',
		props: {test: number}
	): void;
export function test(type: 'test2'): void;
export function test(type: string, props?: Record<string, any>) {
		console.log(type, props);
	}

Everything seens fine on the IDE but I still get this weird Rollup Error when running Vite or on the Playground:

[vite] Error when evaluating SSR module /src/routes/+layout.server.ts:
|- RollupError: Expected '{', got ';'
    at getRollupError (file:///D:/Coding/Projetos/Playably/github/advent-calendar-template/node_modules/.pnpm/rollup@4.27.2/node_modules/rollup/dist/es/shared/parseAst.js:396:41)
    at convertProgram (file:///D:/Coding/Projetos/Playably/github/advent-calendar-template/node_modules/.pnpm/rollup@4.27.2/node_modules/rollup/dist/es/shared/parseAst.js:1084:26)
    at parseAstAsync (file:///D:/Coding/Projetos/Playably/github/advent-calendar-template/node_modules/.pnpm/rollup@4.27.2/node_modules/rollup/dist/es/shared/parseAst.js:2070:106)
    at async ssrTransformScript (file:///D:/Coding/Projetos/Playably/github/advent-calendar-template/node_modules/.pnpm/vite@5.4.11_@types+node@22.9.0/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:52381:11)
    at async loadAndTransform (file:///D:/Coding/Projetos/Playably/github/advent-calendar-template/node_modules/.pnpm/vite@5.4.11_@types+node@22.9.0/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:51979:72)
    at async instantiateModule (file:///D:/Coding/Projetos/Playably/github/advent-calendar-template/node_modules/.pnpm/vite@5.4.11_@types+node@22.9.0/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:52874:44)

Reproduction

https://svelte.dev/playground/721e958b91b744a192d9557d007fd316?version=5.2.9

<script module lang="ts">
  // Component.svelte
  export function test(
		  type: 'test',
		  props: {test: number}
	  ): void;
  export function test(type: 'test2'): void;
  export function test(type: string, props?: Record<string, any>) {
		  console.log(type, props);
	  }
</script>

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
    Memory: 22.88 GB / 31.92 GB
Binaries:
    Node: 20.11.1 - C:\Program Files\nodejs\node.EXE
    npm: 9.7.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.14.2 - ~\AppData\Local\pnpm\pnpm.CMD
Browsers:
    Chrome: 131.0.6778.86
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.19041.4355
npmPackages:
    svelte: ^5.2.1 => 5.2.1

Severity

annoyance

@dummdidumm
Copy link
Member

We need to detect this and either handle it while stripping types or error and require devs to use a TS preprocessor. Since this doesn't require anything besides removing types we should be able to do the former

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants