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

Avoid reusing AST nodes #4309

Closed
wants to merge 2 commits into from
Closed

Avoid reusing AST nodes #4309

wants to merge 2 commits into from

Conversation

eoin
Copy link
Contributor

@eoin eoin commented May 10, 2023

Reusing AST nodes can result in subtle bugs, for example this issue is caused by AST node reuse breaking memoization in the @babel/plugin-transform-modules-commonjs plugin.

The first commit here introduces @babel/helper-check-duplicated-nodes which breaks a number of tests. The second commit fixes those tests.

Fixes #3856.

@captbaritone
Copy link
Contributor

Awesome! Thanks for working on this. Would it be possible to add a regression test for #3856. It should be as simple as adding a file to https://github.com/facebook/relay/tree/main/packages/babel-plugin-relay/__tests__/fixtures

@captbaritone
Copy link
Contributor

Also, babel-check-duplicated-nodes looks pretty simple and pretty stable. Could we just vendor that one function instead of taking on the additional dependency?

@eoin eoin force-pushed the 3856 branch 2 times, most recently from f14f6fc to f41b61e Compare May 10, 2023 20:34
@eoin
Copy link
Contributor Author

eoin commented May 10, 2023

@captbaritone thanks for the review. I hadn't spotted that there's also @babel/helper-check-duplicate-nodes which appears to have changed more over time, has test coverage and is used by babel itself. I'm inclined to depend on that, instead of vendoring. What do you think?

Regarding a regression test; the fixture + snapshot approach is tricky, in that for the issue to manifest we need to add something to the transform chain that relies on AST node uniqueness. That's doable, but before I go down that path, is it worth it?

@captbaritone
Copy link
Contributor

Makes sense. I'll import this as is. Thanks again!

@facebook-github-bot
Copy link
Contributor

@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@captbaritone merged this pull request in 39ebc1c.

@eoin eoin deleted the 3856 branch September 20, 2023 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants