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

"Uncaught SyntaxError: Unexpected token '<'" when using primitive as parameter in arrow function declaration #23881

Open
ploiu opened this issue May 18, 2024 · 1 comment

Comments

@ploiu
Copy link

ploiu commented May 18, 2024

deno --version:
deno 1.43.5 (release, x86_64-pc-windows-msvc)
v8 12.4.254.13
typescript 5.4.5

I did not find this issue after searching in the issues tab for this repository.


about: deno gives a confusing error message when incorrectly declaring an arrow function.
example from REPL:

> (0) => 1
Uncaught SyntaxError: Unexpected token '<'

This can be extremely confusing in normal development because there is no < in the source code for the user to refer to.

  • Can be replicated with regular deno run as well as the REPL
  • Can be replicated when using a number, string, boolean, or null as the parameter
  • Can not be replicated when using an object as the parameter (e.g. Infinity, [], {}, undefined, etc. all successfully create an anonymous function)
  • Can be replicated when mixing object and non-object parameters (e.g. (1, undefined) => 0 replicates this)
  • Can not be replicated if the parameter is not wrapped in parenthesis (e.g. 0 => 1 gives back parse error: Expected ';', '}' or <eof>)

This appears to happen regardless of context. Attempting this with a non-arrow function results in a much more helpful error message. Browsers and tsc each give a different error message, and none of them mention < anywhere (browsers tried were chromium-edge and firefox).


Please let me know if this is the wrong bug report format or if this is the wrong place to submit this report, as this is my first issue report in a long time :)

@marvinhagemeister
Copy link
Contributor

Thanks for the detailed bug report. The message is indeed confusing. Might be related to the outer REPL code. SWC alone throws this error:

  x Not a pattern
   ,-[input.tsx:1:1]
 1 | (0) => 1
   :  ^
   `----


Caused by:
    0: failed to process js file
    1: Syntax Error

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