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

[ts] Check if param is assignable when parsing arrow return type #13581

Merged
merged 3 commits into from Jul 26, 2021

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jul 20, 2021

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser area: typescript labels Jul 20, 2021
return node.properties.every((prop, i) => {
return (
prop.type !== "ObjectMethod" &&
(i === last || prop.type !== "SpreadElement") &&
Copy link
Member Author

Choose a reason for hiding this comment

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

The bug that caused the regression was that this was using === "SpreadElement" instead of !==.

This comment was marked as resolved.

Copy link

Choose a reason for hiding this comment

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

Why use 'every' ? It's slow vs a native for-loop

@babel-bot
Copy link
Collaborator

babel-bot commented Jul 20, 2021

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 20, 2021

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 24c017a:

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

@nicolo-ribaudo
Copy link
Member Author

The failure is a regression.

@@ -60,7 +60,7 @@ export default class LValParser extends NodeUtils {
- RestElement is not the last element
- Missing `=` in assignment pattern

NOTE: There is a corresponding "isAssignable" method in flow.js.
NOTE: There is a corresponding "isAssignable" method.
When this one is updated, please check if also that one needs to be updated.
Copy link
Contributor

Choose a reason for hiding this comment

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

This note can be removed then since it is moved to base parser.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually like this comment: even if they are in the same file, it's still easy to miss isAssignable when updating toAssignable.

@@ -235,6 +236,7 @@ export default class LValParser extends NodeUtils {
case "ObjectPattern":
case "ArrayPattern":
case "AssignmentPattern":
case "RestElement":
Copy link

Choose a reason for hiding this comment

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

@nicolo-ribaudo What about a lookup table? This switch is slow because of 1) string comparison 2) many cases 3) hard to optimize in v8

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this switch relies on string comparisons: these strings are always constants in our code so V8 will atomize them and just compare them as pointers (but @JLHwung knows more than me about this)

Copy link

Choose a reason for hiding this comment

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

v8 will convert this switch to a lookup, so it's faster if you do it.

@nicolo-ribaudo nicolo-ribaudo merged commit 4a56387 into babel:main Jul 26, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the bug-11038 branch July 26, 2021 15:58
@KFlash
Copy link

KFlash commented Jul 26, 2021

Merged, but performance not improved. What's the reason?

@nicolo-ribaudo
Copy link
Member Author

That change doesn't have an observable impact on the normal @babel/parser usage.

@cederom
Copy link

cederom commented Aug 23, 2021

Thank you guys :-) Then this release will land into npm? 7.15.0 is still the latest one over there :-)

@JLHwung
Copy link
Contributor

JLHwung commented Aug 23, 2021

It is fixed in @babel/parser 7.15.3, @babel/parser is a dependency of @babel/core.

@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 Nov 23, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 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
6 participants