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] Fails to parse arrow function with generic argument #325

Closed
DreierF opened this issue Aug 12, 2020 · 2 comments
Closed

[Bug] Fails to parse arrow function with generic argument #325

DreierF opened this issue Aug 12, 2020 · 2 comments

Comments

@DreierF
Copy link

DreierF commented Aug 12, 2020

ESBuild fails to parse a rather complex arrow function in my project.

Minimal example:

export const values = <V>(obj: Record<string, V>): V[] => Object.keys(obj).map(k => obj[k]);
Module build failed (from ./node_modules/esbuild-loader/src/index.js):
Error: Transform failed with 1 error:
.../src/test.ts:1:44: error: Expected ">" but found ","
    at failureErrorWithLog (.../node_modules/esbuild-loader/node_modules/esbuild/lib/main.js:303:15)
    at .../node_modules/esbuild-loader/node_modules/esbuild/lib/main.js:258:29
    at handleResponse (.../node_modules/esbuild-loader/node_modules/esbuild/lib/main.js:229:7)
    at Socket.readFromStdout (.../node_modules/esbuild-loader/node_modules/esbuild/lib/main.js:159:7)
@evanw
Copy link
Owner

evanw commented Aug 12, 2020

This builds fine with esbuild when the file extension is .ts but fails with this error when the file extension is .tsx, so I'm assuming your file has a .tsx file extension:

example.tsx:1:44: error: Expected ">" but found ","
export const values = <V>(obj: Record<string, V>): V[] => Object.keys(obj).map(k => obj[k]);
                                            ^

If you try building this with the official TypeScript compiler, that also gives a similar error:

example.tsx:1:45 - error TS1003: Identifier expected.
export const values = <V>(obj: Record<string, V>): V[] => Object.keys(obj).map(k => obj[k]);
                                            ~

So this doesn't look like a bug with esbuild to me. The behavior of esbuild matches the behavior of the official TypeScript compiler. Perhaps you are using the incorrect file extension? Or perhaps you're using esbuild's API and incorrectly passing tsx as the loader instead of ts?

@DreierF
Copy link
Author

DreierF commented Aug 12, 2020

Ah that makes sense!
I was actually using a ts file extension but had it wired up to options: { loader: 'tsx' } not considering the implications on parsing such constructs.

Thanks for the fast reply and sorry for the noise.

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

No branches or pull requests

2 participants