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 transform of named import with shadowed namespace import #15898

Merged
merged 1 commit into from Sep 10, 2023

Conversation

dhlolo
Copy link
Contributor

@dhlolo dhlolo commented Aug 27, 2023

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

@babel-bot
Copy link
Collaborator

babel-bot commented Aug 27, 2023

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

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories area: modules labels Aug 28, 2023
@nicolo-ribaudo nicolo-ribaudo changed the title fix: #15879 Fix transform of named import with shadowed namespace import Aug 28, 2023
@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Aug 28, 2023

Thank you! Could you add some tests in packages/babel-plugin-transform-modules-commonjs/test/fixtures to show the fixed behavior?

If it is the first time that you contribute to Babel, follow these steps: (you need to have make and yarn available on your machine)

  1. Run yarn && make bootstrap to prepare the repository for running the tests
  2. Wait ⏳
  3. Run make watch (or make build whenever you change a file)
  4. Add a test (only input.js; output.js will be automatically generated)
  5. Update the code!
  6. yarn jest modules to run the tests
    • If some test outputs don't match but the new results are correct, you can delete the bad output.js files and run the tests again
    • If you prefer, you can run OVERWRITE=true yarn jest code and they will be automatically updated.
  7. If it is working, run make test to run all the tests

@dhlolo
Copy link
Contributor Author

dhlolo commented Aug 31, 2023

Thank you! Could you add some tests in packages/babel-plugin-transform-modules-commonjs/test/fixtures to show the fixed behavior?

If it is the first time that you contribute to Babel, follow these steps: (you need to have make and yarn available on your machine)

  1. Run yarn && make bootstrap to prepare the repository for running the tests

  2. Wait ⏳

  3. Run make watch (or make build whenever you change a file)

  4. Add a test (only input.js; output.js will be automatically generated)

  5. Update the code!

  6. yarn jest modules to run the tests

    • If some test outputs don't match but the new results are correct, you can delete the bad output.js files and run the tests again
    • If you prefer, you can run OVERWRITE=true yarn jest code and they will be automatically updated.
  7. If it is working, run make test to run all the tests

Hi, nicola, I updated code and add a input.mjs for test. But expected output is to throw an Error for now. I don't know how to make jest know that the result of my input.mjs should be such an error in babel system.

@dhlolo dhlolo closed this Aug 31, 2023
@dhlolo dhlolo reopened this Aug 31, 2023
@dhlolo
Copy link
Contributor Author

dhlolo commented Sep 5, 2023

You can copy what https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested-exported/options.json does

Can this temp PR be merged and pub a patch version for now ? As our team met this problem in production for twice.

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.

Instead of throwing an error, could you try fixing this issue by updating this check to be "if there is at least one namespace import and zero other imports"?

Also, you could update the line below to use destructuring as described in the comment in the code, since we don't compile it as loose anymore :)

@dhlolo
Copy link
Contributor Author

dhlolo commented Sep 5, 2023

Instead of throwing an error, could you try fixing this issue by updating this check to be "if there is at least one namespace import and zero other imports"?

Also, you could update the line below to use destructuring as described in the comment in the code, since we don't compile it as loose anymore :)

Thx for your advice. It is done. And to be on the safe side, I do not revert the changes of throwing error.

@nicolo-ribaudo
Copy link
Member

And to be on the safe side, I do not revert the changes of throwing error.

Since we have now tests to make sure that it works, I would prefer to revert it :) It adds quite a bit of noise to the code, just for an error that is never expected to happen.

@dhlolo
Copy link
Contributor Author

dhlolo commented Sep 5, 2023

And to be on the safe side, I do not revert the changes of throwing error.

Since we have now tests to make sure that it works, I would prefer to revert it :) It adds quite a bit of noise to the code, just for an error that is never expected to happen.

It sounds reasonable. It is reverted.

@dhlolo dhlolo force-pushed the patch-1 branch 2 times, most recently from d1511fe to 60af27f Compare September 5, 2023 17:14
Copy link
Member

@liuxingbaoyu liuxingbaoyu left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

Thank you! :)

@nicolo-ribaudo nicolo-ribaudo merged commit 7af5e0d into babel:main Sep 10, 2023
48 checks passed
@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 30, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: modules 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
4 participants