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

test_transform should possibly use parse_program instead of parse_module #8713

Open
levi-nz opened this issue Mar 8, 2024 · 1 comment
Open
Milestone

Comments

@levi-nz
Copy link
Contributor

levi-nz commented Mar 8, 2024

Describe the feature

The problem right now with test_transform is that, because it uses parse_module to parse code internally, visitors that use visit_script/visit_mut_script/fold_script will not work because these functions are never called due to the parsed code being a module (thanks to apply_transform):

To fix this, we could make test_transform use parse_program instead, but this might introduce breaking changes. A Program can be either a Module or Script, but if we make test_transform use parse_program it might break existing unit tests (1st or 3rd party) that use visit_module instead of visit_program (or the other two functions). Some of the code related to this would also need to be changed, but that doesn't seem too big of an issue.

Overall, making test_transform would make people's lives a bit easier when making visitors that use specific functions like visit_script if they know they will never need to use the program or module functions, but I'm curious what the maintainers think about this as I'm not sure if I'm right.

Babel plugin or link to the feature description

No response

Additional context

No response

@levi-nz
Copy link
Contributor Author

levi-nz commented Mar 8, 2024

Also just came to thought, I believe visit_program (and others) will also not work in unit tests because a Module is not a Program, as far as I know. So to my understanding right now, only visit_module/visit_mut_module/fold_module can be called from test_transform, while visit_program and visit_script can never be called, due to the parsed code always being a Module.

@kdy1 kdy1 added this to the Planned milestone Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants