Fix ternaries where "true" is a parenthesized variable and "false" is a function expression #30699
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 likePreviously, the error wasJSDoc types can only be used inside documentation comments
. With this change, it becomes a series of nasty parse errors andCannot find name 'function'
. 😕Possible simple options off the top of my head:
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 thatfunction()
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.