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

Look-ahead for arrow function expressions too permissive when encountering "()" #34

Closed
DanielRosenwasser opened this issue Jul 16, 2014 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@DanielRosenwasser
Copy link
Member

When encountering code like

().toString();

We make a strange assumption, which is that the () belongs to an arrow function like the following:

() => x

This is weird because it bubbles up to nothing better than the error

Cannot find name 'toString'.

In this case, we should check to see if the next token is an arrow (=>).

@JsonFreeman
Copy link
Contributor

Make sure to check if the next token is either an arrow or open brace. The open brace corresponds to a function expression where the user forgot the arrow.

@sophiajt sophiajt added the Bug label Jul 16, 2014
@sophiajt sophiajt added this to the TypeScript 2.0 milestone Jul 16, 2014
DanielRosenwasser added a commit that referenced this issue Jul 22, 2014
Fixes issue #34.

Specifically:
    * We no longer automatically assume "()" is a function expression. It must be followed by an arrow, colon, or curly brace.
    * If an arrow is missing following a signature, but a curly brace is present, we assume the user forgot the arrow and try to parse the body anyway.
DanielRosenwasser added a commit that referenced this issue Jul 23, 2014
Fixes issue #34.

Specifically:
    * We no longer automatically assume "()" is a function expression. It must be followed by an arrow, colon, or curly brace.
    * If an arrow is missing following a signature, but a curly brace is present, we assume the user forgot the arrow and try to parse the body anyway.
@DanielRosenwasser
Copy link
Member Author

Addressed in #203, with the potential "issue" that

a ? () : c

parses as a lambda as well.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants