vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.14k stars 6.14k forks source link

Transform fails with Unexpected "..." #10501

Closed IMax153 closed 1 year ago

IMax153 commented 2 years ago

Describe the bug

When running vitest, annotating the following re-exported function with it's type:

/**
 * Constructs a tuple of results from a tuple of `SafeEval`s.
 *
 * @since 1.0.0
 * @category constructors
 */
export const tuple: <EN extends ReadonlyArray<SafeEval<any>>>(
  ...[e1, e2, ...es]: EN & {
    readonly 0: SafeEval<any>
    readonly 1: SafeEval<any>
  }
) => SafeEval<Readonly<{ [K in keyof EN]: [EN[K]] extends [SafeEval<infer A>] ? A : never }>> =
  SE.tuple

causes vitest to fail with the following error:

❯ failureErrorWithLog node_modules/.pnpm/esbuild@0.15.11/node_modules/esbuild/lib/main.js:1566:15
Error: Transform failed with 1 error:
/workspace/data/src/SafeEval.ts:86:2: ERROR: Unexpected "..."
❯ node_modules/.pnpm/esbuild@0.15.11/node_modules/esbuild/lib/main.js:805:29
❯ responseCallbacks.<computed> node_modules/.pnpm/esbuild@0.15.11/node_modules/esbuild/lib/main.js:671:9
❯ handleIncomingPacket node_modules/.pnpm/esbuild@0.15.11/node_modules/esbuild/lib/main.js:726:9
❯ Socket.readFromStdout node_modules/.pnpm/esbuild@0.15.11/node_modules/esbuild/lib/main.js:647:7
❯ Socket.emit node:events:513:28

The error references an Unexpected "..." in the type annotation (preceding the tuple parameter) even though this is perfectly valid typescript.

Removing the type annotation causes tests to pass successfully:

/**
 * Constructs a tuple of results from a tuple of `SafeEval`s.
 *
 * @since 1.0.0
 * @category constructors
 */
export const tuple = SE.tuple

Downstream issue for reference: https://github.com/vitest-dev/vitest/issues/2157

Reproduction

https://gitpod.io/#https://github.com/fp-ts/data

Steps to reproduce

Navigate to the following GitPod url:

https://gitpod.io/#https://github.com/fp-ts/data

Add the type annotation to tuple in the SafeEval module here.

Run pnpm install followed by pnpm test.

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)
    CPU: (16) x64 AMD EPYC 7B13
    Memory: 41.06 GB / 62.80 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.1/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm
  npmPackages:
    vite: ^2.9.13 => 2.9.15 
    vitest: 0.24.3 => 0.24.3

Used Package Manager

pnpm

Logs

No response

Validations

sapphi-red commented 2 years ago

Because this happens only with esbuild, this is an upstream issue. Please create an issue to esbuild.

reproduction ts playground

evanw commented 1 year ago

The fix for this has been published by the way. Thanks for reporting it in the esbuild repo.

sapphi-red commented 1 year ago

Thanks for the fix 💚