Skip to content
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

Anonymous generator function expression with typescript generic fails to parse #11435

Closed
devongovett opened this issue Apr 16, 2020 · 4 comments · Fixed by #11449
Closed

Anonymous generator function expression with typescript generic fails to parse #11435

devongovett opened this issue Apr 16, 2020 · 4 comments · Fixed by #11449
Assignees
Labels
area: typescript Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser Spec: Async Generators

Comments

@devongovett
Copy link
Contributor

Bug Report

Current Behavior

Anonymous generator functions with typescript generics fail to parse:

const fn = function* <T>(input: T): Generator<number> {
  yield 2;
}

SyntaxError: Unexpected token, expected "(" (1:21)

When adding a name to the function it works as expected:

const fn = function* fn<T>(input: T): Generator<number> {
  yield 2;
}

TSC parses anonymous generator functions with generics as expected.

Input Code

const fn = function* <T>(input: T): Generator<number> {
  yield 2;
}

Expected behavior/code

Should parse as an anonymous generator function with generic.

Additional info

Appears that the current behavior is correct for function declarations, but not function expressions. TSC throws a parse error when the function is parsed as a declaration, but not when parsed as an expression (as above).

Environment

- Babel version(s): v7.9.4
- Node/npm version: 12
- OS: macOS
- Monorepo: N/A
- How you are using Babel: `@babel/parser`
@babel-bot
Copy link
Collaborator

Hey @devongovett! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

devongovett added a commit to adobe/react-spectrum that referenced this issue Apr 16, 2020
dannify added a commit to adobe/react-spectrum that referenced this issue Apr 20, 2020
* Initial commit for v3 Table and useGrid

* Selection

* Dynamic

* Refactor API

* Cleanup

* Marshall focus to focusable elements inside cells

* Label rows by the column headers and cells in the row

* Improve column group algorithm and add selection checkboxes

* Get dynamic cells based on columns working

* linting

* fix pkg

* More test

* More tests for dynamic data and nested columns

* Tests for keyboard focus and selection

* Work around babel bug with anonymous generators and TS

babel/babel#11435

* Update useGridCell.ts

Co-authored-by: Danni <drobinson@livefyre.com>
@existentialism
Copy link
Member

Note the error only occurs when jsx is enabled too (REPL).

@hzoo
Copy link
Member

hzoo commented Apr 20, 2020

Good catch - later, should we just enable jsx parsing by default in the tests or run them separately?

plugins: isTSX ? plugins.concat("jsx") : plugins,

@devongovett
Copy link
Contributor Author

Good catch on JSX, and thanks for fixing @existentialism! 😍

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript Has PR i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser Spec: Async Generators
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants