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

refactor(parser): remove refNeedsArrowPos #13419

Merged

Conversation

tony-go
Copy link
Contributor

@tony-go tony-go commented Jun 3, 2021

Q                      
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? 👍
Documentation PR Link
Any Dependency Changes?
License MIT

Hey @JLHwung 👋

Following your comment on my previous PR, I open this draft PR. Let me know If I'm wrong or If I misunderstand something.

🚀

@babel-bot
Copy link
Collaborator

babel-bot commented Jun 3, 2021

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

@nicolo-ribaudo
Copy link
Member

The CI failure seems to be unrelated.

@tony-go
Copy link
Contributor Author

tony-go commented Jun 3, 2021

The CI failure seems to be unrelated.

I received the same message for my previous PR.

@JLHwung
Copy link
Contributor

JLHwung commented Jun 3, 2021

I am wondering if we could remove all the refNeedsArrowPos usage, according to

// FIXME: Disabling this for now since can't seem to get it to play nicely
// eslint-disable-next-line no-unused-vars
refNeedsArrowPos?: ?Pos,

it is not engaging with the parser.

The refNeedsArrowPos is changed only in Flow / TypeScript plugin:

refNeedsArrowPos.start = result.error.pos || this.state.start;

refNeedsArrowPos.start = result.error.pos || this.state.start;

We could try removing it and see if it breaks any test.

@tony-go
Copy link
Contributor Author

tony-go commented Jun 4, 2021

We could try removing it and see if it breaks any test.

Hey 👋 @JLHwung ^^ It breaks a lot of tests (20 at least) and as you predicted it's on flow an typescript tests.

For example in this code:

refNeedsArrowPos.start = result.error.pos || this.state.start;

Maybe could we pass a boolean instead of refNeedsArrowPos as it's only use to match a branch and .start is reset with result.error.pos || this.state.start.

WDYT ?

@tony-go
Copy link
Contributor Author

tony-go commented Jun 7, 2021

Ping @JLHwung ^^

@JLHwung
Copy link
Contributor

JLHwung commented Jun 8, 2021

@tony-go refNeedsArrowPos.start is a number, Babel parser throws when it is not zero. So I guess boolean does not work here.

It seems to me refNeedsArrowPos is set in flow/typescript plugin only. Maybe we can move

if (refNeedsArrowPos.start) this.unexpected(refNeedsArrowPos.start);
to these plugins so when parsing plain JavaScript we don't care refNeedsArrowPos.

@tony-go
Copy link
Contributor Author

tony-go commented Jun 9, 2021

Hi 👋 @JLHwung

Regarding the issue #13419 I pushed a test branch (which contains the move of if (refNeedsArrowPos.start) this.unexpected(refNeedsArrowPos.start); in the flow/ts files.)

Where I’m trying to figured out why test fails :/

Even with the callstack debugger I didn’t understand why en expression like const f = (x?) => {} throw there. (modifié)

@tony-go
Copy link
Contributor Author

tony-go commented Jun 11, 2021

Update: I continue to dig with the help of @JLHwung ^^

We merge few things but it still remains two tests which fails. I'm actively working on it ^^

Sorry for the wait.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 11, 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 6d9321e:

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

@tony-go
Copy link
Contributor Author

tony-go commented Jun 11, 2021

Let me fix linter :/

this.parseExprListItem(
false,
refExpressionErrors,
{ start: 0 },
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: refNeedsArrowPos is reset here. Do we need to reset refExpressionErrors.optionalParameters to -1? Maybe worth a test covering this.

@JLHwung JLHwung added the PR: Internal 🏠 A type of pull request used for our changelog categories label Jun 11, 2021
@JLHwung JLHwung changed the title fix(parser:expression): remove refNeedsArrowPos in parseExprListItem refactor(parser): remove refNeedsArrowPos Jun 11, 2021
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

I like how there are more deleted lines than added lines 😄

packages/babel-parser/src/parser/expression.js Outdated Show resolved Hide resolved
packages/babel-parser/src/parser/expression.js Outdated Show resolved Hide resolved
@tony-go
Copy link
Contributor Author

tony-go commented Jun 11, 2021

Did all corrections.

Just left this [comment](#13419 (comment):

Q: refNeedsArrowPos is reset here. Do we need to reset refExpressionErrors.optionalParameters to -1? Maybe worth a test covering this.

As I did found the test relevant test case for now :/

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

The PR generally looks good to me! Left some nit comments on extra checking.

packages/babel-parser/src/parser/expression.js Outdated Show resolved Hide resolved
packages/babel-parser/src/plugins/flow/index.js Outdated Show resolved Hide resolved
packages/babel-parser/src/plugins/flow/index.js Outdated Show resolved Hide resolved
packages/babel-parser/src/parser/expression.js Outdated Show resolved Hide resolved
@tony-go tony-go requested a review from JLHwung June 16, 2021 13:03
@tony-go tony-go requested a review from JLHwung June 18, 2021 14:19
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Thanks!

@tony-go
Copy link
Contributor Author

tony-go commented Jun 18, 2021

Thanks!

Thanks you for you time. You (and @nicolo-ribaudo) provide me an excellent OSS experience ^^

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

I'm surprised that we need these changed in code that looks unrelated 🤔

packages/babel-parser/src/plugins/flow/index.js Outdated Show resolved Hide resolved
packages/babel-parser/src/plugins/typescript/index.js Outdated Show resolved Hide resolved
packages/babel-parser/src/plugins/typescript/index.js Outdated Show resolved Hide resolved
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

🎉

@nicolo-ribaudo nicolo-ribaudo merged commit 101249f into babel:main Jun 19, 2021
@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 Sep 19, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants