Skip to content

TypeScript 2.5.1 RC parse error (not in TS 2.4.2) #18123

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

Closed
JamesHenry opened this issue Aug 29, 2017 · 3 comments
Closed

TypeScript 2.5.1 RC parse error (not in TS 2.4.2) #18123

JamesHenry opened this issue Aug 29, 2017 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority

Comments

@JamesHenry
Copy link
Contributor

As of v1.6 of Prettier we are using the TypeScript 2.5 RC and we have had a bug report for some code which worked fine pre-1.6 but is now broken.

Using tsc directly, I can confirm that when the following code is parsed with TypeScript 2.4.2 it produces an AST just fine, but when parsed with TypeScript 2.5.1 it produces "'=' expected."

Code

const foo = (x:string):void => (
  bar(
    x,
    () => {},
    () => {}
  )
);

Original issue: prettier/prettier#2702

@sandersn
Copy link
Member

This is a result of parsing JSDoc types in normal typescript. JSDoc's function(number): number syntax has no parameter names, so now the start of a parameter can be the start of a type. But this results in nested lookahead when parsing arrow functions that fails in a way that I haven't fully understood.

There are two possible fixes: (1) fork the code paths (2) fix the lookahead in isStartOfType. Fix 1 is fast and simple but doesn't address the underlying issue: the lookahead in isStartOfType might not be necessary (or at least may be simplified).

Right now I'm planning to fix this bug in 2.5.3 and pursue option (2).

@sandersn
Copy link
Member

Here's a smaller repro:

(bar(x,
    () => {},
    () => {}))

@JamesHenry
Copy link
Contributor Author

Thanks, @sandersn!

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 High Priority
Projects
None yet
Development

No branches or pull requests

3 participants