Skip to content

refactor(parser): remove refNeedsArrowPos#13419

Merged
nicolo-ribaudo merged 13 commits intobabel:mainfrom
tony-go:remove-refNeedsArrowPos-in-parseExprListItem
Jun 19, 2021
Merged

refactor(parser): remove refNeedsArrowPos#13419
nicolo-ribaudo merged 13 commits intobabel:mainfrom
tony-go:remove-refNeedsArrowPos-in-parseExprListItem

Conversation

@tony-go
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

The CI failure seems to be unrelated.

@tony-go
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

tony-go commented Jun 7, 2021

Ping @JLHwung ^^

@JLHwung
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Contributor Author

tony-go commented Jun 11, 2021

Let me fix linter :/

Comment thread packages/babel-parser/src/parser/expression.js Outdated
this.parseExprListItem(
false,
refExpressionErrors,
{ start: 0 },
Copy link
Copy Markdown
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.

Comment thread packages/babel-parser/src/parser/expression.js Outdated
Comment thread packages/babel-parser/src/plugins/flow/index.js Outdated
Comment thread packages/babel-parser/src/parser/util.js
@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
Copy Markdown
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 😄

Comment thread packages/babel-parser/src/parser/expression.js Outdated
Comment thread packages/babel-parser/src/parser/expression.js Outdated
Comment thread packages/babel-parser/src/parser/expression.js
Comment thread packages/babel-parser/src/parser/util.js
@tony-go
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread packages/babel-parser/src/parser/expression.js Outdated
Comment thread packages/babel-parser/src/plugins/flow/index.js Outdated
Comment thread packages/babel-parser/src/plugins/flow/index.js Outdated
Comment thread packages/babel-parser/src/parser/expression.js Outdated
@tony-go tony-go requested a review from JLHwung June 16, 2021 13:03
Comment thread packages/babel-parser/src/parser/expression.js Outdated
@tony-go tony-go requested a review from nicolo-ribaudo June 18, 2021 10:19
@tony-go tony-go mentioned this pull request Jun 18, 2021
1 task
Comment thread packages/babel-parser/src/parser/util.js
Comment thread packages/babel-parser/src/parser/expression.js Outdated
Comment thread packages/babel-parser/src/parser/expression.js Outdated
@tony-go tony-go requested a review from JLHwung June 18, 2021 14:19
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

tony-go commented Jun 18, 2021

Thanks!

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

Comment thread packages/babel-parser/src/parser/util.js Outdated
Copy link
Copy Markdown
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 🤔

Comment thread packages/babel-parser/src/plugins/flow/index.js Outdated
Comment thread packages/babel-parser/src/plugins/typescript/index.js Outdated
Comment thread packages/babel-parser/src/plugins/typescript/index.js Outdated
Copy link
Copy Markdown
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.

4 participants