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

fix(helpers): match Reflect.get behaviour #13862

Merged
merged 2 commits into from Nov 9, 2021

Conversation

lightmare
Copy link
Contributor

@lightmare lightmare commented Oct 19, 2021

Q                       A
Fixed Issues? no related issue found
Patch: Bug Fix? ✔️
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? ✔️
Documentation PR Link
Any Dependency Changes?
License MIT

The first call to babelHelpers.get substitutes target for falsy 3rd argument receiver. That is not correct for several reasons:

  1. subsequent calls don't do that (because the implementation is invoked directly)
  2. a falsy 3rd argument is still a valid receiver
  3. Reflect.get step 3. "If receiver is not present, then ... Set receiver to target."

The reimplementation should follow Reflect.get spec, i.e. only substitute target when receiver argument is missing, not when it's falsy or nullish.

Regarding tests, I think I know how to devise a test for the falsy receiver issue, but I have no idea how to test the first-call stub behaviour.

@babel-bot
Copy link
Collaborator

babel-bot commented Oct 19, 2021

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 19, 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 cbc533a:

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

@nicolo-ribaudo
Copy link
Member

To test this you can set "externalHelpers": false in the test options, so that the helper is inlined and you can capture the behavior of the first call.

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Oct 22, 2021
@lightmare
Copy link
Contributor Author

Rebased on main, and added 2 tests that fail before the patch, pass after.

@lightmare lightmare marked this pull request as ready for review November 9, 2021 12:26
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.

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit 74bec41 into babel:main Nov 9, 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 Feb 9, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2022
@lightmare lightmare deleted the fix-helper-get-first-call branch September 2, 2023 19:47
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 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.

None yet

4 participants