Skip to content

Fix: check if param is assignable when parsing arrow return type annotation #11992

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

Merged
merged 3 commits into from
Oct 14, 2020

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Aug 21, 2020

Q                       A
Fixed Issues? Fixes #11038
Patch: Bug Fix? Yes
Tests Added + Pass? Yes
License MIT

This PR applies extra isAssignable check when we decide that a : TSType should be parsed as a return type for arrow function.

This PR also moves isAssignable from flow plugin to lval. And then simplifies the interface since we do not use isAssignable(#, false) in the codebase.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser area: typescript labels Aug 21, 2020
@@ -0,0 +1 @@
0 ? v => (v) : v => 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although it is a valid javascript, tsc will throw on this production: microsoft/TypeScript#16241 Here we align to the tsc behaviour.

@babel-bot
Copy link
Collaborator

babel-bot commented Aug 21, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/27755/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 21, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 51e71b4:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

return false;
}
}

Copy link

@KFlash KFlash Aug 22, 2020

Choose a reason for hiding this comment

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

Massive use of property access is very expensive. And I guess the validation happens a lot during the parsing. Why not use a mutual parser flag in case any flags need passed by reference and use them to track is assignable?

for (a.b of []); should be parsed / transformed as an assignment pattern, not as an binding pattern as mentioned here. It's only a binding pattern if you use 'let', 'const' or 'var. But I think the Babel AST does not distinguish between a pattern and an assignment?

This case for (a.b of [] = x); illustrate it should be an assignment not an binding pattern. This case for (let a of [] = b); the LHS should be parsed as an binding pattern and the RHS should be parsed as an assignment pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for (a.b of []); should be parsed / transformed as an assignment pattern, not as an binding pattern as mentioned here.

Yeah, in the comment I wrote a.b is not a binding pattern.

Massive use of property access is very expensive.

Indeed, I plan to revisit later.

@existentialism existentialism self-assigned this Sep 18, 2020
@existentialism existentialism removed their assignment Oct 14, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit 136e630 into babel:main Oct 14, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the fix-11038 branch October 14, 2020 18:09
@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 Jan 14, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

typescript preset: incompatible with += operator inside arrow functions, nested in ternary
5 participants