Skip to content

Disable isStartOfType's lookahead when called from isStartOfParameter#18296

Merged
sandersn merged 3 commits into
masterfrom
disable-lookahead-isStartOfParameter
Sep 7, 2017
Merged

Disable isStartOfType's lookahead when called from isStartOfParameter#18296
sandersn merged 3 commits into
masterfrom
disable-lookahead-isStartOfParameter

Conversation

@sandersn

@sandersn sandersn commented Sep 6, 2017

Copy link
Copy Markdown
Member

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

Comment thread src/compiler/parser.ts Outdated
}

function isStartOfType(): boolean {
function isStartOfType(disableLookahead?: boolean): boolean {

Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sure. done.

==== tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors2.ts (21 errors) ====
var tt1 = (a, (b, c)) => a+b+c;
~
!!! error TS1003: Identifier expected.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Thanks guys 👍

@mhegazy

mhegazy commented Sep 8, 2017

Copy link
Copy Markdown
Contributor

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

@sandersn

sandersn commented Sep 8, 2017

Copy link
Copy Markdown
Member Author

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