Skip to content

Conversation

andrewbranch
Copy link
Member

@andrewbranch andrewbranch commented Apr 1, 2019

Fixes #30635

Decided to try parsing JSDoc function types (e.g. /** @type {function(): void} */) only inside JSDoc per @weswigham’s suggestion, see what breaks, and gather feedback.

Looks like what breaks is the error message on code like

var g: function(number, number): number = (n,m) => n + m;

Previously, the error was JSDoc types can only be used inside documentation comments. With this change, it becomes a series of nasty parse errors and Cannot find name 'function'. 😕

Possible simple options off the top of my head:

  • Go with this because people probably don't often try to write code like the snippet above
  • Try to disable JSDoc function keyword parsing only when parsing the whenTrue of a conditional expression: super magically edge-casey but keeps all existing nice error messages.

Thoughts?


EDIT

Updated with a different approach. Typically, arrow functions parse successfully even if they're missing the => token, since in most cases it's still unambiguously an arrow function that's just missing a =>. When parsing the true side of a conditional expression, combined with the fact that function() parses as a type for JSDoc compatibility, it's not unambiguously an arrow function.

So, when the arrow function in-progress has a JSDocFunctionType type, I don't allow a missing => token.

@andrewbranch andrewbranch changed the title Don’t parse JSDoc function types outside of JSDoc Fix ternaries where "true" is a parenthesized variable and "false" is a function expression Apr 2, 2019
@andrewbranch andrewbranch merged commit 3f3444b into microsoft:master Apr 2, 2019
@andrewbranch andrewbranch deleted the bug/30635 branch April 2, 2019 21:03
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

Successfully merging this pull request may close these issues.

3 participants