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

[Bug]: Missing registerDeclaration in plugin-transform-typescript #15486

Closed
1 task done
amoeller opened this issue Mar 11, 2023 · 2 comments · Fixed by #15489
Closed
1 task done

[Bug]: Missing registerDeclaration in plugin-transform-typescript #15486

amoeller opened this issue Mar 11, 2023 · 2 comments · Fixed by #15489
Assignees
Labels
area: typescript i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@amoeller
Copy link
Contributor

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

import foo = bar

Configuration file name

No response

Configuration

No response

Current and expected behavior

plugin-transform-typescript fails to register the declaration at

        path.replaceWith(
          t.variableDeclaration("var", [
            t.variableDeclarator(
              path.node.id,
              entityNameToExpr(path.node.moduleReference),
            ),
          ]),
        );

in packages/babel-plugin-transform-typescript/src/index.ts.

Environment

@babel/plugin-transform-typescript: 7.20.13

Possible solution

Insert

path.scope.registerDeclaration(path);

after this line:

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @amoeller! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@nicolo-ribaudo
Copy link
Member

Thank you! I'm assigning this issue to you since you selected "Would you like to work on a fix?"

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. Fork the repo
  2. Run git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel
  3. Run yarn && make bootstrap
  4. Wait ⏳
  5. Run make watch (or make build whenever you change a file)
  6. Add a test in https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-typescript/test. Testing this is a bit hard, maybe we could create a test with a custom plugin.js (like https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-typescript/test/fixtures/regression/10162) which logs all the registered declaration on Program:exit, and with the "validateLogs": true option enabled.
  7. Update the code!
  8. yarn jest transform-typescript 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 [name-of-the-package-to-test] and they will be automatically updated.
  9. If it is working, run make test to run all the tests
  10. Run git push and open a PR!

Feel free to ask here if you need any other help :)

amoeller added a commit to amoeller/babel that referenced this issue Mar 13, 2023
amoeller added a commit to amoeller/babel that referenced this issue Mar 13, 2023
@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 Jun 14, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants