Skip to content

Disable isStartOfType's lookahead when called from isStartOfParameter #18296

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

Merged
merged 3 commits into from
Sep 7, 2017

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Sep 6, 2017

isStartOfType has lookahead for parenthesized types. Now that unified JSDoc parsing allows types to start parameters, this lookahead compounds with speculative arrow-function parsing's lookahead (which also cares about parentheses). Disable the lookahead when isStartOfType is called from isStartOfParameter, which was introduced with the addition of unified JSDoc parsing.

Fixes #18123

@@ -2698,7 +2699,7 @@ namespace ts {
}
}

function isStartOfType(): boolean {
function isStartOfType(disableLookahead?: boolean): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a more declarative name, like inJSDocType or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. done.

var tt1 = (a, (b, c)) => a+b+c;
~
!!! error TS1003: Identifier expected.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. so we had this test originally? why did not we catch this the first time around then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the baseline change but (1) I thought that removal of 3 errors was actually an improvement (2) didn't think it was indicative on any further problem. I also looked at the emitted code and thought it was better -- closer to what was written at least.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well.. the new error is a parse error. so a bit worse than the 3 semantic ones.

@sandersn sandersn merged commit 2bc9ecb into master Sep 7, 2017
@sandersn sandersn deleted the disable-lookahead-isStartOfParameter branch September 7, 2017 20:57
@JamesHenry
Copy link
Contributor

Thanks guys 👍

@mhegazy
Copy link
Contributor

mhegazy commented Sep 8, 2017

@sandersn can you port this to release-2.5 as well

@sandersn
Copy link
Member Author

sandersn commented Sep 8, 2017

It's in release-2.5 now.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants