Skip to content
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

bug: ts rest parameters syntax (...args) not properly parsed in Svelte components #15293

Closed
rxliuli opened this issue Feb 14, 2025 · 1 comment

Comments

@rxliuli
Copy link

rxliuli commented Feb 14, 2025

Describe the bug

I'm trying to define an async function with rest parameters in a Svelte component using TypeScript:

<script lang="ts">
const f = async (...args: any) => {
}
</script>

Svelte's parser throws an "Unexpected token" error when trying to parse the rest parameters syntax:

Unexpected token 
https://svelte.dev/e/js_parse_error
(js_parse_error)

Reproduction

https://svelte.dev/playground/hello-world?version=5.20.0#H4sIAAAAAAAAE3WRTWvDMAyG_4owOyQQsntIArvtsEMZudU9qInSGVy5WOraUPLfh9ePrfu4ydL7SK_kk2HckqnMM3kf4BCiHyCjwSkNuSnM6DyJqZYno9Mu6VLCFFfqabcr5Z28ptwahf7K94GVWMVUppY-up2CR9401qhY01ruA4vCCA2gTNxDVpYlxo1UgDzl0LRwsmzV8my5fjy3aC1bNoVROqqpNO5pLv4xqSR6cVOq3Bv9Vftm1qonBR9wcLwRaOBBFJXqV-pDHGrR6HhTwDoET8htm53m3DLAuOdeXWA4OH17OeN1B3RU4kHut1uuPvdbxLB1QjXy1LZZagIwcgVdcY7dUH3jFhhxS0pR6q795C9ekjivoEv3Slgk3UeG7OdZfze4AHBbd-mGqz5fQQPpwleNxukLuE3BAzqFkW_YVTHD6Bi9v4P-mzOil9ug-RzMOaBAlx7z_Zev5g-1TUS9wQIAAA==

Logs

System Info

System:
    OS: macOS 15.2
    CPU: (12) arm64 Apple M2 Max
    Memory: 3.30 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - /usr/local/bin/node
    npm: 10.9.2 - /usr/local/bin/npm
    pnpm: 10.3.0 - /usr/local/bin/pnpm
    bun: 1.1.6 - ~/.bun/bin/bun
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 131.1.73.105
    Chrome: 133.0.6943.55
    Safari: 18.2

Severity

annoyance

@JeanJPNM
Copy link

JeanJPNM commented Feb 14, 2025

This seems to be an issue with acorn. I can reproduce the issue on deno with the versions currently used by svelte of acorn and acorn-typescript:

svelte/pnpm-lock.yaml

Lines 71 to 76 in 8b97725

acorn:
specifier: ^8.12.1
version: 8.12.1
acorn-typescript:
specifier: ^1.4.13
version: 1.4.13(acorn@8.12.1)

// both used by svelte according to the repo's lockfile
import * as acorn from "npm:acorn@8.12.1"; 
import tsPlugin from "npm:acorn-typescript@1.4.13";

const node = acorn.Parser.extend(tsPlugin({ allowSatisfies: true })).parse(
  "const f = (...args: any) => {}",
  {
    sourceType: "module",
    ecmaVersion: 13,
    locations: true,
  }
);
console.log(node);

Produces the same error. But the problem is fixed when using acorn@8.14.0

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

No branches or pull requests

3 participants